Merge pull request #5246 from nikvas0/nikvas0/fix_minmax_null

[wip] fix null minmax
This commit is contained in:
alexey-milovidov 2019-05-25 16:11:23 +03:00 committed by GitHub
commit e0e35f3258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 6 deletions

View File

@ -32,9 +32,21 @@ void MergeTreeMinMaxGranule::serializeBinary(WriteBuffer & ostr) const
for (size_t i = 0; i < index.columns.size(); ++i)
{
const DataTypePtr & type = index.data_types[i];
type->serializeBinary(parallelogram[i].left, ostr);
type->serializeBinary(parallelogram[i].right, ostr);
if (!type->isNullable())
{
type->serializeBinary(parallelogram[i].left, ostr);
type->serializeBinary(parallelogram[i].right, ostr);
}
else
{
bool is_null = parallelogram[i].left.isNull() || parallelogram[i].right.isNull(); // one is enough
writeBinary(is_null, ostr);
if (!is_null)
{
type->serializeBinary(parallelogram[i].left, ostr);
type->serializeBinary(parallelogram[i].right, ostr);
}
}
}
}
@ -46,9 +58,26 @@ void MergeTreeMinMaxGranule::deserializeBinary(ReadBuffer & istr)
for (size_t i = 0; i < index.columns.size(); ++i)
{
const DataTypePtr & type = index.data_types[i];
type->deserializeBinary(min_val, istr);
type->deserializeBinary(max_val, istr);
if (!type->isNullable())
{
type->deserializeBinary(min_val, istr);
type->deserializeBinary(max_val, istr);
}
else
{
bool is_null;
readBinary(is_null, istr);
if (!is_null)
{
type->deserializeBinary(min_val, istr);
type->deserializeBinary(max_val, istr);
}
else
{
min_val = Null();
max_val = Null();
}
}
parallelogram.emplace_back(min_val, true, max_val, true);
}
}
@ -111,6 +140,9 @@ bool MinMaxCondition::mayBeTrueOnGranule(MergeTreeIndexGranulePtr idx_granule) c
if (!granule)
throw Exception(
"Minmax index condition got a granule with the wrong type.", ErrorCodes::LOGICAL_ERROR);
for (const auto & range : granule->parallelogram)
if (range.left.isNull() || range.right.isNull())
return true;
return condition.mayBeTrueInParallelogram(granule->parallelogram, index.data_types);
}

View File

@ -0,0 +1,4 @@
0
2
4
0

View File

@ -0,0 +1,24 @@
DROP TABLE IF EXISTS min_max_with_nullable_string;
SET allow_experimental_data_skipping_indices = 1;
CREATE TABLE min_max_with_nullable_string (
t DateTime,
nullable_str Nullable(String),
INDEX nullable_str_min_max nullable_str TYPE minmax GRANULARITY 8192
) ENGINE = MergeTree ORDER BY (t);
INSERT INTO min_max_with_nullable_string(t) VALUES (now()) (now());
SELECT count() FROM min_max_with_nullable_string WHERE nullable_str = '.';
INSERT INTO min_max_with_nullable_string(t, nullable_str) VALUES (now(), '.') (now(), '.');
SELECT count() FROM min_max_with_nullable_string WHERE nullable_str = '.';
INSERT INTO min_max_with_nullable_string(t, nullable_str) VALUES (now(), NULL) (now(), '.') (now(), NULL) (now(), '.') (now(), NULL);
SELECT count() FROM min_max_with_nullable_string WHERE nullable_str = '.';
SELECT count() FROM min_max_with_nullable_string WHERE nullable_str = '';
DROP TABLE min_max_with_nullable_string;