OmniSciDB  5ade3759e0
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  const size_t entry_count,
28  ColumnCacheMap& column_map,
29  Executor* executor,
30  const std::vector<InnerOuter>& inner_outer_pairs)
31  : BaselineJoinHashTable(condition,
32  query_infos,
33  memory_level,
35  entry_count,
36  column_map,
37  executor,
38  inner_outer_pairs) {}
39 
40  ~OverlapsJoinHashTable() override {}
41 
42  static std::shared_ptr<OverlapsJoinHashTable> getInstance(
43  const std::shared_ptr<Analyzer::BinOper> condition,
44  const std::vector<InputTableInfo>& query_infos,
45  const Data_Namespace::MemoryLevel memory_level,
46  const int device_count,
47  ColumnCacheMap& column_map,
48  Executor* executor);
49 
50  size_t countBufferOff() const noexcept override {
51  LOG(FATAL) << "Not supported for this layout";
52  return 0;
53  }
54 
55  size_t payloadBufferOff() const noexcept override {
56  LOG(FATAL) << "Not supported for this layout";
57  return 0;
58  }
59 
60  static auto yieldCacheInvalidator() -> std::function<void()> {
61  return []() -> void {
62  std::lock_guard<std::mutex> guard(auto_tuner_cache_mutex_);
63  auto_tuner_cache_.clear();
64  };
65  }
66 
67  protected:
68  void reifyWithLayout(const int device_count,
69  const JoinHashTableInterface::HashType layout) override;
70 
71  std::pair<size_t, size_t> calculateCounts(
72  size_t shard_count,
73  const Fragmenter_Namespace::TableInfo& query_info,
74  const int device_count,
75  std::vector<BaselineJoinHashTable::ColumnsForDevice>& columns_per_device);
76 
77  size_t calculateHashTableSize(size_t number_of_dimensions,
78  size_t emitted_keys_count,
79  size_t entry_count) const;
80 
82  const std::deque<Fragmenter_Namespace::FragmentInfo>& fragments,
83  const int device_id) override;
84 
85  std::pair<size_t, size_t> approximateTupleCount(
86  const std::vector<ColumnsForDevice>&) const override;
87 
88  size_t getKeyComponentWidth() const override;
89 
90  size_t getKeyComponentCount() const override;
91 
92  int initHashTableOnCpu(const std::vector<JoinColumn>& join_columns,
93  const std::vector<JoinColumnTypeInfo>& join_column_types,
94  const std::vector<JoinBucketInfo>& join_bucket_info,
95  const JoinHashTableInterface::HashType layout) override;
96 
97  int initHashTableOnGpu(const std::vector<JoinColumn>& join_columns,
98  const std::vector<JoinColumnTypeInfo>& join_column_types,
99  const std::vector<JoinBucketInfo>& join_bucket_info,
101  const size_t key_component_width,
102  const size_t key_component_count,
103  const int device_id) override;
104 
105  llvm::Value* codegenKey(const CompilationOptions&) 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 std::vector<InnerOuter>& inner_outer_pairs);
114 
115  std::vector<double> bucket_sizes_for_dimension_;
117 };
118 
119 #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_
#define LOG(tag)
Definition: Logger.h:182
std::pair< size_t, size_t > calculateCounts(size_t shard_count, const Fragmenter_Namespace::TableInfo &query_info, const int device_count, std::vector< BaselineJoinHashTable::ColumnsForDevice > &columns_per_device)
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::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_map, Executor *executor)
static std::map< HashTableCacheKey, double > auto_tuner_cache_
llvm::Value * codegenKey(const CompilationOptions &) override
ColumnsForDevice fetchColumnsForDevice(const std::deque< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id) override
static auto yieldCacheInvalidator() -> std::function< void()>
size_t calculateHashTableSize(size_t number_of_dimensions, size_t emitted_keys_count, size_t entry_count) const
void reifyWithLayout(const int device_count, const JoinHashTableInterface::HashType layout) override
OverlapsJoinHashTable(const std::shared_ptr< Analyzer::BinOper > condition, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, const size_t entry_count, ColumnCacheMap &column_map, Executor *executor, const std::vector< InnerOuter > &inner_outer_pairs)
size_t getKeyComponentCount() const override
std::pair< size_t, size_t > approximateTupleCount(const std::vector< ColumnsForDevice > &) const override
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
size_t countBufferOff() const noexcept override
size_t payloadBufferOff() const noexcept override
void computeBucketSizes(std::vector< double > &bucket_sizes_for_dimension, const JoinColumn &join_column, const std::vector< InnerOuter > &inner_outer_pairs)
size_t getKeyComponentWidth() const override