Transient "SQL logic error" bug in FTS5
(1.1) By oldmoe on 2023-09-12 21:56:13 edited from 1.0 [source]
Hi there,
I have seen this error message thrown from one of the applications I am working on and I was able to reproduce in the terminal, It happens only when:
- I have repeatedly (more than once) called the insert rank command
- I am trying to query the fts table in another process with a query that uses the rank function
As an example:
In terminal 1 after opening db.sqlite3:
CREATE VIRTUAL TABLE t USING fts5 (a, b);
INSERT INTO t (a, b) VALUES ('data1', 'sentence1'), ('data2', 'sentence2');
INSERT INTO t(t, rank) VALUES ('rank', 'bm25(10.0,1.0)') -- any value
Now in terminal 2, after opening the same db.sqlite3 file:
SELECT *, rank FROM t('data*') ORDER BY RANK; -- this works perfectly
At this point go back to terminal 1 and re-issue the insert rank command
INSERT INTO t(t, rank) VALUES ('rank', 'bm25(10.0,1.0)') -- any value
Now again in terminal 2
SELECT *, rank FROM t('data*') ORDER BY RANK; -- this breaks
This will throw a SQL logic error then will resume working if the statement is re-ran. It will break again if I run the insert again in the other terminal, but only once, and so on.
This doesn't happen if I insert the data directly into the t_settings table, i.e.
INSERT OR REPLACE INOT t_config(k, v) VALUES ('rank', 'bm25(10.0, 1.0)');
I am using version 3.40, I have discovered this while doing some multi-process testing, but I have seen the above mentioned error and another one that would be saying something like: 10 is not a function (whatever value I had for the first argument to bm25), I am not yet able to reproduce that other error using the cli.
(2) By Richard Hipp (drh) on 2023-09-13 10:19:31 in reply to 1.1 [link] [source]
Please try again using the check-in cb54c2da52d31758 or later and report back if that fails to resolve your issue.
(3) By oldmoe on 2023-09-14 22:31:59 in reply to 2 [link] [source]
Thanks for the quick fix, works perfectly now