-- Statistik-Indexe fuer grosse Datenmengen
-- Vor dem Einspielen auf Produktivsystemen zuerst EXPLAIN pruefen.
-- Diese Indexe zielen auf admin/statistics/statistics_ajax.php.

ALTER TABLE send_queue
    ADD INDEX idx_sq_status_sent_at (status, sent_at),
    ADD INDEX idx_sq_status_created_at (status, created_at),
    ADD INDEX idx_sq_campaign_status_sent_at (campaign_id, status, sent_at),
    ADD INDEX idx_sq_list_status_sent_at (list_id, status, sent_at);

ALTER TABLE email_opens
    ADD INDEX idx_email_opens_opened_at_queue (opened_at, queue_id);

ALTER TABLE email_link_tracking
    ADD INDEX idx_email_link_tracking_clicked_at_queue (clicked_at, queue_id);

ALTER TABLE email_bounces
    ADD INDEX idx_email_bounces_logged_at (logged_at),
    ADD INDEX idx_email_bounces_queue_logged_at (queue_id, logged_at);

ALTER TABLE recipients
    ADD INDEX idx_recipients_unsubscribed_at (unsubscribed_at);

ALTER TABLE pdf_download_stats
    ADD INDEX idx_pdf_download_stats_downloaded_at (downloaded_at);