SQLite Forum

An assertion failure in function isSimpleCount()
Login

An assertion failure in function isSimpleCount()

(1) By Wang Ke (krking) on 2021-11-05 09:25:04

Hello developers,

We found an assertion failure in SQLite version 3.37.0 2021-11-02 07:32:13 with debug enabled.

The test case is as follows:

```
CREATE TABLE t1(a TEXT AS(1>=1),b CHAR(1));
CREATE INDEX t1ab ON t1(a,b);
SELECT * FROM t1 WHERE (a, b) IN (SELECT count(CASE WHEN t1.b='xyz' THEN 10 END), COUNT(*) AS ca0 FROM t1 AS ra0) AND t1.b=0;
```

which causes:

> sqlite3.c:137964: isSimpleCount: Assertion `0' failed.

in line:

>   if( NEVER(pAggInfo->nFunc==0) ) return 0;

Bisecting shows the issue may be related to [check-in e994c9f2](https://sqlite.org/src/info/e994c9f29f).

Hope the problem will be handled properly :)

(2) By Richard Hipp (drh) on 2021-11-05 12:03:39 in reply to 1 [link]

Thanks for the report.  Now fixed [on trunk][1].

Wang Ke probably already knows this, but for the benefit of other readers,
the NEVER() macro in SQLite basically means "we don't have a test case
for this condition but we should probably check it anyhow."  On debug
builds, the NEVER() raises an assertion fault if it is ever true, but for
release builds it is a no-op.  In that way, NEVER() macros alert us to
new untested branches.  Release builds are unaffected.

Hence, this is not a problem in release builds.

The simplest fix here would be to simply delete the NEVER().  But I took
the opportunity to also clean up the isSimpleCount() function a little.
Test cases were added to [TH3][2] and [dbsqlfuzz][3].

[1]: src:/info/2927185be81a5aa0
[2]: https://sqlite.org/th3.html
[3]: https://sqlite.org/testing.html#the_dbsqlfuzz_fuzzer