I am trying to import some spatial data (OSM) into an SQLite database. The SQLite reference states that an INTEGER PRIMARY KEY becomes an alias for the rowid (if WITHOUT ROWID is not specified). Just to be sure, I created my main table in two different manners:
CREATE TABLE points (tags BLOB NOT NULL,
lon INTEGER NOT NULL,
lat INTEGER NOT NULL)
vs.
CREATE TABLE points (id INTEGER PRIMARY KEY,
tags BLOB NOT NULL,
lon INTEGER NOT NULL,
lat INTEGER NOT NULL)
I expected the same results, but after running the application twice, my two database files clearly differ in size: The version with explicit primary key takes about 100 MB more of disk space (1.5 GB vs 1.4 GB). My insert statements are equal apart from the fact that one uses "id", the other one "rowid" as destination column for the point ID.
Does anyone have a clue where this massive difference in size comes from? Thanks in advance.
id
androwid
of the corresponding rows the same? Are the rows inserted in the same order? – Keepsqlite3_analyzer
for both. – KeepDROP TABLE IF EXISTS points; CREATE TABLE IF NOT EXISTS points (id INTEGER PRIMARY KEY, tags BLOB NOT NULL, lon INTEGER NOT NULL, lat INTEGER NOT NULL); WITH RECURSIVE counter(tags,lon,lat) AS (SELECT x'00000000', 0,0 UNION ALL SELECT tags, random() AS lon, random() AS lat FROM counter LIMIT 1000000) INSERT INTO points (tags,lon,lat) SELECT * FROM counter;
. (first without id column obviously) and first is 29484Kb, latter with id is 30600kb. Also did VACUUM doesn't change sizes. So there does appear to an overhead for having an alias. – Cynthia