Merge pull request #71517 from ClickHouse/backport/24.8/71476

Backport #71476 to 24.8: Fix constants in WHERE expression which could apparently contain Join.
This commit is contained in:
robot-clickhouse 2024-11-06 16:17:35 +01:00 committed by GitHub
commit f8bd728c73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 2 deletions

View File

@ -1960,7 +1960,9 @@ ExpressionAnalysisResult::ExpressionAnalysisResult(
Block before_prewhere_sample = source_header;
if (sanitizeBlock(before_prewhere_sample))
{
before_prewhere_sample = prewhere_dag_and_flags->dag.updateHeader(before_prewhere_sample);
ExpressionActions(
prewhere_dag_and_flags->dag.clone(),
ExpressionActionsSettings::fromSettings(context->getSettingsRef())).execute(before_prewhere_sample);
auto & column_elem = before_prewhere_sample.getByName(query.prewhere()->getColumnName());
/// If the filter column is a constant, record it.
if (column_elem.column)
@ -1992,7 +1994,9 @@ ExpressionAnalysisResult::ExpressionAnalysisResult(
before_where_sample = source_header;
if (sanitizeBlock(before_where_sample))
{
before_where_sample = before_where->dag.updateHeader(before_where_sample);
ExpressionActions(
before_where->dag.clone(),
ExpressionActionsSettings::fromSettings(context->getSettingsRef())).execute(before_where_sample);
auto & column_elem
= before_where_sample.getByName(query.where()->getColumnName());

View File

@ -0,0 +1,23 @@
WITH
multiIf('-1' = '-1', 10080, '-1' = '7', 60, '-1' = '1', 5, 1440) AS interval_start, -- noqa
multiIf('-1' = '-1', CEIL((today() - toDate('2017-06-22')) / 7)::UInt16, '-1' = '7', 168, '-1' = '1', 288, 90) AS days_run, -- noqa:L045
block_time as (SELECT arrayJoin(
arrayMap(
i -> toDateTime(toStartOfInterval(now(), INTERVAL interval_start MINUTE) - interval_start * 60 * i, 'UTC'),
range(days_run)
)
)),
sales AS (
SELECT
toDateTime(toStartOfInterval(now(), INTERVAL interval_start MINUTE), 'UTC') AS block_time
FROM
numbers(1)
GROUP BY
block_time
ORDER BY
block_time)
SELECT
block_time
FROM sales where block_time >= (SELECT MIN(block_time) FROM sales) format Null;