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

#include <BoundingBoxIntersectJoinHashTable.h>

+ Inheritance diagram for BoundingBoxIntersectJoinHashTable:
+ Collaboration diagram for BoundingBoxIntersectJoinHashTable:

Classes

struct  AlternativeCacheKeyForBoundingBoxIntersection
 

Public Member Functions

 BoundingBoxIntersectJoinHashTable (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 ~BoundingBoxIntersectJoinHashTable ()
 
- 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
< BoundingBoxIntersectJoinHashTable
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
BoundingBoxIntersectTuningParamRecycler
getBoundingBoxIntersectTuningParamCache ()
 
- Static Public Member Functions inherited from HashJoin
static size_t getMaximumNumHashEntriesCanHold (MemoryLevel memory_level, const Executor *executor, size_t rowid_size) noexcept
 
static std::string generateTooManyHashEntriesErrMsg (size_t num_entries, size_t threshold, MemoryLevel memory_level)
 
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_bbox_intersect=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 BaselineHashTableEntryInfo hash_table_entry_info, 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
< BoundingBoxIntersectMetaInfo
getBoundingBoxIntersectMetaInfo ()
 
QueryPlanHash getAlternativeCacheKey (AlternativeCacheKeyForBoundingBoxIntersection &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 setBoundingBoxIntersectionMetaInfo (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_bbox_intersect_bucket_threshold_
 
size_t chosen_bbox_intersect_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
< BoundingBoxIntersectTuningParamRecycler
auto_tuner_cache_
 

Additional Inherited Members

- Static Public Attributes inherited from HashJoin
static constexpr size_t MAX_NUM_HASH_ENTRIES = size_t(1) << 31
 
- 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 29 of file BoundingBoxIntersectJoinHashTable.h.

Constructor & Destructor Documentation

BoundingBoxIntersectJoinHashTable::BoundingBoxIntersectJoinHashTable ( 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 31 of file BoundingBoxIntersectJoinHashTable.h.

References CHECK_GT, device_count_, and HashJoin::hash_tables_for_device_.

42  : condition_(condition)
43  , join_type_(join_type)
44  , query_infos_(query_infos)
45  , memory_level_(memory_level)
46  , executor_(executor)
47  , column_cache_(column_cache)
48  , inner_outer_pairs_(inner_outer_pairs)
49  , device_count_(device_count)
50  , query_hints_(query_hints)
51  , hashtable_build_dag_map_(hashtable_build_dag_map)
52  , table_id_to_node_map_(table_id_to_node_map) {
54  hash_tables_for_device_.resize(std::max(device_count_, 1));
55  }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:378
const std::shared_ptr< Analyzer::BinOper > condition_
#define CHECK_GT(x, y)
Definition: Logger.h:305
const Data_Namespace::MemoryLevel memory_level_
const std::vector< InputTableInfo > & query_infos_
virtual BoundingBoxIntersectJoinHashTable::~BoundingBoxIntersectJoinHashTable ( )
inlinevirtual

Definition at line 57 of file BoundingBoxIntersectJoinHashTable.h.

57 {}

Member Function Documentation

std::pair< size_t, size_t > BoundingBoxIntersectJoinHashTable::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 1005 of file BoundingBoxIntersectJoinHashTable.cpp.

References gpu_enabled::accumulate(), approximate_distinct_tuples_bbox_intersect(), approximate_distinct_tuples_on_device_bbox_intersect(), threading_serial::async(), BBOX_INTERSECT_HT, 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_, transfer_flat_object_to_gpu(), transfer_vector_of_flat_objects_to_gpu(), UNREACHABLE, and VLOG.

Referenced by computeHashTableCounts().

1009  {
1010  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
1011  CountDistinctDescriptor count_distinct_desc{
1013  0,
1014  0,
1015  11,
1016  true,
1017  effective_memory_level == Data_Namespace::MemoryLevel::GPU_LEVEL
1020  1};
1021  const auto padded_size_bytes = count_distinct_desc.bitmapPaddedSizeBytes();
1022 
1023  CHECK(!columns_per_device.empty() && !columns_per_device.front().join_columns.empty());
1024  if (columns_per_device.front().join_columns.front().num_elems == 0) {
1025  return std::make_pair(0, 0);
1026  }
1027 
1028  // TODO: state management in here should be revisited, but this should be safe enough
1029  // for now
1030  // re-compute bucket counts per device based on global bucket size
1031  for (size_t device_id = 0; device_id < columns_per_device.size(); ++device_id) {
1032  auto& columns_for_device = columns_per_device[device_id];
1033  columns_for_device.setBucketInfo(inverse_bucket_sizes_for_dimension,
1035  }
1036 
1037  // Number of keys must match dimension of buckets
1038  CHECK_EQ(columns_per_device.front().join_columns.size(),
1039  columns_per_device.front().join_buckets.size());
1040  if (effective_memory_level == Data_Namespace::MemoryLevel::CPU_LEVEL) {
1041  // Note that this path assumes each device has the same hash table (for GPU hash
1042  // join w/ hash table built on CPU)
1043  const auto cached_count_info =
1047  if (cached_count_info) {
1048  VLOG(1) << "Using a cached tuple count: " << cached_count_info->first
1049  << ", emitted keys count: " << cached_count_info->second;
1050  return *cached_count_info;
1051  }
1052  int thread_count = cpu_threads();
1053  std::vector<uint8_t> hll_buffer_all_cpus(thread_count * padded_size_bytes);
1054  auto hll_result = &hll_buffer_all_cpus[0];
1055 
1056  std::vector<int32_t> num_keys_for_row;
1057  // TODO(adb): support multi-column bounding box intersection
1058  num_keys_for_row.resize(columns_per_device.front().join_columns[0].num_elems);
1059 
1061  hll_result,
1062  num_keys_for_row,
1063  count_distinct_desc.bitmap_sz_bits,
1064  padded_size_bytes,
1065  columns_per_device.front().join_columns,
1066  columns_per_device.front().join_column_types,
1067  columns_per_device.front().join_buckets,
1068  thread_count);
1069  for (int i = 1; i < thread_count; ++i) {
1070  hll_unify(hll_result,
1071  hll_result + i * padded_size_bytes,
1072  size_t(1) << count_distinct_desc.bitmap_sz_bits);
1073  }
1074  return std::make_pair(
1075  hll_size(hll_result, count_distinct_desc.bitmap_sz_bits),
1076  static_cast<size_t>(num_keys_for_row.size() > 0 ? num_keys_for_row.back() : 0));
1077  }
1078 #ifdef HAVE_CUDA
1079  auto data_mgr = executor_->getDataMgr();
1080  std::vector<std::vector<uint8_t>> host_hll_buffers(device_count_);
1081  for (auto& host_hll_buffer : host_hll_buffers) {
1082  host_hll_buffer.resize(count_distinct_desc.bitmapPaddedSizeBytes());
1083  }
1084  std::vector<size_t> emitted_keys_count_device_threads(device_count_, 0);
1085  std::vector<std::future<void>> approximate_distinct_device_threads;
1086  for (int device_id = 0; device_id < device_count_; ++device_id) {
1087  approximate_distinct_device_threads.emplace_back(std::async(
1089  [device_id,
1090  &columns_per_device,
1091  &count_distinct_desc,
1092  data_mgr,
1093  &host_hll_buffers,
1094  &emitted_keys_count_device_threads] {
1095  auto allocator = std::make_unique<CudaAllocator>(
1096  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
1097  auto device_hll_buffer =
1098  allocator->alloc(count_distinct_desc.bitmapPaddedSizeBytes());
1099  data_mgr->getCudaMgr()->zeroDeviceMem(
1100  device_hll_buffer,
1101  count_distinct_desc.bitmapPaddedSizeBytes(),
1102  device_id,
1104  const auto& columns_for_device = columns_per_device[device_id];
1105  auto join_columns_gpu = transfer_vector_of_flat_objects_to_gpu(
1106  columns_for_device.join_columns, *allocator);
1107 
1108  CHECK_GT(columns_for_device.join_buckets.size(), 0u);
1109  const auto& inverse_bucket_sizes_for_dimension =
1110  columns_for_device.join_buckets[0].inverse_bucket_sizes_for_dimension;
1111  auto inverse_bucket_sizes_gpu = allocator->alloc(
1112  inverse_bucket_sizes_for_dimension.size() * sizeof(double));
1113  allocator->copyToDevice(
1114  inverse_bucket_sizes_gpu,
1115  inverse_bucket_sizes_for_dimension.data(),
1116  inverse_bucket_sizes_for_dimension.size() * sizeof(double));
1117  const size_t row_counts_buffer_sz =
1118  columns_per_device.front().join_columns[0].num_elems * sizeof(int32_t);
1119  auto row_counts_buffer = allocator->alloc(row_counts_buffer_sz);
1120  data_mgr->getCudaMgr()->zeroDeviceMem(
1121  row_counts_buffer,
1122  row_counts_buffer_sz,
1123  device_id,
1125  const auto key_handler = BoundingBoxIntersectKeyHandler(
1126  inverse_bucket_sizes_for_dimension.size(),
1127  join_columns_gpu,
1128  reinterpret_cast<double*>(inverse_bucket_sizes_gpu));
1129  const auto key_handler_gpu =
1130  transfer_flat_object_to_gpu(key_handler, *allocator);
1132  reinterpret_cast<uint8_t*>(device_hll_buffer),
1133  count_distinct_desc.bitmap_sz_bits,
1134  reinterpret_cast<int32_t*>(row_counts_buffer),
1135  key_handler_gpu,
1136  columns_for_device.join_columns[0].num_elems);
1137 
1138  auto& host_emitted_keys_count = emitted_keys_count_device_threads[device_id];
1139  allocator->copyFromDevice(
1140  &host_emitted_keys_count,
1141  row_counts_buffer +
1142  (columns_per_device.front().join_columns[0].num_elems - 1) *
1143  sizeof(int32_t),
1144  sizeof(int32_t));
1145 
1146  auto& host_hll_buffer = host_hll_buffers[device_id];
1147  allocator->copyFromDevice(&host_hll_buffer[0],
1148  device_hll_buffer,
1149  count_distinct_desc.bitmapPaddedSizeBytes());
1150  }));
1151  }
1152  for (auto& child : approximate_distinct_device_threads) {
1153  child.get();
1154  }
1155  CHECK_EQ(Data_Namespace::MemoryLevel::GPU_LEVEL, effective_memory_level);
1156  auto& result_hll_buffer = host_hll_buffers.front();
1157  auto hll_result = reinterpret_cast<int32_t*>(&result_hll_buffer[0]);
1158  for (int device_id = 1; device_id < device_count_; ++device_id) {
1159  auto& host_hll_buffer = host_hll_buffers[device_id];
1160  hll_unify(hll_result,
1161  reinterpret_cast<int32_t*>(&host_hll_buffer[0]),
1162  size_t(1) << count_distinct_desc.bitmap_sz_bits);
1163  }
1164  const size_t emitted_keys_count =
1165  std::accumulate(emitted_keys_count_device_threads.begin(),
1166  emitted_keys_count_device_threads.end(),
1167  0);
1168  return std::make_pair(hll_size(hll_result, count_distinct_desc.bitmap_sz_bits),
1169  emitted_keys_count);
1170 #else
1171  UNREACHABLE();
1172  return {0, 0};
1173 #endif // HAVE_CUDA
1174 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) const
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:338
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
void approximate_distinct_tuples_on_device_bbox_intersect(uint8_t *hll_buffer, const uint32_t b, int32_t *row_counts_buffer, const BoundingBoxIntersectKeyHandler *key_handler, const int64_t num_elems)
void approximate_distinct_tuples_bbox_intersect(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::optional< std::pair< size_t, size_t > > getApproximateTupleCountFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier)
T * transfer_vector_of_flat_objects_to_gpu(const std::vector< T > &vec, DeviceAllocator &allocator)
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
int cpu_threads()
Definition: thread_count.h:25
#define VLOG(n)
Definition: Logger.h:388

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 933 of file BoundingBoxIntersectJoinHashTable.cpp.

References getKeyComponentWidth().

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

936  {
937  const auto key_component_width = getKeyComponentWidth();
938  const auto key_component_count = number_of_dimensions;
939  const auto entry_size = key_component_count * key_component_width;
940  const auto keys_for_all_rows = emitted_keys_count;
941  const size_t one_to_many_hash_entries = 2 * entry_count + keys_for_all_rows;
942  const size_t hash_table_size =
943  entry_size * entry_count + one_to_many_hash_entries * sizeof(int32_t);
944  return hash_table_size;
945 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1483 of file BoundingBoxIntersectJoinHashTable.cpp.

References AUTOMATIC_IR_METADATA, CodeGenerator::castArrayPointer(), CHECK, CHECK_EQ, CodeGenerator::codegen(), 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().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1596 of file BoundingBoxIntersectJoinHashTable.cpp.

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

Referenced by codegenMatchingSet().

1597  {
1598  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
1599  const auto key_component_width = getKeyComponentWidth();
1600  CHECK(key_component_width == 4 || key_component_width == 8);
1601  auto hash_table = getHashTableForDevice(size_t(0));
1602  CHECK(hash_table);
1604 
1605  VLOG(1) << "Performing codgen for ManyToMany";
1606  const auto& inner_outer_pair = inner_outer_pairs_[0];
1607  const auto outer_col = inner_outer_pair.second;
1608 
1609  CodeGenerator code_generator(executor_);
1610  const auto col_lvs = code_generator.codegen(outer_col, true, co);
1611  CHECK_EQ(col_lvs.size(), size_t(1));
1612 
1613  const auto outer_col_var = dynamic_cast<const Analyzer::ColumnVar*>(outer_col);
1614  CHECK(outer_col_var);
1615  const auto coords_cd =
1616  Catalog_Namespace::get_metadata_for_column(outer_col_var->getColumnKey());
1617  CHECK(coords_cd);
1618 
1619  const auto array_ptr = executor_->cgen_state_->emitExternalCall(
1620  "array_buff",
1621  llvm::Type::getInt8PtrTy(executor_->cgen_state_->context_),
1622  {col_lvs.front(), code_generator.posArg(outer_col)});
1623 
1624  // TODO(jclay): this seems to cast to double, and causes the GPU build to fail.
1625  // const auto arr_ptr =
1626  // code_generator.castArrayPointer(array_ptr,
1627  // coords_cd->columnType.get_elem_type());
1628  array_ptr->setName("array_ptr");
1629 
1630  auto num_keys_lv = executor_->cgen_state_->emitExternalCall(
1631  "get_num_buckets_for_bounds",
1632  get_int_type(32, LL_CONTEXT),
1633  {array_ptr,
1634  LL_INT(0),
1637  num_keys_lv->setName("num_keys_lv");
1638 
1639  return {num_keys_lv, array_ptr};
1640 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const ColumnDescriptor * get_metadata_for_column(const ::shared::ColumnKey &column_key)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
#define AUTOMATIC_IR_METADATA(CGENSTATE)
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:296
HashType getHashType() const noexceptoverride
#define CHECK(condition)
Definition: Logger.h:291
#define VLOG(n)
Definition: Logger.h:388

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Implements HashJoin.

Definition at line 1642 of file BoundingBoxIntersectJoinHashTable.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_, kMaxBBoxOverlapsCount, LL_BUILDER, LL_CONTEXT, LL_FP, LL_INT, ManyToMany, offsetBufferOff(), OneToMany, to_string(), UNREACHABLE, and VLOG.

1644  {
1645  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
1646  if (getHashType() == HashType::ManyToMany) {
1647  VLOG(1) << "Building codegenMatchingSet for ManyToMany";
1648  const auto key_component_width = getKeyComponentWidth();
1649  CHECK(key_component_width == 4 || key_component_width == 8);
1650  auto many_to_many_args = codegenManyKey(co);
1651  auto hash_ptr = HashJoin::codegenHashTableLoad(index, executor_);
1652  const auto composite_dict_ptr_type =
1653  llvm::Type::getIntNPtrTy(LL_CONTEXT, key_component_width * 8);
1654  const auto composite_key_dict =
1655  hash_ptr->getType()->isPointerTy()
1656  ? LL_BUILDER.CreatePointerCast(hash_ptr, composite_dict_ptr_type)
1657  : LL_BUILDER.CreateIntToPtr(hash_ptr, composite_dict_ptr_type);
1658  const auto key_component_count = getKeyComponentCount();
1659 
1660  auto one_to_many_ptr = hash_ptr;
1661 
1662  if (one_to_many_ptr->getType()->isPointerTy()) {
1663  one_to_many_ptr =
1664  LL_BUILDER.CreatePtrToInt(hash_ptr, llvm::Type::getInt64Ty(LL_CONTEXT));
1665  } else {
1666  CHECK(one_to_many_ptr->getType()->isIntegerTy(64));
1667  }
1668 
1669  const auto composite_key_dict_size = offsetBufferOff();
1670  one_to_many_ptr =
1671  LL_BUILDER.CreateAdd(one_to_many_ptr, LL_INT(composite_key_dict_size));
1672 
1673  const auto arr_type = get_int_array_type(32, kMaxBBoxOverlapsCount, LL_CONTEXT);
1674  const auto out_arr_lv = LL_BUILDER.CreateAlloca(arr_type);
1675  out_arr_lv->setName("out_arr");
1676 
1677  const auto casted_out_arr_lv =
1678  LL_BUILDER.CreatePointerCast(out_arr_lv, arr_type->getPointerTo());
1679 
1680  const auto element_ptr = LL_BUILDER.CreateGEP(arr_type, casted_out_arr_lv, LL_INT(0));
1681 
1682  auto rowid_ptr_i32 =
1683  LL_BUILDER.CreatePointerCast(element_ptr, llvm::Type::getInt32PtrTy(LL_CONTEXT));
1684 
1685  const auto error_code_ptr = LL_BUILDER.CreateAlloca(
1686  get_int_type(32, LL_CONTEXT), nullptr, "candidate_rows_error_code");
1687  LL_BUILDER.CreateStore(LL_INT(int32_t(0)), error_code_ptr);
1688 
1689  const auto candidate_count_lv = executor_->cgen_state_->emitExternalCall(
1690  "get_candidate_rows",
1691  llvm::Type::getInt64Ty(LL_CONTEXT),
1692  {rowid_ptr_i32,
1693  error_code_ptr,
1695  many_to_many_args[1],
1696  LL_INT(0),
1699  many_to_many_args[0],
1700  LL_INT(key_component_count), // key_component_count
1701  composite_key_dict, // ptr to hash table
1702  LL_INT(getEntryCount()), // entry_count
1703  LL_INT(composite_key_dict_size), // offset_buffer_ptr_offset
1704  LL_INT(getEntryCount() * sizeof(int32_t)), // sub_buff_size
1705  LL_INT(int32_t(heavyai::ErrorCode::BBOX_OVERLAPS_LIMIT_EXCEEDED))});
1706 
1707  const auto slot_lv = LL_INT(int64_t(0));
1708  auto error_code_lv = LL_BUILDER.CreateLoad(
1709  error_code_ptr->getType()->getPointerElementType(), error_code_ptr);
1710  return {rowid_ptr_i32, candidate_count_lv, slot_lv, error_code_lv};
1711  } else {
1712  VLOG(1) << "Building codegenMatchingSet for Baseline";
1713  // TODO: duplicated w/ BaselineJoinHashTable -- push into the hash table builder?
1714  const auto key_component_width = getKeyComponentWidth();
1715  CHECK(key_component_width == 4 || key_component_width == 8);
1716  auto key_buff_lv = codegenKey(co);
1718  auto hash_ptr = HashJoin::codegenHashTableLoad(index, executor_);
1719  const auto composite_dict_ptr_type =
1720  llvm::Type::getIntNPtrTy(LL_CONTEXT, key_component_width * 8);
1721  const auto composite_key_dict =
1722  hash_ptr->getType()->isPointerTy()
1723  ? LL_BUILDER.CreatePointerCast(hash_ptr, composite_dict_ptr_type)
1724  : LL_BUILDER.CreateIntToPtr(hash_ptr, composite_dict_ptr_type);
1725  const auto key_component_count = getKeyComponentCount();
1726  const auto key = executor_->cgen_state_->emitExternalCall(
1727  "get_composite_key_index_" + std::to_string(key_component_width * 8),
1728  get_int_type(64, LL_CONTEXT),
1729  {key_buff_lv,
1730  LL_INT(key_component_count),
1731  composite_key_dict,
1732  LL_INT(getEntryCount())});
1733  auto one_to_many_ptr = hash_ptr;
1734  if (one_to_many_ptr->getType()->isPointerTy()) {
1735  one_to_many_ptr =
1736  LL_BUILDER.CreatePtrToInt(hash_ptr, llvm::Type::getInt64Ty(LL_CONTEXT));
1737  } else {
1738  CHECK(one_to_many_ptr->getType()->isIntegerTy(64));
1739  }
1740  const auto composite_key_dict_size = offsetBufferOff();
1741  one_to_many_ptr =
1742  LL_BUILDER.CreateAdd(one_to_many_ptr, LL_INT(composite_key_dict_size));
1744  std::vector<llvm::Value*>{
1745  one_to_many_ptr, key, LL_INT(int64_t(0)), LL_INT(getEntryCount() - 1)},
1746  false,
1747  false,
1748  false,
1750  executor_);
1751  }
1752  UNREACHABLE();
1753  return HashJoinMatchingSet{};
1754 }
virtual HashJoinMatchingSet codegenMatchingSet(const CompilationOptions &, const size_t)=0
static llvm::Value * codegenHashTableLoad(const size_t table_idx, Executor *executor)
Definition: HashJoin.cpp:259
llvm::Value * codegenKey(const CompilationOptions &)
#define UNREACHABLE()
Definition: Logger.h:338
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::vector< llvm::Value * > codegenManyKey(const CompilationOptions &)
std::string to_string(char const *&&v)
#define AUTOMATIC_IR_METADATA(CGENSTATE)
HashType getHashType() const noexceptoverride
#define CHECK(condition)
Definition: Logger.h:291
constexpr int32_t kMaxBBoxOverlapsCount
llvm::ArrayType * get_int_array_type(int const width, int count, llvm::LLVMContext &context)
#define VLOG(n)
Definition: Logger.h:388
size_t getComponentBufferSize() const noexceptoverride

+ Here is the call graph for this function:

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

Implements HashJoin.

Definition at line 209 of file BoundingBoxIntersectJoinHashTable.h.

References UNREACHABLE.

209  {
210  UNREACHABLE(); // not applicable for bounding box intersection
211  return nullptr;
212  }
#define UNREACHABLE()
Definition: Logger.h:338
std::pair< size_t, size_t > BoundingBoxIntersectJoinHashTable::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 986 of file BoundingBoxIntersectJoinHashTable.cpp.

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

Referenced by reifyWithLayout().

991  {
992  CHECK(!inverse_bucket_sizes_for_dimension.empty());
993  const auto [tuple_count, emitted_keys_count] =
994  approximateTupleCount(inverse_bucket_sizes_for_dimension,
995  columns_per_device,
996  chosen_max_hashtable_size,
997  chosen_bucket_threshold);
998  const auto entry_count = 2 * std::max(tuple_count, size_t(1));
999 
1000  return std::make_pair(
1001  get_entries_per_device(entry_count, shard_count, device_count_, memory_level_),
1002  emitted_keys_count);
1003 }
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)
const Data_Namespace::MemoryLevel memory_level_
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t BoundingBoxIntersectJoinHashTable::countBufferOff ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 271 of file BoundingBoxIntersectJoinHashTable.h.

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

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

271  {
274  } else {
275  return getKeyBufferSize();
276  }
277  }
HashType getHashType() const noexceptoverride
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:176
size_t getComponentBufferSize() const noexceptoverride

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 947 of file BoundingBoxIntersectJoinHashTable.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().

950  {
951  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
952 
953  std::vector<JoinColumn> join_columns;
954  std::vector<std::shared_ptr<Chunk_NS::Chunk>> chunks_owner;
955  std::vector<JoinColumnTypeInfo> join_column_types;
956  std::vector<std::shared_ptr<void>> malloc_owner;
957  for (const auto& inner_outer_pair : inner_outer_pairs_) {
958  const auto inner_col = inner_outer_pair.first;
959  const auto inner_cd = get_column_descriptor_maybe(inner_col->getColumnKey());
960  if (inner_cd && inner_cd->isVirtualCol) {
962  }
963  join_columns.emplace_back(fetchJoinColumn(inner_col,
964  fragments,
965  effective_memory_level,
966  device_id,
967  chunks_owner,
968  dev_buff_owner,
969  malloc_owner,
970  executor_,
971  &column_cache_));
972  const auto& ti = inner_col->get_type_info();
973  join_column_types.emplace_back(JoinColumnTypeInfo{static_cast<size_t>(ti.get_size()),
974  0,
975  0,
976  inline_int_null_value<int64_t>(),
977  false,
978  0,
980  CHECK(ti.is_array())
981  << "Bounding box intersection currently only supported for arrays.";
982  }
983  return {join_columns, join_column_types, chunks_owner, {}, malloc_owner};
984 }
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) 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)
Definition: HashJoin.cpp:60
const ColumnDescriptor * get_column_descriptor_maybe(const shared::ColumnKey &column_key)
Definition: Execute.h:241
ColumnType get_join_column_type_kind(const SQLTypeInfo &ti)
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BoundingBoxIntersectJoinHashTable::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 346 of file BoundingBoxIntersectJoinHashTable.h.

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

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

351  {
352  for (int device_id = 0; device_id < device_count; ++device_id) {
353  auto hash_val = boost::hash_value(hashtable_cache_key_[device_id]);
354  boost::hash_combine(hash_val, max_hashtable_size);
355  boost::hash_combine(hash_val, bucket_threshold);
356  boost::hash_combine(hash_val, bucket_sizes);
357  boost::hash_combine(hash_val,
358  HashJoin::collectFragmentIds(fragments_per_device[device_id]));
359  hashtable_cache_key_[device_id] = hash_val;
360  hash_table_cache_->addQueryPlanDagForTableKeys(hashtable_cache_key_[device_id],
361  table_keys_);
362  }
363  }
static std::vector< int > collectFragmentIds(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments)
Definition: HashJoin.cpp:461
static std::unique_ptr< HashtableRecycler > hash_table_cache_
std::size_t hash_value(RexAbstractInput const &rex_ab_input)
Definition: RelAlgDag.cpp:3548

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QueryPlanHash BoundingBoxIntersectJoinHashTable::getAlternativeCacheKey ( AlternativeCacheKeyForBoundingBoxIntersection info)
inlineprotected

Definition at line 326 of file BoundingBoxIntersectJoinHashTable.h.

References BoundingBoxIntersectJoinHashTable::AlternativeCacheKeyForBoundingBoxIntersection::bucket_threshold, BoundingBoxIntersectJoinHashTable::AlternativeCacheKeyForBoundingBoxIntersection::chunk_key_hash, BoundingBoxIntersectJoinHashTable::AlternativeCacheKeyForBoundingBoxIntersection::inner_outer_pairs, BoundingBoxIntersectJoinHashTable::AlternativeCacheKeyForBoundingBoxIntersection::inverse_bucket_sizes, BoundingBoxIntersectJoinHashTable::AlternativeCacheKeyForBoundingBoxIntersection::max_hashtable_size, BoundingBoxIntersectJoinHashTable::AlternativeCacheKeyForBoundingBoxIntersection::num_elements, and BoundingBoxIntersectJoinHashTable::AlternativeCacheKeyForBoundingBoxIntersection::optype.

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

327  {
328  auto hash = info.chunk_key_hash;
329  for (InnerOuter inner_outer : info.inner_outer_pairs) {
330  auto inner_col = inner_outer.first;
331  auto rhs_col_var = dynamic_cast<const Analyzer::ColumnVar*>(inner_outer.second);
332  auto outer_col = rhs_col_var ? rhs_col_var : inner_col;
333  boost::hash_combine(hash, inner_col->toString());
334  if (inner_col->get_type_info().is_string()) {
335  boost::hash_combine(hash, outer_col->toString());
336  }
337  }
338  boost::hash_combine(hash, info.num_elements);
339  boost::hash_combine(hash, info.optype);
340  boost::hash_combine(hash, info.max_hashtable_size);
341  boost::hash_combine(hash, info.bucket_threshold);
342  boost::hash_combine(hash, info.inverse_bucket_sizes);
343  return hash;
344  }
std::pair< const Analyzer::ColumnVar *, const Analyzer::Expr * > InnerOuter
Definition: HashJoin.h:105

+ Here is the caller graph for this function:

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

Definition at line 1877 of file BoundingBoxIntersectJoinHashTable.cpp.

References HashtableCacheMetaInfo::bbox_intersect_meta_info, CHECK, getBoundingBoxIntersectMetaInfo(), and hash_table_cache_.

Referenced by approximateTupleCount().

1880  {
1882  HashtableCacheMetaInfo metaInfo;
1884  auto cached_hashtable =
1885  hash_table_cache_->getItemFromCache(key, item_type, device_identifier, metaInfo);
1886  if (cached_hashtable) {
1887  return std::make_pair(cached_hashtable->getEntryCount() / 2,
1888  cached_hashtable->getEmittedKeysCount());
1889  }
1890  return std::nullopt;
1891 }
std::optional< BoundingBoxIntersectMetaInfo > bbox_intersect_meta_info
std::optional< BoundingBoxIntersectMetaInfo > getBoundingBoxIntersectMetaInfo()
static std::unique_ptr< HashtableRecycler > hash_table_cache_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::optional<BoundingBoxIntersectMetaInfo> BoundingBoxIntersectJoinHashTable::getBoundingBoxIntersectMetaInfo ( )
inlineprotected

Definition at line 312 of file BoundingBoxIntersectJoinHashTable.h.

References HashtableCacheMetaInfo::bbox_intersect_meta_info, and hashtable_cache_meta_info_.

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

312  {
314  }
std::optional< BoundingBoxIntersectMetaInfo > bbox_intersect_meta_info

+ Here is the caller graph for this function:

static BoundingBoxIntersectTuningParamRecycler* BoundingBoxIntersectJoinHashTable::getBoundingBoxIntersectTuningParamCache ( )
inlinestatic

Definition at line 104 of file BoundingBoxIntersectJoinHashTable.h.

References auto_tuner_cache_, and CHECK.

Referenced by QueryRunner::QueryRunner::getNumberOfCachedItem(), and anonymous_namespace{DBHandler.cpp}::log_cache_size().

104  {
106  return auto_tuner_cache_.get();
107  }
static std::unique_ptr< BoundingBoxIntersectTuningParamRecycler > auto_tuner_cache_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

QueryPlanHash BoundingBoxIntersectJoinHashTable::getCacheKey ( int  device_id) const
inlineprotected

Definition at line 365 of file BoundingBoxIntersectJoinHashTable.h.

References hashtable_cache_key_.

365  {
366  return hashtable_cache_key_[device_id];
367  }
size_t BoundingBoxIntersectJoinHashTable::getComponentBufferSize ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 230 of file BoundingBoxIntersectJoinHashTable.h.

References CHECK, and HashJoin::hash_tables_for_device_.

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

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

+ Here is the caller graph for this function:

int BoundingBoxIntersectJoinHashTable::getDeviceCount ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 177 of file BoundingBoxIntersectJoinHashTable.h.

References device_count_.

Data_Namespace::MemoryLevel BoundingBoxIntersectJoinHashTable::getEffectiveMemoryLevel ( const std::vector< InnerOuter > &  inner_outer_pairs) const
protected

Definition at line 1838 of file BoundingBoxIntersectJoinHashTable.cpp.

References RegisteredQueryHint::bbox_intersect_allow_gpu_build, Data_Namespace::CPU_LEVEL, Data_Namespace::GPU_LEVEL, RegisteredQueryHint::isHintRegistered(), kBBoxIntersectAllowGpuBuild, memory_level_, and query_hints_.

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t BoundingBoxIntersectJoinHashTable::getEmittedKeysCount ( ) const
inlineprotected

Definition at line 224 of file BoundingBoxIntersectJoinHashTable.h.

References CHECK, and HashJoin::getHashTableForDevice().

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

+ Here is the call graph for this function:

size_t BoundingBoxIntersectJoinHashTable::getEntryCount ( ) const
inlineprotected

Definition at line 218 of file BoundingBoxIntersectJoinHashTable.h.

References CHECK, and HashJoin::getHashTableForDevice().

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

218  {
219  auto hash_table = getHashTableForDevice(0);
220  CHECK(hash_table);
221  return hash_table->getEntryCount();
222  }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:296
#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 BoundingBoxIntersectJoinHashTable::getHashJoinType ( ) const
inlinefinalprotectedvirtual

Implements HashJoin.

Definition at line 287 of file BoundingBoxIntersectJoinHashTable.h.

287  {
288  return "BoundingBoxIntersect";
289  }
static HashtableRecycler* BoundingBoxIntersectJoinHashTable::getHashTableCache ( )
inlinestatic

Definition at line 98 of file BoundingBoxIntersectJoinHashTable.h.

References CHECK, and hash_table_cache_.

Referenced by QueryRunner::QueryRunner::getCachedHashtableWithoutCacheKey(), QueryRunner::QueryRunner::getCacheItemMetric(), QueryRunner::QueryRunner::getNumberOfCachedItem(), anonymous_namespace{DBHandler.cpp}::log_cache_size(), and CommandLineOptions::parse_command_line().

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

+ Here is the caller graph for this function:

HashType BoundingBoxIntersectJoinHashTable::getHashType ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Reimplemented in RangeJoinHashTable.

Definition at line 164 of file BoundingBoxIntersectJoinHashTable.h.

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

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

164  {
165  if (layout_override_) {
166  return *layout_override_;
167  }
168  auto hash_table = getHashTableForDevice(0);
169  CHECK(hash_table);
170  return hash_table->getLayout();
171  }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:296
#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>& BoundingBoxIntersectJoinHashTable::getInnerOuterPairs ( ) const
inlineprotected

Definition at line 369 of file BoundingBoxIntersectJoinHashTable.h.

References inner_outer_pairs_.

Referenced by RangeJoinHashTable::isProbeCompressed().

369  {
370  return inner_outer_pairs_;
371  }

+ Here is the caller graph for this function:

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

Implements HashJoin.

Definition at line 1850 of file BoundingBoxIntersectJoinHashTable.cpp.

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

Referenced by RangeJoinHashTable::reifyWithLayout().

1850  {
1851  try {
1853  } catch (...) {
1854  CHECK(false);
1855  }
1856  return {};
1857 }
virtual shared::TableKey getInnerTableId() const noexcept=0
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int BoundingBoxIntersectJoinHashTable::getInnerTableRteIdx ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 250 of file BoundingBoxIntersectJoinHashTable.h.

References CHECK, and inner_outer_pairs_.

250  {
251  CHECK(!inner_outer_pairs_.empty());
252  const auto first_inner_col = inner_outer_pairs_.front().first;
253  return first_inner_col->get_rte_idx();
254  }
#define CHECK(condition)
Definition: Logger.h:291
std::shared_ptr< BoundingBoxIntersectJoinHashTable > BoundingBoxIntersectJoinHashTable::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 40 of file BoundingBoxIntersectJoinHashTable.cpp.

References CHECK, CHECK_EQ, RegisteredQueryHint::force_baseline_hash_join, RegisteredQueryHint::force_one_to_many_hash_join, get_inner_query_info(), HashJoin::getHashTypeString(), HashJoin::getInnerTableId(), RangeJoinHashTable::getInstance(), Fragmenter_Namespace::TableInfo::getNumTuplesUpperBound(), InputTableInfo::info, logger::INFO, LOG, ManyToMany, HashJoin::MAX_NUM_HASH_ENTRIES, HashJoin::normalizeColumnPairs(), OneToMany, VLOG, and VLOGGING.

Referenced by HashJoin::getInstance().

50  {
51  decltype(std::chrono::steady_clock::now()) ts1, ts2;
52  auto copied_query_hints = query_hints;
53  if (query_hints.force_one_to_many_hash_join) {
54  LOG(INFO) << "Ignoring query hint \'force_one_to_many_hash_join\' for bounding box "
55  "intersection";
56  copied_query_hints.force_one_to_many_hash_join = false;
57  }
58  if (query_hints.force_baseline_hash_join) {
59  LOG(INFO) << "Ignoring query hint \'force_baseline_hash_join\' for bounding box "
60  "intersection";
61  copied_query_hints.force_baseline_hash_join = false;
62  }
63  std::vector<InnerOuter> inner_outer_pairs;
64  if (const auto range_expr =
65  dynamic_cast<const Analyzer::RangeOper*>(condition->get_right_operand())) {
66  return RangeJoinHashTable::getInstance(condition,
67  range_expr,
68  query_infos,
69  memory_level,
70  join_type,
71  device_count,
72  column_cache,
73  executor,
74  hashtable_build_dag_map,
75  copied_query_hints,
76  table_id_to_node_map);
77  } else {
78  inner_outer_pairs =
79  HashJoin::normalizeColumnPairs(condition.get(), executor->getTemporaryTables())
80  .first;
81  }
82  CHECK(!inner_outer_pairs.empty());
83 
84  const auto getHashTableType =
85  [](const std::shared_ptr<Analyzer::BinOper> condition,
86  const std::vector<InnerOuter>& inner_outer_pairs) -> HashType {
88  if (condition->is_bbox_intersect_oper()) {
89  CHECK_EQ(inner_outer_pairs.size(), size_t(1));
90  if (inner_outer_pairs[0].first->get_type_info().is_array() &&
91  inner_outer_pairs[0].second->get_type_info().is_array() &&
92  // Bounds vs constructed points, former should yield ManyToMany
93  inner_outer_pairs[0].second->get_type_info().get_size() == 32) {
94  layout = HashType::ManyToMany;
95  }
96  }
97  return layout;
98  };
99 
100  const auto layout = getHashTableType(condition, inner_outer_pairs);
101 
102  if (VLOGGING(1)) {
103  VLOG(1) << "Building geo hash table " << getHashTypeString(layout)
104  << " for qual: " << condition->toString();
105  ts1 = std::chrono::steady_clock::now();
106  }
107 
108  const auto qi_0 = query_infos[0].info.getNumTuplesUpperBound();
109  const auto qi_1 = query_infos[1].info.getNumTuplesUpperBound();
110 
111  VLOG(1) << "table_key = " << query_infos[0].table_key << " has " << qi_0 << " tuples.";
112  VLOG(1) << "table_key = " << query_infos[1].table_key << " has " << qi_1 << " tuples.";
113 
114  const auto& query_info =
115  get_inner_query_info(HashJoin::getInnerTableId(inner_outer_pairs), query_infos)
116  .info;
117  const auto total_entries = 2 * query_info.getNumTuplesUpperBound();
118  if (total_entries > HashJoin::MAX_NUM_HASH_ENTRIES) {
119  throw TooManyHashEntries();
120  }
121 
122  auto join_hash_table =
123  std::make_shared<BoundingBoxIntersectJoinHashTable>(condition,
124  join_type,
125  query_infos,
126  memory_level,
127  column_cache,
128  executor,
129  inner_outer_pairs,
130  device_count,
131  copied_query_hints,
132  hashtable_build_dag_map,
133  table_id_to_node_map);
134  try {
135  join_hash_table->reify(layout);
136  } catch (const HashJoinFail& e) {
137  throw HashJoinFail(std::string("Could not build a 1-to-1 correspondence for columns "
138  "involved in bounding box intersection | ") +
139  e.what());
140  } catch (const ColumnarConversionNotSupported& e) {
141  throw HashJoinFail(
142  std::string("Could not build hash tables for bounding box intersection | "
143  "Inner table too big. Attempt manual table reordering "
144  "or create a single fragment inner table. | ") +
145  e.what());
146  } catch (const JoinHashTableTooBig& e) {
147  throw e;
148  } catch (const std::exception& e) {
149  throw HashJoinFail(
150  std::string("Failed to build hash tables for bounding box intersection | ") +
151  e.what());
152  }
153  if (VLOGGING(1)) {
154  ts2 = std::chrono::steady_clock::now();
155  VLOG(1) << "Built geo hash table " << getHashTypeString(layout) << " in "
156  << std::chrono::duration_cast<std::chrono::milliseconds>(ts2 - ts1).count()
157  << " ms";
158  }
159  return join_hash_table;
160 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Fragmenter_Namespace::TableInfo info
Definition: InputMetadata.h:35
#define LOG(tag)
Definition: Logger.h:285
const InputTableInfo & get_inner_query_info(const shared::TableKey &inner_table_key, const std::vector< InputTableInfo > &query_infos)
static constexpr size_t MAX_NUM_HASH_ENTRIES
Definition: HashJoin.h:137
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:180
#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:1015
HashType
Definition: HashTable.h:19
#define VLOG(n)
Definition: Logger.h:388

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t BoundingBoxIntersectJoinHashTable::getKeyBufferSize ( ) const
inlineprotectednoexcept

Definition at line 256 of file BoundingBoxIntersectJoinHashTable.h.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t BoundingBoxIntersectJoinHashTable::getKeyComponentCount ( ) const
protected

Definition at line 1196 of file BoundingBoxIntersectJoinHashTable.cpp.

References CHECK, and inverse_bucket_sizes_for_dimension_.

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

1196  {
1199 }
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

size_t BoundingBoxIntersectJoinHashTable::getKeyComponentWidth ( ) const
protected

Definition at line 1192 of file BoundingBoxIntersectJoinHashTable.cpp.

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

1192  {
1193  return 8;
1194 }

+ Here is the caller graph for this function:

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

Implements HashJoin.

Definition at line 173 of file BoundingBoxIntersectJoinHashTable.h.

References memory_level_.

173  {
174  return memory_level_;
175  }
const Data_Namespace::MemoryLevel memory_level_
const RegisteredQueryHint& BoundingBoxIntersectJoinHashTable::getRegisteredQueryHint ( )
inlineprotected

Definition at line 214 of file BoundingBoxIntersectJoinHashTable.h.

References query_hints_.

214  {
215  return query_hints_;
216  }
std::shared_ptr< BaselineHashTable > BoundingBoxIntersectJoinHashTable::initHashTableOnCpu ( const std::vector< JoinColumn > &  join_columns,
const std::vector< JoinColumnTypeInfo > &  join_column_types,
const std::vector< JoinBucketInfo > &  join_bucket_info,
const BaselineHashTableEntryInfo  hash_table_entry_info,
const bool  skip_hashtable_caching 
)
protected

Definition at line 1328 of file BoundingBoxIntersectJoinHashTable.cpp.

References BBOX_INTERSECT_HT, CHECK, composite_key_info_, DataRecyclerUtil::CPU_DEVICE_IDENTIFIER, cpu_hash_table_buff_mutex_, DEBUG_TIMER, executor_, HashTableEntryInfo::getHashTableLayout(), hashtable_cache_key_, BaselineJoinHashTableBuilder::initHashTableOnCpu(), initHashTableOnCpuFromCache(), join_type_, layout_override_, HashJoin::layoutRequiresAdditionalBuffers(), ManyToMany, OneToMany, putHashTableOnCpuToCache(), query_hints_, to_string(), and VLOG.

Referenced by reifyForDevice().

1333  {
1334  auto timer = DEBUG_TIMER(__func__);
1335  decltype(std::chrono::steady_clock::now()) ts1, ts2;
1336  ts1 = std::chrono::steady_clock::now();
1337  CHECK(!join_columns.empty());
1338  CHECK(!join_bucket_info.empty());
1339  std::lock_guard<std::mutex> cpu_hash_table_buff_lock(cpu_hash_table_buff_mutex_);
1340  auto const hash_table_layout = hash_table_entry_info.getHashTableLayout();
1341  if (auto generic_hash_table =
1344  DataRecyclerUtil::CPU_DEVICE_IDENTIFIER)) {
1345  if (auto hash_table =
1346  std::dynamic_pointer_cast<BaselineHashTable>(generic_hash_table)) {
1347  VLOG(1) << "Using cached CPU hash table for initialization.";
1348  // See if a hash table of a different layout was returned.
1349  // If it was OneToMany, we can reuse it on ManyToMany.
1350  if (hash_table_layout == HashType::ManyToMany &&
1351  hash_table->getLayout() == HashType::OneToMany) {
1352  // use the cached hash table
1354  return hash_table;
1355  }
1356  if (hash_table_layout == hash_table->getLayout()) {
1357  return hash_table;
1358  }
1359  }
1360  }
1361  CHECK(layoutRequiresAdditionalBuffers(hash_table_layout));
1362  const auto key_component_count =
1363  join_bucket_info[0].inverse_bucket_sizes_for_dimension.size();
1364 
1365  const auto key_handler = BoundingBoxIntersectKeyHandler(
1366  key_component_count,
1367  &join_columns[0],
1368  join_bucket_info[0].inverse_bucket_sizes_for_dimension.data());
1371  dummy_str_proxy_translation_maps_ptrs_and_offsets;
1372  const auto err =
1373  builder.initHashTableOnCpu(&key_handler,
1375  join_columns,
1376  join_column_types,
1377  join_bucket_info,
1378  dummy_str_proxy_translation_maps_ptrs_and_offsets,
1379  hash_table_entry_info,
1380  join_type_,
1381  executor_,
1382  query_hints_);
1383  ts2 = std::chrono::steady_clock::now();
1384  if (err) {
1385  throw HashJoinFail(std::string("Unrecognized error when initializing CPU hash table "
1386  "for bounding box intersection(") +
1387  std::to_string(err) + std::string(")"));
1388  }
1389  std::shared_ptr<BaselineHashTable> hash_table = builder.getHashTable();
1390  if (skip_hashtable_caching) {
1391  VLOG(1) << "Skip to cache join hashtable for bounding box intersection";
1392  } else {
1393  auto hashtable_build_time =
1394  std::chrono::duration_cast<std::chrono::milliseconds>(ts2 - ts1).count();
1397  hash_table,
1399  hashtable_build_time);
1400  }
1401  return hash_table;
1402 }
std::lock_guard< T > lock_guard
std::string to_string(char const *&&v)
CacheItemType
Definition: DataRecycler.h:38
std::pair< std::vector< const int32_t * >, std::vector< int32_t >> StrProxyTranslationMapsPtrsAndOffsets
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 BaselineHashTableEntryInfo hash_table_entry_info, const JoinType join_type, const Executor *executor, 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)
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:412
std::shared_ptr< HashTable > initHashTableOnCpuFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier)
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
#define VLOG(n)
Definition: Logger.h:388
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:176

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1859 of file BoundingBoxIntersectJoinHashTable.cpp.

References HashtableCacheMetaInfo::bbox_intersect_meta_info, CHECK, DEBUG_TIMER, getBoundingBoxIntersectMetaInfo(), hash_table_cache_, and VLOG.

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

1862  {
1863  auto timer = DEBUG_TIMER(__func__);
1864  VLOG(1) << "Checking CPU hash table cache.";
1866  HashtableCacheMetaInfo meta_info;
1868  auto cached_hashtable =
1869  hash_table_cache_->getItemFromCache(key, item_type, device_identifier, meta_info);
1870  if (cached_hashtable) {
1871  return cached_hashtable;
1872  }
1873  return nullptr;
1874 }
std::optional< BoundingBoxIntersectMetaInfo > bbox_intersect_meta_info
std::optional< BoundingBoxIntersectMetaInfo > getBoundingBoxIntersectMetaInfo()
static std::unique_ptr< HashtableRecycler > hash_table_cache_
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:412
#define VLOG(n)
Definition: Logger.h:388

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void BoundingBoxIntersectJoinHashTable::invalidateCache ( )
inlinestatic

Definition at line 72 of file BoundingBoxIntersectJoinHashTable.h.

References auto_tuner_cache_, CHECK, and hash_table_cache_.

72  {
74  auto_tuner_cache_->clearCache();
75 
77  hash_table_cache_->clearCache();
78  }
static std::unique_ptr< BoundingBoxIntersectTuningParamRecycler > auto_tuner_cache_
static std::unique_ptr< HashtableRecycler > hash_table_cache_
#define CHECK(condition)
Definition: Logger.h:291
bool BoundingBoxIntersectJoinHashTable::isBitwiseEq ( ) const
overrideprotectedvirtual

Implements HashJoin.

Definition at line 1914 of file BoundingBoxIntersectJoinHashTable.cpp.

References condition_, and kBW_EQ.

1914  {
1915  return condition_->get_optype() == kBW_EQ;
1916 }
const std::shared_ptr< Analyzer::BinOper > condition_
Definition: sqldefs.h:33
static void BoundingBoxIntersectJoinHashTable::markCachedItemAsDirty ( size_t  table_key)
inlinestatic

Definition at line 80 of file BoundingBoxIntersectJoinHashTable.h.

References auto_tuner_cache_, BBOX_INTERSECT_AUTO_TUNER_PARAM, BBOX_INTERSECT_HT, CHECK, DataRecyclerUtil::CPU_DEVICE_IDENTIFIER, and hash_table_cache_.

80  {
83  auto candidate_table_keys =
84  hash_table_cache_->getMappedQueryPlanDagsWithTableKey(table_key);
85  if (candidate_table_keys.has_value()) {
86  auto_tuner_cache_->markCachedItemAsDirty(
87  table_key,
88  *candidate_table_keys,
91  hash_table_cache_->markCachedItemAsDirty(table_key,
92  *candidate_table_keys,
95  }
96  }
static std::unique_ptr< BoundingBoxIntersectTuningParamRecycler > auto_tuner_cache_
static std::unique_ptr< HashtableRecycler > hash_table_cache_
#define CHECK(condition)
Definition: Logger.h:291
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
size_t BoundingBoxIntersectJoinHashTable::offsetBufferOff ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 267 of file BoundingBoxIntersectJoinHashTable.h.

References getKeyBufferSize().

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

267  {
268  return getKeyBufferSize();
269  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t BoundingBoxIntersectJoinHashTable::payloadBufferOff ( ) const
inlineoverrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 279 of file BoundingBoxIntersectJoinHashTable.h.

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

Referenced by toSet(), and toString().

279  {
282  } else {
283  return getKeyBufferSize();
284  }
285  }
HashType getHashType() const noexceptoverride
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:176
size_t getComponentBufferSize() const noexceptoverride

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1893 of file BoundingBoxIntersectJoinHashTable.cpp.

References HashtableCacheMetaInfo::bbox_intersect_meta_info, CHECK, CPU, getBoundingBoxIntersectMetaInfo(), hash_table_cache_, and query_hints_.

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

1898  {
1900  CHECK(hashtable_ptr && !hashtable_ptr->getGpuBuffer());
1901  HashtableCacheMetaInfo meta_info;
1903  meta_info.registered_query_hint = query_hints_;
1904  hash_table_cache_->putItemToCache(
1905  key,
1906  hashtable_ptr,
1907  item_type,
1908  device_identifier,
1909  hashtable_ptr->getHashTableBufferSize(ExecutorDeviceType::CPU),
1910  hashtable_building_time,
1911  meta_info);
1912 }
std::optional< BoundingBoxIntersectMetaInfo > bbox_intersect_meta_info
std::optional< BoundingBoxIntersectMetaInfo > getBoundingBoxIntersectMetaInfo()
static std::unique_ptr< HashtableRecycler > hash_table_cache_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BoundingBoxIntersectJoinHashTable::reify ( const HashType  preferred_layout)
protected

Definition at line 1201 of file BoundingBoxIntersectJoinHashTable.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.

1201  {
1202  auto timer = DEBUG_TIMER(__func__);
1203  CHECK_LT(0, device_count_);
1205 
1206  CHECK(condition_->is_bbox_intersect_oper());
1207  CHECK_EQ(inner_outer_pairs_.size(), size_t(1));
1208  HashType layout;
1209  if (inner_outer_pairs_[0].second->get_type_info().is_fixlen_array() &&
1210  inner_outer_pairs_[0].second->get_type_info().get_size() == 32) {
1211  // bounds array
1212  layout = HashType::ManyToMany;
1213  } else {
1214  layout = HashType::OneToMany;
1215  }
1216  try {
1217  reifyWithLayout(layout);
1218  return;
1219  } catch (const JoinHashTableTooBig& e) {
1220  throw e;
1221  } catch (const std::exception& e) {
1222  VLOG(1) << "Caught exception while building baseline hash table for bounding box "
1223  "intersection: "
1224  << e.what();
1225  throw;
1226  }
1227 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const std::shared_ptr< Analyzer::BinOper > condition_
#define CHECK_LT(x, y)
Definition: Logger.h:303
virtual void reifyWithLayout(const HashType layout)
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:412
HashType
Definition: HashTable.h:19
#define VLOG(n)
Definition: Logger.h:388
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:470

+ Here is the call graph for this function:

void BoundingBoxIntersectJoinHashTable::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 1270 of file BoundingBoxIntersectJoinHashTable.cpp.

References CHECK, CHECK_EQ, CHECK_LT, Data_Namespace::CPU_LEVEL, DEBUG_TIMER_NEW_THREAD, getEffectiveMemoryLevel(), getKeyComponentCount(), 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().

1277  {
1278  logger::LocalIdsScopeGuard lisg = parent_thread_local_ids.setNewThreadId();
1279  DEBUG_TIMER_NEW_THREAD(parent_thread_local_ids.thread_id_);
1280  CHECK_EQ(getKeyComponentWidth(), size_t(8));
1282  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
1283  BaselineHashTableEntryInfo hash_table_entry_info(entry_count,
1284  emitted_keys_count,
1285  sizeof(int32_t),
1288  layout,
1289  false);
1290  if (effective_memory_level == Data_Namespace::MemoryLevel::CPU_LEVEL) {
1291  VLOG(1) << "Building join hash table for bounding box intersection on CPU.";
1292  auto hash_table = initHashTableOnCpu(columns_for_device.join_columns,
1293  columns_for_device.join_column_types,
1294  columns_for_device.join_buckets,
1295  hash_table_entry_info,
1296  skip_hashtable_caching);
1297  CHECK(hash_table);
1298 
1299 #ifdef HAVE_CUDA
1301  auto gpu_hash_table = copyCpuHashTableToGpu(hash_table, device_id);
1302  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
1303  hash_tables_for_device_[device_id] = std::move(gpu_hash_table);
1304  } else {
1305 #else
1306  CHECK_EQ(Data_Namespace::CPU_LEVEL, effective_memory_level);
1307 #endif
1308  CHECK_EQ(hash_tables_for_device_.size(), size_t(1));
1309  hash_tables_for_device_[0] = hash_table;
1310 #ifdef HAVE_CUDA
1311  }
1312 #endif
1313  } else {
1314 #ifdef HAVE_CUDA
1315  auto hash_table = initHashTableOnGpu(columns_for_device.join_columns,
1316  columns_for_device.join_column_types,
1317  columns_for_device.join_buckets,
1318  hash_table_entry_info,
1319  device_id);
1320  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
1321  hash_tables_for_device_[device_id] = std::move(hash_table);
1322 #else
1323  UNREACHABLE();
1324 #endif
1325  }
1326 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) const
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:378
#define UNREACHABLE()
Definition: Logger.h:338
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 BaselineHashTableEntryInfo hash_table_entry_info, const bool skip_hashtable_caching)
#define DEBUG_TIMER_NEW_THREAD(parent_thread_id)
Definition: Logger.h:417
const std::vector< JoinColumnTypeInfo > join_column_types
Definition: HashJoin.h:111
const Data_Namespace::MemoryLevel memory_level_
#define CHECK_LT(x, y)
Definition: Logger.h:303
LocalIdsScopeGuard setNewThreadId() const
Definition: Logger.cpp:538
#define CHECK(condition)
Definition: Logger.h:291
ThreadId thread_id_
Definition: Logger.h:138
std::vector< JoinBucketInfo > join_buckets
Definition: HashJoin.h:113
const std::vector< JoinColumn > join_columns
Definition: HashJoin.h:110
#define VLOG(n)
Definition: Logger.h:388
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:176

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BoundingBoxIntersectJoinHashTable::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 1229 of file BoundingBoxIntersectJoinHashTable.cpp.

References threading_serial::async(), chosen_bbox_intersect_bucket_threshold_, chosen_bbox_intersect_max_table_size_bytes_, device_count_, Fragmenter_Namespace::TableInfo::fragments, inverse_bucket_sizes_for_dimension_, only_shards_for_device(), reifyForDevice(), setBoundingBoxIntersectionMetaInfo(), and logger::thread_local_ids().

Referenced by reifyWithLayout().

1238  {
1239  std::vector<std::future<void>> init_threads;
1240  chosen_bbox_intersect_bucket_threshold_ = chosen_bucket_threshold;
1241  chosen_bbox_intersect_max_table_size_bytes_ = chosen_max_hashtable_size;
1245 
1246  for (int device_id = 0; device_id < device_count_; ++device_id) {
1247  const auto fragments =
1248  shard_count
1249  ? only_shards_for_device(query_info.fragments, device_id, device_count_)
1250  : query_info.fragments;
1251  init_threads.push_back(std::async(std::launch::async,
1253  this,
1254  columns_per_device[device_id],
1255  layout,
1256  entry_count,
1257  emitted_keys_count,
1258  skip_hashtable_caching,
1259  device_id,
1261  }
1262  for (auto& init_thread : init_threads) {
1263  init_thread.wait();
1264  }
1265  for (auto& init_thread : init_threads) {
1266  init_thread.get();
1267  }
1268 }
void setBoundingBoxIntersectionMetaInfo(size_t max_table_size_bytes, double bucket_threshold, std::vector< double > &bucket_sizes)
std::vector< FragmentInfo > fragments
Definition: Fragmenter.h:171
future< Result > async(Fn &&fn, Args &&...args)
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 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)
ThreadLocalIds thread_local_ids()
Definition: Logger.cpp:882

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BoundingBoxIntersectJoinHashTable::reifyWithLayout ( const HashType  layout)
protectedvirtual

Reimplemented in RangeJoinHashTable.

Definition at line 553 of file BoundingBoxIntersectJoinHashTable.cpp.

References gpu_enabled::accumulate(), auto_tuner_cache_, RegisteredQueryHint::bbox_intersect_allow_gpu_build, BBOX_INTERSECT_AUTO_TUNER_PARAM, RegisteredQueryHint::bbox_intersect_bucket_threshold, BBOX_INTERSECT_HT, RegisteredQueryHint::bbox_intersect_keys_per_bin, RegisteredQueryHint::bbox_intersect_max_size, 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_bbox_intersect_max_table_size_bytes, g_bbox_intersect_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_, hash_value(), 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_, kBBoxIntersectAllowGpuBuild, kBBoxIntersectBucketThreshold, kBBoxIntersectKeysPerBin, kBBoxIntersectMaxSize, kBBoxIntersectNoCache, HashJoin::layoutRequiresAdditionalBuffers(), memory_level_, only_shards_for_device(), query_hints_, query_infos_, reifyImpl(), setBoundingBoxIntersectionMetaInfo(), setInverseBucketSizeInfo(), shardCount(), table_keys_, and VLOG.

Referenced by reify().

553  {
554  auto timer = DEBUG_TIMER(__func__);
556  const auto& query_info =
558  .info;
559  auto [db_id, table_id] = HashJoin::getInnerTableId(inner_outer_pairs_);
560  VLOG(1) << "Reify with layout " << getHashTypeString(layout) << "for db_id: " << db_id
561  << ", table_id: " << table_id;
562  if (query_info.fragments.empty()) {
563  return;
564  }
565 
566  auto bbox_intersect_max_table_size_bytes = g_bbox_intersect_max_table_size_bytes;
567  std::optional<double> bbox_intersect_threshold_override;
568  double bbox_intersect_target_entries_per_bin = g_bbox_intersect_target_entries_per_bin;
569  auto skip_hashtable_caching = false;
571  VLOG(1) << "Setting bounding box intersection bucket threshold "
572  "\'bbox_intersect_bucket_threshold\' via "
573  "query hint: "
575  bbox_intersect_threshold_override = query_hints_.bbox_intersect_bucket_threshold;
576  }
578  std::ostringstream oss;
579  oss << "User requests to change a threshold \'bbox_intersect_max_table_size_bytes\' "
580  "via "
581  "query hint";
582  if (!bbox_intersect_threshold_override.has_value()) {
583  oss << ": " << bbox_intersect_max_table_size_bytes << " -> "
585  bbox_intersect_max_table_size_bytes = query_hints_.bbox_intersect_max_size;
586  } else {
587  oss << ", but is skipped since the query hint also changes the threshold "
588  "\'bbox_intersect_bucket_threshold\'";
589  }
590  VLOG(1) << oss.str();
591  }
593  VLOG(1) << "User requests to skip caching join hashtable for bounding box "
594  "intersection and its tuned "
595  "parameters for this query";
596  skip_hashtable_caching = true;
597  }
599  VLOG(1) << "User requests to change a threshold \'bbox_intersect_keys_per_bin\' via "
600  "query "
601  "hint: "
602  << bbox_intersect_target_entries_per_bin << " -> "
604  bbox_intersect_target_entries_per_bin = query_hints_.bbox_intersect_keys_per_bin;
605  }
606 
607  auto data_mgr = executor_->getDataMgr();
608  // we prioritize CPU when building a join hashtable for bounding box intersection, but
609  // if we have GPU and user-given hint is given we selectively allow GPU to build it but
610  // even if we have GPU but user foces to set CPU as execution device type we should not
611  // allow to use GPU for building it
612  auto allow_gpu_hashtable_build =
615  if (allow_gpu_hashtable_build) {
616  if (data_mgr->gpusPresent() &&
618  VLOG(1) << "A user forces to build GPU hash table for bounding box intersection";
619  } else {
620  allow_gpu_hashtable_build = false;
621  VLOG(1) << "A user forces to build GPU hash table for bounding box intersection "
622  "but we skip it since either GPU is not presented or CPU execution mode "
623  "is set";
624  }
625  }
626 
627  std::vector<ColumnsForDevice> columns_per_device;
628  std::vector<std::unique_ptr<CudaAllocator>> dev_buff_owners;
630  allow_gpu_hashtable_build) {
631  for (int device_id = 0; device_id < device_count_; ++device_id) {
632  dev_buff_owners.emplace_back(std::make_unique<CudaAllocator>(
633  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id)));
634  }
635  }
636 
637  std::vector<std::vector<Fragmenter_Namespace::FragmentInfo>> fragments_per_device;
638  const auto shard_count = shardCount();
639  size_t total_num_tuples = 0;
640  for (int device_id = 0; device_id < device_count_; ++device_id) {
641  fragments_per_device.emplace_back(
642  shard_count
643  ? only_shards_for_device(query_info.fragments, device_id, device_count_)
644  : query_info.fragments);
645  const size_t crt_num_tuples =
646  std::accumulate(fragments_per_device.back().begin(),
647  fragments_per_device.back().end(),
648  size_t(0),
649  [](const auto& sum, const auto& fragment) {
650  return sum + fragment.getNumTuples();
651  });
652  total_num_tuples += crt_num_tuples;
653  const auto columns_for_device =
654  fetchColumnsForDevice(fragments_per_device.back(),
655  device_id,
657  allow_gpu_hashtable_build
658  ? dev_buff_owners[device_id].get()
659  : nullptr);
660  columns_per_device.push_back(columns_for_device);
661  }
662 
663  // try to extract cache key for hash table and its relevant info
664  auto hashtable_access_path_info =
666  {},
667  condition_->get_optype(),
668  join_type_,
671  shard_count,
672  fragments_per_device,
673  executor_);
674  hashtable_cache_key_ = hashtable_access_path_info.hashed_query_plan_dag;
675  hashtable_cache_meta_info_ = hashtable_access_path_info.meta_info;
676  table_keys_ = hashtable_access_path_info.table_keys;
677 
678  auto get_inner_table_key = [this]() {
679  auto col_var = inner_outer_pairs_.front().first;
680  return col_var->getTableKey();
681  };
682 
683  if (table_keys_.empty()) {
684  const auto& table_key = get_inner_table_key();
687  }
688  CHECK(!table_keys_.empty());
689 
690  if (bbox_intersect_threshold_override) {
691  // compute bucket sizes based on the user provided threshold
692  BucketSizeTuner tuner(/*initial_threshold=*/*bbox_intersect_threshold_override,
693  /*step=*/1.0,
694  /*min_threshold=*/0.0,
696  columns_per_device,
698  total_num_tuples,
699  executor_);
700  const auto inverse_bucket_sizes = tuner.getInverseBucketSizes();
701 
702  auto [entry_count, emitted_keys_count] =
703  computeHashTableCounts(shard_count,
704  inverse_bucket_sizes,
705  columns_per_device,
706  bbox_intersect_max_table_size_bytes,
707  *bbox_intersect_threshold_override);
708  setInverseBucketSizeInfo(inverse_bucket_sizes, columns_per_device, device_count_);
709  // reifyImpl will check the hash table cache for an appropriate hash table w/ those
710  // bucket sizes (or within tolerances) if a hash table exists use it, otherwise build
711  // one
712  generateCacheKey(bbox_intersect_max_table_size_bytes,
713  *bbox_intersect_threshold_override,
714  inverse_bucket_sizes,
715  fragments_per_device,
716  device_count_);
717  reifyImpl(columns_per_device,
718  query_info,
719  layout,
720  shard_count,
721  entry_count,
722  emitted_keys_count,
723  skip_hashtable_caching,
724  bbox_intersect_max_table_size_bytes,
725  *bbox_intersect_threshold_override);
726  } else {
727  double bbox_intersect_bucket_threshold = std::numeric_limits<double>::max();
728  generateCacheKey(bbox_intersect_max_table_size_bytes,
729  bbox_intersect_bucket_threshold,
730  {},
731  fragments_per_device,
732  device_count_);
733  std::vector<size_t> per_device_chunk_key;
734  if (HashtableRecycler::isInvalidHashTableCacheKey(hashtable_cache_key_) &&
735  get_inner_table_key().table_id > 0) {
736  for (int device_id = 0; device_id < device_count_; ++device_id) {
738  boost::hash_combine(
739  chunk_key_hash,
740  HashJoin::collectFragmentIds(fragments_per_device[device_id]));
741  per_device_chunk_key.push_back(chunk_key_hash);
742  AlternativeCacheKeyForBoundingBoxIntersection cache_key{
744  columns_per_device.front().join_columns.front().num_elems,
745  chunk_key_hash,
746  condition_->get_optype(),
747  bbox_intersect_max_table_size_bytes,
748  bbox_intersect_bucket_threshold,
749  {}};
750  hashtable_cache_key_[device_id] = getAlternativeCacheKey(cache_key);
751  hash_table_cache_->addQueryPlanDagForTableKeys(hashtable_cache_key_[device_id],
752  table_keys_);
753  }
754  }
755 
756  auto cached_bucket_threshold = auto_tuner_cache_->getItemFromCache(
757  hashtable_cache_key_.front(),
760  if (cached_bucket_threshold) {
761  bbox_intersect_bucket_threshold = cached_bucket_threshold->bucket_threshold;
762  auto inverse_bucket_sizes = cached_bucket_threshold->bucket_sizes;
763  setBoundingBoxIntersectionMetaInfo(bbox_intersect_max_table_size_bytes,
764  bbox_intersect_bucket_threshold,
765  inverse_bucket_sizes);
766  generateCacheKey(bbox_intersect_max_table_size_bytes,
767  bbox_intersect_bucket_threshold,
768  inverse_bucket_sizes,
769  fragments_per_device,
770  device_count_);
771 
772  if (auto hash_table =
773  hash_table_cache_->getItemFromCache(hashtable_cache_key_[device_count_],
776  std::nullopt)) {
777  // if we already have a built hash table, we can skip the scans required for
778  // computing bucket size and tuple count
779  // reset as the hash table sizes can vary a bit
780  setInverseBucketSizeInfo(inverse_bucket_sizes, columns_per_device, device_count_);
781  CHECK(hash_table);
782 
783  VLOG(1) << "Using cached hash table bucket size";
784 
785  reifyImpl(columns_per_device,
786  query_info,
787  layout,
788  shard_count,
789  hash_table->getEntryCount(),
790  hash_table->getEmittedKeysCount(),
791  skip_hashtable_caching,
792  bbox_intersect_max_table_size_bytes,
793  bbox_intersect_bucket_threshold);
794  } else {
795  VLOG(1) << "Computing bucket size for cached bucket threshold";
796  // compute bucket size using our cached tuner value
797  BucketSizeTuner tuner(/*initial_threshold=*/bbox_intersect_bucket_threshold,
798  /*step=*/1.0,
799  /*min_threshold=*/0.0,
801  columns_per_device,
803  total_num_tuples,
804  executor_);
805 
806  const auto inverse_bucket_sizes = tuner.getInverseBucketSizes();
807 
808  auto [entry_count, emitted_keys_count] =
809  computeHashTableCounts(shard_count,
810  inverse_bucket_sizes,
811  columns_per_device,
812  bbox_intersect_max_table_size_bytes,
813  bbox_intersect_bucket_threshold);
814  setInverseBucketSizeInfo(inverse_bucket_sizes, columns_per_device, device_count_);
815 
816  generateCacheKey(bbox_intersect_max_table_size_bytes,
817  bbox_intersect_bucket_threshold,
818  inverse_bucket_sizes,
819  fragments_per_device,
820  device_count_);
821 
822  reifyImpl(columns_per_device,
823  query_info,
824  layout,
825  shard_count,
826  entry_count,
827  emitted_keys_count,
828  skip_hashtable_caching,
829  bbox_intersect_max_table_size_bytes,
830  bbox_intersect_bucket_threshold);
831  }
832  } else {
833  // compute bucket size using the auto tuner
834  BucketSizeTuner tuner(
835  /*initial_threshold=*/bbox_intersect_bucket_threshold,
836  /*step=*/2.0,
837  /*min_threshold=*/1e-7,
839  columns_per_device,
841  total_num_tuples,
842  executor_);
843 
844  VLOG(1) << "Running auto tune logic for bounding box intersection with parameters: "
845  << tuner;
846 
847  // manages the tuning state machine
848  TuningState tuning_state(bbox_intersect_max_table_size_bytes,
849  bbox_intersect_target_entries_per_bin);
850  while (tuner.tuneOneStep(tuning_state.tuning_direction)) {
851  const auto inverse_bucket_sizes = tuner.getInverseBucketSizes();
852 
853  const auto [crt_entry_count, crt_emitted_keys_count] =
854  computeHashTableCounts(shard_count,
855  inverse_bucket_sizes,
856  columns_per_device,
857  tuning_state.bbox_intersect_max_table_size_bytes,
858  tuning_state.chosen_bbox_intersect_threshold);
859  const size_t hash_table_size = calculateHashTableSize(
860  inverse_bucket_sizes.size(), crt_emitted_keys_count, crt_entry_count);
861  HashTableProps crt_props(crt_entry_count,
862  crt_emitted_keys_count,
863  hash_table_size,
864  inverse_bucket_sizes);
865  VLOG(1) << "Tuner output: " << tuner << " with properties " << crt_props;
866 
867  const auto should_continue = tuning_state(crt_props, tuner.getMinBucketSize());
869  tuning_state.crt_props.bucket_sizes, columns_per_device, device_count_);
870  if (!should_continue) {
871  break;
872  }
873  }
874 
875  const auto& crt_props = tuning_state.crt_props;
876  // sanity check that the hash table size has not changed. this is a fairly
877  // inexpensive check to ensure the above algorithm is consistent
878  const size_t hash_table_size =
880  crt_props.emitted_keys_count,
881  crt_props.entry_count);
882  CHECK_EQ(crt_props.hash_table_size, hash_table_size);
883 
885  hash_table_size > bbox_intersect_max_table_size_bytes) {
886  VLOG(1) << "Could not find suitable parameters to create hash "
887  "table for bounding box intersectionunder max allowed size ("
888  << bbox_intersect_max_table_size_bytes << ") bytes.";
889  throw TooBigHashTableForBoundingBoxIntersect(bbox_intersect_max_table_size_bytes);
890  }
891 
892  VLOG(1) << "Final tuner output: " << tuner << " with properties " << crt_props;
894  VLOG(1) << "Final bucket sizes: ";
895  for (size_t dim = 0; dim < inverse_bucket_sizes_for_dimension_.size(); dim++) {
896  VLOG(1) << "dim[" << dim
897  << "]: " << 1.0 / inverse_bucket_sizes_for_dimension_[dim];
898  }
899  CHECK_GE(tuning_state.chosen_bbox_intersect_threshold, double(0));
900  generateCacheKey(tuning_state.bbox_intersect_max_table_size_bytes,
901  tuning_state.chosen_bbox_intersect_threshold,
902  {},
903  fragments_per_device,
904  device_count_);
905  const auto candidate_auto_tuner_cache_key = hashtable_cache_key_.front();
906  if (skip_hashtable_caching) {
907  VLOG(1) << "Skip to add tuned parameters to auto tuner";
908  } else {
909  AutoTunerMetaInfo meta_info{tuning_state.bbox_intersect_max_table_size_bytes,
910  tuning_state.chosen_bbox_intersect_threshold,
912  auto_tuner_cache_->putItemToCache(candidate_auto_tuner_cache_key,
913  meta_info,
916  0,
917  0);
918  }
919  bbox_intersect_bucket_threshold = tuning_state.chosen_bbox_intersect_threshold;
920  reifyImpl(columns_per_device,
921  query_info,
922  layout,
923  shard_count,
924  crt_props.entry_count,
925  crt_props.emitted_keys_count,
926  skip_hashtable_caching,
927  bbox_intersect_max_table_size_bytes,
928  bbox_intersect_bucket_threshold);
929  }
930  }
931 }
static std::vector< int > collectFragmentIds(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments)
Definition: HashJoin.cpp:461
static std::unique_ptr< BoundingBoxIntersectTuningParamRecycler > auto_tuner_cache_
#define CHECK_EQ(x, y)
Definition: Logger.h:301
void setBoundingBoxIntersectionMetaInfo(size_t max_table_size_bytes, double bucket_threshold, std::vector< double > &bucket_sizes)
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)
Fragmenter_Namespace::TableInfo info
Definition: InputMetadata.h:35
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) const
size_t calculateHashTableSize(size_t number_of_dimensions, size_t emitted_keys_count, size_t entry_count) const
static bool isInvalidHashTableCacheKey(const std::vector< QueryPlanHash > &cache_keys)
std::vector< ChunkKey > cache_key_chunks
Definition: HashJoin.h:130
double bbox_intersect_keys_per_bin
Definition: QueryHint.h:368
const std::shared_ptr< Analyzer::BinOper > condition_
#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 g_bbox_intersect_target_entries_per_bin
Definition: Execute.cpp:115
void setInverseBucketSizeInfo(const std::vector< double > &inverse_bucket_sizes, std::vector< ColumnsForDevice > &columns_per_device, const size_t device_count)
ColumnsForDevice fetchColumnsForDevice(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, DeviceAllocator *dev_buff_owner)
const Data_Namespace::MemoryLevel memory_level_
double bbox_intersect_bucket_threshold
Definition: QueryHint.h:363
static std::unique_ptr< HashtableRecycler > hash_table_cache_
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)
std::vector< Fragmenter_Namespace::FragmentInfo > only_shards_for_device(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, const int device_count)
const std::vector< InputTableInfo > & query_infos_
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
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)
static std::unordered_set< size_t > getAlternativeTableKeys(const std::vector< ChunkKey > &chunk_keys, const shared::TableKey &inner_table_key)
Definition: DataRecycler.h:154
QueryPlanHash getAlternativeCacheKey(AlternativeCacheKeyForBoundingBoxIntersection &info)
virtual shared::TableKey getInnerTableId() const noexcept=0
static std::string getHashTypeString(HashType ht) noexcept
Definition: HashJoin.h:180
bool isHintRegistered(const QueryHint hint) const
Definition: QueryHint.h:398
size_t bbox_intersect_max_size
Definition: QueryHint.h:365
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
std::size_t hash_value(RexAbstractInput const &rex_ab_input)
Definition: RelAlgDag.cpp:3548
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:412
bool bbox_intersect_allow_gpu_build
Definition: QueryHint.h:366
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)
#define VLOG(n)
Definition: Logger.h:388
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:176
size_t g_bbox_intersect_max_table_size_bytes
Definition: Execute.cpp:114

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 373 of file BoundingBoxIntersectJoinHashTable.h.

References BoundingBoxIntersectMetaInfo::bbox_intersect_bucket_threshold, BoundingBoxIntersectMetaInfo::bbox_intersect_max_table_size_bytes, HashtableCacheMetaInfo::bbox_intersect_meta_info, BoundingBoxIntersectMetaInfo::bucket_sizes, and hashtable_cache_meta_info_.

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

375  {
376  BoundingBoxIntersectMetaInfo bbox_intersect_meta_info;
377  bbox_intersect_meta_info.bucket_sizes = bucket_sizes;
378  bbox_intersect_meta_info.bbox_intersect_max_table_size_bytes = max_table_size_bytes;
379  bbox_intersect_meta_info.bbox_intersect_bucket_threshold = bucket_threshold;
380  HashtableCacheMetaInfo meta_info;
381  meta_info.bbox_intersect_meta_info = bbox_intersect_meta_info;
382  hashtable_cache_meta_info_ = meta_info;
383  }
std::optional< BoundingBoxIntersectMetaInfo > bbox_intersect_meta_info
std::vector< double > bucket_sizes

+ Here is the caller graph for this function:

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

Definition at line 1176 of file BoundingBoxIntersectJoinHashTable.cpp.

References CHECK_EQ, inner_outer_pairs_, and inverse_bucket_sizes_for_dimension_.

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

1179  {
1180  // set global bucket size
1181  inverse_bucket_sizes_for_dimension_ = inverse_bucket_sizes;
1182 
1183  // re-compute bucket counts per device based on global bucket size
1184  CHECK_EQ(columns_per_device.size(), static_cast<size_t>(device_count));
1185  for (size_t device_id = 0; device_id < device_count; ++device_id) {
1186  auto& columns_for_device = columns_per_device[device_id];
1187  columns_for_device.setBucketInfo(inverse_bucket_sizes_for_dimension_,
1189  }
1190 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301

+ Here is the caller graph for this function:

size_t BoundingBoxIntersectJoinHashTable::shardCount ( ) const
inlineprotected

Definition at line 237 of file BoundingBoxIntersectJoinHashTable.h.

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

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

237  {
239  return 0;
240  }
243  }
const std::shared_ptr< Analyzer::BinOper > condition_
const Data_Namespace::MemoryLevel memory_level_
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 > BoundingBoxIntersectJoinHashTable::toSet ( const ExecutorDeviceType  device_type,
const int  device_id 
) const
overrideprotectedvirtual

Implements HashJoin.

Definition at line 1802 of file BoundingBoxIntersectJoinHashTable.cpp.

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

1804  {
1805  auto buffer = getJoinHashBuffer(device_type, device_id);
1806  auto hash_table = getHashTableForDevice(device_id);
1807  CHECK(hash_table);
1808  auto buffer_size = hash_table->getHashTableBufferSize(device_type);
1809 #ifdef HAVE_CUDA
1810  std::unique_ptr<int8_t[]> buffer_copy;
1811  if (device_type == ExecutorDeviceType::GPU) {
1812  buffer_copy = std::make_unique<int8_t[]>(buffer_size);
1813  CHECK(executor_);
1814  auto data_mgr = executor_->getDataMgr();
1815  auto allocator = std::make_unique<CudaAllocator>(
1816  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
1817 
1818  allocator->copyFromDevice(buffer_copy.get(), buffer, buffer_size);
1819  }
1820  auto ptr1 = buffer_copy ? buffer_copy.get() : reinterpret_cast<const int8_t*>(buffer);
1821 #else
1822  auto ptr1 = reinterpret_cast<const int8_t*>(buffer);
1823 #endif // HAVE_CUDA
1824  auto ptr2 = ptr1 + offsetBufferOff();
1825  auto ptr3 = ptr1 + countBufferOff();
1826  auto ptr4 = ptr1 + payloadBufferOff();
1827  const auto layout = getHashType();
1828  return HashTable::toSet(getKeyComponentCount() + (layout == HashType::OneToOne ? 1 : 0),
1830  hash_table->getEntryCount(),
1831  ptr1,
1832  ptr2,
1833  ptr3,
1834  ptr4,
1835  buffer_size);
1836 }
int8_t * getJoinHashBuffer(const ExecutorDeviceType device_type, const int device_id) const
Definition: HashJoin.h:315
size_t payloadBufferOff() const noexceptoverride
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:296
HashType getHashType() const noexceptoverride
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
#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 BoundingBoxIntersectJoinHashTable::toString ( const ExecutorDeviceType  device_type,
const int  device_id = 0,
bool  raw = false 
) const
overrideprotectedvirtual

Implements HashJoin.

Definition at line 1756 of file BoundingBoxIntersectJoinHashTable.cpp.

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

1759  {
1760  auto buffer = getJoinHashBuffer(device_type, device_id);
1761  if (!buffer) {
1762  return "EMPTY";
1763  }
1764  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
1765  auto hash_table = hash_tables_for_device_[device_id];
1766  CHECK(hash_table);
1767  auto buffer_size = hash_table->getHashTableBufferSize(device_type);
1768 #ifdef HAVE_CUDA
1769  std::unique_ptr<int8_t[]> buffer_copy;
1770  if (device_type == ExecutorDeviceType::GPU) {
1771  buffer_copy = std::make_unique<int8_t[]>(buffer_size);
1772  CHECK(executor_);
1773  auto data_mgr = executor_->getDataMgr();
1774  auto device_allocator = std::make_unique<CudaAllocator>(
1775  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
1776 
1777  device_allocator->copyFromDevice(buffer_copy.get(), buffer, buffer_size);
1778  }
1779  auto ptr1 = buffer_copy ? buffer_copy.get() : reinterpret_cast<const int8_t*>(buffer);
1780 #else
1781  auto ptr1 = reinterpret_cast<const int8_t*>(buffer);
1782 #endif // HAVE_CUDA
1783  auto ptr2 = ptr1 + offsetBufferOff();
1784  auto ptr3 = ptr1 + countBufferOff();
1785  auto ptr4 = ptr1 + payloadBufferOff();
1786  CHECK(hash_table);
1787  const auto layout = getHashType();
1788  return HashTable::toString(
1789  "geo",
1790  getHashTypeString(layout),
1791  getKeyComponentCount() + (layout == HashType::OneToOne ? 1 : 0),
1793  hash_table->getEntryCount(),
1794  ptr1,
1795  ptr2,
1796  ptr3,
1797  ptr4,
1798  buffer_size,
1799  raw);
1800 }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:378
int8_t * getJoinHashBuffer(const ExecutorDeviceType device_type, const int device_id) const
Definition: HashJoin.h:315
size_t payloadBufferOff() const noexceptoverride
#define CHECK_LT(x, y)
Definition: Logger.h:303
HashType getHashType() const noexceptoverride
static std::string getHashTypeString(HashType ht) noexcept
Definition: HashJoin.h:180
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
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

Member Data Documentation

std::unique_ptr< BoundingBoxIntersectTuningParamRecycler > BoundingBoxIntersectJoinHashTable::auto_tuner_cache_
staticprotected
Initial value:
=
std::make_unique<BoundingBoxIntersectTuningParamRecycler>()

Definition at line 416 of file BoundingBoxIntersectJoinHashTable.h.

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

double BoundingBoxIntersectJoinHashTable::chosen_bbox_intersect_bucket_threshold_
protected

Definition at line 398 of file BoundingBoxIntersectJoinHashTable.h.

Referenced by reifyImpl().

size_t BoundingBoxIntersectJoinHashTable::chosen_bbox_intersect_max_table_size_bytes_
protected

Definition at line 399 of file BoundingBoxIntersectJoinHashTable.h.

Referenced by reifyImpl().

ColumnCacheMap& BoundingBoxIntersectJoinHashTable::column_cache_
protected

Definition at line 391 of file BoundingBoxIntersectJoinHashTable.h.

Referenced by fetchColumnsForDevice().

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

Definition at line 419 of file BoundingBoxIntersectJoinHashTable.h.

const TableIdToNodeMap BoundingBoxIntersectJoinHashTable::table_id_to_node_map_
protected

Definition at line 423 of file BoundingBoxIntersectJoinHashTable.h.

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

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