以下是我的查詢以從各種表中獲取信息。Mysql查詢需要很長時間才能執行
我正在使用mysql數據庫。
$sql="select c.cid,c.id,c.compid, c.firstname,c.lastname,c.phone,c.home_phone,c.payment,c.status,c.pstatus, c.pstatus2, c.reservation, u.triptype,u.flight_type_arr, u.flight_type_dep, c.email,c.sugg_pickup_date_time,c.sugg_airport_pickup_time,u.triptype,u.traveltype,
dr_arr.driver_name as driver_name_arr, dr_arr.driver_email as driver_email_arr,
dr_dep.driver_name as driver_name_dep, dr_dep.driver_email as driver_email_dep,
ar.rid,ar.finalprice1, ar.finalprice2, ap.p1, ap.p2, ap.p3, ap.transaction_id
from customer c
left join vehicle_fees vf1 on (vf1.vehicle_id=c.vehicle_id1)
left join vehicle_fees vf2 on (vf2.vehicle_id=c.vehicle_id2)
left join userinfo u on (u.id=c.id)
left join holiday_fees hf1 on (hf1.holidayfee_Date=u.date)
left join holiday_fees hf2 on (hf2.holidayfee_Date=u.date1)
left join airport_reservation ar on (ar.cid = c.cid)
left join driver dr_arr on (dr_arr.did = ar.did_arr)
left join driver dr_dep on (dr_dep.did = ar.did_dep)
left join airport_payment ap on (ap.cid = c.cid)
where (c.reservation = 'booked' or c.reservation = 'cancelled') ORDER BY c.cid DESC" .$var_limit;
但它需要更多時間來執行。
有人可以建議我的查詢是否錯誤或正確?
向我們展示'explain select'輸出。 –
讓這個查詢變慢是非常正常的!它使用10個連接..我相信一些(所有?!)表沒有索引。爲了更好地幫助你,你應該給我們表格結構和聲明索引。 – Yousf