diff --git a/src/Functions/ignore.cpp b/src/Functions/ignore.cpp index 6b02c3a462d..1348144cb05 100644 --- a/src/Functions/ignore.cpp +++ b/src/Functions/ignore.cpp @@ -29,6 +29,7 @@ public: } bool useDefaultImplementationForNulls() const override { return false; } + bool isSuitableForConstantFolding() const override { return false; } /// We should never return LowCardinality result, cause we declare that result is always constant zero. /// (in getResultIfAlwaysReturnsConstantAndHasArguments) diff --git a/src/Interpreters/ExpressionAnalyzer.cpp b/src/Interpreters/ExpressionAnalyzer.cpp index 3f65a6f3f58..8a421d06b72 100644 --- a/src/Interpreters/ExpressionAnalyzer.cpp +++ b/src/Interpreters/ExpressionAnalyzer.cpp @@ -89,8 +89,7 @@ bool allowEarlyConstantFolding(const ActionsDAG & actions, const Settings & sett { if (node.type == ActionsDAG::ActionType::FUNCTION && node.function_base) { - auto name = node.function_base->getName(); - if (name == "ignore") + if (!node.function_base->isSuitableForConstantFolding()) return false; } } diff --git a/tests/integration/test_system_merges/test.py b/tests/integration/test_system_merges/test.py index 1f2da606cd1..672b637f783 100644 --- a/tests/integration/test_system_merges/test.py +++ b/tests/integration/test_system_merges/test.py @@ -134,7 +134,9 @@ def test_mutation_simple(started_cluster, replicated): result_part = "all_{}_{}_0_{}".format(starting_block, starting_block, starting_block + 1) def alter(): - node1.query("ALTER TABLE {name} UPDATE a = 42 WHERE sleep(2) OR 1".format(name=name)) + node1.query("ALTER TABLE {name} UPDATE a = 42 WHERE sleep(2) OR 1".format(name=name), settings={ + 'mutations_sync': 1, + }) t = threading.Thread(target=alter) t.start() @@ -159,8 +161,6 @@ def test_mutation_simple(started_cluster, replicated): ] t.join() - time.sleep(1.5) - assert node_check.query("SELECT * FROM system.merges WHERE table = '{name}'".format(name=table_name)) == "" finally: diff --git a/tests/queries/0_stateless/00597_push_down_predicate.reference b/tests/queries/0_stateless/00597_push_down_predicate.reference index cea533d6ccb..794d9e7af5f 100644 --- a/tests/queries/0_stateless/00597_push_down_predicate.reference +++ b/tests/queries/0_stateless/00597_push_down_predicate.reference @@ -115,6 +115,7 @@ FROM SELECT 1 AS id, identity(cast(1, \'UInt8\')) AS subquery + WHERE subquery = 1 ) WHERE subquery = 1 1 1 diff --git a/tests/queries/0_stateless/01029_early_constant_folding.reference b/tests/queries/0_stateless/01029_early_constant_folding.reference index 7e2f6c7ce76..8a1d4cec388 100644 --- a/tests/queries/0_stateless/01029_early_constant_folding.reference +++ b/tests/queries/0_stateless/01029_early_constant_folding.reference @@ -2,7 +2,7 @@ SELECT 1 WHERE 0 SELECT 1 SELECT 1 -WHERE 0 +WHERE (1 IN (0, 2)) AND (2 = (identity(cast(2, \'UInt8\')) AS subquery)) SELECT 1 WHERE 1 IN ( ( diff --git a/tests/queries/0_stateless/01029_early_constant_folding.sql b/tests/queries/0_stateless/01029_early_constant_folding.sql index 428c3625295..6336b62e080 100644 --- a/tests/queries/0_stateless/01029_early_constant_folding.sql +++ b/tests/queries/0_stateless/01029_early_constant_folding.sql @@ -4,7 +4,7 @@ EXPLAIN SYNTAX SELECT 1 WHERE 1 = 0; EXPLAIN SYNTAX SELECT 1 WHERE 1 IN (0, 1, 2); -EXPLAIN SYNTAX SELECT 1 WHERE 1 IN (0, 2) AND 2 = (SELECT 2); +EXPLAIN SYNTAX SELECT 1 WHERE 1 IN (0, 2) AND 2 = ((SELECT 2) AS subquery); -- no constant folding diff --git a/tests/queries/0_stateless/01611_constant_folding_subqueries.reference b/tests/queries/0_stateless/01611_constant_folding_subqueries.reference index ac91b53b754..d10502c5860 100644 --- a/tests/queries/0_stateless/01611_constant_folding_subqueries.reference +++ b/tests/queries/0_stateless/01611_constant_folding_subqueries.reference @@ -7,3 +7,5 @@ EXPLAIN SYNTAX SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUI SELECT identity(cast(0, \'UInt64\')) AS n, toUInt64(10 / n) +SELECT * FROM (WITH (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n) as q SELECT * FROM system.one WHERE q > 0); +0 diff --git a/tests/queries/0_stateless/01611_constant_folding_subqueries.sql b/tests/queries/0_stateless/01611_constant_folding_subqueries.sql index abf67a8ed6a..59f057d1ec5 100644 --- a/tests/queries/0_stateless/01611_constant_folding_subqueries.sql +++ b/tests/queries/0_stateless/01611_constant_folding_subqueries.sql @@ -2,3 +2,4 @@ SELECT * FROM (SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n)) FORMAT CSV; SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n) FORMAT CSV; EXPLAIN SYNTAX SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n); +SELECT * FROM (WITH (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n) as q SELECT * FROM system.one WHERE q > 0);