ClickHouse/tests/queries/0_stateless/02943_order_by_all.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
4.0 KiB
MySQL
Raw Normal View History

-- Tests that sort expression ORDER BY ALL
2023-12-17 08:11:30 +00:00
2023-12-13 07:42:43 +00:00
DROP TABLE IF EXISTS order_by_all;
CREATE TABLE order_by_all
(
a String,
2024-02-21 20:24:32 +00:00
b Nullable(Int32)
2023-12-13 07:42:43 +00:00
)
2023-12-17 08:11:30 +00:00
ENGINE = Memory;
2023-12-13 07:42:43 +00:00
2024-02-21 20:24:32 +00:00
INSERT INTO order_by_all VALUES ('B', 3), ('C', NULL), ('D', 1), ('A', 2);
2023-12-13 07:42:43 +00:00
2023-12-17 08:11:30 +00:00
SELECT '-- no modifiers';
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 0;
SELECT a, b FROM order_by_all ORDER BY ALL;
SELECT b, a FROM order_by_all ORDER BY ALL;
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 1;
SELECT a, b FROM order_by_all ORDER BY ALL;
SELECT b, a FROM order_by_all ORDER BY ALL;
2023-12-17 08:11:30 +00:00
SELECT '-- with ASC/DESC modifiers';
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 0;
SELECT a, b FROM order_by_all ORDER BY ALL ASC;
SELECT a, b FROM order_by_all ORDER BY ALL DESC;
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 1;
SELECT a, b FROM order_by_all ORDER BY ALL ASC;
SELECT a, b FROM order_by_all ORDER BY ALL DESC;
2023-12-17 08:11:30 +00:00
SELECT '-- with NULLS FIRST/LAST modifiers';
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 0;
SELECT b, a FROM order_by_all ORDER BY ALL NULLS FIRST;
SELECT b, a FROM order_by_all ORDER BY ALL NULLS LAST;
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 1;
SELECT b, a FROM order_by_all ORDER BY ALL NULLS FIRST;
SELECT b, a FROM order_by_all ORDER BY ALL NULLS LAST;
2023-12-16 09:59:50 +00:00
2024-02-21 20:24:32 +00:00
SELECT '-- SELECT *';
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 0;
2024-02-21 20:24:32 +00:00
SELECT * FROM order_by_all ORDER BY all;
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 1;
2024-02-21 20:24:32 +00:00
SELECT * FROM order_by_all ORDER BY all;
DROP TABLE order_by_all;
SELECT '-- the trouble starts when "order by all is all" is ambiguous';
CREATE TABLE order_by_all
(
a String,
b Nullable(Int32),
all UInt64
)
ENGINE = Memory;
INSERT INTO order_by_all VALUES ('B', 3, 10), ('C', NULL, 40), ('D', 1, 20), ('A', 2, 30);
2024-02-21 20:24:32 +00:00
SELECT ' -- columns';
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 0;
SELECT a, b, all FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION }
SELECT a, b, all FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
2024-02-21 20:24:32 +00:00
SELECT a FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION }
SELECT a FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
SELECT * FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION }
SELECT * FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 1;
SELECT a, b, all FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION }
SELECT a, b, all FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
2024-02-21 20:24:32 +00:00
SELECT a FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
-- SELECT * FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION } -- (*) see below
SELECT * FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
-- SELECT a FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION } -- (*) see below
2024-02-21 20:24:32 +00:00
-- (*) These queries show the expected behavior for analyzer. Unfortunately, it is not implemented that way yet,
-- which is not wrong but a bit unintuitive (some may say a landmine). Keeping the queries for now for reference.
SELECT ' -- column aliases';
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 0;
SELECT a, b AS all FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION }
SELECT a, b AS all FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 1;
SELECT a, b AS all FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION }
SELECT a, b AS all FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
2024-02-21 20:24:32 +00:00
SELECT ' -- expressions';
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 0;
SELECT format('{} {}', a, b) AS all FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION }
SELECT format('{} {}', a, b) AS all FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 1;
SELECT format('{} {}', a, b) AS all FROM order_by_all ORDER BY all; -- { serverError UNEXPECTED_EXPRESSION }
SELECT format('{} {}', a, b) AS all FROM order_by_all ORDER BY all SETTINGS enable_order_by_all = false;
2024-02-21 20:24:32 +00:00
SELECT ' -- ORDER BY ALL loses its special meaning when used in conjunction with other columns';
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 0;
SELECT a, b, all FROM order_by_all ORDER BY all, a;
2024-07-12 12:49:26 +00:00
SET enable_analyzer = 1;
SELECT a, b, all FROM order_by_all ORDER BY all, a;
DROP TABLE order_by_all;