SQLite

View Ticket
Login
2016-09-07
12:08
The ORDER BY LIMIT optimization is not valid unless the inner-most IN operator loop is actually used by the query plan. Fix for ticket [0c4df46116e90f92]. (check-in: b4f8be1f user: drh tags: branch-3.14)
01:56 Fixed ticket [0c4df461]: Incorrect result with ORDER BY DESC and LIMIT plus 5 other changes (artifact: 1f53b3e5 user: drh)
01:51
The ORDER BY LIMIT optimization is not valid unless the inner-most IN operator loop is actually used by the query plan. Fix for ticket [0c4df46116e90f92]. (check-in: 820644b8 user: drh tags: trunk)
00:42 New ticket [0c4df461] Incorrect result with ORDER BY DESC and LIMIT. (artifact: 51389ac4 user: drh)

Ticket Hash: 0c4df46116e90f927a54103c4ed82a825a18763f
Title: Incorrect result with ORDER BY DESC and LIMIT
Status: Fixed Type: Code_Defect
Severity: Severe Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2016-09-07 01:56:06
Version Found In: 3.14.1
User Comments:
drh added on 2016-09-07 00:42:45:

In the following SQL, the first query gives the correct 3 lines of result in the correct order. But the second query returns the second line of result, not the first line as it should:

CREATE TABLE t1(a,b,c);
CREATE INDEX t1x ON t1(a,b,c);
INSERT INTO t1 VALUES(0,1,99),(0,1,0),(0,0,0);
SELECT * FROM t1 WHERE a=0 AND (c=0 OR c=99) ORDER BY c DESC;
SELECT * FROM t1 WHERE a=0 AND (c=0 OR c=99) ORDER BY c DESC LIMIT 1;

This problem seems to have been introduced by check-in [559733b09e96] on 2016-05-20 and was released with version 3.14.0.