-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FTS table with 7 rows has _fts_docsize table with 9,141 rows #149
Comments
First posted on SQLite forum here but I'm pretty sure this is a bug in how |
Another likely culprit: CREATE TABLE [licenses] (
[key] TEXT PRIMARY KEY,
[name] TEXT,
[spdx_id] TEXT,
[url] TEXT,
[node_id] TEXT
); |
Even though that table doesn't declare an integer primary key it does have a
https://www.sqlite.org/rowidtable.html explains has this clue:
|
Aha! I have managed to replicate the bug:
Note that the number of records in |
reading through the code for def save_license(db, license):
if license is None:
return None
return db["licenses"].insert(license, pk="key", replace=True).last_pk |
Using
|
And the SQLite documentation says:
|
This replicates the problem:
Note how the number of rows in The number went up by ten. I used tracing from #151 to show that the following SQL executed ten times:
Then I tried executing |
https://www.sqlite.org/pragma.html#pragma_recursive_triggers says:
So I think the fix is to turn on |
The second challenge here is cleaning up all of those junk rows in existing DELETE FROM [licenses_fts_docsize] WHERE id NOT IN (
SELECT rowid FROM [licenses_fts]); I can do that as part of the existing |
To get the fix for this issue: simonw/sqlite-utils#149
I'm seeing a weird issue with some of the SQLite databases that I am using with the FTS5 module.
I have a database with a
licenses
table that contains 7 rows: https://github-to-sqlite.dogsheep.net/github/licensesThe FTS table also has 7 rows: https://github-to-sqlite.dogsheep.net/github/licenses_fts
Somehow the accompanying
licenses_fts_docsize
shadow table now has 9,141 rows in it! https://github-to-sqlite.dogsheep.net/github/licenses_fts_docsizeAnd
licenses_fts_data
has 41 rows - should I expect that to have 7 rows? https://github-to-sqlite.dogsheep.net/github/licenses_fts_dataI have a hunch that it might be a problem with the triggers. These are the triggers that are updating that FTS table: https://github-to-sqlite.dogsheep.net/github?sql=select+*+from+sqlite_master+where+type+%3D+%27trigger%27+and+tbl_name+%3D+%27licenses%27
CREATE TRIGGER [licenses_ai] AFTER INSERT ON [licenses] BEGIN INSERT INTO [licenses_fts] (rowid, [name]) VALUES (new.rowid, new.[name]); END
CREATE TRIGGER [licenses_ad] AFTER DELETE ON [licenses] BEGIN INSERT INTO [licenses_fts] ([licenses_fts], rowid, [name]) VALUES('delete', old.rowid, old.[name]); END
CREATE TRIGGER [licenses_au] AFTER UPDATE ON [licenses] BEGIN INSERT INTO [licenses_fts] ([licenses_fts], rowid, [name]) VALUES('delete', old.rowid, old.[name]); INSERT INTO [licenses_fts] (rowid, [name]) VALUES (new.rowid, new.[name]); END
The text was updated successfully, but these errors were encountered: