SQL BenchMEASURED, NOT GUESSED

    ↑↓ to select, Enter to open, Esc to close

    COUNT(*) is ~1.81× faster than COUNT(score)

    Counter-intuitive but consistent: `COUNT(*)` is 1.8× faster. It only counts rows, while `COUNT(col)` reads values and checks for NULL.

    Result

    RunCOUNT(*)COUNT(score)Ratio
    Run 14.3528.1120.54×
    Run 23.7726.8390.55×
    Run 33.8046.7180.57×

    Spread over 3 runs: COUNT(*) CV 7.0% / COUNT(score) CV 9.2% / Ratio CV 2.1%

    COUNT(*): 4.35msCOUNT(score): 8.11msRun1COUNT(*): 3.77msCOUNT(score): 6.84msRun2COUNT(*): 3.80msCOUNT(score): 6.72msRun3

    The statement

    SELECT COUNT(*) FROM items;
    SELECT COUNT(score) FROM items;

    Conditions

    100,000 rows; `score` is NOT NULL.

    Where this number does not apply

    If the column is indexed and nullable-free, SQLite may walk only the index and the gap narrows.

    Reproduce

    cd bench && python sqbench.py --samples 9 --out ../data/run.json