OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OverlapsJoinHashTable Class Reference

#include <OverlapsJoinHashTable.h>

+ Inheritance diagram for OverlapsJoinHashTable:
+ Collaboration diagram for OverlapsJoinHashTable:

Classes

struct  AlternativeCacheKeyForOverlapsHashJoin
 

Public Member Functions

 OverlapsJoinHashTable (const std::shared_ptr< Analyzer::BinOper > condition, const JoinType join_type, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, ColumnCacheMap &column_cache, Executor *executor, const std::vector< InnerOuter > &inner_outer_pairs, const int device_count, const RegisteredQueryHint &query_hints, const HashTableBuildDagMap &hashtable_build_dag_map, const TableIdToNodeMap &table_id_to_node_map)
 
virtual ~OverlapsJoinHashTable ()
 
- Public Member Functions inherited from HashJoin
virtual std::string toStringFlat64 (const ExecutorDeviceType device_type, const int device_id) const
 
virtual std::string toStringFlat32 (const ExecutorDeviceType device_type, const int device_id) const
 
JoinColumn fetchJoinColumn (const Analyzer::ColumnVar *hash_col, const std::vector< Fragmenter_Namespace::FragmentInfo > &fragment_info, const Data_Namespace::MemoryLevel effective_memory_level, const int device_id, std::vector< std::shared_ptr< Chunk_NS::Chunk >> &chunks_owner, DeviceAllocator *dev_buff_owner, std::vector< std::shared_ptr< void >> &malloc_owner, Executor *executor, ColumnCacheMap *column_cache)
 
HashTablegetHashTableForDevice (const size_t device_id) const
 
size_t getJoinHashBufferSize (const ExecutorDeviceType device_type)
 
size_t getJoinHashBufferSize (const ExecutorDeviceType device_type, const int device_id) const
 
int8_t * getJoinHashBuffer (const ExecutorDeviceType device_type, const int device_id) const
 
void freeHashBufferMemory ()
 

Static Public Member Functions

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 JoinType join_type, const int device_count, ColumnCacheMap &column_cache, Executor *executor, const HashTableBuildDagMap &hashtable_build_dag_map, const RegisteredQueryHint &query_hint, const TableIdToNodeMap &table_id_to_node_map)
 Make hash table from an in-flight SQL query's parse tree etc. More...
 
static void invalidateCache ()
 
static void markCachedItemAsDirty (size_t table_key)
 
static HashtableRecyclergetHashTableCache ()
 
static
OverlapsTuningParamRecycler
getOverlapsTuningParamCache ()
 
- Static Public Member Functions inherited from HashJoin
static bool layoutRequiresAdditionalBuffers (HashType layout) noexcept
 
static std::string getHashTypeString (HashType ht) noexcept
 
static HashJoinMatchingSet codegenMatchingSet (const std::vector< llvm::Value * > &hash_join_idx_args_in, const bool is_sharded, const bool col_is_nullable, const bool is_bw_eq, const int64_t sub_buff_size, Executor *executor, const bool is_bucketized=false)
 
static llvm::Value * codegenHashTableLoad (const size_t table_idx, Executor *executor)
 
static std::shared_ptr< HashJoingetInstance (const std::shared_ptr< Analyzer::BinOper > qual_bin_oper, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, const JoinType join_type, const HashType preferred_hash_type, const int device_count, ColumnCacheMap &column_cache, Executor *executor, const HashTableBuildDagMap &hashtable_build_dag_map, const RegisteredQueryHint &query_hint, const TableIdToNodeMap &table_id_to_node_map)
 Make hash table from an in-flight SQL query's parse tree etc. More...
 
static std::shared_ptr< HashJoingetSyntheticInstance (std::string_view table1, std::string_view column1, const Catalog_Namespace::Catalog &catalog1, std::string_view table2, std::string_view column2, const Catalog_Namespace::Catalog &catalog2, const Data_Namespace::MemoryLevel memory_level, const HashType preferred_hash_type, const int device_count, ColumnCacheMap &column_cache, Executor *executor)
 Make hash table from named tables and columns (such as for testing). More...
 
static std::shared_ptr< HashJoingetSyntheticInstance (const std::shared_ptr< Analyzer::BinOper > qual_bin_oper, const Data_Namespace::MemoryLevel memory_level, const HashType preferred_hash_type, const int device_count, ColumnCacheMap &column_cache, Executor *executor)
 Make hash table from named tables and columns (such as for testing). More...
 
static std::pair< std::string,
std::shared_ptr< HashJoin > > 
getSyntheticInstance (std::vector< std::shared_ptr< Analyzer::BinOper >>, const Data_Namespace::MemoryLevel memory_level, const HashType preferred_hash_type, const int device_count, ColumnCacheMap &column_cache, Executor *executor)
 
static shared::TableKey getInnerTableId (const std::vector< InnerOuter > &inner_outer_pairs)
 
static bool canAccessHashTable (bool allow_hash_table_recycling, bool invalid_cache_key, JoinType join_type)
 
static void checkHashJoinReplicationConstraint (const shared::TableKey &table_key, const size_t shard_count, const Executor *executor)
 
static std::pair< InnerOuter,
InnerOuterStringOpInfos
normalizeColumnPair (const Analyzer::Expr *lhs, const Analyzer::Expr *rhs, const TemporaryTables *temporary_tables, const bool is_overlaps_join=false)
 
template<typename T >
static const T * getHashJoinColumn (const Analyzer::Expr *expr)
 
static std::pair< std::vector
< InnerOuter >, std::vector
< InnerOuterStringOpInfos > > 
normalizeColumnPairs (const Analyzer::BinOper *condition, const TemporaryTables *temporary_tables)
 
static std::vector< int > collectFragmentIds (const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments)
 
static CompositeKeyInfo getCompositeKeyInfo (const std::vector< InnerOuter > &inner_outer_pairs, const Executor *executor, const std::vector< InnerOuterStringOpInfos > &inner_outer_string_op_infos_pairs={})
 
static std::vector< const
StringDictionaryProxy::IdMap * > 
translateCompositeStrDictProxies (const CompositeKeyInfo &composite_key_info, const std::vector< InnerOuterStringOpInfos > &string_op_infos_for_keys, const Executor *executor)
 
static std::pair< const
StringDictionaryProxy
*, StringDictionaryProxy * > 
getStrDictProxies (const InnerOuter &cols, const Executor *executor, const bool has_string_ops)
 
static const
StringDictionaryProxy::IdMap
translateInnerToOuterStrDictProxies (const InnerOuter &cols, const InnerOuterStringOpInfos &inner_outer_string_op_infos, ExpressionRange &old_col_range, const Executor *executor)
 

Protected Member Functions

void reify (const HashType preferred_layout)
 
virtual void reifyWithLayout (const HashType layout)
 
virtual void reifyImpl (std::vector< ColumnsForDevice > &columns_per_device, const Fragmenter_Namespace::TableInfo &query_info, const HashType layout, const size_t shard_count, const size_t entry_count, const size_t emitted_keys_count, const bool skip_hashtable_caching, const size_t chosen_max_hashtable_size, const double chosen_bucket_threshold)
 
void reifyForDevice (const ColumnsForDevice &columns_for_device, const HashType layout, const size_t entry_count, const size_t emitted_keys_count, const bool skip_hashtable_caching, const int device_id, const logger::ThreadLocalIds parent_thread_local_ids)
 
size_t calculateHashTableSize (size_t number_of_dimensions, size_t emitted_keys_count, size_t entry_count) const
 
ColumnsForDevice fetchColumnsForDevice (const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, DeviceAllocator *dev_buff_owner)
 
virtual std::pair< size_t, size_t > approximateTupleCount (const std::vector< double > &inverse_bucket_sizes_for_dimension, std::vector< ColumnsForDevice > &, const size_t chosen_max_hashtable_size, const double chosen_bucket_threshold)
 
virtual std::pair< size_t, size_t > computeHashTableCounts (const size_t shard_count, const std::vector< double > &inverse_bucket_sizes_for_dimension, std::vector< ColumnsForDevice > &columns_per_device, const size_t chosen_max_hashtable_size, const double chosen_bucket_threshold)
 
void setInverseBucketSizeInfo (const std::vector< double > &inverse_bucket_sizes, std::vector< ColumnsForDevice > &columns_per_device, const size_t device_count)
 
size_t getKeyComponentWidth () const
 
size_t getKeyComponentCount () const
 
HashType getHashType () const noexceptoverride
 
Data_Namespace::MemoryLevel getMemoryLevel () const noexceptoverride
 
int getDeviceCount () const noexceptoverride
 
std::shared_ptr
< BaselineHashTable
initHashTableOnCpu (const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const std::vector< JoinBucketInfo > &join_bucket_info, const HashType layout, const size_t entry_count, const size_t emitted_keys_count, const bool skip_hashtable_caching)
 
HashJoinMatchingSet codegenMatchingSet (const CompilationOptions &, const size_t) override
 
std::string toString (const ExecutorDeviceType device_type, const int device_id=0, bool raw=false) const override
 
DecodedJoinHashBufferSet toSet (const ExecutorDeviceType device_type, const int device_id) const override
 
llvm::Value * codegenSlot (const CompilationOptions &, const size_t) override
 
const RegisteredQueryHintgetRegisteredQueryHint ()
 
size_t getEntryCount () const
 
size_t getEmittedKeysCount () const
 
size_t getComponentBufferSize () const noexceptoverride
 
size_t shardCount () const
 
Data_Namespace::MemoryLevel getEffectiveMemoryLevel (const std::vector< InnerOuter > &inner_outer_pairs) const
 
shared::TableKey getInnerTableId () const noexceptoverride
 
int getInnerTableRteIdx () const noexceptoverride
 
size_t getKeyBufferSize () const noexcept
 
size_t offsetBufferOff () const noexceptoverride
 
size_t countBufferOff () const noexceptoverride
 
size_t payloadBufferOff () const noexceptoverride
 
std::string getHashJoinType () const final
 
bool isBitwiseEq () const override
 
std::shared_ptr< HashTableinitHashTableOnCpuFromCache (QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier)
 
std::optional< std::pair
< size_t, size_t > > 
getApproximateTupleCountFromCache (QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier)
 
void putHashTableOnCpuToCache (QueryPlanHash key, CacheItemType item_type, std::shared_ptr< HashTable > hashtable_ptr, DeviceIdentifier device_identifier, size_t hashtable_building_time)
 
llvm::Value * codegenKey (const CompilationOptions &)
 
std::vector< llvm::Value * > codegenManyKey (const CompilationOptions &)
 
std::optional
< OverlapsHashTableMetaInfo
getOverlapsHashTableMetaInfo ()
 
QueryPlanHash getAlternativeCacheKey (AlternativeCacheKeyForOverlapsHashJoin &info)
 
void generateCacheKey (const size_t max_hashtable_size, const double bucket_threshold, const std::vector< double > &bucket_sizes, std::vector< std::vector< Fragmenter_Namespace::FragmentInfo >> &fragments_per_device, int device_count)
 
QueryPlanHash getCacheKey (int device_id) const
 
const std::vector< InnerOuter > & getInnerOuterPairs () const
 
void setOverlapsHashtableMetaInfo (size_t max_table_size_bytes, double bucket_threshold, std::vector< double > &bucket_sizes)
 

Protected Attributes

const std::shared_ptr
< Analyzer::BinOper
condition_
 
const JoinType join_type_
 
const std::vector
< InputTableInfo > & 
query_infos_
 
const Data_Namespace::MemoryLevel memory_level_
 
Executorexecutor_
 
ColumnCacheMapcolumn_cache_
 
std::vector< InnerOuterinner_outer_pairs_
 
const int device_count_
 
RegisteredQueryHint query_hints_
 
std::vector< double > inverse_bucket_sizes_for_dimension_
 
double chosen_overlaps_bucket_threshold_
 
size_t chosen_overlaps_max_table_size_bytes_
 
CompositeKeyInfo composite_key_info_
 
std::optional< HashTypelayout_override_
 
std::mutex cpu_hash_table_buff_mutex_
 
HashTableBuildDagMap hashtable_build_dag_map_
 
QueryPlanDAG query_plan_dag_
 
std::vector< QueryPlanHashhashtable_cache_key_
 
HashtableCacheMetaInfo hashtable_cache_meta_info_
 
std::unordered_set< size_t > table_keys_
 
const TableIdToNodeMap table_id_to_node_map_
 
- Protected Attributes inherited from HashJoin
std::vector< std::shared_ptr
< HashTable > > 
hash_tables_for_device_
 

Static Protected Attributes

static std::unique_ptr
< HashtableRecycler
hash_table_cache_
 
static std::unique_ptr
< OverlapsTuningParamRecycler
auto_tuner_cache_
 

Additional Inherited Members

- Static Protected Member Functions inherited from HashJoin
static llvm::Value * codegenColOrStringOper (const Analyzer::Expr *col_or_string_oper, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos, CodeGenerator &code_generator, const CompilationOptions &co)
 

Detailed Description

Definition at line 24 of file OverlapsJoinHashTable.h.

Constructor & Destructor Documentation

OverlapsJoinHashTable::OverlapsJoinHashTable ( const std::shared_ptr< Analyzer::BinOper condition,
const JoinType  join_type,
const std::vector< InputTableInfo > &  query_infos,
const Data_Namespace::MemoryLevel  memory_level,
ColumnCacheMap column_cache,
Executor executor,
const std::vector< InnerOuter > &  inner_outer_pairs,
const int  device_count,
const RegisteredQueryHint query_hints,
const HashTableBuildDagMap hashtable_build_dag_map,
const TableIdToNodeMap table_id_to_node_map 
)
inline

Definition at line 26 of file OverlapsJoinHashTable.h.

References CHECK_GT, device_count_, and HashJoin::hash_tables_for_device_.

37  : condition_(condition)
38  , join_type_(join_type)
39  , query_infos_(query_infos)
40  , memory_level_(memory_level)
41  , executor_(executor)
42  , column_cache_(column_cache)
43  , inner_outer_pairs_(inner_outer_pairs)
44  , device_count_(device_count)
45  , query_hints_(query_hints)
46  , hashtable_build_dag_map_(hashtable_build_dag_map)
47  , table_id_to_node_map_(table_id_to_node_map) {
49  hash_tables_for_device_.resize(std::max(device_count_, 1));
50  }
const TableIdToNodeMap table_id_to_node_map_
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:363
#define CHECK_GT(x, y)
Definition: Logger.h:305
const std::shared_ptr< Analyzer::BinOper > condition_
ColumnCacheMap & column_cache_
RegisteredQueryHint query_hints_
const std::vector< InputTableInfo > & query_infos_
HashTableBuildDagMap hashtable_build_dag_map_
const Data_Namespace::MemoryLevel memory_level_
std::vector< InnerOuter > inner_outer_pairs_
virtual OverlapsJoinHashTable::~OverlapsJoinHashTable ( )
inlinevirtual

Definition at line 52 of file OverlapsJoinHashTable.h.

52 {}

Member Function Documentation

std::pair< size_t, size_t > OverlapsJoinHashTable::approximateTupleCount ( const std::vector< double > &  inverse_bucket_sizes_for_dimension,
std::vector< ColumnsForDevice > &  columns_per_device,
const size_t  chosen_max_hashtable_size,
const double  chosen_bucket_threshold 
)
protectedvirtual

Reimplemented in RangeJoinHashTable.

Definition at line 979 of file OverlapsJoinHashTable.cpp.

References gpu_enabled::accumulate(), approximate_distinct_tuples_on_device_overlaps(), approximate_distinct_tuples_overlaps(), threading_serial::async(), Bitmap, CHECK, CHECK_EQ, CHECK_GT, CPU, DataRecyclerUtil::CPU_DEVICE_IDENTIFIER, Data_Namespace::CPU_LEVEL, cpu_threads(), device_count_, executor_, getApproximateTupleCountFromCache(), getEffectiveMemoryLevel(), getQueryEngineCudaStreamForDevice(), GPU, Data_Namespace::GPU_LEVEL, hashtable_cache_key_, hll_size(), hll_unify(), inner_outer_pairs_, OVERLAPS_HT, transfer_flat_object_to_gpu(), transfer_vector_of_flat_objects_to_gpu(), UNREACHABLE, and VLOG.

Referenced by computeHashTableCounts().

983  {
984  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
985  CountDistinctDescriptor count_distinct_desc{
987  0,
988  11,
989  true,
990  effective_memory_level == Data_Namespace::MemoryLevel::GPU_LEVEL
993  1};
994  const auto padded_size_bytes = count_distinct_desc.bitmapPaddedSizeBytes();
995 
996  CHECK(!columns_per_device.empty() && !columns_per_device.front().join_columns.empty());
997  if (columns_per_device.front().join_columns.front().num_elems == 0) {
998  return std::make_pair(0, 0);
999  }
1000 
1001  // TODO: state management in here should be revisited, but this should be safe enough
1002  // for now
1003  // re-compute bucket counts per device based on global bucket size
1004  for (size_t device_id = 0; device_id < columns_per_device.size(); ++device_id) {
1005  auto& columns_for_device = columns_per_device[device_id];
1006  columns_for_device.setBucketInfo(inverse_bucket_sizes_for_dimension,
1008  }
1009 
1010  // Number of keys must match dimension of buckets
1011  CHECK_EQ(columns_per_device.front().join_columns.size(),
1012  columns_per_device.front().join_buckets.size());
1013  if (effective_memory_level == Data_Namespace::MemoryLevel::CPU_LEVEL) {
1014  // Note that this path assumes each device has the same hash table (for GPU hash
1015  // join w/ hash table built on CPU)
1016  const auto cached_count_info =
1020  if (cached_count_info) {
1021  VLOG(1) << "Using a cached tuple count: " << cached_count_info->first
1022  << ", emitted keys count: " << cached_count_info->second;
1023  return *cached_count_info;
1024  }
1025  int thread_count = cpu_threads();
1026  std::vector<uint8_t> hll_buffer_all_cpus(thread_count * padded_size_bytes);
1027  auto hll_result = &hll_buffer_all_cpus[0];
1028 
1029  std::vector<int32_t> num_keys_for_row;
1030  // TODO(adb): support multi-column overlaps join
1031  num_keys_for_row.resize(columns_per_device.front().join_columns[0].num_elems);
1032 
1034  num_keys_for_row,
1035  count_distinct_desc.bitmap_sz_bits,
1036  padded_size_bytes,
1037  columns_per_device.front().join_columns,
1038  columns_per_device.front().join_column_types,
1039  columns_per_device.front().join_buckets,
1040  thread_count);
1041  for (int i = 1; i < thread_count; ++i) {
1042  hll_unify(hll_result,
1043  hll_result + i * padded_size_bytes,
1044  1 << count_distinct_desc.bitmap_sz_bits);
1045  }
1046  return std::make_pair(
1047  hll_size(hll_result, count_distinct_desc.bitmap_sz_bits),
1048  static_cast<size_t>(num_keys_for_row.size() > 0 ? num_keys_for_row.back() : 0));
1049  }
1050 #ifdef HAVE_CUDA
1051  auto data_mgr = executor_->getDataMgr();
1052  std::vector<std::vector<uint8_t>> host_hll_buffers(device_count_);
1053  for (auto& host_hll_buffer : host_hll_buffers) {
1054  host_hll_buffer.resize(count_distinct_desc.bitmapPaddedSizeBytes());
1055  }
1056  std::vector<size_t> emitted_keys_count_device_threads(device_count_, 0);
1057  std::vector<std::future<void>> approximate_distinct_device_threads;
1058  for (int device_id = 0; device_id < device_count_; ++device_id) {
1059  approximate_distinct_device_threads.emplace_back(std::async(
1061  [device_id,
1062  &columns_per_device,
1063  &count_distinct_desc,
1064  data_mgr,
1065  &host_hll_buffers,
1066  &emitted_keys_count_device_threads] {
1067  auto allocator = std::make_unique<CudaAllocator>(
1068  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
1069  auto device_hll_buffer =
1070  allocator->alloc(count_distinct_desc.bitmapPaddedSizeBytes());
1071  data_mgr->getCudaMgr()->zeroDeviceMem(
1072  device_hll_buffer,
1073  count_distinct_desc.bitmapPaddedSizeBytes(),
1074  device_id,
1076  const auto& columns_for_device = columns_per_device[device_id];
1077  auto join_columns_gpu = transfer_vector_of_flat_objects_to_gpu(
1078  columns_for_device.join_columns, *allocator);
1079 
1080  CHECK_GT(columns_for_device.join_buckets.size(), 0u);
1081  const auto& inverse_bucket_sizes_for_dimension =
1082  columns_for_device.join_buckets[0].inverse_bucket_sizes_for_dimension;
1083  auto inverse_bucket_sizes_gpu = allocator->alloc(
1084  inverse_bucket_sizes_for_dimension.size() * sizeof(double));
1085  allocator->copyToDevice(
1086  inverse_bucket_sizes_gpu,
1087  inverse_bucket_sizes_for_dimension.data(),
1088  inverse_bucket_sizes_for_dimension.size() * sizeof(double));
1089  const size_t row_counts_buffer_sz =
1090  columns_per_device.front().join_columns[0].num_elems * sizeof(int32_t);
1091  auto row_counts_buffer = allocator->alloc(row_counts_buffer_sz);
1092  data_mgr->getCudaMgr()->zeroDeviceMem(
1093  row_counts_buffer,
1094  row_counts_buffer_sz,
1095  device_id,
1097  const auto key_handler =
1098  OverlapsKeyHandler(inverse_bucket_sizes_for_dimension.size(),
1099  join_columns_gpu,
1100  reinterpret_cast<double*>(inverse_bucket_sizes_gpu));
1101  const auto key_handler_gpu =
1102  transfer_flat_object_to_gpu(key_handler, *allocator);
1104  reinterpret_cast<uint8_t*>(device_hll_buffer),
1105  count_distinct_desc.bitmap_sz_bits,
1106  reinterpret_cast<int32_t*>(row_counts_buffer),
1107  key_handler_gpu,
1108  columns_for_device.join_columns[0].num_elems);
1109 
1110  auto& host_emitted_keys_count = emitted_keys_count_device_threads[device_id];
1111  allocator->copyFromDevice(
1112  &host_emitted_keys_count,
1113  row_counts_buffer +
1114  (columns_per_device.front().join_columns[0].num_elems - 1) *
1115  sizeof(int32_t),
1116  sizeof(int32_t));
1117 
1118  auto& host_hll_buffer = host_hll_buffers[device_id];
1119  allocator->copyFromDevice(&host_hll_buffer[0],
1120  device_hll_buffer,
1121  count_distinct_desc.bitmapPaddedSizeBytes());
1122  }));
1123  }
1124  for (auto& child : approximate_distinct_device_threads) {
1125  child.get();
1126  }
1127  CHECK_EQ(Data_Namespace::MemoryLevel::GPU_LEVEL, effective_memory_level);
1128  auto& result_hll_buffer = host_hll_buffers.front();
1129  auto hll_result = reinterpret_cast<int32_t*>(&result_hll_buffer[0]);
1130  for (int device_id = 1; device_id < device_count_; ++device_id) {
1131  auto& host_hll_buffer = host_hll_buffers[device_id];
1132  hll_unify(hll_result,
1133  reinterpret_cast<int32_t*>(&host_hll_buffer[0]),
1134  1 << count_distinct_desc.bitmap_sz_bits);
1135  }
1136  const size_t emitted_keys_count =
1137  std::accumulate(emitted_keys_count_device_threads.begin(),
1138  emitted_keys_count_device_threads.end(),
1139  0);
1140  return std::make_pair(hll_size(hll_result, count_distinct_desc.bitmap_sz_bits),
1141  emitted_keys_count);
1142 #else
1143  UNREACHABLE();
1144  return {0, 0};
1145 #endif // HAVE_CUDA
1146 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
T * transfer_flat_object_to_gpu(const T &object, DeviceAllocator &allocator)
void hll_unify(T1 *lhs, T2 *rhs, const size_t m)
Definition: HyperLogLog.h:107
#define UNREACHABLE()
Definition: Logger.h:337
std::optional< std::pair< size_t, size_t > > getApproximateTupleCountFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier)
size_t hll_size(const T *M, const size_t bitmap_sz_bits)
Definition: HyperLogLog.h:88
#define CHECK_GT(x, y)
Definition: Logger.h:305
future< Result > async(Fn &&fn, Args &&...args)
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
std::vector< QueryPlanHash > hashtable_cache_key_
void approximate_distinct_tuples_overlaps(uint8_t *hll_buffer_all_cpus, std::vector< int32_t > &row_counts, const uint32_t b, const size_t padded_size_bytes, const std::vector< JoinColumn > &join_column_per_key, const std::vector< JoinColumnTypeInfo > &type_info_per_key, const std::vector< JoinBucketInfo > &join_buckets_per_key, const int thread_count)
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
#define CHECK(condition)
Definition: Logger.h:291
std::vector< InnerOuter > inner_outer_pairs_
T * transfer_vector_of_flat_objects_to_gpu(const std::vector< T > &vec, DeviceAllocator &allocator)
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) const
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
int cpu_threads()
Definition: thread_count.h:25
void approximate_distinct_tuples_on_device_overlaps(uint8_t *hll_buffer, const uint32_t b, int32_t *row_counts_buffer, const OverlapsKeyHandler *key_handler, const int64_t num_elems)
#define VLOG(n)
Definition: Logger.h:387

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t OverlapsJoinHashTable::calculateHashTableSize ( size_t  number_of_dimensions,
size_t  emitted_keys_count,
size_t  entry_count 
) const
protected

Definition at line 909 of file OverlapsJoinHashTable.cpp.

References getKeyComponentWidth().

Referenced by RangeJoinHashTable::reifyWithLayout(), and reifyWithLayout().

911  {
912  const auto key_component_width = getKeyComponentWidth();
913  const auto key_component_count = number_of_dimensions;
914  const auto entry_size = key_component_count * key_component_width;
915  const auto keys_for_all_rows = emitted_keys_count;
916  const size_t one_to_many_hash_entries = 2 * entry_count + keys_for_all_rows;
917  const size_t hash_table_size =
918  entry_size * entry_count + one_to_many_hash_entries * sizeof(int32_t);
919  return hash_table_size;
920 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Value * OverlapsJoinHashTable::codegenKey ( const CompilationOptions co)
protected

Definition at line 1469 of file OverlapsJoinHashTable.cpp.

References AUTOMATIC_IR_METADATA, CodeGenerator::castArrayPointer(), CHECK, CHECK_EQ, CodeGenerator::codegen(), executor_, Catalog_Namespace::get_metadata_for_column(), getKeyComponentCount(), getKeyComponentWidth(), inner_outer_pairs_, inverse_bucket_sizes_for_dimension_, kPOINT, kTINYINT, LL_BUILDER, LL_CONTEXT, LL_INT, CodeGenerator::posArg(), and UNREACHABLE.

Referenced by codegenMatchingSet().

1469  {
1470  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
1471  const auto key_component_width = getKeyComponentWidth();
1472  CHECK(key_component_width == 4 || key_component_width == 8);
1473  const auto key_size_lv = LL_INT(getKeyComponentCount() * key_component_width);
1474  llvm::Value* key_buff_lv{nullptr};
1475  switch (key_component_width) {
1476  case 4:
1477  key_buff_lv =
1478  LL_BUILDER.CreateAlloca(llvm::Type::getInt32Ty(LL_CONTEXT), key_size_lv);
1479  break;
1480  case 8:
1481  key_buff_lv =
1482  LL_BUILDER.CreateAlloca(llvm::Type::getInt64Ty(LL_CONTEXT), key_size_lv);
1483  break;
1484  default:
1485  CHECK(false);
1486  }
1487 
1488  const auto& inner_outer_pair = inner_outer_pairs_[0];
1489  const auto outer_geo = inner_outer_pair.second;
1490  const auto outer_geo_ti = outer_geo->get_type_info();
1491 
1492  llvm::Value* arr_ptr = nullptr;
1493  CodeGenerator code_generator(executor_);
1494  CHECK_EQ(inverse_bucket_sizes_for_dimension_.size(), static_cast<size_t>(2));
1495 
1496  if (outer_geo_ti.is_geometry()) {
1497  // TODO(adb): for points we will use the coords array, but for other geometries we
1498  // will need to use the bounding box. For now only support points.
1499  CHECK_EQ(outer_geo_ti.get_type(), kPOINT);
1500 
1501  if (const auto outer_geo_col = dynamic_cast<const Analyzer::ColumnVar*>(outer_geo)) {
1502  const auto outer_geo_col_lvs = code_generator.codegen(outer_geo_col, true, co);
1503  CHECK_EQ(outer_geo_col_lvs.size(), size_t(1));
1504  auto column_key = outer_geo_col->getColumnKey();
1505  column_key.column_id = column_key.column_id + 1;
1506  const auto coords_cd = Catalog_Namespace::get_metadata_for_column(column_key);
1507  CHECK(coords_cd);
1508 
1509  const auto array_ptr = executor_->cgen_state_->emitExternalCall(
1510  "array_buff",
1511  llvm::Type::getInt8PtrTy(executor_->cgen_state_->context_),
1512  {outer_geo_col_lvs.front(), code_generator.posArg(outer_geo_col)});
1513  CHECK(coords_cd->columnType.get_elem_type().get_type() == kTINYINT)
1514  << "Only TINYINT coordinates columns are supported in geo overlaps hash "
1515  "join.";
1516  arr_ptr = code_generator.castArrayPointer(array_ptr,
1517  coords_cd->columnType.get_elem_type());
1518  } else if (const auto outer_geo_function_operator =
1519  dynamic_cast<const Analyzer::GeoOperator*>(outer_geo)) {
1520  // Process points dynamically constructed by geo function operators
1521  const auto outer_geo_function_operator_lvs =
1522  code_generator.codegen(outer_geo_function_operator, true, co);
1523  CHECK_EQ(outer_geo_function_operator_lvs.size(), size_t(2));
1524  arr_ptr = outer_geo_function_operator_lvs.front();
1525  } else if (const auto outer_geo_expr =
1526  dynamic_cast<const Analyzer::GeoExpr*>(outer_geo)) {
1527  UNREACHABLE() << outer_geo_expr->toString();
1528  }
1529  } else if (outer_geo_ti.is_fixlen_array()) {
1530  // Process dynamically constructed points
1531  const auto outer_geo_cast_coord_array =
1532  dynamic_cast<const Analyzer::UOper*>(outer_geo);
1533  CHECK_EQ(outer_geo_cast_coord_array->get_optype(), kCAST);
1534  const auto outer_geo_coord_array = dynamic_cast<const Analyzer::ArrayExpr*>(
1535  outer_geo_cast_coord_array->get_operand());
1536  CHECK(outer_geo_coord_array);
1537  CHECK(outer_geo_coord_array->isLocalAlloc());
1538  CHECK_EQ(outer_geo_coord_array->getElementCount(), 2);
1539  auto elem_size = (outer_geo_ti.get_compression() == kENCODING_GEOINT)
1540  ? sizeof(int32_t)
1541  : sizeof(double);
1542  CHECK_EQ(outer_geo_ti.get_size(), int(2 * elem_size));
1543  const auto outer_geo_constructed_lvs = code_generator.codegen(outer_geo, true, co);
1544  // CHECK_EQ(outer_geo_constructed_lvs.size(), size_t(2)); // Pointer and size
1545  const auto array_ptr = outer_geo_constructed_lvs.front(); // Just need the pointer
1546  arr_ptr = LL_BUILDER.CreateGEP(
1547  array_ptr->getType()->getScalarType()->getPointerElementType(),
1548  array_ptr,
1549  LL_INT(0));
1550  arr_ptr = code_generator.castArrayPointer(array_ptr, SQLTypeInfo(kTINYINT, true));
1551  }
1552  if (!arr_ptr) {
1553  LOG(FATAL) << "Overlaps key currently only supported for geospatial columns and "
1554  "constructed points.";
1555  }
1556 
1557  for (size_t i = 0; i < 2; i++) {
1558  const auto key_comp_dest_lv = LL_BUILDER.CreateGEP(
1559  key_buff_lv->getType()->getScalarType()->getPointerElementType(),
1560  key_buff_lv,
1561  LL_INT(i));
1562 
1563  // Note that get_bucket_key_for_range_compressed will need to be specialized for
1564  // future compression schemes
1565  auto bucket_key =
1566  outer_geo_ti.get_compression() == kENCODING_GEOINT
1567  ? executor_->cgen_state_->emitExternalCall(
1568  "get_bucket_key_for_range_compressed",
1569  get_int_type(64, LL_CONTEXT),
1571  : executor_->cgen_state_->emitExternalCall(
1572  "get_bucket_key_for_range_double",
1573  get_int_type(64, LL_CONTEXT),
1574  {arr_ptr, LL_INT(i), LL_FP(inverse_bucket_sizes_for_dimension_[i])});
1575  const auto col_lv = LL_BUILDER.CreateSExt(
1576  bucket_key, get_int_type(key_component_width * 8, LL_CONTEXT));
1577  LL_BUILDER.CreateStore(col_lv, key_comp_dest_lv);
1578  }
1579  return key_buff_lv;
1580 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define LOG(tag)
Definition: Logger.h:285
#define LL_FP(v)
#define UNREACHABLE()
Definition: Logger.h:337
const ColumnDescriptor * get_metadata_for_column(const ::shared::ColumnKey &column_key)
Definition: sqldefs.h:48
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
#define LL_BUILDER
#define AUTOMATIC_IR_METADATA(CGENSTATE)
std::vector< double > inverse_bucket_sizes_for_dimension_
#define LL_INT(v)
#define CHECK(condition)
Definition: Logger.h:291
std::vector< InnerOuter > inner_outer_pairs_
#define LL_CONTEXT

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< llvm::Value * > OverlapsJoinHashTable::codegenManyKey ( const CompilationOptions co)
protected

Definition at line 1582 of file OverlapsJoinHashTable.cpp.

References AUTOMATIC_IR_METADATA, CHECK, CHECK_EQ, CodeGenerator::codegen(), executor_, Catalog_Namespace::get_metadata_for_column(), HashJoin::getHashTableForDevice(), getHashType(), getKeyComponentWidth(), inner_outer_pairs_, ManyToMany, CodeGenerator::posArg(), and VLOG.

Referenced by codegenMatchingSet().

1583  {
1584  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
1585  const auto key_component_width = getKeyComponentWidth();
1586  CHECK(key_component_width == 4 || key_component_width == 8);
1587  auto hash_table = getHashTableForDevice(size_t(0));
1588  CHECK(hash_table);
1590 
1591  VLOG(1) << "Performing codgen for ManyToMany";
1592  const auto& inner_outer_pair = inner_outer_pairs_[0];
1593  const auto outer_col = inner_outer_pair.second;
1594 
1595  CodeGenerator code_generator(executor_);
1596  const auto col_lvs = code_generator.codegen(outer_col, true, co);
1597  CHECK_EQ(col_lvs.size(), size_t(1));
1598 
1599  const auto outer_col_var = dynamic_cast<const Analyzer::ColumnVar*>(outer_col);
1600  CHECK(outer_col_var);
1601  const auto coords_cd =
1602  Catalog_Namespace::get_metadata_for_column(outer_col_var->getColumnKey());
1603  CHECK(coords_cd);
1604 
1605  const auto array_ptr = executor_->cgen_state_->emitExternalCall(
1606  "array_buff",
1607  llvm::Type::getInt8PtrTy(executor_->cgen_state_->context_),
1608  {col_lvs.front(), code_generator.posArg(outer_col)});
1609 
1610  // TODO(jclay): this seems to cast to double, and causes the GPU build to fail.
1611  // const auto arr_ptr =
1612  // code_generator.castArrayPointer(array_ptr,
1613  // coords_cd->columnType.get_elem_type());
1614  array_ptr->setName("array_ptr");
1615 
1616  auto num_keys_lv = executor_->cgen_state_->emitExternalCall(
1617  "get_num_buckets_for_bounds",
1618  get_int_type(32, LL_CONTEXT),
1619  {array_ptr,
1620  LL_INT(0),
1623  num_keys_lv->setName("num_keys_lv");
1624 
1625  return {num_keys_lv, array_ptr};
1626 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define LL_FP(v)
const ColumnDescriptor * get_metadata_for_column(const ::shared::ColumnKey &column_key)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
HashType getHashType() const noexceptoverride
#define AUTOMATIC_IR_METADATA(CGENSTATE)
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:281
std::vector< double > inverse_bucket_sizes_for_dimension_
#define LL_INT(v)
#define CHECK(condition)
Definition: Logger.h:291
std::vector< InnerOuter > inner_outer_pairs_
#define LL_CONTEXT
#define VLOG(n)
Definition: Logger.h:387

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HashJoinMatchingSet OverlapsJoinHashTable::codegenMatchingSet ( const CompilationOptions co,
const size_t  index 
)
overrideprotectedvirtual

Implements HashJoin.

Definition at line 1628 of file OverlapsJoinHashTable.cpp.

References AUTOMATIC_IR_METADATA, CHECK, HashJoin::codegenHashTableLoad(), codegenKey(), codegenManyKey(), HashJoin::codegenMatchingSet(), executor_, get_int_array_type(), get_int_type(), getComponentBufferSize(), getEntryCount(), getHashType(), getKeyComponentCount(), getKeyComponentWidth(), inverse_bucket_sizes_for_dimension_, LL_BUILDER, LL_CONTEXT, LL_FP, LL_INT, ManyToMany, offsetBufferOff(), OneToMany, to_string(), UNREACHABLE, and VLOG.

1630  {
1631  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
1632  if (getHashType() == HashType::ManyToMany) {
1633  VLOG(1) << "Building codegenMatchingSet for ManyToMany";
1634  const auto key_component_width = getKeyComponentWidth();
1635  CHECK(key_component_width == 4 || key_component_width == 8);
1636  auto many_to_many_args = codegenManyKey(co);
1637  auto hash_ptr = HashJoin::codegenHashTableLoad(index, executor_);
1638  const auto composite_dict_ptr_type =
1639  llvm::Type::getIntNPtrTy(LL_CONTEXT, key_component_width * 8);
1640  const auto composite_key_dict =
1641  hash_ptr->getType()->isPointerTy()
1642  ? LL_BUILDER.CreatePointerCast(hash_ptr, composite_dict_ptr_type)
1643  : LL_BUILDER.CreateIntToPtr(hash_ptr, composite_dict_ptr_type);
1644  const auto key_component_count = getKeyComponentCount();
1645 
1646  auto one_to_many_ptr = hash_ptr;
1647 
1648  if (one_to_many_ptr->getType()->isPointerTy()) {
1649  one_to_many_ptr =
1650  LL_BUILDER.CreatePtrToInt(hash_ptr, llvm::Type::getInt64Ty(LL_CONTEXT));
1651  } else {
1652  CHECK(one_to_many_ptr->getType()->isIntegerTy(64));
1653  }
1654 
1655  const auto composite_key_dict_size = offsetBufferOff();
1656  one_to_many_ptr =
1657  LL_BUILDER.CreateAdd(one_to_many_ptr, LL_INT(composite_key_dict_size));
1658 
1659  // NOTE(jclay): A fixed array of size 200 is allocated on the stack.
1660  // this is likely the maximum value we can do that is safe to use across
1661  // all supported GPU architectures.
1662  const int max_array_size = 200;
1663  const auto arr_type = get_int_array_type(32, max_array_size, LL_CONTEXT);
1664  const auto out_arr_lv = LL_BUILDER.CreateAlloca(arr_type);
1665  out_arr_lv->setName("out_arr");
1666 
1667  const auto casted_out_arr_lv =
1668  LL_BUILDER.CreatePointerCast(out_arr_lv, arr_type->getPointerTo());
1669 
1670  const auto element_ptr = LL_BUILDER.CreateGEP(arr_type, casted_out_arr_lv, LL_INT(0));
1671 
1672  auto rowid_ptr_i32 =
1673  LL_BUILDER.CreatePointerCast(element_ptr, llvm::Type::getInt32PtrTy(LL_CONTEXT));
1674 
1675  const auto candidate_count_lv = executor_->cgen_state_->emitExternalCall(
1676  "get_candidate_rows",
1677  llvm::Type::getInt64Ty(LL_CONTEXT),
1678  {
1679  rowid_ptr_i32,
1680  LL_INT(max_array_size),
1681  many_to_many_args[1],
1682  LL_INT(0),
1685  many_to_many_args[0],
1686  LL_INT(key_component_count), // key_component_count
1687  composite_key_dict, // ptr to hash table
1688  LL_INT(getEntryCount()), // entry_count
1689  LL_INT(composite_key_dict_size), // offset_buffer_ptr_offset
1690  LL_INT(getEntryCount() * sizeof(int32_t)) // sub_buff_size
1691  });
1692 
1693  const auto slot_lv = LL_INT(int64_t(0));
1694 
1695  return {rowid_ptr_i32, candidate_count_lv, slot_lv};
1696  } else {
1697  VLOG(1) << "Building codegenMatchingSet for Baseline";
1698  // TODO: duplicated w/ BaselineJoinHashTable -- push into the hash table builder?
1699  const auto key_component_width = getKeyComponentWidth();
1700  CHECK(key_component_width == 4 || key_component_width == 8);
1701  auto key_buff_lv = codegenKey(co);
1703  auto hash_ptr = HashJoin::codegenHashTableLoad(index, executor_);
1704  const auto composite_dict_ptr_type =
1705  llvm::Type::getIntNPtrTy(LL_CONTEXT, key_component_width * 8);
1706  const auto composite_key_dict =
1707  hash_ptr->getType()->isPointerTy()
1708  ? LL_BUILDER.CreatePointerCast(hash_ptr, composite_dict_ptr_type)
1709  : LL_BUILDER.CreateIntToPtr(hash_ptr, composite_dict_ptr_type);
1710  const auto key_component_count = getKeyComponentCount();
1711  const auto key = executor_->cgen_state_->emitExternalCall(
1712  "get_composite_key_index_" + std::to_string(key_component_width * 8),
1713  get_int_type(64, LL_CONTEXT),
1714  {key_buff_lv,
1715  LL_INT(key_component_count),
1716  composite_key_dict,
1717  LL_INT(getEntryCount())});
1718  auto one_to_many_ptr = hash_ptr;
1719  if (one_to_many_ptr->getType()->isPointerTy()) {
1720  one_to_many_ptr =
1721  LL_BUILDER.CreatePtrToInt(hash_ptr, llvm::Type::getInt64Ty(LL_CONTEXT));
1722  } else {
1723  CHECK(one_to_many_ptr->getType()->isIntegerTy(64));
1724  }
1725  const auto composite_key_dict_size = offsetBufferOff();
1726  one_to_many_ptr =
1727  LL_BUILDER.CreateAdd(one_to_many_ptr, LL_INT(composite_key_dict_size));
1729  std::vector<llvm::Value*>{
1730  one_to_many_ptr, key, LL_INT(int64_t(0)), LL_INT(getEntryCount() - 1)},
1731  false,
1732  false,
1733  false,
1735  executor_);
1736  }
1737  UNREACHABLE();
1738  return HashJoinMatchingSet{};
1739 }
llvm::Value * codegenKey(const CompilationOptions &)
virtual HashJoinMatchingSet codegenMatchingSet(const CompilationOptions &, const size_t)=0
static llvm::Value * codegenHashTableLoad(const size_t table_idx, Executor *executor)
Definition: HashJoin.cpp:257
#define LL_FP(v)
#define UNREACHABLE()
Definition: Logger.h:337
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
HashType getHashType() const noexceptoverride
std::string to_string(char const *&&v)
#define LL_BUILDER
std::vector< llvm::Value * > codegenManyKey(const CompilationOptions &)
#define AUTOMATIC_IR_METADATA(CGENSTATE)
std::vector< double > inverse_bucket_sizes_for_dimension_
#define LL_INT(v)
size_t offsetBufferOff() const noexceptoverride
#define CHECK(condition)
Definition: Logger.h:291
size_t getComponentBufferSize() const noexceptoverride
#define LL_CONTEXT
llvm::ArrayType * get_int_array_type(int const width, int count, llvm::LLVMContext &context)
#define VLOG(n)
Definition: Logger.h:387

+ Here is the call graph for this function:

llvm::Value* OverlapsJoinHashTable::codegenSlot ( const CompilationOptions ,
const size_t   
)
inlineoverrideprotectedvirtual

Implements HashJoin.

Definition at line 209 of file OverlapsJoinHashTable.h.

References UNREACHABLE.

209  {
210  UNREACHABLE(); // not applicable for overlaps join
211  return nullptr;
212  }
#define UNREACHABLE()
Definition: Logger.h:337
std::pair< size_t, size_t > OverlapsJoinHashTable::computeHashTableCounts ( const size_t  shard_count,
const std::vector< double > &  inverse_bucket_sizes_for_dimension,
std::vector< ColumnsForDevice > &  columns_per_device,
const size_t  chosen_max_hashtable_size,
const double  chosen_bucket_threshold 
)
protectedvirtual

Definition at line 960 of file OverlapsJoinHashTable.cpp.

References approximateTupleCount(), CHECK, device_count_, get_entries_per_device(), and memory_level_.

Referenced by reifyWithLayout().

965  {
966  CHECK(!inverse_bucket_sizes_for_dimension.empty());
967  const auto [tuple_count, emitted_keys_count] =
968  approximateTupleCount(inverse_bucket_sizes_for_dimension,
969  columns_per_device,
970  chosen_max_hashtable_size,
971  chosen_bucket_threshold);
972  const auto entry_count = 2 * std::max(tuple_count, size_t(1));
973 
974  return std::make_pair(
975  get_entries_per_device(entry_count, shard_count, device_count_, memory_level_),
976  emitted_keys_count);
977 }
virtual std::pair< size_t, size_t > approximateTupleCount(const std::vector< double > &inverse_bucket_sizes_for_dimension, std::vector< ColumnsForDevice > &, const size_t chosen_max_hashtable_size, const double chosen_bucket_threshold)
size_t get_entries_per_device(const size_t total_entries, const size_t shard_count, const size_t device_count, const Data_Namespace::MemoryLevel memory_level)
#define CHECK(condition)
Definition: Logger.h:291
const Data_Namespace::MemoryLevel memory_level_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t OverlapsJoinHashTable::countBufferOff ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 267 of file OverlapsJoinHashTable.h.

References getComponentBufferSize(), getHashType(), getKeyBufferSize(), HashJoin::layoutRequiresAdditionalBuffers(), and offsetBufferOff().

Referenced by payloadBufferOff(), toSet(), and toString().

267  {
270  } else {
271  return getKeyBufferSize();
272  }
273  }
HashType getHashType() const noexceptoverride
size_t offsetBufferOff() const noexceptoverride
size_t getComponentBufferSize() const noexceptoverride
size_t getKeyBufferSize() const noexcept
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:161

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ColumnsForDevice OverlapsJoinHashTable::fetchColumnsForDevice ( const std::vector< Fragmenter_Namespace::FragmentInfo > &  fragments,
const int  device_id,
DeviceAllocator dev_buff_owner 
)
protected

Definition at line 922 of file OverlapsJoinHashTable.cpp.

References CHECK, column_cache_, executor_, HashJoin::fetchJoinColumn(), get_column_descriptor_maybe(), get_join_column_type_kind(), getEffectiveMemoryLevel(), and inner_outer_pairs_.

Referenced by RangeJoinHashTable::reifyWithLayout(), and reifyWithLayout().

925  {
926  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
927 
928  std::vector<JoinColumn> join_columns;
929  std::vector<std::shared_ptr<Chunk_NS::Chunk>> chunks_owner;
930  std::vector<JoinColumnTypeInfo> join_column_types;
931  std::vector<std::shared_ptr<void>> malloc_owner;
932  for (const auto& inner_outer_pair : inner_outer_pairs_) {
933  const auto inner_col = inner_outer_pair.first;
934  const auto inner_cd = get_column_descriptor_maybe(inner_col->getColumnKey());
935  if (inner_cd && inner_cd->isVirtualCol) {
937  }
938  join_columns.emplace_back(fetchJoinColumn(inner_col,
939  fragments,
940  effective_memory_level,
941  device_id,
942  chunks_owner,
943  dev_buff_owner,
944  malloc_owner,
945  executor_,
946  &column_cache_));
947  const auto& ti = inner_col->get_type_info();
948  join_column_types.emplace_back(JoinColumnTypeInfo{static_cast<size_t>(ti.get_size()),
949  0,
950  0,
951  inline_int_null_value<int64_t>(),
952  false,
953  0,
955  CHECK(ti.is_array()) << "Overlaps join currently only supported for arrays.";
956  }
957  return {join_columns, join_column_types, chunks_owner, {}, malloc_owner};
958 }
JoinColumn fetchJoinColumn(const Analyzer::ColumnVar *hash_col, const std::vector< Fragmenter_Namespace::FragmentInfo > &fragment_info, const Data_Namespace::MemoryLevel effective_memory_level, const int device_id, std::vector< std::shared_ptr< Chunk_NS::Chunk >> &chunks_owner, DeviceAllocator *dev_buff_owner, std::vector< std::shared_ptr< void >> &malloc_owner, Executor *executor, ColumnCacheMap *column_cache)
Definition: HashJoin.cpp:58
const ColumnDescriptor * get_column_descriptor_maybe(const shared::ColumnKey &column_key)
Definition: Execute.h:220
ColumnCacheMap & column_cache_
ColumnType get_join_column_type_kind(const SQLTypeInfo &ti)
#define CHECK(condition)
Definition: Logger.h:291
std::vector< InnerOuter > inner_outer_pairs_
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void OverlapsJoinHashTable::generateCacheKey ( const size_t  max_hashtable_size,
const double  bucket_threshold,
const std::vector< double > &  bucket_sizes,
std::vector< std::vector< Fragmenter_Namespace::FragmentInfo >> &  fragments_per_device,
int  device_count 
)
inlineprotected

Definition at line 339 of file OverlapsJoinHashTable.h.

References HashJoin::collectFragmentIds(), hash_table_cache_, hashtable_cache_key_, and table_keys_.

Referenced by RangeJoinHashTable::reifyWithLayout(), and reifyWithLayout().

344  {
345  for (int device_id = 0; device_id < device_count; ++device_id) {
346  auto hash_val = boost::hash_value(hashtable_cache_key_[device_id]);
347  boost::hash_combine(hash_val, max_hashtable_size);
348  boost::hash_combine(hash_val, bucket_threshold);
349  boost::hash_combine(hash_val, bucket_sizes);
350  boost::hash_combine(hash_val,
351  HashJoin::collectFragmentIds(fragments_per_device[device_id]));
352  hashtable_cache_key_[device_id] = hash_val;
353  hash_table_cache_->addQueryPlanDagForTableKeys(hashtable_cache_key_[device_id],
354  table_keys_);
355  }
356  }
static std::vector< int > collectFragmentIds(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments)
Definition: HashJoin.cpp:452
std::vector< QueryPlanHash > hashtable_cache_key_
static std::unique_ptr< HashtableRecycler > hash_table_cache_
std::unordered_set< size_t > table_keys_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QueryPlanHash OverlapsJoinHashTable::getAlternativeCacheKey ( AlternativeCacheKeyForOverlapsHashJoin info)
inlineprotected

Definition at line 320 of file OverlapsJoinHashTable.h.

References OverlapsJoinHashTable::AlternativeCacheKeyForOverlapsHashJoin::bucket_threshold, OverlapsJoinHashTable::AlternativeCacheKeyForOverlapsHashJoin::chunk_key_hash, OverlapsJoinHashTable::AlternativeCacheKeyForOverlapsHashJoin::inner_outer_pairs, OverlapsJoinHashTable::AlternativeCacheKeyForOverlapsHashJoin::inverse_bucket_sizes, OverlapsJoinHashTable::AlternativeCacheKeyForOverlapsHashJoin::max_hashtable_size, OverlapsJoinHashTable::AlternativeCacheKeyForOverlapsHashJoin::num_elements, and OverlapsJoinHashTable::AlternativeCacheKeyForOverlapsHashJoin::optype.

Referenced by RangeJoinHashTable::reifyWithLayout(), and reifyWithLayout().

320  {
321  auto hash = info.chunk_key_hash;
322  for (InnerOuter inner_outer : info.inner_outer_pairs) {
323  auto inner_col = inner_outer.first;
324  auto rhs_col_var = dynamic_cast<const Analyzer::ColumnVar*>(inner_outer.second);
325  auto outer_col = rhs_col_var ? rhs_col_var : inner_col;
326  boost::hash_combine(hash, inner_col->toString());
327  if (inner_col->get_type_info().is_string()) {
328  boost::hash_combine(hash, outer_col->toString());
329  }
330  }
331  boost::hash_combine(hash, info.num_elements);
332  boost::hash_combine(hash, info.optype);
333  boost::hash_combine(hash, info.max_hashtable_size);
334  boost::hash_combine(hash, info.bucket_threshold);
335  boost::hash_combine(hash, info.inverse_bucket_sizes);
336  return hash;
337  }
std::pair< const Analyzer::ColumnVar *, const Analyzer::Expr * > InnerOuter
Definition: HashJoin.h:106

+ Here is the caller graph for this function:

std::optional< std::pair< size_t, size_t > > OverlapsJoinHashTable::getApproximateTupleCountFromCache ( QueryPlanHash  key,
CacheItemType  item_type,
DeviceIdentifier  device_identifier 
)
protected

Definition at line 1858 of file OverlapsJoinHashTable.cpp.

References CHECK, getOverlapsHashTableMetaInfo(), hash_table_cache_, and HashtableCacheMetaInfo::overlaps_meta_info.

Referenced by approximateTupleCount().

1861  {
1863  HashtableCacheMetaInfo metaInfo;
1865  auto cached_hashtable =
1866  hash_table_cache_->getItemFromCache(key, item_type, device_identifier, metaInfo);
1867  if (cached_hashtable) {
1868  return std::make_pair(cached_hashtable->getEntryCount() / 2,
1869  cached_hashtable->getEmittedKeysCount());
1870  }
1871  return std::nullopt;
1872 }
std::optional< OverlapsHashTableMetaInfo > overlaps_meta_info
#define CHECK(condition)
Definition: Logger.h:291
static std::unique_ptr< HashtableRecycler > hash_table_cache_
std::optional< OverlapsHashTableMetaInfo > getOverlapsHashTableMetaInfo()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QueryPlanHash OverlapsJoinHashTable::getCacheKey ( int  device_id) const
inlineprotected

Definition at line 358 of file OverlapsJoinHashTable.h.

References hashtable_cache_key_.

358  {
359  return hashtable_cache_key_[device_id];
360  }
std::vector< QueryPlanHash > hashtable_cache_key_
size_t OverlapsJoinHashTable::getComponentBufferSize ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 228 of file OverlapsJoinHashTable.h.

References CHECK, and HashJoin::hash_tables_for_device_.

Referenced by codegenMatchingSet(), RangeJoinHashTable::codegenMatchingSetWithOffset(), countBufferOff(), and payloadBufferOff().

228  {
229  CHECK(!hash_tables_for_device_.empty());
230  auto hash_table = hash_tables_for_device_.front();
231  CHECK(hash_table);
232  return hash_table->getEntryCount() * sizeof(int32_t);
233  }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:363
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

int OverlapsJoinHashTable::getDeviceCount ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 170 of file OverlapsJoinHashTable.h.

References device_count_.

170 { return device_count_; };
Data_Namespace::MemoryLevel OverlapsJoinHashTable::getEffectiveMemoryLevel ( const std::vector< InnerOuter > &  inner_outer_pairs) const
protected

Definition at line 1819 of file OverlapsJoinHashTable.cpp.

References Data_Namespace::CPU_LEVEL, executor_, Data_Namespace::GPU_LEVEL, RegisteredQueryHint::isHintRegistered(), kOverlapsAllowGpuBuild, memory_level_, RegisteredQueryHint::overlaps_allow_gpu_build, and query_hints_.

Referenced by approximateTupleCount(), fetchColumnsForDevice(), reifyForDevice(), RangeJoinHashTable::reifyWithLayout(), and reifyWithLayout().

1820  {
1823  this->executor_->getDataMgr()->gpusPresent() &&
1826  }
1827  // otherwise, try to build on CPU
1829 }
bool overlaps_allow_gpu_build
Definition: QueryHint.h:318
RegisteredQueryHint query_hints_
bool isHintRegistered(const QueryHint hint) const
Definition: QueryHint.h:348
const Data_Namespace::MemoryLevel memory_level_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t OverlapsJoinHashTable::getEmittedKeysCount ( ) const
inlineprotected

Definition at line 222 of file OverlapsJoinHashTable.h.

References CHECK, and HashJoin::getHashTableForDevice().

222  {
223  auto hash_table = getHashTableForDevice(0);
224  CHECK(hash_table);
225  return hash_table->getEmittedKeysCount();
226  }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:281
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

size_t OverlapsJoinHashTable::getEntryCount ( ) const
inlineprotected

Definition at line 216 of file OverlapsJoinHashTable.h.

References CHECK, and HashJoin::getHashTableForDevice().

Referenced by codegenMatchingSet(), RangeJoinHashTable::codegenMatchingSetWithOffset(), and getKeyBufferSize().

216  {
217  auto hash_table = getHashTableForDevice(0);
218  CHECK(hash_table);
219  return hash_table->getEntryCount();
220  }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:281
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string OverlapsJoinHashTable::getHashJoinType ( ) const
inlinefinalprotectedvirtual

Implements HashJoin.

Definition at line 283 of file OverlapsJoinHashTable.h.

283 { return "Overlaps"; }
static HashtableRecycler* OverlapsJoinHashTable::getHashTableCache ( )
inlinestatic

Definition at line 92 of file OverlapsJoinHashTable.h.

References CHECK, and hash_table_cache_.

Referenced by QueryRunner::QueryRunner::getCachedHashtableWithoutCacheKey(), QueryRunner::QueryRunner::getCacheItemMetric(), and QueryRunner::QueryRunner::getNumberOfCachedItem().

92  {
94  return hash_table_cache_.get();
95  }
#define CHECK(condition)
Definition: Logger.h:291
static std::unique_ptr< HashtableRecycler > hash_table_cache_

+ Here is the caller graph for this function:

HashType OverlapsJoinHashTable::getHashType ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Reimplemented in RangeJoinHashTable.

Definition at line 157 of file OverlapsJoinHashTable.h.

References CHECK, HashJoin::getHashTableForDevice(), and layout_override_.

Referenced by codegenManyKey(), codegenMatchingSet(), countBufferOff(), getKeyBufferSize(), payloadBufferOff(), toSet(), and toString().

157  {
158  if (layout_override_) {
159  return *layout_override_;
160  }
161  auto hash_table = getHashTableForDevice(0);
162  CHECK(hash_table);
163  return hash_table->getLayout();
164  }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:281
std::optional< HashType > layout_override_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::vector<InnerOuter>& OverlapsJoinHashTable::getInnerOuterPairs ( ) const
inlineprotected

Definition at line 362 of file OverlapsJoinHashTable.h.

References inner_outer_pairs_.

Referenced by RangeJoinHashTable::isProbeCompressed().

362 { return inner_outer_pairs_; }
std::vector< InnerOuter > inner_outer_pairs_

+ Here is the caller graph for this function:

shared::TableKey OverlapsJoinHashTable::getInnerTableId ( ) const
overrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 1831 of file OverlapsJoinHashTable.cpp.

References CHECK, HashJoin::getInnerTableId(), and inner_outer_pairs_.

Referenced by RangeJoinHashTable::reifyWithLayout().

1831  {
1832  try {
1834  } catch (...) {
1835  CHECK(false);
1836  }
1837  return {};
1838 }
virtual shared::TableKey getInnerTableId() const noexcept=0
#define CHECK(condition)
Definition: Logger.h:291
std::vector< InnerOuter > inner_outer_pairs_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int OverlapsJoinHashTable::getInnerTableRteIdx ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 248 of file OverlapsJoinHashTable.h.

References CHECK, and inner_outer_pairs_.

248  {
249  CHECK(!inner_outer_pairs_.empty());
250  const auto first_inner_col = inner_outer_pairs_.front().first;
251  return first_inner_col->get_rte_idx();
252  }
#define CHECK(condition)
Definition: Logger.h:291
std::vector< InnerOuter > inner_outer_pairs_
std::shared_ptr< OverlapsJoinHashTable > OverlapsJoinHashTable::getInstance ( const std::shared_ptr< Analyzer::BinOper condition,
const std::vector< InputTableInfo > &  query_infos,
const Data_Namespace::MemoryLevel  memory_level,
const JoinType  join_type,
const int  device_count,
ColumnCacheMap column_cache,
Executor executor,
const HashTableBuildDagMap hashtable_build_dag_map,
const RegisteredQueryHint query_hint,
const TableIdToNodeMap table_id_to_node_map 
)
static

Make hash table from an in-flight SQL query's parse tree etc.

Definition at line 37 of file OverlapsJoinHashTable.cpp.

References CHECK, CHECK_EQ, get_inner_query_info(), HashJoin::getHashTypeString(), HashJoin::getInnerTableId(), RangeJoinHashTable::getInstance(), Fragmenter_Namespace::TableInfo::getNumTuplesUpperBound(), InputTableInfo::info, ManyToMany, HashJoin::normalizeColumnPairs(), OneToMany, VLOG, and VLOGGING.

Referenced by HashJoin::getInstance().

47  {
48  decltype(std::chrono::steady_clock::now()) ts1, ts2;
49 
50  std::vector<InnerOuter> inner_outer_pairs;
51 
52  if (const auto range_expr =
53  dynamic_cast<const Analyzer::RangeOper*>(condition->get_right_operand())) {
54  return RangeJoinHashTable::getInstance(condition,
55  range_expr,
56  query_infos,
57  memory_level,
58  join_type,
59  device_count,
60  column_cache,
61  executor,
62  hashtable_build_dag_map,
63  query_hints,
64  table_id_to_node_map);
65  } else {
66  inner_outer_pairs =
67  HashJoin::normalizeColumnPairs(condition.get(), executor->getTemporaryTables())
68  .first;
69  }
70  CHECK(!inner_outer_pairs.empty());
71 
72  const auto getHashTableType =
73  [](const std::shared_ptr<Analyzer::BinOper> condition,
74  const std::vector<InnerOuter>& inner_outer_pairs) -> HashType {
76  if (condition->is_overlaps_oper()) {
77  CHECK_EQ(inner_outer_pairs.size(), size_t(1));
78  if (inner_outer_pairs[0].first->get_type_info().is_array() &&
79  inner_outer_pairs[0].second->get_type_info().is_array() &&
80  // Bounds vs constructed points, former should yield ManyToMany
81  inner_outer_pairs[0].second->get_type_info().get_size() == 32) {
82  layout = HashType::ManyToMany;
83  }
84  }
85  return layout;
86  };
87 
88  const auto layout = getHashTableType(condition, inner_outer_pairs);
89 
90  if (VLOGGING(1)) {
91  VLOG(1) << "Building geo hash table " << getHashTypeString(layout)
92  << " for qual: " << condition->toString();
93  ts1 = std::chrono::steady_clock::now();
94  }
95 
96  const auto qi_0 = query_infos[0].info.getNumTuplesUpperBound();
97  const auto qi_1 = query_infos[1].info.getNumTuplesUpperBound();
98 
99  VLOG(1) << "table_key = " << query_infos[0].table_key << " has " << qi_0 << " tuples.";
100  VLOG(1) << "table_key = " << query_infos[1].table_key << " has " << qi_1 << " tuples.";
101 
102  const auto& query_info =
103  get_inner_query_info(HashJoin::getInnerTableId(inner_outer_pairs), query_infos)
104  .info;
105  const auto total_entries = 2 * query_info.getNumTuplesUpperBound();
106  if (total_entries > static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
107  throw TooManyHashEntries();
108  }
109 
110  auto join_hash_table = std::make_shared<OverlapsJoinHashTable>(condition,
111  join_type,
112  query_infos,
113  memory_level,
114  column_cache,
115  executor,
116  inner_outer_pairs,
117  device_count,
118  query_hints,
119  hashtable_build_dag_map,
120  table_id_to_node_map);
121  try {
122  join_hash_table->reify(layout);
123  } catch (const HashJoinFail& e) {
124  throw HashJoinFail(std::string("Could not build a 1-to-1 correspondence for columns "
125  "involved in overlaps join | ") +
126  e.what());
127  } catch (const ColumnarConversionNotSupported& e) {
128  throw HashJoinFail(std::string("Could not build hash tables for overlaps join | "
129  "Inner table too big. Attempt manual table reordering "
130  "or create a single fragment inner table. | ") +
131  e.what());
132  } catch (const JoinHashTableTooBig& e) {
133  throw e;
134  } catch (const std::exception& e) {
135  throw HashJoinFail(std::string("Failed to build hash tables for overlaps join | ") +
136  e.what());
137  }
138  if (VLOGGING(1)) {
139  ts2 = std::chrono::steady_clock::now();
140  VLOG(1) << "Built geo hash table " << getHashTypeString(layout) << " in "
141  << std::chrono::duration_cast<std::chrono::milliseconds>(ts2 - ts1).count()
142  << " ms";
143  }
144  return join_hash_table;
145 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Fragmenter_Namespace::TableInfo info
Definition: InputMetadata.h:35
std::pair< const Analyzer::ColumnVar *, const Analyzer::Expr * > InnerOuter
Definition: HashJoin.h:106
const InputTableInfo & get_inner_query_info(const shared::TableKey &inner_table_key, const std::vector< InputTableInfo > &query_infos)
static std::shared_ptr< RangeJoinHashTable > getInstance(const std::shared_ptr< Analyzer::BinOper > condition, const Analyzer::RangeOper *range_expr, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, const JoinType join_type, const int device_count, ColumnCacheMap &column_cache, Executor *executor, const HashTableBuildDagMap &hashtable_build_dag_map, const RegisteredQueryHint &query_hints, const TableIdToNodeMap &table_id_to_node_map)
virtual shared::TableKey getInnerTableId() const noexcept=0
#define VLOGGING(n)
Definition: Logger.h:289
static std::string getHashTypeString(HashType ht) noexcept
Definition: HashJoin.h:165
#define CHECK(condition)
Definition: Logger.h:291
static std::pair< std::vector< InnerOuter >, std::vector< InnerOuterStringOpInfos > > normalizeColumnPairs(const Analyzer::BinOper *condition, const TemporaryTables *temporary_tables)
Definition: HashJoin.cpp:996
HashType
Definition: HashTable.h:19
#define VLOG(n)
Definition: Logger.h:387

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t OverlapsJoinHashTable::getKeyBufferSize ( ) const
inlineprotectednoexcept

Definition at line 254 of file OverlapsJoinHashTable.h.

References CHECK, getEntryCount(), getHashType(), getKeyComponentCount(), getKeyComponentWidth(), and HashJoin::layoutRequiresAdditionalBuffers().

Referenced by countBufferOff(), offsetBufferOff(), and payloadBufferOff().

254  {
255  const auto key_component_width = getKeyComponentWidth();
256  CHECK(key_component_width == 4 || key_component_width == 8);
257  const auto key_component_count = getKeyComponentCount();
259  return getEntryCount() * key_component_count * key_component_width;
260  } else {
261  return getEntryCount() * (key_component_count + 1) * key_component_width;
262  }
263  }
HashType getHashType() const noexceptoverride
#define CHECK(condition)
Definition: Logger.h:291
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:161

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t OverlapsJoinHashTable::getKeyComponentCount ( ) const
protected

Definition at line 1168 of file OverlapsJoinHashTable.cpp.

References CHECK, and inverse_bucket_sizes_for_dimension_.

Referenced by RangeJoinHashTable::codegenKey(), codegenKey(), codegenMatchingSet(), RangeJoinHashTable::codegenMatchingSetWithOffset(), getKeyBufferSize(), RangeJoinHashTable::initHashTableOnCpu(), initHashTableOnCpu(), toSet(), and toString().

1168  {
1171 }
std::vector< double > inverse_bucket_sizes_for_dimension_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

size_t OverlapsJoinHashTable::getKeyComponentWidth ( ) const
protected

Definition at line 1164 of file OverlapsJoinHashTable.cpp.

Referenced by calculateHashTableSize(), RangeJoinHashTable::codegenKey(), codegenKey(), codegenManyKey(), codegenMatchingSet(), RangeJoinHashTable::codegenMatchingSetWithOffset(), getKeyBufferSize(), RangeJoinHashTable::initHashTableOnCpu(), initHashTableOnCpu(), RangeJoinHashTable::reifyForDevice(), reifyForDevice(), toSet(), and toString().

1164  {
1165  return 8;
1166 }

+ Here is the caller graph for this function:

Data_Namespace::MemoryLevel OverlapsJoinHashTable::getMemoryLevel ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 166 of file OverlapsJoinHashTable.h.

References memory_level_.

166  {
167  return memory_level_;
168  }
const Data_Namespace::MemoryLevel memory_level_
std::optional<OverlapsHashTableMetaInfo> OverlapsJoinHashTable::getOverlapsHashTableMetaInfo ( )
inlineprotected

Definition at line 306 of file OverlapsJoinHashTable.h.

References hashtable_cache_meta_info_, and HashtableCacheMetaInfo::overlaps_meta_info.

Referenced by getApproximateTupleCountFromCache(), initHashTableOnCpuFromCache(), and putHashTableOnCpuToCache().

306  {
308  }
std::optional< OverlapsHashTableMetaInfo > overlaps_meta_info
HashtableCacheMetaInfo hashtable_cache_meta_info_

+ Here is the caller graph for this function:

static OverlapsTuningParamRecycler* OverlapsJoinHashTable::getOverlapsTuningParamCache ( )
inlinestatic

Definition at line 97 of file OverlapsJoinHashTable.h.

References auto_tuner_cache_, and CHECK.

Referenced by QueryRunner::QueryRunner::getNumberOfCachedItem().

97  {
99  return auto_tuner_cache_.get();
100  }
static std::unique_ptr< OverlapsTuningParamRecycler > auto_tuner_cache_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

const RegisteredQueryHint& OverlapsJoinHashTable::getRegisteredQueryHint ( )
inlineprotected

Definition at line 214 of file OverlapsJoinHashTable.h.

References query_hints_.

214 { return query_hints_; }
RegisteredQueryHint query_hints_
std::shared_ptr< BaselineHashTable > OverlapsJoinHashTable::initHashTableOnCpu ( const std::vector< JoinColumn > &  join_columns,
const std::vector< JoinColumnTypeInfo > &  join_column_types,
const std::vector< JoinBucketInfo > &  join_bucket_info,
const HashType  layout,
const size_t  entry_count,
const size_t  emitted_keys_count,
const bool  skip_hashtable_caching 
)
protected

Definition at line 1297 of file OverlapsJoinHashTable.cpp.

References CHECK, composite_key_info_, DataRecyclerUtil::CPU_DEVICE_IDENTIFIER, cpu_hash_table_buff_mutex_, DEBUG_TIMER, getKeyComponentCount(), getKeyComponentWidth(), hashtable_cache_key_, BaselineJoinHashTableBuilder::initHashTableOnCpu(), initHashTableOnCpuFromCache(), join_type_, layout_override_, HashJoin::layoutRequiresAdditionalBuffers(), ManyToMany, OneToMany, OVERLAPS_HT, putHashTableOnCpuToCache(), query_hints_, to_string(), and VLOG.

Referenced by reifyForDevice().

1304  {
1305  auto timer = DEBUG_TIMER(__func__);
1306  decltype(std::chrono::steady_clock::now()) ts1, ts2;
1307  ts1 = std::chrono::steady_clock::now();
1308  CHECK(!join_columns.empty());
1309  CHECK(!join_bucket_info.empty());
1310  std::lock_guard<std::mutex> cpu_hash_table_buff_lock(cpu_hash_table_buff_mutex_);
1311  if (auto generic_hash_table =
1314  DataRecyclerUtil::CPU_DEVICE_IDENTIFIER)) {
1315  if (auto hash_table =
1316  std::dynamic_pointer_cast<BaselineHashTable>(generic_hash_table)) {
1317  VLOG(1) << "Using cached CPU hash table for initialization.";
1318  // See if a hash table of a different layout was returned.
1319  // If it was OneToMany, we can reuse it on ManyToMany.
1320  if (layout == HashType::ManyToMany &&
1321  hash_table->getLayout() == HashType::OneToMany) {
1322  // use the cached hash table
1324  return hash_table;
1325  }
1326  if (layout == hash_table->getLayout()) {
1327  return hash_table;
1328  }
1329  }
1330  }
1332  const auto key_component_count =
1333  join_bucket_info[0].inverse_bucket_sizes_for_dimension.size();
1334 
1335  const auto key_handler =
1336  OverlapsKeyHandler(key_component_count,
1337  &join_columns[0],
1338  join_bucket_info[0].inverse_bucket_sizes_for_dimension.data());
1341  dummy_str_proxy_translation_maps_ptrs_and_offsets;
1342  const auto err =
1343  builder.initHashTableOnCpu(&key_handler,
1345  join_columns,
1346  join_column_types,
1347  join_bucket_info,
1348  dummy_str_proxy_translation_maps_ptrs_and_offsets,
1349  entry_count,
1350  emitted_keys_count,
1351  layout,
1352  join_type_,
1355  query_hints_);
1356  ts2 = std::chrono::steady_clock::now();
1357  if (err) {
1358  throw HashJoinFail(
1359  std::string("Unrecognized error when initializing CPU overlaps hash table (") +
1360  std::to_string(err) + std::string(")"));
1361  }
1362  std::shared_ptr<BaselineHashTable> hash_table = builder.getHashTable();
1363  if (skip_hashtable_caching) {
1364  VLOG(1) << "Skip to cache overlaps join hashtable";
1365  } else {
1366  auto hashtable_build_time =
1367  std::chrono::duration_cast<std::chrono::milliseconds>(ts2 - ts1).count();
1370  hash_table,
1372  hashtable_build_time);
1373  }
1374  return hash_table;
1375 }
std::lock_guard< T > lock_guard
std::shared_ptr< HashTable > initHashTableOnCpuFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier)
int initHashTableOnCpu(KEY_HANDLER *key_handler, const CompositeKeyInfo &composite_key_info, const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const std::vector< JoinBucketInfo > &join_bucket_info, const StrProxyTranslationMapsPtrsAndOffsets &str_proxy_translation_maps_ptrs_and_offsets, const size_t keyspace_entry_count, const size_t keys_for_all_rows, const HashType layout, const JoinType join_type, const size_t key_component_width, const size_t key_component_count, const RegisteredQueryHint &query_hint)
void putHashTableOnCpuToCache(QueryPlanHash key, CacheItemType item_type, std::shared_ptr< HashTable > hashtable_ptr, DeviceIdentifier device_identifier, size_t hashtable_building_time)
std::string to_string(char const *&&v)
CacheItemType
Definition: DataRecycler.h:38
RegisteredQueryHint query_hints_
std::vector< QueryPlanHash > hashtable_cache_key_
std::optional< HashType > layout_override_
std::pair< std::vector< const int32_t * >, std::vector< int32_t >> StrProxyTranslationMapsPtrsAndOffsets
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:411
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
CompositeKeyInfo composite_key_info_
#define VLOG(n)
Definition: Logger.h:387
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:161

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< HashTable > OverlapsJoinHashTable::initHashTableOnCpuFromCache ( QueryPlanHash  key,
CacheItemType  item_type,
DeviceIdentifier  device_identifier 
)
protected

Definition at line 1840 of file OverlapsJoinHashTable.cpp.

References CHECK, DEBUG_TIMER, getOverlapsHashTableMetaInfo(), hash_table_cache_, HashtableCacheMetaInfo::overlaps_meta_info, and VLOG.

Referenced by initHashTableOnCpu(), and RangeJoinHashTable::reifyWithLayout().

1843  {
1844  auto timer = DEBUG_TIMER(__func__);
1845  VLOG(1) << "Checking CPU hash table cache.";
1847  HashtableCacheMetaInfo meta_info;
1849  auto cached_hashtable =
1850  hash_table_cache_->getItemFromCache(key, item_type, device_identifier, meta_info);
1851  if (cached_hashtable) {
1852  return cached_hashtable;
1853  }
1854  return nullptr;
1855 }
std::optional< OverlapsHashTableMetaInfo > overlaps_meta_info
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:411
static std::unique_ptr< HashtableRecycler > hash_table_cache_
std::optional< OverlapsHashTableMetaInfo > getOverlapsHashTableMetaInfo()
#define VLOG(n)
Definition: Logger.h:387

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void OverlapsJoinHashTable::invalidateCache ( )
inlinestatic

Definition at line 67 of file OverlapsJoinHashTable.h.

References auto_tuner_cache_, CHECK, and hash_table_cache_.

67  {
69  auto_tuner_cache_->clearCache();
70 
72  hash_table_cache_->clearCache();
73  }
static std::unique_ptr< OverlapsTuningParamRecycler > auto_tuner_cache_
#define CHECK(condition)
Definition: Logger.h:291
static std::unique_ptr< HashtableRecycler > hash_table_cache_
bool OverlapsJoinHashTable::isBitwiseEq ( ) const
overrideprotectedvirtual

Implements HashJoin.

Definition at line 1895 of file OverlapsJoinHashTable.cpp.

References condition_, and kBW_EQ.

1895  {
1896  return condition_->get_optype() == kBW_EQ;
1897 }
const std::shared_ptr< Analyzer::BinOper > condition_
Definition: sqldefs.h:30
static void OverlapsJoinHashTable::markCachedItemAsDirty ( size_t  table_key)
inlinestatic

Definition at line 75 of file OverlapsJoinHashTable.h.

References auto_tuner_cache_, CHECK, DataRecyclerUtil::CPU_DEVICE_IDENTIFIER, hash_table_cache_, OVERLAPS_AUTO_TUNER_PARAM, and OVERLAPS_HT.

75  {
78  auto candidate_table_keys =
79  hash_table_cache_->getMappedQueryPlanDagsWithTableKey(table_key);
80  if (candidate_table_keys.has_value()) {
81  auto_tuner_cache_->markCachedItemAsDirty(table_key,
82  *candidate_table_keys,
85  hash_table_cache_->markCachedItemAsDirty(table_key,
86  *candidate_table_keys,
89  }
90  }
static std::unique_ptr< OverlapsTuningParamRecycler > auto_tuner_cache_
#define CHECK(condition)
Definition: Logger.h:291
static std::unique_ptr< HashtableRecycler > hash_table_cache_
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
size_t OverlapsJoinHashTable::offsetBufferOff ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 265 of file OverlapsJoinHashTable.h.

References getKeyBufferSize().

Referenced by codegenMatchingSet(), RangeJoinHashTable::codegenMatchingSetWithOffset(), countBufferOff(), toSet(), and toString().

265 { return getKeyBufferSize(); }
size_t getKeyBufferSize() const noexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t OverlapsJoinHashTable::payloadBufferOff ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 275 of file OverlapsJoinHashTable.h.

References countBufferOff(), getComponentBufferSize(), getHashType(), getKeyBufferSize(), and HashJoin::layoutRequiresAdditionalBuffers().

Referenced by toSet(), and toString().

275  {
278  } else {
279  return getKeyBufferSize();
280  }
281  }
HashType getHashType() const noexceptoverride
size_t countBufferOff() const noexceptoverride
size_t getComponentBufferSize() const noexceptoverride
size_t getKeyBufferSize() const noexcept
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:161

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void OverlapsJoinHashTable::putHashTableOnCpuToCache ( QueryPlanHash  key,
CacheItemType  item_type,
std::shared_ptr< HashTable hashtable_ptr,
DeviceIdentifier  device_identifier,
size_t  hashtable_building_time 
)
protected

Definition at line 1874 of file OverlapsJoinHashTable.cpp.

References CHECK, CPU, getOverlapsHashTableMetaInfo(), hash_table_cache_, HashtableCacheMetaInfo::overlaps_meta_info, and query_hints_.

Referenced by RangeJoinHashTable::initHashTableOnCpu(), and initHashTableOnCpu().

1879  {
1881  CHECK(hashtable_ptr && !hashtable_ptr->getGpuBuffer());
1882  HashtableCacheMetaInfo meta_info;
1884  meta_info.registered_query_hint = query_hints_;
1885  hash_table_cache_->putItemToCache(
1886  key,
1887  hashtable_ptr,
1888  item_type,
1889  device_identifier,
1890  hashtable_ptr->getHashTableBufferSize(ExecutorDeviceType::CPU),
1891  hashtable_building_time,
1892  meta_info);
1893 }
std::optional< OverlapsHashTableMetaInfo > overlaps_meta_info
RegisteredQueryHint query_hints_
#define CHECK(condition)
Definition: Logger.h:291
static std::unique_ptr< HashtableRecycler > hash_table_cache_
std::optional< OverlapsHashTableMetaInfo > getOverlapsHashTableMetaInfo()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void OverlapsJoinHashTable::reify ( const HashType  preferred_layout)
protected

Definition at line 1173 of file OverlapsJoinHashTable.cpp.

References CHECK, CHECK_EQ, CHECK_LT, composite_key_info_, condition_, DEBUG_TIMER, device_count_, executor_, HashJoin::getCompositeKeyInfo(), inner_outer_pairs_, ManyToMany, OneToMany, reifyWithLayout(), and VLOG.

1173  {
1174  auto timer = DEBUG_TIMER(__func__);
1175  CHECK_LT(0, device_count_);
1177 
1178  CHECK(condition_->is_overlaps_oper());
1179  CHECK_EQ(inner_outer_pairs_.size(), size_t(1));
1180  HashType layout;
1181  if (inner_outer_pairs_[0].second->get_type_info().is_fixlen_array() &&
1182  inner_outer_pairs_[0].second->get_type_info().get_size() == 32) {
1183  // bounds array
1184  layout = HashType::ManyToMany;
1185  } else {
1186  layout = HashType::OneToMany;
1187  }
1188  try {
1189  reifyWithLayout(layout);
1190  return;
1191  } catch (const JoinHashTableTooBig& e) {
1192  throw e;
1193  } catch (const std::exception& e) {
1194  VLOG(1) << "Caught exception while building overlaps baseline hash table: "
1195  << e.what();
1196  throw;
1197  }
1198 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
virtual void reifyWithLayout(const HashType layout)
const std::shared_ptr< Analyzer::BinOper > condition_
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:411
std::vector< InnerOuter > inner_outer_pairs_
CompositeKeyInfo composite_key_info_
HashType
Definition: HashTable.h:19
#define VLOG(n)
Definition: Logger.h:387
static CompositeKeyInfo getCompositeKeyInfo(const std::vector< InnerOuter > &inner_outer_pairs, const Executor *executor, const std::vector< InnerOuterStringOpInfos > &inner_outer_string_op_infos_pairs={})
Definition: HashJoin.cpp:461

+ Here is the call graph for this function:

void OverlapsJoinHashTable::reifyForDevice ( const ColumnsForDevice columns_for_device,
const HashType  layout,
const size_t  entry_count,
const size_t  emitted_keys_count,
const bool  skip_hashtable_caching,
const int  device_id,
const logger::ThreadLocalIds  parent_thread_local_ids 
)
protected

Definition at line 1240 of file OverlapsJoinHashTable.cpp.

References CHECK, CHECK_EQ, CHECK_LT, Data_Namespace::CPU_LEVEL, DEBUG_TIMER_NEW_THREAD, getEffectiveMemoryLevel(), getKeyComponentWidth(), Data_Namespace::GPU_LEVEL, HashJoin::hash_tables_for_device_, initHashTableOnCpu(), inner_outer_pairs_, ColumnsForDevice::join_buckets, ColumnsForDevice::join_column_types, ColumnsForDevice::join_columns, HashJoin::layoutRequiresAdditionalBuffers(), memory_level_, logger::ThreadLocalIds::setNewThreadId(), logger::ThreadLocalIds::thread_id_, UNREACHABLE, and VLOG.

Referenced by reifyImpl().

1247  {
1248  logger::LocalIdsScopeGuard lisg = parent_thread_local_ids.setNewThreadId();
1249  DEBUG_TIMER_NEW_THREAD(parent_thread_local_ids.thread_id_);
1250  CHECK_EQ(getKeyComponentWidth(), size_t(8));
1252  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
1253 
1254  if (effective_memory_level == Data_Namespace::MemoryLevel::CPU_LEVEL) {
1255  VLOG(1) << "Building overlaps join hash table on CPU.";
1256  auto hash_table = initHashTableOnCpu(columns_for_device.join_columns,
1257  columns_for_device.join_column_types,
1258  columns_for_device.join_buckets,
1259  layout,
1260  entry_count,
1261  emitted_keys_count,
1262  skip_hashtable_caching);
1263  CHECK(hash_table);
1264 
1265 #ifdef HAVE_CUDA
1267  auto gpu_hash_table = copyCpuHashTableToGpu(
1268  hash_table, layout, entry_count, emitted_keys_count, device_id);
1269  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
1270  hash_tables_for_device_[device_id] = std::move(gpu_hash_table);
1271  } else {
1272 #else
1273  CHECK_EQ(Data_Namespace::CPU_LEVEL, effective_memory_level);
1274 #endif
1275  CHECK_EQ(hash_tables_for_device_.size(), size_t(1));
1276  hash_tables_for_device_[0] = hash_table;
1277 #ifdef HAVE_CUDA
1278  }
1279 #endif
1280  } else {
1281 #ifdef HAVE_CUDA
1282  auto hash_table = initHashTableOnGpu(columns_for_device.join_columns,
1283  columns_for_device.join_column_types,
1284  columns_for_device.join_buckets,
1285  layout,
1286  entry_count,
1287  emitted_keys_count,
1288  device_id);
1289  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
1290  hash_tables_for_device_[device_id] = std::move(hash_table);
1291 #else
1292  UNREACHABLE();
1293 #endif
1294  }
1295 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:363
#define UNREACHABLE()
Definition: Logger.h:337
#define DEBUG_TIMER_NEW_THREAD(parent_thread_id)
Definition: Logger.h:416
std::shared_ptr< BaselineHashTable > initHashTableOnCpu(const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const std::vector< JoinBucketInfo > &join_bucket_info, const HashType layout, const size_t entry_count, const size_t emitted_keys_count, const bool skip_hashtable_caching)
const std::vector< JoinColumnTypeInfo > join_column_types
Definition: HashJoin.h:112
#define CHECK_LT(x, y)
Definition: Logger.h:303
LocalIdsScopeGuard setNewThreadId() const
Definition: Logger.cpp:532
#define CHECK(condition)
Definition: Logger.h:291
const Data_Namespace::MemoryLevel memory_level_
std::vector< InnerOuter > inner_outer_pairs_
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) const
ThreadId thread_id_
Definition: Logger.h:138
std::vector< JoinBucketInfo > join_buckets
Definition: HashJoin.h:114
const std::vector< JoinColumn > join_columns
Definition: HashJoin.h:111
#define VLOG(n)
Definition: Logger.h:387
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:161

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void OverlapsJoinHashTable::reifyImpl ( std::vector< ColumnsForDevice > &  columns_per_device,
const Fragmenter_Namespace::TableInfo query_info,
const HashType  layout,
const size_t  shard_count,
const size_t  entry_count,
const size_t  emitted_keys_count,
const bool  skip_hashtable_caching,
const size_t  chosen_max_hashtable_size,
const double  chosen_bucket_threshold 
)
protectedvirtual

Definition at line 1200 of file OverlapsJoinHashTable.cpp.

References threading_serial::async(), chosen_overlaps_bucket_threshold_, chosen_overlaps_max_table_size_bytes_, device_count_, Fragmenter_Namespace::TableInfo::fragments, inverse_bucket_sizes_for_dimension_, only_shards_for_device(), reifyForDevice(), setOverlapsHashtableMetaInfo(), and logger::thread_local_ids().

Referenced by reifyWithLayout().

1208  {
1209  std::vector<std::future<void>> init_threads;
1210  chosen_overlaps_bucket_threshold_ = chosen_bucket_threshold;
1211  chosen_overlaps_max_table_size_bytes_ = chosen_max_hashtable_size;
1215 
1216  for (int device_id = 0; device_id < device_count_; ++device_id) {
1217  const auto fragments =
1218  shard_count
1219  ? only_shards_for_device(query_info.fragments, device_id, device_count_)
1220  : query_info.fragments;
1221  init_threads.push_back(std::async(std::launch::async,
1223  this,
1224  columns_per_device[device_id],
1225  layout,
1226  entry_count,
1227  emitted_keys_count,
1228  skip_hashtable_caching,
1229  device_id,
1231  }
1232  for (auto& init_thread : init_threads) {
1233  init_thread.wait();
1234  }
1235  for (auto& init_thread : init_threads) {
1236  init_thread.get();
1237  }
1238 }
std::vector< FragmentInfo > fragments
Definition: Fragmenter.h:171
future< Result > async(Fn &&fn, Args &&...args)
void reifyForDevice(const ColumnsForDevice &columns_for_device, const HashType layout, const size_t entry_count, const size_t emitted_keys_count, const bool skip_hashtable_caching, const int device_id, const logger::ThreadLocalIds parent_thread_local_ids)
std::vector< Fragmenter_Namespace::FragmentInfo > only_shards_for_device(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, const int device_count)
void setOverlapsHashtableMetaInfo(size_t max_table_size_bytes, double bucket_threshold, std::vector< double > &bucket_sizes)
std::vector< double > inverse_bucket_sizes_for_dimension_
ThreadLocalIds thread_local_ids()
Definition: Logger.cpp:874

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void OverlapsJoinHashTable::reifyWithLayout ( const HashType  layout)
protectedvirtual

Reimplemented in RangeJoinHashTable.

Definition at line 534 of file OverlapsJoinHashTable.cpp.

References gpu_enabled::accumulate(), auto_tuner_cache_, CompositeKeyInfo::cache_key_chunks, calculateHashTableSize(), CHECK, CHECK_EQ, CHECK_GE, HashJoin::collectFragmentIds(), composite_key_info_, computeHashTableCounts(), condition_, DataRecyclerUtil::CPU_DEVICE_IDENTIFIER, DEBUG_TIMER, device_count_, executor_, fetchColumnsForDevice(), g_overlaps_max_table_size_bytes, g_overlaps_target_entries_per_bin, generateCacheKey(), get_inner_query_info(), getAlternativeCacheKey(), DataRecyclerUtil::getAlternativeTableKeys(), getEffectiveMemoryLevel(), HashtableRecycler::getHashtableAccessPathInfo(), HashJoin::getHashTypeString(), HashJoin::getInnerTableId(), getQueryEngineCudaStreamForDevice(), Data_Namespace::GPU_LEVEL, hash_table_cache_, hashtable_build_dag_map_, hashtable_cache_key_, hashtable_cache_meta_info_, InputTableInfo::info, inner_outer_pairs_, inverse_bucket_sizes_for_dimension_, RegisteredQueryHint::isHintRegistered(), HashtableRecycler::isInvalidHashTableCacheKey(), join_type_, kOverlapsAllowGpuBuild, kOverlapsBucketThreshold, kOverlapsKeysPerBin, kOverlapsMaxSize, kOverlapsNoCache, HashJoin::layoutRequiresAdditionalBuffers(), memory_level_, only_shards_for_device(), RegisteredQueryHint::overlaps_allow_gpu_build, OVERLAPS_AUTO_TUNER_PARAM, RegisteredQueryHint::overlaps_bucket_threshold, OVERLAPS_HT, RegisteredQueryHint::overlaps_keys_per_bin, RegisteredQueryHint::overlaps_max_size, query_hints_, query_infos_, reifyImpl(), setInverseBucketSizeInfo(), setOverlapsHashtableMetaInfo(), shardCount(), table_keys_, and VLOG.

Referenced by reify().

534  {
535  auto timer = DEBUG_TIMER(__func__);
537  const auto& query_info =
539  .info;
540  auto [db_id, table_id] = HashJoin::getInnerTableId(inner_outer_pairs_);
541  VLOG(1) << "Reify with layout " << getHashTypeString(layout) << "for db_id: " << db_id
542  << ", table_id: " << table_id;
543  if (query_info.fragments.empty()) {
544  return;
545  }
546 
547  auto overlaps_max_table_size_bytes = g_overlaps_max_table_size_bytes;
548  std::optional<double> overlaps_threshold_override;
549  double overlaps_target_entries_per_bin = g_overlaps_target_entries_per_bin;
550  auto skip_hashtable_caching = false;
552  VLOG(1) << "Setting overlaps bucket threshold "
553  "\'overlaps_hashjoin_bucket_threshold\' via "
554  "query hint: "
556  overlaps_threshold_override = query_hints_.overlaps_bucket_threshold;
557  }
559  std::ostringstream oss;
560  oss << "User requests to change a threshold \'overlaps_max_table_size_bytes\' via "
561  "query hint";
562  if (!overlaps_threshold_override.has_value()) {
563  oss << ": " << overlaps_max_table_size_bytes << " -> "
565  overlaps_max_table_size_bytes = query_hints_.overlaps_max_size;
566  } else {
567  oss << ", but is skipped since the query hint also changes the threshold "
568  "\'overlaps_hashjoin_bucket_threshold\'";
569  }
570  VLOG(1) << oss.str();
571  }
573  VLOG(1) << "User requests to skip caching overlaps join hashtable and its tuned "
574  "parameters for this query";
575  skip_hashtable_caching = true;
576  }
578  VLOG(1) << "User requests to change a threshold \'overlaps_keys_per_bin\' via query "
579  "hint: "
580  << overlaps_target_entries_per_bin << " -> "
582  overlaps_target_entries_per_bin = query_hints_.overlaps_keys_per_bin;
583  }
584 
585  auto data_mgr = executor_->getDataMgr();
586  // we prioritize CPU when building an overlaps join hashtable, but if we have GPU and
587  // user-given hint is given we selectively allow GPU to build it but even if we have GPU
588  // but user foces to set CPU as execution device type we should not allow to use GPU for
589  // building it
590  auto allow_gpu_hashtable_build =
593  if (allow_gpu_hashtable_build) {
594  if (data_mgr->gpusPresent() &&
596  VLOG(1) << "A user forces to build GPU hash table for this overlaps join operator";
597  } else {
598  allow_gpu_hashtable_build = false;
599  VLOG(1) << "A user forces to build GPU hash table for this overlaps join operator "
600  "but we "
601  "skip it since either GPU is not presented or CPU execution mode is set";
602  }
603  }
604 
605  std::vector<ColumnsForDevice> columns_per_device;
606  std::vector<std::unique_ptr<CudaAllocator>> dev_buff_owners;
608  allow_gpu_hashtable_build) {
609  for (int device_id = 0; device_id < device_count_; ++device_id) {
610  dev_buff_owners.emplace_back(std::make_unique<CudaAllocator>(
611  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id)));
612  }
613  }
614 
615  std::vector<std::vector<Fragmenter_Namespace::FragmentInfo>> fragments_per_device;
616  const auto shard_count = shardCount();
617  size_t total_num_tuples = 0;
618  for (int device_id = 0; device_id < device_count_; ++device_id) {
619  fragments_per_device.emplace_back(
620  shard_count
621  ? only_shards_for_device(query_info.fragments, device_id, device_count_)
622  : query_info.fragments);
623  const size_t crt_num_tuples =
624  std::accumulate(fragments_per_device.back().begin(),
625  fragments_per_device.back().end(),
626  size_t(0),
627  [](const auto& sum, const auto& fragment) {
628  return sum + fragment.getNumTuples();
629  });
630  total_num_tuples += crt_num_tuples;
631  const auto columns_for_device =
632  fetchColumnsForDevice(fragments_per_device.back(),
633  device_id,
635  allow_gpu_hashtable_build
636  ? dev_buff_owners[device_id].get()
637  : nullptr);
638  columns_per_device.push_back(columns_for_device);
639  }
640 
641  // try to extract cache key for hash table and its relevant info
642  auto hashtable_access_path_info =
644  {},
645  condition_->get_optype(),
646  join_type_,
649  shard_count,
650  fragments_per_device,
651  executor_);
652  hashtable_cache_key_ = hashtable_access_path_info.hashed_query_plan_dag;
653  hashtable_cache_meta_info_ = hashtable_access_path_info.meta_info;
654  table_keys_ = hashtable_access_path_info.table_keys;
655 
656  auto get_inner_table_key = [this]() {
657  auto col_var = inner_outer_pairs_.front().first;
658  return col_var->getTableKey();
659  };
660 
661  if (table_keys_.empty()) {
662  const auto& table_key = get_inner_table_key();
665  }
666  CHECK(!table_keys_.empty());
667 
668  if (overlaps_threshold_override) {
669  // compute bucket sizes based on the user provided threshold
670  BucketSizeTuner tuner(/*initial_threshold=*/*overlaps_threshold_override,
671  /*step=*/1.0,
672  /*min_threshold=*/0.0,
674  columns_per_device,
676  total_num_tuples,
677  executor_);
678  const auto inverse_bucket_sizes = tuner.getInverseBucketSizes();
679 
680  auto [entry_count, emitted_keys_count] =
681  computeHashTableCounts(shard_count,
682  inverse_bucket_sizes,
683  columns_per_device,
684  overlaps_max_table_size_bytes,
685  *overlaps_threshold_override);
686  setInverseBucketSizeInfo(inverse_bucket_sizes, columns_per_device, device_count_);
687  // reifyImpl will check the hash table cache for an appropriate hash table w/ those
688  // bucket sizes (or within tolerances) if a hash table exists use it, otherwise build
689  // one
690  generateCacheKey(overlaps_max_table_size_bytes,
691  *overlaps_threshold_override,
692  inverse_bucket_sizes,
693  fragments_per_device,
694  device_count_);
695  reifyImpl(columns_per_device,
696  query_info,
697  layout,
698  shard_count,
699  entry_count,
700  emitted_keys_count,
701  skip_hashtable_caching,
702  overlaps_max_table_size_bytes,
703  *overlaps_threshold_override);
704  } else {
705  double overlaps_bucket_threshold = std::numeric_limits<double>::max();
706  generateCacheKey(overlaps_max_table_size_bytes,
707  overlaps_bucket_threshold,
708  {},
709  fragments_per_device,
710  device_count_);
711  std::vector<size_t> per_device_chunk_key;
712  if (HashtableRecycler::isInvalidHashTableCacheKey(hashtable_cache_key_) &&
713  get_inner_table_key().table_id > 0) {
714  for (int device_id = 0; device_id < device_count_; ++device_id) {
715  auto chunk_key_hash = boost::hash_value(composite_key_info_.cache_key_chunks);
716  boost::hash_combine(
717  chunk_key_hash,
718  HashJoin::collectFragmentIds(fragments_per_device[device_id]));
719  per_device_chunk_key.push_back(chunk_key_hash);
720  AlternativeCacheKeyForOverlapsHashJoin cache_key{
722  columns_per_device.front().join_columns.front().num_elems,
723  chunk_key_hash,
724  condition_->get_optype(),
725  overlaps_max_table_size_bytes,
726  overlaps_bucket_threshold,
727  {}};
728  hashtable_cache_key_[device_id] = getAlternativeCacheKey(cache_key);
729  hash_table_cache_->addQueryPlanDagForTableKeys(hashtable_cache_key_[device_id],
730  table_keys_);
731  }
732  }
733 
734  auto cached_bucket_threshold =
735  auto_tuner_cache_->getItemFromCache(hashtable_cache_key_.front(),
738  if (cached_bucket_threshold) {
739  overlaps_bucket_threshold = cached_bucket_threshold->bucket_threshold;
740  auto inverse_bucket_sizes = cached_bucket_threshold->bucket_sizes;
742  overlaps_max_table_size_bytes, overlaps_bucket_threshold, inverse_bucket_sizes);
743  generateCacheKey(overlaps_max_table_size_bytes,
744  overlaps_bucket_threshold,
745  inverse_bucket_sizes,
746  fragments_per_device,
747  device_count_);
748 
749  if (auto hash_table =
750  hash_table_cache_->getItemFromCache(hashtable_cache_key_[device_count_],
753  std::nullopt)) {
754  // if we already have a built hash table, we can skip the scans required for
755  // computing bucket size and tuple count
756  // reset as the hash table sizes can vary a bit
757  setInverseBucketSizeInfo(inverse_bucket_sizes, columns_per_device, device_count_);
758  CHECK(hash_table);
759 
760  VLOG(1) << "Using cached hash table bucket size";
761 
762  reifyImpl(columns_per_device,
763  query_info,
764  layout,
765  shard_count,
766  hash_table->getEntryCount(),
767  hash_table->getEmittedKeysCount(),
768  skip_hashtable_caching,
769  overlaps_max_table_size_bytes,
770  overlaps_bucket_threshold);
771  } else {
772  VLOG(1) << "Computing bucket size for cached bucket threshold";
773  // compute bucket size using our cached tuner value
774  BucketSizeTuner tuner(/*initial_threshold=*/overlaps_bucket_threshold,
775  /*step=*/1.0,
776  /*min_threshold=*/0.0,
778  columns_per_device,
780  total_num_tuples,
781  executor_);
782 
783  const auto inverse_bucket_sizes = tuner.getInverseBucketSizes();
784 
785  auto [entry_count, emitted_keys_count] =
786  computeHashTableCounts(shard_count,
787  inverse_bucket_sizes,
788  columns_per_device,
789  overlaps_max_table_size_bytes,
790  overlaps_bucket_threshold);
791  setInverseBucketSizeInfo(inverse_bucket_sizes, columns_per_device, device_count_);
792 
793  generateCacheKey(overlaps_max_table_size_bytes,
794  overlaps_bucket_threshold,
795  inverse_bucket_sizes,
796  fragments_per_device,
797  device_count_);
798 
799  reifyImpl(columns_per_device,
800  query_info,
801  layout,
802  shard_count,
803  entry_count,
804  emitted_keys_count,
805  skip_hashtable_caching,
806  overlaps_max_table_size_bytes,
807  overlaps_bucket_threshold);
808  }
809  } else {
810  // compute bucket size using the auto tuner
811  BucketSizeTuner tuner(
812  /*initial_threshold=*/overlaps_bucket_threshold,
813  /*step=*/2.0,
814  /*min_threshold=*/1e-7,
816  columns_per_device,
818  total_num_tuples,
819  executor_);
820 
821  VLOG(1) << "Running overlaps join size auto tune with parameters: " << tuner;
822 
823  // manages the tuning state machine
824  TuningState tuning_state(overlaps_max_table_size_bytes,
825  overlaps_target_entries_per_bin);
826  while (tuner.tuneOneStep(tuning_state.tuning_direction)) {
827  const auto inverse_bucket_sizes = tuner.getInverseBucketSizes();
828 
829  const auto [crt_entry_count, crt_emitted_keys_count] =
830  computeHashTableCounts(shard_count,
831  inverse_bucket_sizes,
832  columns_per_device,
833  tuning_state.overlaps_max_table_size_bytes,
834  tuning_state.chosen_overlaps_threshold);
835  const size_t hash_table_size = calculateHashTableSize(
836  inverse_bucket_sizes.size(), crt_emitted_keys_count, crt_entry_count);
837  HashTableProps crt_props(crt_entry_count,
838  crt_emitted_keys_count,
839  hash_table_size,
840  inverse_bucket_sizes);
841  VLOG(1) << "Tuner output: " << tuner << " with properties " << crt_props;
842 
843  const auto should_continue = tuning_state(crt_props, tuner.getMinBucketSize());
845  tuning_state.crt_props.bucket_sizes, columns_per_device, device_count_);
846  if (!should_continue) {
847  break;
848  }
849  }
850 
851  const auto& crt_props = tuning_state.crt_props;
852  // sanity check that the hash table size has not changed. this is a fairly
853  // inexpensive check to ensure the above algorithm is consistent
854  const size_t hash_table_size =
856  crt_props.emitted_keys_count,
857  crt_props.entry_count);
858  CHECK_EQ(crt_props.hash_table_size, hash_table_size);
859 
861  hash_table_size > overlaps_max_table_size_bytes) {
862  VLOG(1) << "Could not find suitable overlaps join parameters to create hash "
863  "table under max allowed size ("
864  << overlaps_max_table_size_bytes << ") bytes.";
865  throw OverlapsHashTableTooBig(overlaps_max_table_size_bytes);
866  }
867 
868  VLOG(1) << "Final tuner output: " << tuner << " with properties " << crt_props;
870  VLOG(1) << "Final bucket sizes: ";
871  for (size_t dim = 0; dim < inverse_bucket_sizes_for_dimension_.size(); dim++) {
872  VLOG(1) << "dim[" << dim
873  << "]: " << 1.0 / inverse_bucket_sizes_for_dimension_[dim];
874  }
875  CHECK_GE(tuning_state.chosen_overlaps_threshold, double(0));
876  generateCacheKey(tuning_state.overlaps_max_table_size_bytes,
877  tuning_state.chosen_overlaps_threshold,
878  {},
879  fragments_per_device,
880  device_count_);
881  const auto candidate_auto_tuner_cache_key = hashtable_cache_key_.front();
882  if (skip_hashtable_caching) {
883  VLOG(1) << "Skip to add tuned parameters to auto tuner";
884  } else {
885  AutoTunerMetaInfo meta_info{tuning_state.overlaps_max_table_size_bytes,
886  tuning_state.chosen_overlaps_threshold,
888  auto_tuner_cache_->putItemToCache(candidate_auto_tuner_cache_key,
889  meta_info,
892  0,
893  0);
894  }
895  overlaps_bucket_threshold = tuning_state.chosen_overlaps_threshold;
896  reifyImpl(columns_per_device,
897  query_info,
898  layout,
899  shard_count,
900  crt_props.entry_count,
901  crt_props.emitted_keys_count,
902  skip_hashtable_caching,
903  overlaps_max_table_size_bytes,
904  overlaps_bucket_threshold);
905  }
906  }
907 }
static std::vector< int > collectFragmentIds(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments)
Definition: HashJoin.cpp:452
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Fragmenter_Namespace::TableInfo info
Definition: InputMetadata.h:35
static bool isInvalidHashTableCacheKey(const std::vector< QueryPlanHash > &cache_keys)
std::vector< ChunkKey > cache_key_chunks
Definition: HashJoin.h:130
virtual void reifyImpl(std::vector< ColumnsForDevice > &columns_per_device, const Fragmenter_Namespace::TableInfo &query_info, const HashType layout, const size_t shard_count, const size_t entry_count, const size_t emitted_keys_count, const bool skip_hashtable_caching, const size_t chosen_max_hashtable_size, const double chosen_bucket_threshold)
bool overlaps_allow_gpu_build
Definition: QueryHint.h:318
#define CHECK_GE(x, y)
Definition: Logger.h:306
const InputTableInfo & get_inner_query_info(const shared::TableKey &inner_table_key, const std::vector< InputTableInfo > &query_infos)
double overlaps_keys_per_bin
Definition: QueryHint.h:320
static std::unique_ptr< OverlapsTuningParamRecycler > auto_tuner_cache_
virtual std::pair< size_t, size_t > computeHashTableCounts(const size_t shard_count, const std::vector< double > &inverse_bucket_sizes_for_dimension, std::vector< ColumnsForDevice > &columns_per_device, const size_t chosen_max_hashtable_size, const double chosen_bucket_threshold)
size_t calculateHashTableSize(size_t number_of_dimensions, size_t emitted_keys_count, size_t entry_count) const
const std::shared_ptr< Analyzer::BinOper > condition_
RegisteredQueryHint query_hints_
QueryPlanHash getAlternativeCacheKey(AlternativeCacheKeyForOverlapsHashJoin &info)
const std::vector< InputTableInfo > & query_infos_
std::vector< Fragmenter_Namespace::FragmentInfo > only_shards_for_device(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, const int device_count)
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
double g_overlaps_target_entries_per_bin
Definition: Execute.cpp:106
HashTableBuildDagMap hashtable_build_dag_map_
static std::unordered_set< size_t > getAlternativeTableKeys(const std::vector< ChunkKey > &chunk_keys, const shared::TableKey &inner_table_key)
Definition: DataRecycler.h:154
size_t g_overlaps_max_table_size_bytes
Definition: Execute.cpp:105
std::vector< QueryPlanHash > hashtable_cache_key_
void setOverlapsHashtableMetaInfo(size_t max_table_size_bytes, double bucket_threshold, std::vector< double > &bucket_sizes)
virtual shared::TableKey getInnerTableId() const noexcept=0
std::vector< double > inverse_bucket_sizes_for_dimension_
size_t overlaps_max_size
Definition: QueryHint.h:317
static std::string getHashTypeString(HashType ht) noexcept
Definition: HashJoin.h:165
void setInverseBucketSizeInfo(const std::vector< double > &inverse_bucket_sizes, std::vector< ColumnsForDevice > &columns_per_device, const size_t device_count)
bool isHintRegistered(const QueryHint hint) const
Definition: QueryHint.h:348
ColumnsForDevice fetchColumnsForDevice(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, DeviceAllocator *dev_buff_owner)
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
HashtableCacheMetaInfo hashtable_cache_meta_info_
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:411
const Data_Namespace::MemoryLevel memory_level_
void generateCacheKey(const size_t max_hashtable_size, const double bucket_threshold, const std::vector< double > &bucket_sizes, std::vector< std::vector< Fragmenter_Namespace::FragmentInfo >> &fragments_per_device, int device_count)
static std::unique_ptr< HashtableRecycler > hash_table_cache_
std::vector< InnerOuter > inner_outer_pairs_
std::unordered_set< size_t > table_keys_
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) const
double overlaps_bucket_threshold
Definition: QueryHint.h:316
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
static HashtableAccessPathInfo getHashtableAccessPathInfo(const std::vector< InnerOuter > &inner_outer_pairs, const std::vector< InnerOuterStringOpInfos > &inner_outer_string_op_infos_pairs, const SQLOps op_type, const JoinType join_type, const HashTableBuildDagMap &hashtable_build_dag_map, int device_count, int shard_count, const std::vector< std::vector< Fragmenter_Namespace::FragmentInfo >> &frags_for_device, Executor *executor)
CompositeKeyInfo composite_key_info_
#define VLOG(n)
Definition: Logger.h:387
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:161

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void OverlapsJoinHashTable::setInverseBucketSizeInfo ( const std::vector< double > &  inverse_bucket_sizes,
std::vector< ColumnsForDevice > &  columns_per_device,
const size_t  device_count 
)
protected

Definition at line 1148 of file OverlapsJoinHashTable.cpp.

References CHECK_EQ, inner_outer_pairs_, and inverse_bucket_sizes_for_dimension_.

Referenced by RangeJoinHashTable::reifyWithLayout(), and reifyWithLayout().

1151  {
1152  // set global bucket size
1153  inverse_bucket_sizes_for_dimension_ = inverse_bucket_sizes;
1154 
1155  // re-compute bucket counts per device based on global bucket size
1156  CHECK_EQ(columns_per_device.size(), static_cast<size_t>(device_count));
1157  for (size_t device_id = 0; device_id < device_count; ++device_id) {
1158  auto& columns_for_device = columns_per_device[device_id];
1159  columns_for_device.setBucketInfo(inverse_bucket_sizes_for_dimension_,
1161  }
1162 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< double > inverse_bucket_sizes_for_dimension_
std::vector< InnerOuter > inner_outer_pairs_

+ Here is the caller graph for this function:

void OverlapsJoinHashTable::setOverlapsHashtableMetaInfo ( size_t  max_table_size_bytes,
double  bucket_threshold,
std::vector< double > &  bucket_sizes 
)
inlineprotected

Definition at line 364 of file OverlapsJoinHashTable.h.

References OverlapsHashTableMetaInfo::bucket_sizes, hashtable_cache_meta_info_, OverlapsHashTableMetaInfo::overlaps_bucket_threshold, OverlapsHashTableMetaInfo::overlaps_max_table_size_bytes, and HashtableCacheMetaInfo::overlaps_meta_info.

Referenced by reifyImpl(), RangeJoinHashTable::reifyWithLayout(), and reifyWithLayout().

366  {
367  OverlapsHashTableMetaInfo overlaps_meta_info;
368  overlaps_meta_info.bucket_sizes = bucket_sizes;
369  overlaps_meta_info.overlaps_max_table_size_bytes = max_table_size_bytes;
370  overlaps_meta_info.overlaps_bucket_threshold = bucket_threshold;
371  HashtableCacheMetaInfo meta_info;
372  meta_info.overlaps_meta_info = overlaps_meta_info;
373  hashtable_cache_meta_info_ = meta_info;
374  }
std::optional< OverlapsHashTableMetaInfo > overlaps_meta_info
HashtableCacheMetaInfo hashtable_cache_meta_info_
std::vector< double > bucket_sizes

+ Here is the caller graph for this function:

size_t OverlapsJoinHashTable::shardCount ( ) const
inlineprotected

Definition at line 235 of file OverlapsJoinHashTable.h.

References condition_, executor_, BaselineJoinHashTable::getShardCountForCondition(), Data_Namespace::GPU_LEVEL, inner_outer_pairs_, and memory_level_.

Referenced by RangeJoinHashTable::reifyWithLayout(), and reifyWithLayout().

235  {
237  return 0;
238  }
241  }
const std::shared_ptr< Analyzer::BinOper > condition_
const Data_Namespace::MemoryLevel memory_level_
std::vector< InnerOuter > inner_outer_pairs_
static size_t getShardCountForCondition(const Analyzer::BinOper *condition, const Executor *executor, const std::vector< InnerOuter > &inner_outer_pairs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::set< DecodedJoinHashBufferEntry > OverlapsJoinHashTable::toSet ( const ExecutorDeviceType  device_type,
const int  device_id 
) const
overrideprotectedvirtual

Implements HashJoin.

Definition at line 1783 of file OverlapsJoinHashTable.cpp.

References CHECK, countBufferOff(), executor_, HashJoin::getHashTableForDevice(), getHashType(), HashJoin::getJoinHashBuffer(), getKeyComponentCount(), getKeyComponentWidth(), getQueryEngineCudaStreamForDevice(), GPU, offsetBufferOff(), OneToOne, payloadBufferOff(), and HashTable::toSet().

1785  {
1786  auto buffer = getJoinHashBuffer(device_type, device_id);
1787  auto hash_table = getHashTableForDevice(device_id);
1788  CHECK(hash_table);
1789  auto buffer_size = hash_table->getHashTableBufferSize(device_type);
1790 #ifdef HAVE_CUDA
1791  std::unique_ptr<int8_t[]> buffer_copy;
1792  if (device_type == ExecutorDeviceType::GPU) {
1793  buffer_copy = std::make_unique<int8_t[]>(buffer_size);
1794  CHECK(executor_);
1795  auto data_mgr = executor_->getDataMgr();
1796  auto allocator = std::make_unique<CudaAllocator>(
1797  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
1798 
1799  allocator->copyFromDevice(buffer_copy.get(), buffer, buffer_size);
1800  }
1801  auto ptr1 = buffer_copy ? buffer_copy.get() : reinterpret_cast<const int8_t*>(buffer);
1802 #else
1803  auto ptr1 = reinterpret_cast<const int8_t*>(buffer);
1804 #endif // HAVE_CUDA
1805  auto ptr2 = ptr1 + offsetBufferOff();
1806  auto ptr3 = ptr1 + countBufferOff();
1807  auto ptr4 = ptr1 + payloadBufferOff();
1808  const auto layout = getHashType();
1809  return HashTable::toSet(getKeyComponentCount() + (layout == HashType::OneToOne ? 1 : 0),
1811  hash_table->getEntryCount(),
1812  ptr1,
1813  ptr2,
1814  ptr3,
1815  ptr4,
1816  buffer_size);
1817 }
HashType getHashType() const noexceptoverride
size_t payloadBufferOff() const noexceptoverride
int8_t * getJoinHashBuffer(const ExecutorDeviceType device_type, const int device_id) const
Definition: HashJoin.h:300
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:281
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
size_t offsetBufferOff() const noexceptoverride
size_t countBufferOff() const noexceptoverride
#define CHECK(condition)
Definition: Logger.h:291
static DecodedJoinHashBufferSet toSet(size_t key_component_count, size_t key_component_width, size_t entry_count, const int8_t *ptr1, const int8_t *ptr2, const int8_t *ptr3, const int8_t *ptr4, size_t buffer_size)
Decode hash table into a std::set for easy inspection and validation.
Definition: HashTable.cpp:139

+ Here is the call graph for this function:

std::string OverlapsJoinHashTable::toString ( const ExecutorDeviceType  device_type,
const int  device_id = 0,
bool  raw = false 
) const
overrideprotectedvirtual

Implements HashJoin.

Definition at line 1741 of file OverlapsJoinHashTable.cpp.

References CHECK, CHECK_LT, countBufferOff(), executor_, getHashType(), HashJoin::getHashTypeString(), HashJoin::getJoinHashBuffer(), getKeyComponentCount(), getKeyComponentWidth(), getQueryEngineCudaStreamForDevice(), GPU, HashJoin::hash_tables_for_device_, offsetBufferOff(), OneToOne, payloadBufferOff(), and HashTable::toString().

1743  {
1744  auto buffer = getJoinHashBuffer(device_type, device_id);
1745  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
1746  auto hash_table = hash_tables_for_device_[device_id];
1747  CHECK(hash_table);
1748  auto buffer_size = hash_table->getHashTableBufferSize(device_type);
1749 #ifdef HAVE_CUDA
1750  std::unique_ptr<int8_t[]> buffer_copy;
1751  if (device_type == ExecutorDeviceType::GPU) {
1752  buffer_copy = std::make_unique<int8_t[]>(buffer_size);
1753  CHECK(executor_);
1754  auto data_mgr = executor_->getDataMgr();
1755  auto device_allocator = std::make_unique<CudaAllocator>(
1756  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
1757 
1758  device_allocator->copyFromDevice(buffer_copy.get(), buffer, buffer_size);
1759  }
1760  auto ptr1 = buffer_copy ? buffer_copy.get() : reinterpret_cast<const int8_t*>(buffer);
1761 #else
1762  auto ptr1 = reinterpret_cast<const int8_t*>(buffer);
1763 #endif // HAVE_CUDA
1764  auto ptr2 = ptr1 + offsetBufferOff();
1765  auto ptr3 = ptr1 + countBufferOff();
1766  auto ptr4 = ptr1 + payloadBufferOff();
1767  CHECK(hash_table);
1768  const auto layout = getHashType();
1769  return HashTable::toString(
1770  "geo",
1771  getHashTypeString(layout),
1772  getKeyComponentCount() + (layout == HashType::OneToOne ? 1 : 0),
1774  hash_table->getEntryCount(),
1775  ptr1,
1776  ptr2,
1777  ptr3,
1778  ptr4,
1779  buffer_size,
1780  raw);
1781 }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:363
HashType getHashType() const noexceptoverride
size_t payloadBufferOff() const noexceptoverride
int8_t * getJoinHashBuffer(const ExecutorDeviceType device_type, const int device_id) const
Definition: HashJoin.h:300
#define CHECK_LT(x, y)
Definition: Logger.h:303
static std::string getHashTypeString(HashType ht) noexcept
Definition: HashJoin.h:165
static std::string toString(const std::string &type, const std::string &layout_type, size_t key_component_count, size_t key_component_width, size_t entry_count, const int8_t *ptr1, const int8_t *ptr2, const int8_t *ptr3, const int8_t *ptr4, size_t buffer_size, bool raw=false)
Decode hash table into a human-readable string.
Definition: HashTable.cpp:226
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
size_t offsetBufferOff() const noexceptoverride
size_t countBufferOff() const noexceptoverride
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

Member Data Documentation

std::unique_ptr< OverlapsTuningParamRecycler > OverlapsJoinHashTable::auto_tuner_cache_
staticprotected
Initial value:
=
std::make_unique<OverlapsTuningParamRecycler>()

Definition at line 407 of file OverlapsJoinHashTable.h.

Referenced by getOverlapsTuningParamCache(), invalidateCache(), markCachedItemAsDirty(), and reifyWithLayout().

double OverlapsJoinHashTable::chosen_overlaps_bucket_threshold_
protected

Definition at line 389 of file OverlapsJoinHashTable.h.

Referenced by reifyImpl().

size_t OverlapsJoinHashTable::chosen_overlaps_max_table_size_bytes_
protected

Definition at line 390 of file OverlapsJoinHashTable.h.

Referenced by reifyImpl().

ColumnCacheMap& OverlapsJoinHashTable::column_cache_
protected

Definition at line 382 of file OverlapsJoinHashTable.h.

Referenced by fetchColumnsForDevice().

CompositeKeyInfo OverlapsJoinHashTable::composite_key_info_
protected
const std::shared_ptr<Analyzer::BinOper> OverlapsJoinHashTable::condition_
protected
std::mutex OverlapsJoinHashTable::cpu_hash_table_buff_mutex_
protected
HashTableBuildDagMap OverlapsJoinHashTable::hashtable_build_dag_map_
protected
HashtableCacheMetaInfo OverlapsJoinHashTable::hashtable_cache_meta_info_
protected
const JoinType OverlapsJoinHashTable::join_type_
protected
std::optional<HashType> OverlapsJoinHashTable::layout_override_
protected
const std::vector<InputTableInfo>& OverlapsJoinHashTable::query_infos_
protected
QueryPlanDAG OverlapsJoinHashTable::query_plan_dag_
protected

Definition at line 410 of file OverlapsJoinHashTable.h.

const TableIdToNodeMap OverlapsJoinHashTable::table_id_to_node_map_
protected

Definition at line 414 of file OverlapsJoinHashTable.h.

std::unordered_set<size_t> OverlapsJoinHashTable::table_keys_
protected

The documentation for this class was generated from the following files: