Assertion failure in ANALYZE for STAT4 (2)
(1) By Song Liu (songliu) on 2023-03-26 04:53:47 [source]
I found an assertion failure while SQLite (latest, ffe23af73fcb324d) executes the following queries.
CREATE TABLE v0(c); CREATE TABLE v1(c); CREATE INDEX i ON v0(0,0,0,0,0||1); CREATE INDEX i0 ON v1(0<1); INSERT INTO v0 VALUES(0); ANALYZE
Here are the outputs:
sqlite3: sqlite3.c:92069: int sqlite3VdbeExec(Vdbe *): Assertion `pIn1!=pOut' failed.  4119 abort ./sqlite3 < poc
We discussed this problem (forum posts bc39e531e5 and 77c4f79270), here are the patches 13c8c60bb6b4447b and 5d554e4d0f59a430. It seems the patches are incomplete and there is another case that can trigger this assertion failure.
Here is the result of bisecting:
2 BAD 2015-09-04 17:32:19 2131a5ca53f0e9b0 3 GOOD 2015-09-04 12:54:01 3d3df79bfaf9dbc7 CURRENT
The assertion failure may be caused by the optimizations. SQLite crashes by default with all optimizations enabled. If I disable the SQLITE_Stat4 optimization, SQLite works well.
CREATE TABLE v0(c); CREATE TABLE v1(c); CREATE INDEX i ON v0(0,0,0,0,0||1); CREATE INDEX i0 ON v1(0<1); INSERT INTO v0 VALUES(0); .testctrl optimizations 0x00000800; .print '-- disable optimization of SQLITE_Stat4' ANALYZE
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-26 16:56:45 in reply to 1 [link] [source]
It seems the bug is fixed at commit 6f8b97f31a4c8552. Thanks for your work!