SQLite Forum

Assertion failure in sqlite3FindInIndex function
Login

Assertion failure in sqlite3FindInIndex function

(1) By Song Liu (songliu) on 2023-04-04 14:30:38 [source]

I found an assertion failure while SQLite (latest, 0421cc03e0efa8f1) executes the following queries.

CREATE TABLE v0 (c0);
CREATE INDEX i ON v0 (c0, +c0 COLLATE NOCASE);
SELECT * FROM v0 AS a0 JOIN v0 GROUP BY a0.c0 HAVING (SELECT sum(v0.c0 IS +a0.c0 COLLATE NOCASE IN (SELECT c0 FROM v0)));

Here are the outputs:

sqlite3: sqlite3.c:108883: sqlite3FindInIndex: Assertion `pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr' failed.
[1]    737975 abort      ./sqlite3 < poc

Here is the result of bisecting:

 11 BAD     2022-11-25 16:10:48 b9190d3da70c4171 CURRENT                                                                                                                                
  9 GOOD    2022-11-25 15:52:00 1ad41840c5e0fa70       

It's the same result in forum post ab2247b44fef6dc6

The assertion failure may be caused by the optimizations. SQLite crashes by default with all optimizations enabled. If I disable the SQLITE_IndexedExpr optimization, SQLite works well.

.testctrl optimizations 0x01000000;

My compilation flags:

    export CFLAGS="-g -O0 -DSQLITE_DEBUG 
                -DSQLITE_ENABLE_TREETRACE 
                -DSQLITE_ENABLE_WHERETRACE
                -DSQLITE_ENABLE_CURSOR_HINTS 
                -DSQLITE_COUNTOFVIEW_OPTIMIZATION 
                -DSQLITE_ENABLE_STAT4" 

(2) By Song Liu (songliu) on 2023-04-04 18:40:29 in reply to 1 [link] [source]

It seems the bug is fixed at commit 2b23dd249d0bc254. Thanks for your work!