SQLite

View Ticket
Login
2018-09-17
15:30 Fixed ticket [510cde27]: Endless loop on a query with window functions, ORDER BY, and LIMIT plus 5 other changes (artifact: c0db9c39 user: drh)
15:25
Disable the ORDER BY LIMIT optimization in queries using window functions. This fixes a problem that was introduced by check-in [206720129ed2fa8875a286] which attempted to fix ticket [9936b2fa443fec03ff25f9]. This changes is a fix for the follow-in tocket [510cde277783b5fb5de628]. (check-in: 36c75fd5 user: drh tags: branch-3.25)
15:19
Disable the ORDER BY LIMIT optimization in queries using window functions. This fixes a problem that was introduced by check-in [206720129ed2fa8875a286] which attempted to fix ticket [9936b2fa443fec03ff25f9]. This changes is a fix for the follow-in tocket [510cde277783b5fb5de628]. (check-in: c6c9585f user: drh tags: trunk)
14:28 New ticket [510cde27] Endless loop on a query with window functions, ORDER BY, and LIMIT. (artifact: 614870a8 user: drh)

Ticket Hash: 510cde277783b5fb5de628393959849dff377eb3
Title: Endless loop on a query with window functions, ORDER BY, and LIMIT
Status: Fixed Type: Code_Defect
Severity: Severe Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2018-09-17 15:30:05
Version Found In: 3.25.0
User Comments:
drh added on 2018-09-17 14:28:12:

The following query hits an assert() in the byte-code engine, or if assert()s are disabled, goes into an endless loop in the byte code.

CREATE TABLE t1(id, b, c);
INSERT INTO t1 VALUES(1, 'A', 'one');
INSERT INTO t1 VALUES(2, 'B', 'two');
INSERT INTO t1 VALUES(3, 'C', 'three');
INSERT INTO t1 VALUES(4, 'D', 'one');
INSERT INTO t1 VALUES(5, 'E', 'two');
SELECT id, b, lead(c,1) OVER(ORDER BY c) AS x FROM t1 WHERE id>1 ORDER BY b LIMIT 1;

This problem appears to have been introduced by check-in [206720129ed2fa8875a2] which was a fix for ticket [9936b2fa443fec03ff25] which was the previous problem of an endless loop due to the ORDER BY LIMIT optimization.