From 610f1203e3f96539553465145ad785caf0998706 Mon Sep 17 00:00:00 2001 From: Igor Markelov Date: Tue, 28 May 2024 11:22:37 +0000 Subject: [PATCH] Add equivalence classes test --- ...r_during_insert_equivalence_classes.reference | 16 ++++++++++++++++ ...w_order_during_insert_equivalence_classes.sql | 15 +++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/queries/0_stateless/03166_optimize_row_order_during_insert_equivalence_classes.reference create mode 100644 tests/queries/0_stateless/03166_optimize_row_order_during_insert_equivalence_classes.sql diff --git a/tests/queries/0_stateless/03166_optimize_row_order_during_insert_equivalence_classes.reference b/tests/queries/0_stateless/03166_optimize_row_order_during_insert_equivalence_classes.reference new file mode 100644 index 00000000000..922371c4d38 --- /dev/null +++ b/tests/queries/0_stateless/03166_optimize_row_order_during_insert_equivalence_classes.reference @@ -0,0 +1,16 @@ +AB 1 9.81 0 +A\0 0 2.7 1 +A\0 1 2.7 1 +B\0 0 2.7 1 +B\0 1 2.7 1 +A\0 1 42 1 +B\0 0 42 1 +A\0 0 3.14 \N +B\0 -1 3.14 \N +B\0 2 3.14 \N +AB 0 42 \N +AB 0 42 \N +B\0 0 42 \N +A\0 1 42 \N +A\0 1 42 \N +B\0 1 42 \N diff --git a/tests/queries/0_stateless/03166_optimize_row_order_during_insert_equivalence_classes.sql b/tests/queries/0_stateless/03166_optimize_row_order_during_insert_equivalence_classes.sql new file mode 100644 index 00000000000..6c04093023c --- /dev/null +++ b/tests/queries/0_stateless/03166_optimize_row_order_during_insert_equivalence_classes.sql @@ -0,0 +1,15 @@ +-- Checks that RowOptimizer correctly selects the order for columns according to cardinality in each equivalence class obtained using SortDescription. +-- There are two columns in the SortDescription: {flag, money} in this order. +-- So there are 5 equivalence classes: {9.81, 9}, {2.7, 1}, {42, 1}, {3.14, Null}, {42, Null}. +-- For the first three of them cardinalities of the other 2 columns are equal, so they are sorted in order {0, 1} in these classes. +-- In the fourth class cardinalities: {name : 2, timestamp : 3}, so they are sorted in order {name, timestamp} in this class. +-- In the fifth class cardinalities: {name : 3, timestamp : 2}, so they are sorted in order {timestamp, name} in this class. + +DROP TABLE IF EXISTS tab; + +CREATE TABLE tab (name FixedString(2), timestamp Float32, money Float64, flag Nullable(Int32)) ENGINE = MergeTree ORDER BY (flag, money) SETTINGS allow_experimental_optimized_row_order = True, allow_nullable_key = True; +INSERT INTO tab VALUES ('AB', 0, 42, Null), ('AB', 0, 42, Null), ('A', 1, 42, Null), ('AB', 1, 9.81, 0), ('B', 0, 42, Null), ('B', -1, 3.14, Null), ('B', 1, 2.7, 1), ('B', 0, 42, 1), ('A', 1, 42, 1), ('B', 1, 42, Null), ('B', 0, 2.7, 1), ('A', 0, 2.7, 1), ('B', 2, 3.14, Null), ('A', 0, 3.14, Null), ('A', 1, 2.7, 1), ('A', 1, 42, Null); + +SELECT * FROM tab SETTINGS max_threads=1; + +DROP TABLE tab;