mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Merge pull request #21766 from amosbird/indexfix
Fix scalar subquery index analysis
This commit is contained in:
commit
c08289517a
@ -444,7 +444,8 @@ bool KeyCondition::addCondition(const String & column, const Range & range)
|
||||
*/
|
||||
bool KeyCondition::getConstant(const ASTPtr & expr, Block & block_with_constants, Field & out_value, DataTypePtr & out_type)
|
||||
{
|
||||
String column_name = expr->getColumnNameWithoutAlias();
|
||||
// Constant expr should use alias names if any
|
||||
String column_name = expr->getColumnName();
|
||||
|
||||
if (const auto * lit = expr->as<ASTLiteral>())
|
||||
{
|
||||
@ -607,7 +608,8 @@ bool KeyCondition::canConstantBeWrappedByMonotonicFunctions(
|
||||
if (strict)
|
||||
return false;
|
||||
|
||||
String expr_name = node->getColumnNameWithoutAlias();
|
||||
// Constant expr should use alias names if any
|
||||
String expr_name = node->getColumnName();
|
||||
const auto & sample_block = key_expr->getSampleBlock();
|
||||
if (!sample_block.has(expr_name))
|
||||
return false;
|
||||
@ -675,7 +677,8 @@ bool KeyCondition::canConstantBeWrappedByFunctions(
|
||||
if (strict)
|
||||
return false;
|
||||
|
||||
String expr_name = ast->getColumnNameWithoutAlias();
|
||||
// Constant expr should use alias names if any
|
||||
String expr_name = ast->getColumnName();
|
||||
const auto & sample_block = key_expr->getSampleBlock();
|
||||
if (!sample_block.has(expr_name))
|
||||
return false;
|
||||
@ -1011,6 +1014,8 @@ bool KeyCondition::isKeyPossiblyWrappedByMonotonicFunctionsImpl(
|
||||
* Therefore, use the full name of the expression for search.
|
||||
*/
|
||||
const auto & sample_block = key_expr->getSampleBlock();
|
||||
|
||||
// Key columns should use canonical names for index analysis
|
||||
String name = node->getColumnNameWithoutAlias();
|
||||
|
||||
auto it = key_columns.find(name);
|
||||
|
@ -6,6 +6,6 @@ insert into alias_key_condition values (1, 2), (3, 4);
|
||||
|
||||
set force_primary_key = 1;
|
||||
|
||||
with i as k select * from alias_key_condition where k = 3;
|
||||
with i as k select * from alias_key_condition where k = (select i from alias_key_condition where i = 3);
|
||||
|
||||
drop table if exists alias_key_condition;
|
||||
|
Loading…
Reference in New Issue
Block a user