fix null minmax

This commit is contained in:
Nikita Vasilev 2019-05-12 20:01:36 +03:00
parent 8ef7f3589a
commit 3e02eaf28d
3 changed files with 63 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);
}
}

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;