Merge pull request #22235 from ClickHouse/quantile-deterministic-msan

Fix MSan report in `quantileDeterministic`
This commit is contained in:
alexey-milovidov 2021-03-30 03:48:58 +03:00 committed by GitHub
commit a6959584d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -13,6 +13,7 @@
#include <Common/NaNUtils.h>
#include <Poco/Exception.h>
namespace DB
{
namespace ErrorCodes
@ -162,6 +163,11 @@ public:
sorted = false;
}
#if !__clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#endif
void write(DB::WriteBuffer & buf) const
{
size_t size = samples.size();
@ -169,9 +175,26 @@ public:
DB::writeIntBinary<size_t>(total_values, buf);
for (size_t i = 0; i < size; ++i)
DB::writePODBinary(samples[i], buf);
{
/// There was a mistake in this function.
/// Instead of correctly serializing the elements,
/// it was writing them with uninitialized padding.
/// Here we ensure that padding is zero without changing the protocol.
/// TODO: After implementation of "versioning aggregate function state",
/// change the serialization format.
Element elem;
memset(&elem, 0, sizeof(elem));
elem = samples[i];
DB::writePODBinary(elem, buf);
}
}
#if !__clang__
#pragma GCC diagnostic pop
#endif
private:
/// We allocate some memory on the stack to avoid allocations when there are many objects with a small number of elements.
using Element = std::pair<T, UInt32>;

View File

@ -0,0 +1 @@
11447494982455782708

View File

@ -0,0 +1 @@
SELECT cityHash64(toString(quantileDeterministicState(number, sipHash64(number)))) FROM numbers(8193);