SQL BenchMEASURED, NOT GUESSED

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

    primary key lookup (id = ?) is ~26.32× faster than search on an unindexed column (0 matches)

    A primary-key lookup is 26× faster. On an unindexed column SQLite reads every row even when nothing matches, so the gap tracks scan volume.

    Result

    Runprimary key lookup (id = ?)search on an unindexed column (0 matches)Ratio
    Run 11.01725.8610.04×
    Run 20.99226.2690.04×
    Run 30.96626.0160.04×

    Spread over 3 runs: primary key lookup (id = ?) CV 2.1% / search on an unindexed column (0 matches) CV 0.6% / Ratio CV 2.1%

    primary key lookup (id = ?): 1.02mssearch on an unindexed column (0 matches): 25.86msRun1primary key lookup (id = ?): 0.99mssearch on an unindexed column (0 matches): 26.27msRun2primary key lookup (id = ?): 0.97mssearch on an unindexed column (0 matches): 26.02msRun3

    The statement

    SELECT * FROM items WHERE id = 54321;
    SELECT * FROM items WHERE payload = 'not-there';

    Conditions

    100,000 rows; `payload` is the same value in every row.

    Where this number does not apply

    On a table small enough to sit in cache, the scan is fast too and the gap shrinks.

    Reproduce

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