SQLite Forum

Assertion failure in agginfoPersistExprCb function (2)
Login

Assertion failure in agginfoPersistExprCb function (2)

(1.1) By Song Liu (songliu) on 2023-04-11 14:57:13 edited from 1.0 [source]

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

CREATE TABLE v0 (c0, c2);
CREATE INDEX i ON v0 (c0+c2);
SELECT count((SELECT count(a0.c0+a0.c2) ORDER BY sum(0) OVER (PARTITION BY 0))) FROM v0 AS a0 JOIN v0 AS a1 GROUP BY a1.c0;

Here are the outputs:

sqlite3: sqlite3.c:112378: agginfoPersistExprCb: Assertion `0' failed.
[1]    1309991 abort      ./sqlite3 < poc

We discussed similar problem that happened in agginfoPersistExprCb function before (forum posts bad532820c)

Here is the result of bisecting:

 11 BAD     2022-11-28 19:42:48 e3474d79b27298e9 CURRENT
 10 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 or SQLITE_CoverIdxScan optimization, assertion failure will not happen.

.testctrl optimizations 0x00000020;
.testctrl optimizations 0x01000000;

here are the error messages if I disabled SQLITE_IndexedExpr or SQLITE_CoverIdxScan optimization

Parse error near line 4: misuse of aggregate: count()
  SELECT count((SELECT count(a0.c0+a0.c2) ORDER BY sum(0) OVER (PARTITION BY 0))
                       ^--- error here

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"