java mysql order by_mysql使用order by缓慢复杂查询

  • Post author:
  • Post category:java


以下查询即使没有 order by 也非常慢,我可以猜测它是 where date_affidavit_file 但是我怎样才能使它快速 order by ?也许job_id上的sublect与where匹配,然后将其传递给代码的其余部分,但我仍然需要通过服务器命令这样的服务器名称 . 有什么建议?

explain select sql_no_cache court_county, job.id as jid, job_status,

DATE_FORMAT(job.datetime_served, ‘%m/%d/%Y’) as dserved ,

CONCAT(server.namefirst, ‘ ‘, server.namelast) as servername, client_name,

DATE_FORMAT(job.datetime_received, ‘%m/%d/%Y’) as dtrec ,

DATE_FORMAT(job.datetime_give2server, ‘%m/%d/%Y’) as dtg2s,

DATE_FORMAT(date_kase_filed, ‘%m/%d/%Y’) as dkf,

DATE_FORMAT(job.date_sent_to_court, ‘%m/%d/%Y’) as dtstc ,

TO_DAYS(datetime_served )-TO_DAYS(date_kase_filed) as totaldays from job

left join kase on kase.id=job.kase_id

left join server on job.server_id=server.id

left join client on kase.client_id=client.id

left join LUcourt on LUcourt.id=kase.court_id

where date_affidavit_filed is not null and date_affidavit_filed !=” order by servername;

+—-+————-+———+——–+———————-+———+———+———————–+——–+———————————————-+

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

+—-+————-+———+——–+———————-+———+———+———————–+——–+———————————————-+

| 1 | SIMPLE | job | ALL | date_affidavit_filed | NULL | NULL | NULL | 365212 | Using where; Using temporary; Using filesort |

| 1 | SIMPLE | kase | eq_ref | PRIMARY | PRIMARY | 4 | pserve.job.kase_id | 1 | |

| 1 | SIMPLE | server | eq_ref | PRIMARY | PRIMARY | 4 | pserve.job.server_id | 1 | |

| 1 | SIMPLE | client | eq_ref | PRIMARY | PRIMARY | 4 | pserve.kase.client_id | 1 | |

| 1 | SIMPLE | LUcourt | eq_ref | PRIMARY | PRIMARY | 4 | pserve.kase.court_id | 1 | |

+—-+————-+———+——–+———————-+———+———+———————–+——–+———————————————-+



版权声明:本文为weixin_29483853原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。