SQLite

View Ticket
Login
Ticket Hash: c52b09c7f38903b1311cec40369f0009c21cb8ab
Title: Assertion fault in the query planner on a deeply nested query
Status: Fixed Type: Performance_Issue
Severity: Minor Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2019-07-24 23:15:31
Version Found In: 3.29.0
User Comments:
drh added on 2019-07-24 21:03:19:

The dbsqlfuzz fuzzer (as augmented recently with enhancements to the structural mutator component) found the following case that causes an assertion fault in the query planner:

CREATE TABLE t1(c);
CREATE TABLE t2(x PRIMARY KEY, y);
SELECT x FROM t2, t1 WHERE x BETWEEN c AND null OR x AND
x IN ((SELECT x FROM (SELECT x FROM t2, t1 
WHERE x BETWEEN (SELECT x FROM (SELECT x COLLATE rtrim 
FROM t2, t1 WHERE x BETWEEN c AND null
OR x AND x IN (c)), t1 WHERE x BETWEEN c AND null
OR x AND x IN (c)) AND null
OR NOT EXISTS(SELECT -4.81 FROM t1, t2 WHERE x BETWEEN c AND null
OR x AND x IN ((SELECT x FROM (SELECT x FROM t2, t1
WHERE x BETWEEN (SELECT x FROM (SELECT x BETWEEN c AND null
OR x AND x IN (c)), t1 WHERE x BETWEEN c AND null
OR x AND x IN (c)) AND null
OR x AND x IN (c)), t1 WHERE x BETWEEN c AND null
OR x AND x IN (c)))) AND x IN (c)
), t1 WHERE x BETWEEN c AND null
OR x AND x IN (c))));

The query above has been manually simplified to the following:

CREATE TABLE t1(c);
CREATE TABLE t2(x PRIMARY KEY);
SELECT 1 FROM t1 WHERE (
  SELECT 2 FROM t2 WHERE (
    SELECT 3 FROM (
      SELECT x FROM t2 WHERE x=c OR x=(SELECT x FROM (VALUES(0)))
    ) WHERE x>c OR x=c
  )
);

Bisecting shows that the problem was introduced by check-in [e130319317e76119]. Hence, the problem exists in version 3.27, 3.28, and 3.29.


drh added on 2019-07-24 22:44:46:

Oh boo. All that work to try to simplify the test case and to isolate the point of introduction, and I never took the time to actually look at the assert() that is failing:

The assert() is benign. Completely harmless.

I've changed the severity on this ticket to "minor". We'll try to deal with it as we have opportunity. The solution might be to simply delete the assert().