GROUP BY score (indexed) is ~41.67× faster than GROUP BY payload (no index)
`GROUP BY` on an indexed column is 42× faster: reading in index order means the aggregation needs no sort.
Result
| Run | GROUP BY score (indexed) | GROUP BY payload (no index) | Ratio |
|---|---|---|---|
| Run 1 | 1.788 | 74.569 | 0.02× |
| Run 2 | 1.667 | 72.382 | 0.02× |
| Run 3 | 1.730 | 72.168 | 0.02× |
Spread over 3 runs: GROUP BY score (indexed) CV 2.9% / GROUP BY payload (no index) CV 1.5% / Ratio CV 2.0%
The statement
SELECT score, COUNT(*) FROM items GROUP BY score LIMIT 100; SELECT payload, COUNT(*) FROM items GROUP BY payload LIMIT 100; Conditions
100,000 rows; `payload` is identical in every row (so grouping produces one group).
Where this number does not apply
With many groups, or a `WHERE` on another column, the index is used differently.
Reproduce
cd bench && python sqbench.py --samples 9 --out ../data/run.json