From 55fc095c9855acc7e1c06015d08a8ce6c2940748 Mon Sep 17 00:00:00 2001 From: alesapin Date: Mon, 11 Feb 2019 17:36:54 +0300 Subject: [PATCH] Fix big dates comparison with compile expressions (Date and DateTime are not signed types anymore). --- dbms/src/DataTypes/Native.h | 3 +-- dbms/src/Interpreters/ExpressionActions.cpp | 2 +- dbms/src/Interpreters/ExpressionJIT.cpp | 4 ++-- dbms/src/Interpreters/ExpressionJIT.h | 2 +- dbms/src/Interpreters/Settings.h | 1 + .../0_stateless/00745_compile_scalar_subquery.sql | 2 +- .../00746_compile_non_deterministic_function.sql | 2 +- ...compile_expressions_compare_big_dates.reference | 4 ++++ ...00905_compile_expressions_compare_big_dates.sql | 14 ++++++++++++++ 9 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 dbms/tests/queries/0_stateless/00905_compile_expressions_compare_big_dates.reference create mode 100644 dbms/tests/queries/0_stateless/00905_compile_expressions_compare_big_dates.sql diff --git a/dbms/src/DataTypes/Native.h b/dbms/src/DataTypes/Native.h index cf24a1b7b43..26191c17cbe 100644 --- a/dbms/src/DataTypes/Native.h +++ b/dbms/src/DataTypes/Native.h @@ -34,8 +34,7 @@ static inline bool typeIsSigned(const IDataType & type) { return typeIsEither< DataTypeInt8, DataTypeInt16, DataTypeInt32, DataTypeInt64, - DataTypeFloat32, DataTypeFloat64, - DataTypeDate, DataTypeDateTime, DataTypeInterval + DataTypeFloat32, DataTypeFloat64, DataTypeInterval >(type); } diff --git a/dbms/src/Interpreters/ExpressionActions.cpp b/dbms/src/Interpreters/ExpressionActions.cpp index e46790a0e56..08bb663a75b 100644 --- a/dbms/src/Interpreters/ExpressionActions.cpp +++ b/dbms/src/Interpreters/ExpressionActions.cpp @@ -812,7 +812,7 @@ void ExpressionActions::finalize(const Names & output_columns) /// This has to be done before removing redundant actions and inserting REMOVE_COLUMNs /// because inlining may change dependency sets. if (settings.compile_expressions) - compileFunctions(actions, output_columns, sample_block, compilation_cache, settings.min_count_to_compile); + compileFunctions(actions, output_columns, sample_block, compilation_cache, settings.min_count_to_compile_expression); #endif /// Which columns are needed to perform actions from the current to the last. diff --git a/dbms/src/Interpreters/ExpressionJIT.cpp b/dbms/src/Interpreters/ExpressionJIT.cpp index 223594db9b2..41a8e4e318b 100644 --- a/dbms/src/Interpreters/ExpressionJIT.cpp +++ b/dbms/src/Interpreters/ExpressionJIT.cpp @@ -654,7 +654,7 @@ std::vector>> getActionsDependents(cons return dependents; } -void compileFunctions(ExpressionActions::Actions & actions, const Names & output_columns, const Block & sample_block, std::shared_ptr compilation_cache, size_t min_count_to_compile) +void compileFunctions(ExpressionActions::Actions & actions, const Names & output_columns, const Block & sample_block, std::shared_ptr compilation_cache, size_t min_count_to_compile_expression) { static std::unordered_map counter; static std::mutex mutex; @@ -688,7 +688,7 @@ void compileFunctions(ExpressionActions::Actions & actions, const Names & output auto hash_key = ExpressionActions::ActionsHash{}(fused[i]); { std::lock_guard lock(mutex); - if (counter[hash_key]++ < min_count_to_compile) + if (counter[hash_key]++ < min_count_to_compile_expression) continue; } diff --git a/dbms/src/Interpreters/ExpressionJIT.h b/dbms/src/Interpreters/ExpressionJIT.h index f8c638cd03e..e66b5af3f2f 100644 --- a/dbms/src/Interpreters/ExpressionJIT.h +++ b/dbms/src/Interpreters/ExpressionJIT.h @@ -73,7 +73,7 @@ public: /// For each APPLY_FUNCTION action, try to compile the function to native code; if the only uses of a compilable /// function's result are as arguments to other compilable functions, inline it and leave the now-redundant action as-is. -void compileFunctions(ExpressionActions::Actions & actions, const Names & output_columns, const Block & sample_block, std::shared_ptr compilation_cache, size_t min_count_to_compile); +void compileFunctions(ExpressionActions::Actions & actions, const Names & output_columns, const Block & sample_block, std::shared_ptr compilation_cache, size_t min_count_to_compile_expression); } diff --git a/dbms/src/Interpreters/Settings.h b/dbms/src/Interpreters/Settings.h index 20b1e3cffaf..8660a1b9a91 100644 --- a/dbms/src/Interpreters/Settings.h +++ b/dbms/src/Interpreters/Settings.h @@ -77,6 +77,7 @@ struct Settings M(SettingBool, compile, false, "Whether query compilation is enabled.") \ M(SettingBool, compile_expressions, true, "Compile some scalar functions and operators to native code.") \ M(SettingUInt64, min_count_to_compile, 3, "The number of structurally identical queries before they are compiled.") \ + M(SettingUInt64, min_count_to_compile_expression, 3, "The number of identical expressions before they are JIT-compiled") \ M(SettingUInt64, group_by_two_level_threshold, 100000, "From what number of keys, a two-level aggregation starts. 0 - the threshold is not set.") \ M(SettingUInt64, group_by_two_level_threshold_bytes, 100000000, "From what size of the aggregation state in bytes, a two-level aggregation begins to be used. 0 - the threshold is not set. Two-level aggregation is used when at least one of the thresholds is triggered.") \ M(SettingBool, distributed_aggregation_memory_efficient, false, "Is the memory-saving mode of distributed aggregation enabled.") \ diff --git a/dbms/tests/queries/0_stateless/00745_compile_scalar_subquery.sql b/dbms/tests/queries/0_stateless/00745_compile_scalar_subquery.sql index 0ca0e9b8c7c..0012db98f0e 100644 --- a/dbms/tests/queries/0_stateless/00745_compile_scalar_subquery.sql +++ b/dbms/tests/queries/0_stateless/00745_compile_scalar_subquery.sql @@ -1,5 +1,5 @@ SET compile_expressions = 1; -SET min_count_to_compile = 1; +SET min_count_to_compile_expression = 1; SET optimize_move_to_prewhere = 0; SET enable_optimize_predicate_expression=0; diff --git a/dbms/tests/queries/0_stateless/00746_compile_non_deterministic_function.sql b/dbms/tests/queries/0_stateless/00746_compile_non_deterministic_function.sql index 3e83a2284c9..3ca3148b9d6 100644 --- a/dbms/tests/queries/0_stateless/00746_compile_non_deterministic_function.sql +++ b/dbms/tests/queries/0_stateless/00746_compile_non_deterministic_function.sql @@ -1,5 +1,5 @@ SET compile_expressions = 1; -SET min_count_to_compile = 1; +SET min_count_to_compile_expression = 1; DROP TABLE IF EXISTS test.time_table; diff --git a/dbms/tests/queries/0_stateless/00905_compile_expressions_compare_big_dates.reference b/dbms/tests/queries/0_stateless/00905_compile_expressions_compare_big_dates.reference new file mode 100644 index 00000000000..c97590e397a --- /dev/null +++ b/dbms/tests/queries/0_stateless/00905_compile_expressions_compare_big_dates.reference @@ -0,0 +1,4 @@ +2019-02-06 +2019-02-07 +2019-02-08 +2021-02-06 diff --git a/dbms/tests/queries/0_stateless/00905_compile_expressions_compare_big_dates.sql b/dbms/tests/queries/0_stateless/00905_compile_expressions_compare_big_dates.sql new file mode 100644 index 00000000000..6917714e091 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00905_compile_expressions_compare_big_dates.sql @@ -0,0 +1,14 @@ +SET compile_expressions = 1; +SET min_count_to_compile_expression = 1; + +DROP TABLE IF EXISTS test.foo_c; + +CREATE TABLE test.foo_c(d DateTime) ENGINE = Memory; + +INSERT INTO test.foo_c VALUES ('2019-02-06 01:01:01'),('2019-02-07 01:01:01'),('2019-02-08 01:01:01'),('2021-02-06 01:01:01'),('2093-05-29 01:01:01'),('2100-06-06 01:01:01'),('2100-10-14 01:01:01'),('2100-11-01 01:01:01'),('2100-11-15 01:01:01'),('2100-11-30 01:01:01'),('2100-12-11 01:01:01'),('2100-12-21 01:01:01'); + +SELECT toDate(d) AS dd FROM test.foo_c WHERE (dd >= '2019-02-06') AND (toDate(d) <= toDate('2019-08-09')) GROUP BY dd ORDER BY dd; + +SELECT toDate(d) FROM test.foo_c WHERE (d > toDate('2019-02-10')) AND (d <= toDate('2022-01-01')) ORDER BY d; + +DROP TABLE IF EXISTS test.foo_c;