i am running the below MySQL Query in PHP on my web server, the database is located on a separate server:
$sql="select * from call_history where extension_number = '0536*500' and flow = 'in' and DATE(initiated) = '".date("Y-m-d")."' ";
$rs=mysql_query($sql,$pbx01_conn);
echo mysql_num_rows($rs).' Calls IN';
the call_history
table has thousands of rows in, is there any way to speed up the query?
Please note: I only have read only access to the database
$initiated = date("Y-m-d");
$sql = "SELECT COUNT(*) as n FROM `call_history` where extension_number = '0536*500' and flow = 'in' and DATE(initiated) =\"{$initiated}\"";
$rs=mysql_query($sql,$pbx01_conn);
$rs = mysql_fetch_row($rs);
echo $rs['n'] . ' Calls IN';
You can also optimize your tables through phpMyAdmin: Tables -> Operations Tab -> Table Maintenance Section -> Optimize Table
Add indexes to the search columns extension_number
, flow
and initiated
.
MySQL is observable slower on searching among several thousands records if there are no indexes.