Repository navigation
Backport #123796 to 26.8: Derive optimize_and_compare_chain ranges through a DateTime constant compared with DateTime64 - #124065
Conversation
…through a `DateTime` constant compared with `DateTime64`
|
Workflow [BackportPR], commit [f709699] Summary: ✅ |
|
@groeneai please investigate what is broken here |
…his branch tryConvertFieldToTypeExact comes from #121078, which is not on this branch. At this call site only a widening conversion (DateTime or lower-scale DateTime64 to DateTime64) reaches it, which is exact or overflows to Null, so the strict tryConvertFieldToType gives the same result. In 05330, the "implied condition is not duplicated" case compares `a` with a DateTime64 constant instead of a DateTime one: on this branch the existing `a < <DateTime>` conjunct hits TYPE_MISMATCH in tryConvertToColumnType (#117903, fixed on master by #121078), so it is not seen as implying the derived bound. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@yariks5s, the build fails on one missing function: I pushed a one-commit fix for each branch to my fork. Each is a fast-forward of the robot branch: Each commit changes 3 lines:
Validation: I built both branches with the fix (Debug). 05330 fails on the |
|
@groeneai please fix it |
|
@yariks5s, I cannot push to |
|
@yariks5s groeneai has no permission to commit to public backport PRs |
|
@groeneai create a patch that will fix conflicts in this backport |
|
@yariks5s, there is no merge conflict here: the branch merges cleanly but does not compile, because diff --git a/src/Analyzer/Passes/LogicalExpressionOptimizerPass.cpp b/src/Analyzer/Passes/LogicalExpressionOptimizerPass.cpp
--- a/src/Analyzer/Passes/LogicalExpressionOptimizerPass.cpp
+++ b/src/Analyzer/Passes/LogicalExpressionOptimizerPass.cpp
@@ -2212,7 +2212,7 @@ class LogicalExpressionOptimizerVisitor : public InDepthQueryTreeVisitorWithCont
converted = tryConvertFieldToType(
constant_node->getValue(), *other_type, constant_type.get(), getFormatSettings(getContext()));
else if (isLowerScaleTimePoint(constant_type, other_type))
- converted = tryConvertFieldToTypeExact(constant_node->getValue(), *other_type, constant_type.get());
+ converted = tryConvertFieldToType(constant_node->getValue(), *other_type, constant_type.get(), {}, /*strict=*/true);
if (converted.isNull())
return {};
diff --git a/tests/queries/0_stateless/05330_optimize_and_compare_chain_time_point_constant_scale.sql b/tests/queries/0_stateless/05330_optimize_and_compare_chain_time_point_constant_scale.sql
--- a/tests/queries/0_stateless/05330_optimize_and_compare_chain_time_point_constant_scale.sql
+++ b/tests/queries/0_stateless/05330_optimize_and_compare_chain_time_point_constant_scale.sql
@@ -84,12 +84,12 @@ SELECT 'overflowing constant stays unchained',
SELECT 'implied condition is not duplicated',
(SELECT count() FROM (EXPLAIN QUERY TREE
SELECT * FROM values('a DateTime64(6, \'UTC\'), b DateTime64(6, \'UTC\')', ('2020-01-01 00:00:00', '2020-01-01 00:00:01'))
- WHERE a < b AND b < toDateTime('2020-01-01 00:00:02', 'UTC') AND a < toDateTime('2020-01-01 00:00:02', 'UTC')
+ WHERE a < b AND b < toDateTime('2020-01-01 00:00:02', 'UTC') AND a < toDateTime64('2020-01-01 00:00:02', 6, 'UTC')
SETTINGS optimize_and_compare_chain = 1) WHERE explain LIKE '%function_name: less,%')
=
(SELECT count() FROM (EXPLAIN QUERY TREE
SELECT * FROM values('a DateTime64(6, \'UTC\'), b DateTime64(6, \'UTC\')', ('2020-01-01 00:00:00', '2020-01-01 00:00:01'))
- WHERE a < b AND b < toDateTime('2020-01-01 00:00:02', 'UTC') AND a < toDateTime('2020-01-01 00:00:02', 'UTC')
+ WHERE a < b AND b < toDateTime('2020-01-01 00:00:02', 'UTC') AND a < toDateTime64('2020-01-01 00:00:02', 6, 'UTC')
SETTINGS optimize_and_compare_chain = 0) WHERE explain LIKE '%function_name: less,%');
-- The derived condition carries a typed constant, which is sent to the shards as is.The test change is needed because on these branches the As a |
Original pull-request #123796
This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.
The PR source
The PR is created in the CI job
Version info
26.8.26.4