我正在对两个大表执行查询但是当添加一个列进行排序时(ps
。start_time
asc)我的查询死机堵塞并且花了大约25.mins其他没有这个列它采取1-秒。我正在分享我的sql语句:
SELECT
`ji`.`jobsId` AS `jobsId`,
`ji`.`fkCompanyId` AS `fkCompanyId`,
`ji`.`routeNumber` AS `routeNumber`,
`ji`.`fromStop` AS `fromStop`,
`ji`.`toStop` AS `toStop`,
`ji`.`schDeptTime` AS `schDeptTime`,
`ji`.`schArrTime` AS `schArrTime`,
`ji`.`run` AS `run`,
`ji`.`scheduleCode` AS `scheduleCode`,
`ji`.`driverDeptTime` AS `driverDeptTime`,
`ji`.`driverArrTime` AS `driverArrTime`,
`ji`.`serviceType` AS `serviceType`,
`ji`.`days` AS `days`,
`ji`.`busNumber` AS `busNumber`,
`ji`.`hrNumber` AS `hrNumber`,
`ji`.`DriverName` AS `DriverName`,
`ps`.`start_time` AS `start_time`,
`ps`.`start_location` AS `start_location`,
`ps`.`start_areas` AS `start_areas`,
`ps`.`passenger_scan` AS `passenger_scan`,
`ji`.`fkCityId` AS `fkCityId`,
`ji`.`City` AS `City`,
`ji`.`date` AS `date`
FROM (`passenger_scan` `ps`
JOIN `jobs_import` `ji` USE INDEX(jobs_date)
ON ((`ji`.`busNumber` = `ps`.`busInfo`)))
WHERE DATE BETWEEN '2018-d03-01' AND '2018-03-31'
ORDER BY ji.`date` DESC, ji.`City` ASC , ji.`routeNumber` ASC -- ,`ps`.`start_time` asc
Execution Plan without desired sorting column
Execution Plan with desired sorting column (its problem)
Indexes on both tables (all columns indexed in order by clause)
答案 0 :(得分:0)
您的加入字段应按优化顺序编入索引请检查ps
。start_time
是否已编入索引