SQLite

View Ticket
Login
2014-02-26
02:26 Fixed ticket [65bdeb97]: "ORDER BY random()" gets optimized out plus 5 other changes (artifact: 3a374196 user: drh)
02:26
Improved handling of constants and especially constant functions in the ORDER BY clause of a query. Do not optimize out "ORDER BY random()". Fix for ticket [65bdeb9739605cc2296]. (check-in: dca1945a user: drh tags: trunk)
00:48 New ticket [65bdeb97] "ORDER BY random()" gets optimized out. (artifact: 73ee3bfc user: drh)

Ticket Hash: 65bdeb9739605cc22966f49208452996ff29a640
Title: "ORDER BY random()" gets optimized out
Status: Fixed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2014-02-26 02:26:29
Version Found In: 3.8.3.1
User Comments:
drh added on 2014-02-26 00:48:49:

In the following query, the ORDER BY clause is ignored:

CREATE TABLE t1(a INTEGER PRIMARY KEY, b DEFAULT 1);
INSERT INTO t1(a) VALUES(1),(2),(3),(4),(5);
CREATE TABLE t2(x INTEGER PRIMARY KEY);
INSERT INTO t2 VALUES(1);
SELECT * FROM t1, t2 WHERE x=1 ORDER BY random();

This problem appears to have been introduced on 2013-06-21 (version 3.8.0) with the introduction of the NGQP.