DB には何百万ものエントリがあります。
そして、私は3を使用しているためです!! 内部結合と日付の広い範囲の配置このクエリは、最大数分のように非常に長くかかります。
このクエリを改善しても同じデータを取得する方法はありますか?
これは私のクエリです:
SELECT
subscriptions.service_id,
service_send_type.usage,
service_send_type.price, SUM(IF(msg_t.status LIKE 'Success%', 1, 0)) AS s,
COUNT(1) AS t
FROM (`subscriptions`)
INNER JOIN
`msg_t` ON `subscriptions`.`phone` = `msg_t`.`phone` AND subscriptions.id = msg_t.sub_id
INNER JOIN
`msg` ON `msg`.`id` = `msg_t`.`msg_id`
INNER JOIN `service_send_type` ON `msg`.`service_id` = `service_send_type`.`service_id`
AND msg.sushi_service_id = service_send_type.sushi_service_id
AND msg.send_type = service_send_type.name
AND msg.service_id = subscriptions.service_id
WHERE
`subscriptions`.`service_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
AND
`subscriptions`.`added` >= '2013-01-28 00:00:00'
AND
`subscriptions`.`added` <= '2013-01-28 23:59:59'
AND
`msg_t`.`send_time` >= '2013-01-28 00:00:00'
AND
`msg_t`.`send_time` <= '2013-01-28 23:59:59'
GROUP BY
`subscriptions`.`service_id`,
`service_send_type`.`usage`,
`service_send_type`.`price`