diff --git a/src/Interpreters/ExpressionAnalyzer.cpp b/src/Interpreters/ExpressionAnalyzer.cpp index 4146f0c3391b9ee67985e89b76ce6d2dd1b1eee2..38649606e49935f0c23dd20d1be3f86274f21153 100644 --- a/src/Interpreters/ExpressionAnalyzer.cpp +++ b/src/Interpreters/ExpressionAnalyzer.cpp @@ -658,7 +658,12 @@ ActionsDAGPtr SelectQueryExpressionAnalyzer::appendPrewhere( step.required_output.push_back(prewhere_column_name); step.can_remove_required_output.push_back(true); - auto filter_type = (*step.actions()->getIndex().find(prewhere_column_name))->result_type; + const auto & index = step.actions()->getIndex(); + auto it = index.find(prewhere_column_name); + if (it == index.end()) + throw Exception(ErrorCodes::UNKNOWN_IDENTIFIER, "Unknown identifier: '{}'", prewhere_column_name); + + auto filter_type = (*it)->result_type; if (!filter_type->canBeUsedInBooleanContext()) throw Exception("Invalid type for filter in PREWHERE: " + filter_type->getName(), ErrorCodes::ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER); @@ -758,7 +763,12 @@ bool SelectQueryExpressionAnalyzer::appendWhere(ExpressionActionsChain & chain, step.required_output.push_back(where_column_name); step.can_remove_required_output = {true}; - auto filter_type = (*step.actions()->getIndex().find(where_column_name))->result_type; + const auto & index = step.actions()->getIndex(); + auto it = index.find(where_column_name); + if (it == index.end()) + throw Exception(ErrorCodes::UNKNOWN_IDENTIFIER, "Unknown identifier: '{}'", where_column_name); + + auto filter_type = (*it)->result_type; if (!filter_type->canBeUsedInBooleanContext()) throw Exception("Invalid type for filter in WHERE: " + filter_type->getName(), ErrorCodes::ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER); diff --git a/tests/queries/0_stateless/01674_where_prewhere_array_crash.reference b/tests/queries/0_stateless/01674_where_prewhere_array_crash.reference new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/queries/0_stateless/01674_where_prewhere_array_crash.sql b/tests/queries/0_stateless/01674_where_prewhere_array_crash.sql new file mode 100644 index 0000000000000000000000000000000000000000..d6eef000b3604a9930fdb60f307859a0fc98c7ee --- /dev/null +++ b/tests/queries/0_stateless/01674_where_prewhere_array_crash.sql @@ -0,0 +1,5 @@ +drop table if exists tab; +create table tab (x UInt64, `arr.a` Array(UInt64), `arr.b` Array(UInt64)) engine = MergeTree order by x; +select x from tab array join arr prewhere x != 0 where arr; -- { serverError 47; } +select x from tab array join arr prewhere arr where x != 0; -- { serverError 47; } +drop table if exists tab;