Created
August 30, 2025 17:59
-
-
Save AlessandroMinali/d5126b5362a43da98dad0f6d7e7237a3 to your computer and use it in GitHub Desktop.
1brc in sqlite3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PRAGMA synchronous = OFF; | |
PRAGMA journal_mode = OFF; | |
PRAGMA temp_store = MEMPORY; | |
PRAGMA locking_mode = EXCLUSIVE; | |
PRAGMA ignore_check_constraints = TRUE; | |
PRAGMA automatic_index = FALSE; | |
PRAGMA busy_timeout = 0; | |
PRAGMA wal_autocheckpoint = 0; | |
.mode csv | |
.separator ; | |
BEGIN TRANSACTION; | |
CREATE TABLE temperatures(city TEXT, temperature REAL); | |
.timer ON | |
.import measurements.csv temperatures | |
COMMIT; | |
CREATE INDEX idx_city_temp ON temperatures(city, temperature); | |
select city, min(temperature) min_t, avg(temperature) avg_t, max(temperature) max_t | |
from temperatures | |
group by city; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/gunnarmorling/1brc attempt in sqlite3
Original size: 13.8gb
CSV import to sqlite size: 26.3gb(~2x increase from original)
time to query 630s
time to index 1100s, size: 52.8gb(~4x increase from original)
time to query with index 130s