MySQL: Use STRAIGHT_JOIN

STRAIGHT_JOIN forces the optimizer to join the tables in the order in which they are listed in the FROM clause. You can use this to speed up a query if the optimizer joins the tables in non-optimal order

Example:

SELECT STRAIGHT_JOIN Count(*) AS `CallReportNew.total`, SUM(duration) AS `CallReportNew.total_duration`, SUM(costR1) AS `CallReportNew.total_cost` FROM `calls` as `CallReportNew` IGNORE INDEX (IX_CallsCallStart) LEFT JOIN `resellers1` AS `Reseller1` ON (`CallReportNew`.`id_reseller` = `Reseller1`.`id` ) WHERE `CallReportNew`.`call_start` BETWEEN '2009-07-09 00:00:00' AND '2009-07-09 23:59:59' AND `Reseller1`.`id`=1 GROUP BY Reseller1.id ORDER BY null

No comments:

Post a Comment