-- @database: bo
--
-- Index supporting the camera breakdown of `GET /admin/media/stats/cameras`
-- (aggregate per EXIF brand / model).
--
-- `media_meta` only carried its PRIMARY KEY (`media_id`), so every
-- `GROUP BY brand` / `GROUP BY brand, model` meant a full table scan. This
-- composite index makes those aggregates a COVERING index scan: both grouped
-- columns are read straight from the index, the table itself is never touched.
--
-- Column order matters: (brand, model) serves "group by brand", "group by
-- brand+model" AND "filter on one brand then group by model" (the `?brand=`
-- query param) — the reverse order would serve none of them.
--
-- NOTE: the aggregates group on `UPPER(TRIM(col))`, which a plain B-tree index
-- cannot satisfy for direct lookup; the index still pays off because MySQL
-- scans it instead of the (much wider) table rows. Should the library grow to
-- the point where this is not enough, the next step is a generated column
-- holding the normalised brand + an index on it.

ALTER TABLE `media_meta`
    ADD KEY `idx_mm_camera` (`brand`, `model`);
