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.2 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';
SET allow_experimental_analyzer = 0;
SELECT a, b FROM order_by_all ORDER BY ALL;
SELECT b, a FROM order_by_all ORDER BY ALL;
SET allow_experimental_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';
SET allow_experimental_analyzer = 0;
SELECT a, b FROM order_by_all ORDER BY ALL ASC;
SELECT a, b FROM order_by_all ORDER BY ALL DESC;
SET allow_experimental_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';
SET allow_experimental_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;
SET allow_experimental_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 *';
SET allow_experimental_analyzer = 0;
SELECT * FROM order_by_all ORDER BY all;
SET allow_experimental_analyzer = 1;
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';
SET allow_experimental_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;
SET allow_experimental_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';
SET allow_experimental_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;
SET allow_experimental_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';
SET allow_experimental_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;
SET allow_experimental_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';
SET allow_experimental_analyzer = 0;
SELECT a, b, all FROM order_by_all ORDER BY all, a;
SET allow_experimental_analyzer = 1;
SELECT a, b, all FROM order_by_all ORDER BY all, a;
DROP TABLE order_by_all;