SQLite

View Ticket
Login
2018-04-24
14:42 Fixed ticket [7fa80496]: Incorrect result on a LEFT JOIN when using an index plus 5 other changes (artifact: d10434c3 user: drh)
14:18
Add a hyperlink to the ticket on the code comment for the fix to ticket [7fa8049685b50b5aeb0c2]. (check-in: 45247c7f user: drh tags: trunk)
14:05
Do not attempt to read values from indexes-on-expressions if the index is on the RHS of a LEFT JOIN. This won't work if the index cursor points at a null-row. Fix for [7fa80496]. (check-in: b8ef967a user: dan tags: trunk)
12:48 New ticket [7fa80496] Incorrect result on a LEFT JOIN when using an index. (artifact: 66d12dea user: drh)

Ticket Hash: 7fa8049685b50b5aeb0c211a3d97bdc34db3d4f6
Title: Incorrect result on a LEFT JOIN when using an index
Status: Fixed Type: Code_Defect
Severity: Severe Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2018-04-24 14:42:54
Version Found In: 3.23.1
User Comments:
drh added on 2018-04-24 12:48:46:

The query below gets a different result with and without the index. The result without the index is correct.

CREATE TABLE t1(x);
INSERT INTO t1 VALUES(1);
CREATE TABLE t2(y, z);
SELECT ifnull(z, '!!!') FROM t1 LEFT JOIN t2 ON (x=y);
CREATE INDEX t2i ON t2(y, ifnull(z, '!!!'));
SELECT ifnull(z, '!!!') FROM t1 LEFT JOIN t2 ON (x=y);

This problem appears to have been introduced by check-in [a47efb7c8520a01110ce3] on 2017-04-11, and first released with version 3.19.0. The problem was discovered during internal testing and has not been observed in the wild.