我有以下查询:
while ($start_date <= $end_date) {
$date_array[] = date('d/m/Y H:i:s', strtotime($start_date));
$start_date_interval = date('Y-m-d H:i:s', strtotime($start_date) + $interval);
echo date('d/m/Y H:i:s', strtotime($start_date)) . ' ------> ';
$query = "SELECT COUNT(id) AS call_count FROM callsepaug "
. "WHERE (i_billable = 1 AND ((start_time >= '$start_date' AND start_time < '$start_date_interval') "
. "OR (start_time > '$start_date_past' AND start_time < '$start_date_interval' "
. "AND end_time >= '$start_date')));";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$data[] = $row['call_count'];
echo $row["call_count"] . ' active calls.<br>';
$start_date = date('Y-m-d H:i:s', strtotime($start_date) + $interval);
// echo $start_date . '<br>';
}
但是这个查询太慢了。该数据库包含大量数据。检查开始和结束给定时间的 15 分钟间隔的查询大约需要 45 秒。我怎样才能大大提高速度?