mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Pruning is different from counting
This commit is contained in:
parent
aa436a3cb1
commit
2b0085c106
@ -592,7 +592,15 @@ bool KeyCondition::canConstantBeWrappedByMonotonicFunctions(
|
||||
if (!sample_block.has(expr_name))
|
||||
return false;
|
||||
|
||||
/// TODO Nullable index is not yet landed.
|
||||
if (out_value.isNull())
|
||||
return false;
|
||||
|
||||
bool found_transformation = false;
|
||||
auto input_column = sample_block.getByName(expr_name);
|
||||
auto const_column = out_type->createColumnConst(1, out_value);
|
||||
out_value = (*castColumn({const_column, out_type, "c"}, input_column.type))[0];
|
||||
out_type = input_column.type;
|
||||
for (const ExpressionAction & action : key_expr->getActions())
|
||||
{
|
||||
/** The key functional expression constraint may be inferred from a plain column in the expression.
|
||||
@ -644,11 +652,18 @@ bool KeyCondition::canConstantBeWrappedByMonotonicFunctions(
|
||||
bool KeyCondition::canConstantBeWrappedByFunctions(
|
||||
const ASTPtr & node, size_t & out_key_column_num, DataTypePtr & out_key_column_type, Field & out_value, DataTypePtr & out_type)
|
||||
{
|
||||
if (strict)
|
||||
return false;
|
||||
|
||||
String expr_name = node->getColumnName();
|
||||
const auto & sample_block = key_expr->getSampleBlock();
|
||||
if (!sample_block.has(expr_name))
|
||||
return false;
|
||||
|
||||
/// TODO Nullable index is not yet landed.
|
||||
if (out_value.isNull())
|
||||
return false;
|
||||
|
||||
bool found_transformation = false;
|
||||
auto input_column = sample_block.getByName(expr_name);
|
||||
auto const_column = out_type->createColumnConst(1, out_value);
|
||||
@ -950,11 +965,15 @@ bool KeyCondition::tryParseAtomFromAST(const ASTPtr & node, const Context & cont
|
||||
bool is_set_const = false;
|
||||
bool is_constant_transformed = false;
|
||||
|
||||
if (functionIsInOrGlobalInOperator(func_name)
|
||||
&& tryPrepareSetIndex(args, context, out, key_column_num))
|
||||
if (functionIsInOrGlobalInOperator(func_name))
|
||||
{
|
||||
key_arg_pos = 0;
|
||||
is_set_const = true;
|
||||
if (tryPrepareSetIndex(args, context, out, key_column_num))
|
||||
{
|
||||
key_arg_pos = 0;
|
||||
is_set_const = true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (getConstant(args[1], block_with_constants, const_value, const_type))
|
||||
{
|
||||
|
@ -231,7 +231,7 @@ Pipe MergeTreeDataSelectExecutor::readFromParts(
|
||||
if (data.minmax_idx_expr)
|
||||
{
|
||||
minmax_idx_condition.emplace(query_info, context, data.minmax_idx_columns, data.minmax_idx_expr);
|
||||
partition_pruner.emplace(metadata_snapshot->getPartitionKey(), query_info, context);
|
||||
partition_pruner.emplace(metadata_snapshot->getPartitionKey(), query_info, context, false /* strict */);
|
||||
|
||||
if (settings.force_index_by_date && (minmax_idx_condition->alwaysUnknownOrTrue() && partition_pruner->isUseless()))
|
||||
{
|
||||
|
@ -21,10 +21,10 @@ private:
|
||||
using DataPartPtr = std::shared_ptr<const DataPart>;
|
||||
|
||||
public:
|
||||
PartitionPruner(const KeyDescription & partition_key_, const SelectQueryInfo & query_info, const Context & context)
|
||||
PartitionPruner(const KeyDescription & partition_key_, const SelectQueryInfo & query_info, const Context & context, bool strict)
|
||||
: partition_key(partition_key_)
|
||||
, partition_condition(
|
||||
query_info, context, partition_key.column_names, partition_key.expression, true /* single_point */, true /* strict */)
|
||||
query_info, context, partition_key.column_names, partition_key.expression, true /* single_point */, strict)
|
||||
, useless(partition_condition.alwaysUnknownOrTrue())
|
||||
{
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ std::optional<UInt64> StorageMergeTree::totalRows() const
|
||||
std::optional<UInt64> StorageMergeTree::totalRowsByPartitionPredicate(const SelectQueryInfo & query_info, const Context & context) const
|
||||
{
|
||||
auto metadata_snapshot = getInMemoryMetadataPtr();
|
||||
PartitionPruner partition_pruner(metadata_snapshot->getPartitionKey(), query_info, context);
|
||||
PartitionPruner partition_pruner(metadata_snapshot->getPartitionKey(), query_info, context, true /* strict */);
|
||||
if (partition_pruner.isUseless())
|
||||
return {};
|
||||
size_t res = 0;
|
||||
|
@ -3663,7 +3663,7 @@ std::optional<UInt64> StorageReplicatedMergeTree::totalRows() const
|
||||
std::optional<UInt64> StorageReplicatedMergeTree::totalRowsByPartitionPredicate(const SelectQueryInfo & query_info, const Context & context) const
|
||||
{
|
||||
auto metadata_snapshot = getInMemoryMetadataPtr();
|
||||
PartitionPruner partition_pruner(metadata_snapshot->getPartitionKey(), query_info, context);
|
||||
PartitionPruner partition_pruner(metadata_snapshot->getPartitionKey(), query_info, context, true /* strict */);
|
||||
if (partition_pruner.isUseless())
|
||||
return {};
|
||||
size_t res = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user