mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Fix a problem with the query optimizer for LIMIT/OFFSET queries when
underlying query is a UNION ALL and both arms of the UNION ALL are subqueries with an ORDER BY clause. This bug was reported at [forum:/forumpost/6b5e9188f0657616|forum post 6b5e9188f0657616]. The problem was introduced in 2015 (SQLite version 3.9.0) by check-in [4b631364354068af]. See also ticket [b65cb2c8d91f6685]. FossilOrigin-Name: 6c806f64bbc9e98891bad0868575ee2ec5d0951ceb0c71d3ed417b45d5f27561
This commit is contained in:
@ -156,6 +156,47 @@ do_execsql_test offset1-1.4.9 {
|
||||
LIMIT 9 OFFSET 1;
|
||||
} {2 b 3 c 4 d 5 e 6 w 7 x 8 y 9 z}
|
||||
|
||||
|
||||
# 2022-08-04
|
||||
# https://sqlite.org/forum/forumpost/6b5e9188f0657616
|
||||
#
|
||||
do_execsql_test offset1-2.0 {
|
||||
CREATE TABLE employees (
|
||||
id integer primary key,
|
||||
name text,
|
||||
city text,
|
||||
department text,
|
||||
salary integer
|
||||
);
|
||||
INSERT INTO employees VALUES
|
||||
(11,'Diane','London','hr',70),
|
||||
(12,'Bob','London','hr',78),
|
||||
(21,'Emma','London','it',84),
|
||||
(22,'Grace','Berlin','it',90),
|
||||
(23,'Henry','London','it',104),
|
||||
(24,'Irene','Berlin','it',104),
|
||||
(25,'Frank','Berlin','it',120),
|
||||
(31,'Cindy','Berlin','sales',96),
|
||||
(32,'Dave','London','sales',96),
|
||||
(33,'Alice','Berlin','sales',100);
|
||||
CREATE VIEW v AS
|
||||
SELECT * FROM (
|
||||
SELECT * FROM employees
|
||||
WHERE salary < 100
|
||||
ORDER BY salary desc)
|
||||
UNION ALL
|
||||
SELECT * FROM (
|
||||
SELECT * FROM employees
|
||||
WHERE salary >= 100
|
||||
ORDER BY salary asc);
|
||||
} {}
|
||||
do_execsql_test offset1-2.1 {
|
||||
SELECT * FROM v LIMIT 5 OFFSET 2;
|
||||
} {
|
||||
22 Grace Berlin it 90
|
||||
21 Emma London it 84
|
||||
12 Bob London hr 78
|
||||
11 Diane London hr 70
|
||||
33 Alice Berlin sales 100
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user