SQLite

View Ticket
Login
2018-12-12
11:50
Do not use a partial index as a table scan in an IN operator. Fix for ticket [1d958d90596593a77420e59]. (check-in: c1c735a8 user: drh tags: branch-3.26)
2018-12-09
18:55
New test case for ticket [1d958d90596593a77420e59]. (check-in: b7bf3c98 user: drh tags: trunk)
2018-12-08
20:30 Fixed ticket [1d958d90]: Incorrect result with NOT IN operator and partial index plus 5 other changes (artifact: 06dc40aa user: drh)
20:30
Do not use a partial index as a table scan in an IN operator. Fix for ticket [1d958d90596593a77420e59]. (check-in: 15bc915d user: drh tags: trunk)
13:06 New ticket [1d958d90] Incorrect result with NOT IN operator and partial index. (artifact: 17e6b575 user: drh)

Ticket Hash: 1d958d90596593a77420e590a6ab71756484f576
Title: Incorrect result with NOT IN operator and partial index
Status: Fixed Type: Code_Defect
Severity: Severe Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2018-12-08 20:30:39
Version Found In: 3.26.0
User Comments:
drh added on 2018-12-08 13:06:23:

The following script returns no rows before the partial index is created, and one row afterwards. The correct answer is no rows:

CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,1);
INSERT INTO t1 VALUES(2,2);
CREATE TABLE t2(x);
INSERT INTO t2 VALUES(1);
INSERT INTO t2 VALUES(2);
SELECT 'one', * FROM t2 WHERE x NOT IN (SELECT a FROM t1);
CREATE INDEX t1a ON t1(a) WHERE b=1;
SELECT 'two', * FROM t2 WHERE x NOT IN (SELECT a FROM t1);

This problem appears to have been in the code since partial indexes were first introduced with version 3.8.0 (2013-08-26). The problem was first reported on the user mailing list by Deon Brewis.