-- 011_indexes_extra.sql — indeks tambahan performa (Audit Database Engineer, pasca Sprint 10/11)
--
-- Dicek via SHOW INDEX (ADR-005-diperluas: DESCRIBE/SHOW COLUMNS/information_schema.columns
-- DILARANG, memicu crash mysqld) + EXPLAIN thd DB live sanggraloka_fin:
--   - budget_line: uq_budget_line(version_id, department_id, account_id, scenario) SUDAH menutupi
--     query grid input (WHERE version_id=? AND department_id=? AND scenario=? AND account_id IN
--     (...)) — EXPLAIN membuktikan type=range pakai uq_budget_line, 5 baris diperiksa utk 5 akun
--     diminta. TIDAK ada perubahan di sini.
--   - calc_result: uq_calc_result(version_id, measure_code, ref, month) SUDAH menutupi SEMUA
--     query CalcRepository/AnalyticsRepository (WHERE version_id=? AND measure_code=? AND ref=?
--     [AND month...]) sbg leftmost prefix persis urutan filter. TIDAK ada perubahan di sini.
--   - room_rev_detail: uq_room_rev_detail(version_id, room_type_id, segment_id, month) TIDAK
--     menutupi agregasi ringkasan per (version_id, month) lintas SEMUA tipe & segmen (dipakai
--     RoomRevDetailRepository::sumRevByMonth() & CalcRepository::findRoomNightsPaid(), keduanya
--     GROUP BY month WHERE version_id=?). EXPLAIN MEMBUKTIKAN full table scan (type=ALL, rows=1224,
--     "Using temporary; Using filesort") krn month berada di posisi ke-4 index gabungan (di
--     belakang room_type_id & segment_id yg tidak difilter query ini). Indeks baru (version_id,
--     month) ditambahkan di bawah supaya GROUP BY month bisa pakai index scan langsung. Indeks
--     lama (uq_room_rev_detail, idx_room_rev_detail_version) TIDAK dihapus/diubah — murni aditif.

ALTER TABLE room_rev_detail
    ADD INDEX idx_room_rev_detail_version_month (version_id, month);
