mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
dbms: improved performance of aggregation by string key [#METR-2944].
This commit is contained in:
parent
82a44f8eec
commit
95827e2dc2
@ -74,6 +74,25 @@ struct HashMapCell
|
||||
};
|
||||
|
||||
|
||||
template <typename Key, typename TMapped, typename Hash, typename TState = HashTableNoState>
|
||||
struct HashMapCellWithSavedHash : public HashMapCell<Key, TMapped, Hash, TState>
|
||||
{
|
||||
typedef HashMapCell<Key, TMapped, Hash, TState> Base;
|
||||
|
||||
size_t saved_hash;
|
||||
|
||||
HashMapCellWithSavedHash() : Base() {}
|
||||
HashMapCellWithSavedHash(const Key & key_, const typename Base::State & state) : Base(key_, state) {}
|
||||
HashMapCellWithSavedHash(const typename Base::value_type & value_, const typename Base::State & state) : Base(value_, state) {}
|
||||
|
||||
bool keyEquals(const Key & key_) const { return this->value.first == key_; }
|
||||
bool keyEquals(const HashMapCellWithSavedHash & other) const { return saved_hash == other.saved_hash && this->value.first == other.value.first; }
|
||||
|
||||
void setHash(size_t hash_value) { saved_hash = hash_value; }
|
||||
size_t getHash(const Hash & hash) const { return saved_hash; }
|
||||
};
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename Key,
|
||||
@ -112,3 +131,14 @@ template
|
||||
typename Allocator = HashTableAllocator
|
||||
>
|
||||
using HashMap = HashMapTable<Key, HashMapCell<Key, Mapped, Hash>, Hash, Grower, Allocator>;
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename Key,
|
||||
typename Mapped,
|
||||
typename Hash = DefaultHash<Key>,
|
||||
typename Grower = HashTableGrower<>,
|
||||
typename Allocator = HashTableAllocator
|
||||
>
|
||||
using HashMapWithSavedHash = HashMapTable<Key, HashMapCellWithSavedHash<Key, Mapped, Hash>, Hash, Grower, Allocator>;
|
||||
|
@ -14,15 +14,16 @@
|
||||
template
|
||||
<
|
||||
typename Key,
|
||||
typename TCell,
|
||||
typename Hash = DefaultHash<Key>,
|
||||
typename Grower = HashTableGrower<>,
|
||||
typename Allocator = HashTableAllocator
|
||||
>
|
||||
class HashSet : public HashTable<Key, HashTableCell<Key, Hash>, Hash, Grower, Allocator>
|
||||
class HashSetTable : public HashTable<Key, TCell, Hash, Grower, Allocator>
|
||||
{
|
||||
public:
|
||||
typedef HashSet<Key, Hash, Grower, Allocator> Self;
|
||||
typedef HashTableCell<Key, Hash> Cell;
|
||||
typedef HashSetTable<Key, TCell, Hash, Grower, Allocator> Self;
|
||||
typedef TCell Cell;
|
||||
|
||||
void merge(const Self & rhs)
|
||||
{
|
||||
@ -55,3 +56,41 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Key, typename Hash, typename TState = HashTableNoState>
|
||||
struct HashSetCellWithSavedHash : public HashTableCell<Key, Hash, TState>
|
||||
{
|
||||
typedef HashTableCell<Key, Hash, TState> Base;
|
||||
|
||||
size_t saved_hash;
|
||||
|
||||
HashSetCellWithSavedHash() : Base() {}
|
||||
HashSetCellWithSavedHash(const Key & key_, const typename Base::State & state) : Base(key_, state) {}
|
||||
|
||||
bool keyEquals(const Key & key_) const { return this->key == key_; }
|
||||
bool keyEquals(const HashSetCellWithSavedHash & other) const { return saved_hash == other.saved_hash && this->key == other.key; }
|
||||
|
||||
void setHash(size_t hash_value) { saved_hash = hash_value; }
|
||||
size_t getHash(const Hash & hash) const { return saved_hash; }
|
||||
};
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename Key,
|
||||
typename Hash = DefaultHash<Key>,
|
||||
typename Grower = HashTableGrower<>,
|
||||
typename Allocator = HashTableAllocator
|
||||
>
|
||||
using HashSet = HashSetTable<Key, HashTableCell<Key, Hash>, Hash, Grower, Allocator>;
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename Key,
|
||||
typename Hash = DefaultHash<Key>,
|
||||
typename Grower = HashTableGrower<>,
|
||||
typename Allocator = HashTableAllocator
|
||||
>
|
||||
using HashSetWithSavedHash = HashSetTable<Key, HashSetCellWithSavedHash<Key, Hash>, Hash, Grower, Allocator>;
|
||||
|
@ -48,7 +48,7 @@ typedef std::vector<AggregateDescription> AggregateDescriptions;
|
||||
*/
|
||||
typedef AggregateDataPtr AggregatedDataWithoutKey;
|
||||
typedef HashMap<UInt64, AggregateDataPtr> AggregatedDataWithUInt64Key;
|
||||
typedef HashMap<StringRef, AggregateDataPtr> AggregatedDataWithStringKey;
|
||||
typedef HashMapWithSavedHash<StringRef, AggregateDataPtr> AggregatedDataWithStringKey;
|
||||
typedef HashMap<UInt128, AggregateDataPtr, UInt128Hash> AggregatedDataWithKeys128;
|
||||
typedef HashMap<UInt128, std::pair<StringRef*, AggregateDataPtr>, UInt128TrivialHash> AggregatedDataHashed;
|
||||
|
||||
|
@ -94,7 +94,7 @@ private:
|
||||
* одного или нескольких столбцов значений множеству.
|
||||
*/
|
||||
typedef HashSet<UInt64> SetUInt64;
|
||||
typedef HashSet<StringRef> SetString;
|
||||
typedef HashSetWithSavedHash<StringRef> SetString;
|
||||
typedef HashSet<UInt128, UInt128Hash> SetHashed;
|
||||
|
||||
BlockInputStreamPtr source;
|
||||
|
Loading…
Reference in New Issue
Block a user