This commit is contained in:
kssenii 2022-07-30 15:36:01 +03:00
parent efff78819a
commit d66c108a04
7 changed files with 26 additions and 14 deletions

View File

@ -1239,6 +1239,21 @@ TreeRewriterResultPtr TreeRewriter::analyzeSelect(
source_columns_set, right_table.table.getQualifiedNamePrefix());
}
translateQualifiedNames(query, *select_query, source_columns_set, tables_with_columns);
/// Optimizes logical expressions.
LogicalExpressionsOptimizer(select_query, settings.optimize_min_equality_disjunction_chain_length.value).perform();
NameSet all_source_columns_set = source_columns_set;
if (table_join)
{
for (const auto & [name, _] : table_join->columns_from_joined_table)
all_source_columns_set.insert(name);
}
normalize(query, result.aliases, all_source_columns_set, select_options.ignore_alias, settings, /* allow_self_aliases = */ true, getContext());
if (getContext()->getSettingsRef().enable_positional_arguments)
{
if (select_query->groupBy())
@ -1258,20 +1273,6 @@ TreeRewriterResultPtr TreeRewriter::analyzeSelect(
}
}
translateQualifiedNames(query, *select_query, source_columns_set, tables_with_columns);
/// Optimizes logical expressions.
LogicalExpressionsOptimizer(select_query, settings.optimize_min_equality_disjunction_chain_length.value).perform();
NameSet all_source_columns_set = source_columns_set;
if (table_join)
{
for (const auto & [name, _] : table_join->columns_from_joined_table)
all_source_columns_set.insert(name);
}
normalize(query, result.aliases, all_source_columns_set, select_options.ignore_alias, settings, /* allow_self_aliases = */ true, getContext());
/// Remove unneeded columns according to 'required_result_columns'.
/// Leave all selected columns in case of DISTINCT; columns that contain arrayJoin function inside.
/// Must be after 'normalizeTree' (after expanding aliases, for aliases not get lost)

View File

@ -8,6 +8,11 @@
namespace DB
{
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
bool replaceForPositionalArguments(ASTPtr & argument, const ASTSelectQuery * select_query, ASTSelectQuery::Expression expression)
{
auto columns = select_query->select()->children;

View File

@ -1,3 +1,4 @@
#pragma once
#include <Parsers/ASTSelectQuery.h>
namespace DB

View File

@ -1,5 +1,7 @@
-- Tags: shard
set enable_positional_arguments=0;
select 40 as z from (select * from system.numbers limit 3) group by z;
select 41 as z from remote('127.0.0.{2,3}', system.one) group by z;
select count(), 42 AS z from remote('127.0.0.{2,3}', system.one) group by z;

View File

@ -1,6 +1,7 @@
drop table if exists t;
create table t(n int, a Int64, s String) engine = MergeTree() order by a;
set enable_positional_arguments=0;
set optimize_trivial_insert_select=1;
-- due to aggregate functions, optimize_trivial_insert_select will not be applied

View File

@ -8,6 +8,7 @@ CREATE TABLE test
ENGINE = MergeTree()
ORDER BY tuple();
SET enable_positional_arguments=0;
SET optimize_move_functions_out_of_any = 1;
SELECT any(arrayFilter((c, d) -> (4 = d), `Source.C1`, `Source.C2`)[1]) AS x

View File

@ -12,6 +12,7 @@ SELECT c0 + -1, sum(intDivOrZero(intDivOrZero(NULL, NULL), '2'), intDivOrZero(10
SELECT sum(c0 + 257) FROM t_having GROUP BY c0 = -9223372036854775808, NULL, -2147483649, c0 HAVING c0 = -9223372036854775808 SETTINGS enable_optimize_predicate_expression = 0;
SET enable_positional_arguments=0;
SELECT c0 + -2, c0 + -9223372036854775807, c0 = NULL FROM t_having GROUP BY c0 = 0.9998999834060669, 1023, c0 HAVING c0 = 0.9998999834060669 SETTINGS enable_optimize_predicate_expression = 0;
DROP TABLE t_having;