Better check

This commit is contained in:
kssenii 2021-05-22 16:33:08 +00:00
parent 5606e248a7
commit 1ffaf1d793
2 changed files with 31 additions and 15 deletions

View File

@ -599,22 +599,30 @@ bool KeyCondition::canConstantBeWrappedByMonotonicFunctions(
Field & out_value, Field & out_value,
DataTypePtr & out_type) DataTypePtr & out_type)
{ {
auto adjusted_node = node->clone(); const auto & sample_block = key_expr->getSampleBlock();
KeyDescription::moduloToModuloLegacyRecursive(adjusted_node);
String adjusted_expr_name = adjusted_node->getColumnName();
// Constant expr should use alias names if any // Constant expr should use alias names if any
String passed_expr_name = node->getColumnName(); String passed_expr_name = node->getColumnName();
String expr_name; String expr_name;
const auto & sample_block = key_expr->getSampleBlock(); /// sample_block from key_expr cannot contain modulo and moduloLegacy at the same time.
/// For partition key it is always moduloLegacy.
if (sample_block.has(passed_expr_name)) if (sample_block.has(passed_expr_name))
{
expr_name = passed_expr_name; expr_name = passed_expr_name;
else if (sample_block.has(adjusted_expr_name)) }
expr_name = adjusted_expr_name;
else else
{
auto adjusted_ast = node->clone();
KeyDescription::moduloToModuloLegacyRecursive(adjusted_ast);
String adjusted_expr_name = adjusted_ast->getColumnName();
if (!sample_block.has(adjusted_expr_name))
return false; return false;
expr_name = adjusted_expr_name;
}
/// TODO Nullable index is not yet landed. /// TODO Nullable index is not yet landed.
if (out_value.isNull()) if (out_value.isNull())
return false; return false;
@ -677,22 +685,30 @@ bool KeyCondition::canConstantBeWrappedByMonotonicFunctions(
bool KeyCondition::canConstantBeWrappedByFunctions( bool KeyCondition::canConstantBeWrappedByFunctions(
const ASTPtr & ast, size_t & out_key_column_num, DataTypePtr & out_key_column_type, Field & out_value, DataTypePtr & out_type) const ASTPtr & ast, size_t & out_key_column_num, DataTypePtr & out_key_column_type, Field & out_value, DataTypePtr & out_type)
{ {
auto adjusted_ast = ast->clone(); const auto & sample_block = key_expr->getSampleBlock();
KeyDescription::moduloToModuloLegacyRecursive(adjusted_ast);
String adjusted_expr_name = adjusted_ast->getColumnName();
// Constant expr should use alias names if any // Constant expr should use alias names if any
String passed_expr_name = ast->getColumnName(); String passed_expr_name = ast->getColumnName();
String expr_name; String expr_name;
const auto & sample_block = key_expr->getSampleBlock(); /// sample_block from key_expr cannot contain modulo and moduloLegacy at the same time.
/// For partition key it is always moduloLegacy.
if (sample_block.has(passed_expr_name)) if (sample_block.has(passed_expr_name))
{
expr_name = passed_expr_name; expr_name = passed_expr_name;
else if (sample_block.has(adjusted_expr_name)) }
expr_name = adjusted_expr_name;
else else
{
auto adjusted_ast = ast->clone();
KeyDescription::moduloToModuloLegacyRecursive(adjusted_ast);
String adjusted_expr_name = adjusted_ast->getColumnName();
if (!sample_block.has(adjusted_expr_name))
return false; return false;
expr_name = adjusted_expr_name;
}
/// TODO Nullable index is not yet landed. /// TODO Nullable index is not yet landed.
if (out_value.isNull()) if (out_value.isNull())
return false; return false;

View File

@ -47,7 +47,7 @@ public:
static Block executePartitionByExpression(const StorageMetadataPtr & metadata_snapshot, Block & block, ContextPtr context); static Block executePartitionByExpression(const StorageMetadataPtr & metadata_snapshot, Block & block, ContextPtr context);
/// Make a modified partition key with substitution from modulo to moduloLegacy. Used in paritionPruner. /// Make a modified partition key with substitution from modulo to moduloLegacy. Used in paritionPruner.
static KeyDescription adjustPartitionKey(const StorageMetadataPtr & partition_key, ContextPtr context); static KeyDescription adjustPartitionKey(const StorageMetadataPtr & metadata_snapshot, ContextPtr context);
}; };
} }