Mysql查询需要很长时间才能执行

时间:2012-12-23 14:01:59

标签: mysql mysqli

以下是我从各种表中获取信息的查询。

我正在使用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;

但这需要更多时间来执行。

有人可以建议我的查询是错误还是正确?

1 个答案:

答案 0 :(得分:0)

查询看起来合法,我看到的问题是它没有限制。通常,您应该在查询脚本的末尾放置一个LIMIT语句,以限制您想要获得的行数。我想知道有多少记录。