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 `table` ADD INDEX `table_idx_id_product_id_datelast` (`id`,`product_id`,`datelast`);
SELECT
AVG(time)
FROM
(SELECT
UNIX_TIMESTAMP(max(table.datelast)) - UNIX_TIMESTAMP(min(table.datestart)) AS time
FROM
table
WHERE
EXISTS (
SELECT
DISTINCT 1
FROM
table AS table1
WHERE
(
table1.product_id = 12394
AND table1.datelast > '2011-04-13 00:26:59'
)
AND (
table.id = table1.id
)
)
GROUP BY
table.id
ORDER BY
NULL) AS T