Merge pull request #38946 from amosbird/nullable-partition-fix1

Fix incorrect partition pruning when there is a nullable partition
This commit is contained in:
Nikolai Kochetov 2022-07-19 12:14:36 +02:00 committed by GitHub
commit d0db7135cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 0 deletions

View File

@ -15,9 +15,21 @@ bool PartitionPruner::canBePruned(const DataPart & part)
{
const auto & partition_value = part.partition.value;
std::vector<FieldRef> index_value(partition_value.begin(), partition_value.end());
for (auto & field : index_value)
{
// NULL_LAST
if (field.isNull())
field = POSITIVE_INFINITY;
}
is_valid = partition_condition.mayBeTrueInRange(
partition_value.size(), index_value.data(), index_value.data(), partition_key.data_types);
partition_filter_map.emplace(partition_id, is_valid);
if (!is_valid)
{
WriteBufferFromOwnString buf;
part.partition.serializeText(part.storage, buf, FormatSettings{});
LOG_TRACE(&Poco::Logger::get("PartitionPruner"), "Partition {} gets pruned", buf.str());
}
}
return !is_valid;
}

View File

@ -0,0 +1,9 @@
drop table if exists n;
create table n(nc Nullable(int)) engine = MergeTree order by (tuple()) partition by (nc) settings allow_nullable_key = 1;
insert into n values (null);
select * from n where nc is null;
drop table n;