mysql:一旦数据变大,查询速度就会变慢

f8rj6qna  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(498)

我有一个很长的查询,结果很长。可能需要15秒到20秒。在少量数据中,查询似乎还可以,我已经检查了所有索引,以及已经使用索引或where条件的所有内容。
抱歉,我没有发布实际的查询,因为它太多并且连接到其他表。
有人能帮忙吗?如果你需要进一步的信息,请告诉我。
下面是mysql的解释。

1   PRIMARY <derived2>  ALL NULL    NULL    NULL    NULL    210326  
2   DERIVED PQL ref practice_place_id,patient_id,practice_place_id_2,encounter_id,practice_place_id_3,for_comission for_comission   4   const   38950   Using where; Using index; Using temporary; Using filesort   
2   DERIVED EN  eq_ref  PRIMARY,id,practice_id,practice_id_2,practice_id_3  PRIMARY 8   PQL.encounter_id,const  1   Using index 
2   DERIVED PIH ref PRIMARY,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8    practice_id_3   12  const,EN.id 1   Using index condition; Using where  
2   DERIVED RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PQL.patient_id    1       
2   DERIVED PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   timestamp   12  PIH.timestamp,const 1   Using where 
2   DERIVED RV  eq_ref  PRIMARY PRIMARY 4   PID.item_id 1       
2   DERIVED RRV eq_ref  PRIMARY,parent_id   PRIMARY 8   PID.item_id,PID.item_sub_id 1   Using index 
2   DERIVED D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id   1   Using where 
2   DERIVED RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PIH.timestamp   1   Using where 
2   DERIVED PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
2   DERIVED TL  ref reff_id reff_id 12  PIH.timestamp,const 1   Using where 
3   UNION   PQL ref practice_place_id,patient_id,practice_place_id_2,encounter_id,practice_place_id_3,for_comission for_comission   4   const   38950   Using where; Using index; Using temporary; Using filesort   
3   UNION   EN  eq_ref  PRIMARY,id,practice_id,practice_id_2,practice_id_3  PRIMARY 8   PQL.encounter_id,const  1   Using index 
3   UNION   PIH ref PRIMARY,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8    practice_id_3   12  const,EN.id 1   Using index condition; Using where  
3   UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PQL.patient_id    1       
3   UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   timestamp   12  PIH.timestamp,const 1   Using where 
3   UNION   RV  eq_ref  PRIMARY PRIMARY 4   PID.item_id 1       
3   UNION   RRV eq_ref  PRIMARY,parent_id   PRIMARY 8   PID.item_id,PID.item_sub_id 1   Using index 
3   UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id_2 1   Using where 
3   UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PIH.timestamp   1   Using where 
3   UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
3   UNION   TL  ref reff_id reff_id 12  PIH.timestamp,const 1   Using where 
4   UNION   PQL ref practice_place_id,patient_id,practice_place_id_2,encounter_id,practice_place_id_3,for_comission for_comission   4   const   38950   Using where; Using index; Using temporary; Using filesort   
4   UNION   EN  eq_ref  PRIMARY,id,practice_id,practice_id_2,practice_id_3  PRIMARY 8   PQL.encounter_id,const  1   Using index 
4   UNION   PIH ref PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 practice_id_3   12  const,EN.id 1   Using index condition; Using where  
4   UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PQL.patient_id    1       
4   UNION   TL  ref reff_id reff_id 12  PIH.timestamp,const 1   Using where 
4   UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   timestamp   12  PIH.timestamp,const 1   Using where 
4   UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PIH.timestamp   1   Using where 
4   UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
4   UNION   REF eq_ref  PRIMARY,practice_id,type,id,practice_id_3,id_2  PRIMARY 5   PID.item_id,PID.item_type   1   Using where 
4   UNION   DF  eq_ref  PRIMARY PRIMARY 2   REF.form    1   Using where 
4   UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id   1   Using where 
5   UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   practice_id_3   5   const,const 6533    Using index condition; Using where; Using temporary; Using filesort 
5   UNION   REF eq_ref  PRIMARY,practice_id,id,practice_id_2    PRIMARY 4   PID.item_id 1   Using where 
5   UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id   1   Using where 
5   UNION   PIH eq_ref  PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 PRIMARY 12  PID.timestamp,const 1   Using where 
5   UNION   PQL ref practice_place_id,patient_id,practice_place_id_2,encounter_id,practice_place_id_3,for_comission practice_place_id_2 9   const,PIH.reff_id   1   Using index condition; Using where  
5   UNION   EN  eq_ref  PRIMARY,id,practice_id,practice_id_2,practice_id_3  PRIMARY 8   PIH.reff_id,const   1   Using where; Using index    
5   UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PQL.patient_id    1       
5   UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PID.timestamp   1   Using where 
5   UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
5   UNION   TL  ref reff_id reff_id 12  PID.timestamp,const 1   Using where 
6   UNION   PIH ref PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 practice_id_8   5   const,const 10522   Using index condition; Using temporary; Using filesort  
6   UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   timestamp   12  PIH.timestamp,const 1   Using where 
6   UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id   1   Using where 
6   UNION   REF eq_ref  PRIMARY,practice_id,type,id,practice_id_3,id_2  PRIMARY 5   PID.item_id,PID.item_type   1   Using where 
6   UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PIH.timestamp   1   Using where 
6   UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
6   UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PIH.reff_id   1   Using where 
6   UNION   TL  ref reff_id reff_id 12  PIH.timestamp,const 1   Using where 
7   UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   practice_id_3   5   const,const 6533    Using index condition; Using where; Using temporary; Using filesort 
7   UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PID.timestamp   1   Using where 
7   UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
7   UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id   1   Using where 
7   UNION   REF eq_ref  PRIMARY,practice_id,id,practice_id_2    PRIMARY 4   PID.item_id 1   Using where 
7   UNION   PIH eq_ref  PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 PRIMARY 12  PID.timestamp,const 1   Using where 
7   UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PIH.reff_id   1   Using where 
7   UNION   TL  ref reff_id reff_id 12  PID.timestamp,const 1   Using where 
8   UNION   PQL ref practice_place_id,patient_id,practice_place_id_2,encounter_id,practice_place_id_3,for_comission for_comission   4   const   38950   Using where; Using index; Using temporary; Using filesort   
8   UNION   EN  eq_ref  PRIMARY,id,practice_id,practice_id_2,practice_id_3  PRIMARY 8   PQL.encounter_id,const  1   Using index 
8   UNION   PIH ref PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 practice_id_3   12  const,EN.id 1   Using index condition; Using where  
8   UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PQL.patient_id    1       
8   UNION   TL  ref reff_id reff_id 12  PIH.timestamp,const 1   Using where 
8   UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   timestamp   12  PIH.timestamp,const 1   Using where 
8   UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PIH.timestamp   1   Using where 
8   UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
8   UNION   REF eq_ref  PRIMARY,practice_id,type,id,practice_id_3,id_2  PRIMARY 5   PID.item_id,PID.item_type   1   Using where 
8   UNION   DF  eq_ref  PRIMARY PRIMARY 2   REF.form    1   Using where 
8   UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id_2 1   Using where 
9   UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   practice_id_3   5   const,const 6533    Using index condition; Using where; Using temporary; Using filesort 
9   UNION   REF eq_ref  PRIMARY,practice_id,id,practice_id_2    PRIMARY 4   PID.item_id 1   Using where 
9   UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id_2 1   Using where 
9   UNION   PIH eq_ref  PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 PRIMARY 12  PID.timestamp,const 1   Using where 
9   UNION   PQL ref practice_place_id,patient_id,practice_place_id_2,encounter_id,practice_place_id_3,for_comission practice_place_id_2 9   const,PIH.reff_id   1   Using index condition; Using where  
9   UNION   EN  eq_ref  PRIMARY,id,practice_id,practice_id_2,practice_id_3  PRIMARY 8   PIH.reff_id,const   1   Using where; Using index    
9   UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PQL.patient_id    1       
9   UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PID.timestamp   1   Using where 
9   UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
9   UNION   TL  ref reff_id reff_id 12  PID.timestamp,const 1   Using where 
10  UNION   PIH ref PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 practice_id_8   5   const,const 10522   Using index condition; Using temporary; Using filesort  
10  UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   timestamp   12  PIH.timestamp,const 1   Using where 
10  UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id_2 1   Using where 
10  UNION   REF eq_ref  PRIMARY,practice_id,type,id,practice_id_3,id_2  PRIMARY 5   PID.item_id,PID.item_type   1   Using where 
10  UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PIH.timestamp   1   Using where 
10  UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
10  UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PIH.reff_id   1   Using where 
10  UNION   TL  ref reff_id reff_id 12  PIH.timestamp,const 1   Using where 
11  UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   practice_id_3   5   const,const 6533    Using index condition; Using where; Using temporary; Using filesort 
11  UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PID.timestamp   1   Using where 
11  UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
11  UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id_2 1   Using where 
11  UNION   REF eq_ref  PRIMARY,practice_id,id,practice_id_2    PRIMARY 4   PID.item_id 1   Using where 
11  UNION   PIH eq_ref  PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 PRIMARY 12  PID.timestamp,const 1   Using where 
11  UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PIH.reff_id   1   Using where 
11  UNION   TL  ref reff_id reff_id 12  PID.timestamp,const 1   Using where 
12  UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   practice_id_3   5   const,const 525 Using index condition; Using where; Using temporary; Using filesort 
12  UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id   1   Using where 
12  UNION   PIH eq_ref  PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 PRIMARY 12  PID.timestamp,const 1   Using where 

12  UNION   PQL ref practice_place_id,patient_id,practice_place_id_2,encounter_id,practice_place_id_3,for_comission practice_place_id_2 9   const,PIH.reff_id   1   Using index condition; Using where  
12  UNION   EN  eq_ref  PRIMARY,id,practice_id,practice_id_2,practice_id_3  PRIMARY 8   PIH.reff_id,const   1   Using where; Using index    
12  UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PQL.patient_id    1       
12  UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PID.timestamp   1   Using where 
12  UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
12  UNION   TL  ref reff_id reff_id 12  PID.timestamp,const 1   Using where 
12  UNION   PLD ref PRIMARY,practice_id practice_id 8   const,PID.item_id   3   Using index 
12  UNION   PLI eq_ref  PRIMARY,id  PRIMARY 4   PLD.lab_item_id 1   Using index 
12  UNION   PLC eq_ref  PRIMARY PRIMARY 4   PLD.lab_cat_id  1       
13  UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   practice_id_3   5   const,const 525 Using index condition; Using where; Using temporary; Using filesort 
13  UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id   1   Using where 
13  UNION   PIH eq_ref  PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 PRIMARY 12  PID.timestamp,const 1   Using where 
13  UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PIH.reff_id   1   Using where 
13  UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PID.timestamp   1   Using where 
13  UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
13  UNION   TL  ref reff_id reff_id 12  PID.timestamp,const 1   Using where 
13  UNION   PLD ref PRIMARY,practice_id PRIMARY 4   PID.item_id 4   Using where 
13  UNION   PLI eq_ref  PRIMARY,id  PRIMARY 4   PLD.lab_item_id 1   Using index 
13  UNION   PLC eq_ref  PRIMARY PRIMARY 4   PLD.lab_cat_id  1       
14  UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   practice_id_3   5   const,const 525 Using index condition; Using where; Using temporary; Using filesort 
14  UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id_2 1   Using where 
14  UNION   PIH eq_ref  PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 PRIMARY 12  PID.timestamp,const 1   Using where 
14  UNION   PQL ref practice_place_id,patient_id,practice_place_id_2,encounter_id,practice_place_id_3,for_comission practice_place_id_2 9   const,PIH.reff_id   1   Using index condition; Using where  
14  UNION   EN  eq_ref  PRIMARY,id,practice_id,practice_id_2,practice_id_3  PRIMARY 8   PIH.reff_id,const   1   Using where; Using index    
14  UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PQL.patient_id    1       
14  UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PID.timestamp   1   Using where 
14  UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
14  UNION   TL  ref reff_id reff_id 12  PID.timestamp,const 1   Using where 
14  UNION   PLD ref PRIMARY,practice_id practice_id 8   const,PID.item_id   3   Using index 
14  UNION   PLI eq_ref  PRIMARY,id  PRIMARY 4   PLD.lab_item_id 1   Using index 
14  UNION   PLC eq_ref  PRIMARY PRIMARY 4   PLD.lab_cat_id  1       
15  UNION   PID ref item_type,timestamp,practice_id,item_id_2,timestamp_2,practice_id_2,practice_id_3   practice_id_3   5   const,const 525 Using index condition; Using where; Using temporary; Using filesort 
15  UNION   D   ref doc_id,pp_id,id_2,pp_doc    doc_id  4   PID.doctor_id_2 1   Using where 
15  UNION   PIH eq_ref  PRIMARY,source,reff_id,practice_id,timestamp,is_active,practice_id_3,cal_id,practice_id_5,practice_id_6,practice_id_2,practice_id_4,practice_id_7,practice_id_8 PRIMARY 12  PID.timestamp,const 1   Using where 
15  UNION   RPP eq_ref  PRIMARY,patient_id,practice_id,practice_id_2    PRIMARY 8   const,PIH.reff_id   1   Using where 
15  UNION   RPIP    ref timestamp,practice_id,timestamp_2,refunded  timestamp   8   PID.timestamp   1   Using where 
15  UNION   PIC ref practice_id,prc_invoice_detail_id,claim_status,practice_id_2,practice_id_3,practice_id_4,practice_id_5  practice_id 4   const   1   Using where 
15  UNION   TL  ref reff_id reff_id 12  PID.timestamp,const 1   Using where 
15  UNION   PLD ref PRIMARY,practice_id PRIMARY 4   PID.item_id 4   Using where 
15  UNION   PLI eq_ref  PRIMARY,id  PRIMARY 4   PLD.lab_item_id 1   Using index 
15  UNION   PLC eq_ref  PRIMARY PRIMARY 4   PLD.lab_cat_id  1
tpxzln5u

tpxzln5u1#

“我已经检查了所有索引,以及已经使用索引或where条件的所有内容。”—不够好。 Using index condition 可能意味着“综合”指数会有所帮助。让我们看看 SHOW CREATE TABLEs .
让我们看一张8桌 UNIONs .
你用的是什么版本?旧版本在处理多个“派生”表时做得很糟糕——因为没有索引。
结果集真的有210k行吗?或者是有一个 LIMIT 我们看不见的?

相关问题