Assertion failure in Indexed Expression
(1) By Song Liu (songliu) on 2023-03-24 19:05:32 [source]
I found an assertion failure while SQLite (latest, 98d30400e4721b1d) executes the following queries.
CREATE TABLE v1 ( c1 );
CREATE INDEX i1 ON v1 ( c1, c1 == 0 );
SELECT 1 FROM v1 AS a1 WHERE ( SELECT count ( c1 AND a1.c1 = 0 ) FROM v1 GROUP BY hex ( 1 ) ) AND c1 = 0;
Here are the outputs:
sqlite3: sqlite3.c:144976: int aggregateIdxEprRefToColCallback(Walker *, Expr *): Assertion `pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn' failed.
[1] 105074 abort ./sqlite3 < poc2
Here is the result of bisecting:
9 BAD 2022-12-20 01:48:43 f113eebdbe68246f
11 GOOD 2022-12-19 20:14:22 569018170b928cad CURRENT
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.
CREATE TABLE v1 ( c1 );
CREATE INDEX i1 ON v1 ( c1, c1 == 0 );
.testctrl optimizations 0x01000000;
.print '-- disable optimization of SQLITE_IndexedExpr'
SELECT 1 FROM v1 AS a1 WHERE ( SELECT count ( c1 AND a1.c1 = 0 ) FROM v1 GROUP BY hex ( 1 ) ) AND c1 = 0;
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-03-24 22:29:31 in reply to 1 [link] [source]
It seems the bug is fixed at commit 76b90f267c5cc676. Thanks for your work!