或在左联接中减慢SQL查询

时间:2019-09-19 07:37:15

标签: mysql sql performance query-optimization query-performance

在连接中使用OR进行以下SQL查询的速度很慢:

EXPLAIN
SELECT ara.AmenityID,ara.AmenityDescription,ara.FinalAmenityName 
FROM alliance_reservation_amenities ara 
LEFT JOIN alliance_reservation_property_amenities rpa 
ON ara.AmenityID=rpa.AmenityID 
LEFT JOIN hotel_amadeus_properties_amenities apa 
ON ara.AmenityID=apa.AmenityID 
LEFT JOIN hotel_search_result_amadeus hsr 
ON rpa.PropertyID=hsr.AlncPropertyID  or apa.Property_ID=hsr.Property_ID 
WHERE SESSIONID='ddm6ln25n4snjiaqabfa8nnleqhhkq1mkea4560a9lmid8qo4kr1' 
AND userID=3108 and display = 1 
AND hsr.Search_Category !=2 
AND ara.AmenityID IN (9000206,9001587,119,9001596,9001679,9000505,9001036,9001652,
9001654,121,9001256,9001524,132,9001583,9000132,9000133,9001090,9001597,102336,9000807,
9001527,9001528,9001529,9001656,9001657,9000148,9000523,9000524,9000525,9000526,9000558,
9000962,9001024,9001051,9001098,9001099,9001292,9001459,9001462,9001593,9001681,9001682,
9001688,9001689,9001690,9001714,9001731,142,130986,130987,130988,130989,9001068,9001104,
9001694,9001695,9001716,9000190,9001145,9001715,9000527,9000752,9000754,9000755,9000836,
9001027,9001375,9001425,9001426,9001718,73,9000195,9000682,9001153,9001723) 
GROUP BY rpa.AmenityID ORDER BY ara.AmenityDescription ASC

enter image description here

在没有OR的情况下正常工作:

EXPLAIN
SELECT ara.AmenityID,ara.AmenityDescription,ara.FinalAmenityName 
FROM alliance_reservation_amenities ara 
LEFT JOIN alliance_reservation_property_amenities rpa 
ON ara.AmenityID=rpa.AmenityID 
LEFT JOIN hotel_amadeus_properties_amenities apa 
ON ara.AmenityID=apa.AmenityID 
LEFT JOIN hotel_search_result_amadeus hsr 
ON rpa.PropertyID=hsr.AlncPropertyID 
where SESSIONID='ddm6ln25n4snjiaqabfa8nnleqhhkq1mkea4560a9lmid8qo4kr1' 
AND userID=3108 and display = 1 
AND hsr.Search_Category !=2 
AND ara.AmenityID IN (9000206,9001587,119,9001596,9001679,9000505,9001036,9001652,9001654,
121,9001256,9001524,132,9001583,9000132,9000133,9001090,9001597,102336,9000807,9001527,
9001528,9001529,9001656,9001657,9000148,9000523,9000524,9000525,9000526,9000558,9000962,
9001024,9001051,9001098,9001099,9001292,9001459,9001462,9001593,9001681,9001682,9001688,
9001689,9001690,9001714,9001731,142,130986,130987,130988,130989,9001068,9001104,9001694,
9001695,9001716,9000190,9001145,9001715,9000527,9000752,9000754,9000755,9000836,9001027,
9001375,9001425,9001426,9001718,73,9000195,9000682,9001153,9001723) 
GROUP BY rpa.AmenityID ORDER BY ara.AmenityDescription ASC

enter image description here

有人可以帮助我解决导致第一个SQL查询变慢的问题吗?

0 个答案:

没有答案