In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `order` ADD INDEX `order_idx_store_id` (`store_id`);
ALTER TABLE `order_line_item` ADD INDEX `order_item_idx_order_id_code_alternativ` (`order_id`,`code`,`alternative`);
SELECT
oli.*,
oli2.*
FROM
order o LEFT JOIN
order_line_item oli
ON oli.order_id = o.id
LEFT JOIN
order_line_item oli2
ON oli2.id = (
SELECT
oli3.id
FROM
order_line_item oli3
WHERE
oli3.order_id = o.id
AND oli.code = oli3.alternative
GROUP BY
oli3.code,
o.id
ORDER BY
NULL LIMIT 1
)
WHERE
o.store_id != 100
GROUP BY
oli.code,
oli2.code,
o.id
ORDER BY
NULL