SQLite User Forum

Assertion failure in sqlite3ExprAffinity function
Login

Assertion failure in sqlite3ExprAffinity function

(1) By Song Liu (songliu) on 2023-04-03 17:02:26 [source]

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

CREATE TABLE v0 (c0 TEXT);
CREATE INDEX i ON v0 (+c0 COLLATE NOCASE);
SELECT count(+c0 COLLATE NOCASE IN (SELECT 1)) FROM v0 GROUP BY SUBSTR(0,0);

Here are the outputs:

sqlite3: sqlite3.c:106016: sqlite3ExprAffinity: Assertion `pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW)' failed.
[1]    105539 abort      ./sqlite3 < poc

Here is the result of bisecting:

 12 BAD     2022-11-28 19:42:48 e3474d79b27298e9 CURRENT
  8 GOOD    2022-11-28 18:41:41 6db0bc4bc0d272b6

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-03 18:02:58 in reply to 1 [link] [source]

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