OmniSciDB  1dac507f6e
 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  const size_t entry_count,
28  ColumnCacheMap& column_cache,
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_cache,
37  executor,
38  inner_outer_pairs) {}
39 
40  ~OverlapsJoinHashTable() override {}
41 
43  static std::shared_ptr<OverlapsJoinHashTable> getInstance(
44  const std::shared_ptr<Analyzer::BinOper> condition,
45  const std::vector<InputTableInfo>& query_infos,
46  const Data_Namespace::MemoryLevel memory_level,
47  const int device_count,
48  ColumnCacheMap& column_cache,
49  Executor* executor);
50 
52  static std::shared_ptr<OverlapsJoinHashTable> getSyntheticInstance(
53  std::string_view table1,
54  std::string_view column1,
55  std::string_view table2,
56  std::string_view column2,
57  const Data_Namespace::MemoryLevel memory_level,
58  const int device_count,
59  ColumnCacheMap& column_cache,
60  Executor* executor);
61 
62  static auto yieldCacheInvalidator() -> std::function<void()> {
63  return []() -> void {
64  std::lock_guard<std::mutex> guard(auto_tuner_cache_mutex_);
65  auto_tuner_cache_.clear();
66  };
67  }
68 
69  protected:
70  void reifyWithLayout(const int device_count,
71  const JoinHashTableInterface::HashType layout) override;
72 
73  std::pair<size_t, size_t> calculateCounts(
74  size_t shard_count,
75  const Fragmenter_Namespace::TableInfo& query_info,
76  const int device_count,
77  std::vector<BaselineJoinHashTable::ColumnsForDevice>& columns_per_device);
78 
79  size_t calculateHashTableSize(size_t number_of_dimensions,
80  size_t emitted_keys_count,
81  size_t entry_count) const;
82 
83  ColumnsForDevice fetchColumnsForDevice(
84  const std::deque<Fragmenter_Namespace::FragmentInfo>& fragments,
85  const int device_id) override;
86 
87  std::pair<size_t, size_t> approximateTupleCount(
88  const std::vector<ColumnsForDevice>&) const override;
89 
90  size_t getKeyComponentWidth() const override;
91 
92  size_t getKeyComponentCount() const override;
93 
94  int initHashTableOnCpu(const std::vector<JoinColumn>& join_columns,
95  const std::vector<JoinColumnTypeInfo>& join_column_types,
96  const std::vector<JoinBucketInfo>& join_bucket_info,
97  const JoinHashTableInterface::HashType layout) override;
98 
99  int initHashTableOnGpu(const std::vector<JoinColumn>& join_columns,
100  const std::vector<JoinColumnTypeInfo>& join_column_types,
101  const std::vector<JoinBucketInfo>& join_bucket_info,
103  const size_t key_component_width,
104  const size_t key_component_count,
105  const int device_id) override;
106 
107  llvm::Value* codegenKey(const CompilationOptions&) override;
108 
109  static std::map<HashTableCacheKey, double> auto_tuner_cache_;
110  static std::mutex auto_tuner_cache_mutex_;
111 
112  private:
113  void computeBucketSizes(std::vector<double>& bucket_sizes_for_dimension,
114  const JoinColumn& join_column,
115  const std::vector<InnerOuter>& inner_outer_pairs);
116 
117  std::vector<double> bucket_sizes_for_dimension_;
119 };
120 
121 #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.
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::map< HashTableCacheKey, double > auto_tuner_cache_
size_t calculateHashTableSize(size_t number_of_dimensions, size_t emitted_keys_count, size_t entry_count) const
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()>
static std::shared_ptr< OverlapsJoinHashTable > getSyntheticInstance(std::string_view table1, std::string_view column1, std::string_view table2, std::string_view column2, const Data_Namespace::MemoryLevel memory_level, const int device_count, ColumnCacheMap &column_cache, Executor *executor)
Make hash table from named tables and columns (such as for testing).
void reifyWithLayout(const int device_count, const JoinHashTableInterface::HashType layout) override
size_t getKeyComponentCount() const override
std::pair< size_t, size_t > approximateTupleCount(const std::vector< ColumnsForDevice > &) const 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_cache, Executor *executor, const std::vector< InnerOuter > &inner_outer_pairs)
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
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