Hi, > Hi, I am having a problem with the following query. It seems to force php > to timeout after 30secs. The query goes through 150K records. Is there > anything I can do to speed it up? > > code----------------------------------------- > SELECT call_id, C.extn_no AS extn_no, dest, dest_name, call_time, > duration, cost, U.firstname AS firstname, U.surname AS surname > FROM call_data as C LEFT JOIN users as U on C.extn_no = U.extn_no > WHERE C.stamptime >= $unixtimestart > AND C.stamptime <= $unixtimeend > AND direction = 'Out' > ORDER BY cost desc LIMIT 0,16 > --------------------------------------------------------------
You can try using "C.stamptime BETWEEN $unixtimestart AND $unixtimeend" instead, and then put an index on C.stamptime. I have found that BETWEEN ... AND ... is faster than the "<= AND >=" version, especially if you put an index on the column. If you look at the VM code with EXPLAIN, you will see why. > > Lloydie-t Ulrik P. -- Ulrik Petersen, Denmark