dbms: Server: Use another hash function. [#METR-17276]

This commit is contained in:
Alexey Arno 2015-08-12 19:26:53 +03:00
parent 18ed0b2829
commit 3ff1a857fe
2 changed files with 71 additions and 88 deletions

View File

@ -98,7 +98,7 @@ struct AggregateFunctionUniqExactData<String>
template <typename T>
struct AggregateFunctionUniqCombinedData
{
using Key = T;
using Key = UInt32;
using Set = CombinedCardinalityEstimator<Key, HashSet<Key, TrivialHash, HashTableGrower<> >, 16, 14, 17, TrivialHash>;
Set set;
@ -118,30 +118,6 @@ struct AggregateFunctionUniqCombinedData<String>
namespace detail
{
/** Хэширование 64-битных целочисленных значений в 32-битные.
* Источник: https://gist.github.com/badboy/6267743
*/
template<typename T, typename Enable = void>
struct Hash64To32;
template<typename T>
struct Hash64To32<T, typename std::enable_if<std::is_same<T, Int64>::value || std::is_same<T, UInt64>::value>::type>
{
static UInt32 compute(T key)
{
using U = typename std::make_unsigned<T>::type;
auto x = static_cast<U>(key);
x = (~x) + (x << 18);
x = x ^ (x >> 31);
x = x * 21;
x = x ^ (x >> 11);
x = x + (x << 6);
x = x ^ (x >> 22);
return static_cast<UInt32>(x);
}
};
/** Хэш-функция для uniqCombined.
*/
template<typename T, typename Enable = void>
@ -154,26 +130,33 @@ struct CombinedCardinalityTraits
};
template<typename T>
struct CombinedCardinalityTraits<T, typename std::enable_if<std::is_same<T, Int64>::value || std::is_same<T, UInt64>::value>::type>
struct CombinedCardinalityTraits<T, typename std::enable_if<std::is_same<T, Int64>::value>::type>
{
using Op = Hash64To32<T>;
using U = typename std::make_unsigned<T>::type;
static UInt32 hash(T key)
{
return Op::compute(key);
return intHash32<0>(static_cast<U>(key));
};
};
template<typename T>
struct CombinedCardinalityTraits<T, typename std::enable_if<std::is_same<T, UInt64>::value>::type>
{
static UInt32 hash(T key)
{
return intHash32<0>(key);
};
};
template<typename T>
struct CombinedCardinalityTraits<T, typename std::enable_if<std::is_same<T, Float64>::value>::type>
{
using Op = Hash64To32<UInt64>;
static UInt32 hash(T key)
{
UInt64 res = 0;
memcpy(reinterpret_cast<char *>(&res), reinterpret_cast<char *>(&key), sizeof(key));
return Op::compute(res);
return intHash32<0>(res);
}
};

View File

@ -239,25 +239,25 @@
31 162
35 162
36 162
0 53988
1 54083
3 53994
6 53948
7 54209
9 54112
10 27000
11 54058
13 54158
14 53926
17 54094
19 54127
20 54065
21 54207
22 54056
26 53982
31 54156
35 53960
36 54076
0 54226
1 54034
3 54016
6 53982
7 54076
9 54218
10 27075
11 54093
13 54108
14 54096
17 54294
19 54070
20 54028
21 54170
22 54106
26 54103
31 54050
35 54130
36 53868
0.125 1
0.5 1
0.05 1
@ -291,25 +291,25 @@
0.043 162
0.037 162
0.071 162
0.045 54207
0.125 54209
0.5 54083
0.05 54127
0.143 53948
0.091 27000
0.056 54094
0.048 54065
0.083 54058
0.25 53994
1 53988
0.1 54112
0.028 53960
0.027 54076
0.031 54156
0.067 53926
0.043 54056
0.037 53982
0.071 54158
0.045 54170
0.125 54076
0.5 54034
0.05 54070
0.143 53982
0.091 27075
0.056 54294
0.048 54028
0.083 54093
0.25 54016
1 54226
0.1 54218
0.028 54130
0.027 53868
0.031 54050
0.067 54096
0.043 54106
0.037 54103
0.071 54108
0.5 1
0.05 1
0.25 1
@ -343,25 +343,25 @@
0.037 162
0.1 163
1 162
0.5 54083
0.05 54127
0.25 53994
0.048 54065
0.091 27000
0.043 54056
0.071 54158
0.083 54058
0.125 54209
0.031 54156
0.143 53948
0.028 53960
0.067 53926
0.045 54207
0.027 54076
0.056 54094
0.037 53982
0.1 54112
1 53988
0.5 54034
0.05 54070
0.25 54016
0.048 54028
0.091 27075
0.043 54106
0.071 54108
0.083 54093
0.125 54076
0.031 54050
0.143 53982
0.028 54130
0.067 54096
0.045 54170
0.027 53868
0.056 54294
0.037 54103
0.1 54218
1 54226
1 1
3 1
6 1