SQLite

View Ticket
Login
Ticket Hash: 002caede898aee4dc531ae9995281c2b8b03a1c6
Title: LEFT JOIN with OR terms in WHERE clause causes assertion fault
Status: Closed Type: Code_Defect
Severity: Critical Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2011-09-19 17:37:54
Version Found In: 3.7.7.1
Description:
The following SQL code causes an assertion fault in the VDBE:

<blockquote><pre>
CREATE TABLE t1(a,b,c,d);
CREATE TABLE t2(e,f);
INSERT INTO t1 VALUES(1,2,3,4);
INSERT INTO t2 VALUES(10,-8);
CREATE INDEX t1a ON t1(a);
CREATE UNIQUE INDEX t1b ON t1(b);
CREATE TABLE t3(g);
INSERT INTO t3 VALUES(4);
CREATE TABLE t4(h);
INSERT INTO t4 VALUES(5);

SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h
 WHERE (a=1 AND h=3)
     OR b IN (
           SELECT x+1 FROM (SELECT e+f AS x, e FROM t2 ORDER BY 1 LIMIT 2)
           GROUP BY e
        );
</pre></blockquote>

It appears that both LEFT JOINs, the OR operator using indices in the
WHERE clause, and the IN operator with unflattenable 
nested subqueries and located on the right-hand
side of the OR are all necessary conditions for this problem to occur.
In other words, the problem is very obscure.

The problem appears to have been introduced by check-in
[2c2de25266] which was a bug-fix for a similar problem described by
ticket [31338dca7e3d].  This problem might be considered a particular
case of the prior ticket [31338dca7e3d] that was never fixed.

The problem first appeared in release 3.6.22.