What are the categories of bugs we have?
Warm-up · indexing, distinct
Given a table bugs(id, token, title, category, device, reported_at, created_at, updated_at)
with about 10 million rows, select all distinct bug categories. Output the column (category).
Expected columns
category
Hints
Hint 1 — look at the indexes
Run SHOW INDEX FROM bugs and look at the column with Seq_in_index = 1 in the secondary index. An index stores its first column in sorted order.
Hint 2 — let MySQL skip
SELECT DISTINCT category lets MySQL jump from one category to the next inside the index (a loose index scan) instead of reading every row.