From 69792adfa22ff258ee56e0684b5eab15b70424fc Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 10 Sep 2022 05:32:23 +0200 Subject: [PATCH] Add a test for #4242 --- .../02418_tautological_if_index.reference | 2 ++ .../02418_tautological_if_index.sql | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/queries/0_stateless/02418_tautological_if_index.reference create mode 100644 tests/queries/0_stateless/02418_tautological_if_index.sql diff --git a/tests/queries/0_stateless/02418_tautological_if_index.reference b/tests/queries/0_stateless/02418_tautological_if_index.reference new file mode 100644 index 00000000000..6ed281c757a --- /dev/null +++ b/tests/queries/0_stateless/02418_tautological_if_index.reference @@ -0,0 +1,2 @@ +1 +1 diff --git a/tests/queries/0_stateless/02418_tautological_if_index.sql b/tests/queries/0_stateless/02418_tautological_if_index.sql new file mode 100644 index 00000000000..c37f24b29f6 --- /dev/null +++ b/tests/queries/0_stateless/02418_tautological_if_index.sql @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS constCondOptimization; + +CREATE TABLE constCondOptimization +( + d Date DEFAULT today(), + time DateTime DEFAULT now(), + n Int64 +) +ENGINE = MergeTree ORDER BY (time, n) SETTINGS index_granularity = 1; + +INSERT INTO constCondOptimization (n) SELECT number FROM system.numbers LIMIT 10000; + +-- The queries should use index. +SET max_rows_to_read = 2; + +SELECT count() FROM constCondOptimization WHERE if(0, 1, n = 1000); +SELECT count() FROM constCondOptimization WHERE if(0, 1, n = 1000) AND 1 = 1; + +DROP TABLE constCondOptimization;