OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OverlapsJoinHashTable.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef QUERYENGINE_OVERLAPSHASHTABLE_H
18 #define QUERYENGINE_OVERLAPSHASHTABLE_H
19 
20 #include "BaselineJoinHashTable.h"
21 
23  public:
24  OverlapsJoinHashTable(const std::shared_ptr<Analyzer::BinOper> condition,
25  const std::vector<InputTableInfo>& query_infos,
26  const Data_Namespace::MemoryLevel memory_level,
27  JoinHashTableInterface::HashType hash_layout_type,
28  const size_t entry_count,
29  ColumnCacheMap& column_cache,
30  Executor* executor,
31  const std::vector<InnerOuter>& inner_outer_pairs,
32  const int device_count)
33  : BaselineJoinHashTable(condition,
34  query_infos,
35  memory_level,
36  hash_layout_type,
37  entry_count,
38  column_cache,
39  executor,
40  inner_outer_pairs,
41  device_count) {}
42 
43  ~OverlapsJoinHashTable() override {}
44 
46  static std::shared_ptr<OverlapsJoinHashTable> getInstance(
47  const std::shared_ptr<Analyzer::BinOper> condition,
48  const std::vector<InputTableInfo>& query_infos,
49  const Data_Namespace::MemoryLevel memory_level,
50  const int device_count,
51  ColumnCacheMap& column_cache,
52  Executor* executor);
53 
54  static auto yieldCacheInvalidator() -> std::function<void()> {
55  VLOG(1) << "Invalidate " << auto_tuner_cache_.size() << " cached overlaps hashtable.";
56  return []() -> void {
57  std::lock_guard<std::mutex> guard(auto_tuner_cache_mutex_);
58  auto_tuner_cache_.clear();
59  };
60  }
61 
62  protected:
63  void reifyWithLayout(const JoinHashTableInterface::HashType layout) override;
64 
65  std::pair<size_t, size_t> calculateCounts(
66  size_t shard_count,
67  const Fragmenter_Namespace::TableInfo& query_info,
68  std::vector<BaselineJoinHashTable::ColumnsForDevice>& columns_per_device);
69 
70  size_t calculateHashTableSize(size_t number_of_dimensions,
71  size_t emitted_keys_count,
72  size_t entry_count) const;
73 
74  ColumnsForDevice fetchColumnsForDevice(
75  const std::vector<Fragmenter_Namespace::FragmentInfo>& fragments,
76  const int device_id,
77  DeviceAllocator* dev_buff_owner) override;
78 
79  std::vector<JoinBucketInfo> computeBucketInfo(
80  const std::vector<JoinColumn>& join_columns,
81  const std::vector<JoinColumnTypeInfo>& join_column_types,
82  const int device_id);
83 
84  std::pair<size_t, size_t> approximateTupleCount(
85  const std::vector<ColumnsForDevice>&) const override;
86 
87  size_t getKeyComponentWidth() const override;
88 
89  size_t getKeyComponentCount() const override;
90 
91  int initHashTableOnCpu(const std::vector<JoinColumn>& join_columns,
92  const std::vector<JoinColumnTypeInfo>& join_column_types,
93  const std::vector<JoinBucketInfo>& join_bucket_info,
94  const JoinHashTableInterface::HashType layout) override;
95 
96  int initHashTableOnGpu(const std::vector<JoinColumn>& join_columns,
97  const std::vector<JoinColumnTypeInfo>& join_column_types,
98  const std::vector<JoinBucketInfo>& join_bucket_info,
100  const size_t key_component_width,
101  const size_t key_component_count,
102  const int device_id) override;
103 
105  const size_t) override;
106 
107  static std::map<HashTableCacheKey, double> auto_tuner_cache_;
108  static std::mutex auto_tuner_cache_mutex_;
109 
110  private:
111  void computeBucketSizes(std::vector<double>& bucket_sizes_for_dimension,
112  const JoinColumn& join_column,
113  const JoinColumnTypeInfo& join_column_type,
114  const std::vector<InnerOuter>& inner_outer_pairs);
115 
116  llvm::Value* codegenKey(const CompilationOptions&) override;
117  std::vector<llvm::Value*> codegenManyKey(const CompilationOptions&);
118 
119  std::vector<double> bucket_sizes_for_dimension_;
121 };
122 
123 #endif // QUERYENGINE_OVERLAPSHASHTABLE_H
std::vector< double > bucket_sizes_for_dimension_
int initHashTableOnGpu(const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const std::vector< JoinBucketInfo > &join_bucket_info, const JoinHashTableInterface::HashType layout, const size_t key_component_width, const size_t key_component_count, const int device_id) override
static std::mutex auto_tuner_cache_mutex_
static std::shared_ptr< OverlapsJoinHashTable > getInstance(const std::shared_ptr< Analyzer::BinOper > condition, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, const int device_count, ColumnCacheMap &column_cache, Executor *executor)
Make hash table from an in-flight SQL query&#39;s parse tree etc.
ColumnsForDevice fetchColumnsForDevice(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, DeviceAllocator *dev_buff_owner) override
int initHashTableOnCpu(const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const std::vector< JoinBucketInfo > &join_bucket_info, const JoinHashTableInterface::HashType layout) override
static std::map< HashTableCacheKey, double > auto_tuner_cache_
size_t calculateHashTableSize(size_t number_of_dimensions, size_t emitted_keys_count, size_t entry_count) const
std::vector< JoinBucketInfo > computeBucketInfo(const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const int device_id)
llvm::Value * codegenKey(const CompilationOptions &) override
static auto yieldCacheInvalidator() -> std::function< void()>
OverlapsJoinHashTable(const std::shared_ptr< Analyzer::BinOper > condition, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, JoinHashTableInterface::HashType hash_layout_type, const size_t entry_count, ColumnCacheMap &column_cache, Executor *executor, const std::vector< InnerOuter > &inner_outer_pairs, const int device_count)
void computeBucketSizes(std::vector< double > &bucket_sizes_for_dimension, const JoinColumn &join_column, const JoinColumnTypeInfo &join_column_type, const std::vector< InnerOuter > &inner_outer_pairs)
std::vector< llvm::Value * > codegenManyKey(const CompilationOptions &)
std::pair< size_t, size_t > calculateCounts(size_t shard_count, const Fragmenter_Namespace::TableInfo &query_info, std::vector< BaselineJoinHashTable::ColumnsForDevice > &columns_per_device)
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults >>> ColumnCacheMap
void reifyWithLayout(const JoinHashTableInterface::HashType layout) override
HashJoinMatchingSet codegenMatchingSet(const CompilationOptions &, const size_t) override
size_t getKeyComponentCount() const override
std::pair< size_t, size_t > approximateTupleCount(const std::vector< ColumnsForDevice > &) const override
#define VLOG(n)
Definition: Logger.h:291
size_t getKeyComponentWidth() const override