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

#include <BaselineJoinHashTable.h>

+ Inheritance diagram for BaselineJoinHashTable:
+ Collaboration diagram for BaselineJoinHashTable:

Classes

struct  AlternativeCacheKeyForBaselineHashJoin
 

Public Member Functions

std::string toString (const ExecutorDeviceType device_type, const int device_id=0, bool raw=false) const override
 
std::set
< DecodedJoinHashBufferEntry
toSet (const ExecutorDeviceType device_type, const int device_id) const override
 
llvm::Value * codegenSlot (const CompilationOptions &, const size_t) override
 
HashJoinMatchingSet codegenMatchingSet (const CompilationOptions &, const size_t) override
 
shared::TableKey getInnerTableId () const noexceptoverride
 
int getInnerTableRteIdx () const noexceptoverride
 
HashType getHashType () const noexceptoverride
 
Data_Namespace::MemoryLevel getMemoryLevel () const noexceptoverride
 
int getDeviceCount () const noexceptoverride
 
size_t offsetBufferOff () const noexceptoverride
 
size_t countBufferOff () const noexceptoverride
 
size_t payloadBufferOff () const noexceptoverride
 
std::string getHashJoinType () const final
 
const RegisteredQueryHintgetRegisteredQueryHint ()
 
virtual ~BaselineJoinHashTable ()
 
- 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
< BaselineJoinHashTable
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 HashType preferred_hash_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)
 Make hash table from an in-flight SQL query's parse tree etc. More...
 
static size_t getShardCountForCondition (const Analyzer::BinOper *condition, const Executor *executor, const std::vector< InnerOuter > &inner_outer_pairs)
 
static void invalidateCache ()
 
static void markCachedItemAsDirty (size_t table_key)
 
static HashtableRecyclergetHashTableCache ()
 
static HashingSchemeRecyclergetHashingSchemeCache ()
 
- 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

 BaselineJoinHashTable (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 std::vector< InnerOuterStringOpInfos > &col_pairs_string_op_infos, const int device_count, const RegisteredQueryHint &query_hints, const HashTableBuildDagMap &hashtable_build_dag_map, const TableIdToNodeMap &table_id_to_node_map)
 
size_t getComponentBufferSize () const noexceptoverride
 
size_t getKeyBufferSize () const noexcept
 
virtual void reifyWithLayout (const HashType layout)
 
virtual 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< ColumnsForDevice > &) const
 
virtual size_t getKeyComponentWidth () const
 
virtual size_t getKeyComponentCount () const
 
virtual llvm::Value * codegenKey (const CompilationOptions &)
 
size_t shardCount () const
 
Data_Namespace::MemoryLevel getEffectiveMemoryLevel (const std::vector< InnerOuter > &inner_outer_pairs) const
 
void reify (const HashType preferred_layout)
 
void copyCpuHashTableToGpu (std::shared_ptr< BaselineHashTable > &cpu_hash_table, const int device_id, Data_Namespace::DataMgr *data_mgr)
 
virtual void reifyForDevice (const ColumnsForDevice &columns_for_device, const HashType layout, const int device_id, const BaselineHashTableEntryInfo hash_table_entry_info, const logger::ThreadLocalIds parent_thread_local_ids)
 
virtual int initHashTableForDevice (const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const std::vector< JoinBucketInfo > &join_buckets, const HashType layout, const Data_Namespace::MemoryLevel effective_memory_level, const BaselineHashTableEntryInfo hash_table_entry_info, const int device_id)
 
llvm::Value * hashPtr (const size_t index)
 
std::shared_ptr< HashTableinitHashTableOnCpuFromCache (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)
 
bool isBitwiseEq () const override
 
ChunkKey genChunkKey (const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments) const
 

Static Protected Member Functions

static shared::TableKey getInnerTableId (const std::vector< InnerOuter > &inner_outer_pairs)
 
static QueryPlanHash getAlternativeCacheKey (AlternativeCacheKeyForBaselineHashJoin &info)
 
- 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)
 

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::mutex cpu_hash_table_buff_mutex_
 
std::mutex str_proxy_translation_mutex_
 
std::vector< const
StringDictionaryProxy::IdMap * > 
str_proxy_translation_maps_
 
std::vector< InnerOuterinner_outer_pairs_
 
std::vector
< InnerOuterStringOpInfos
inner_outer_string_op_infos_pairs_
 
const int device_count_
 
RegisteredQueryHint query_hints_
 
bool needs_dict_translation_
 
std::optional< HashTypelayout_override_
 
HashTableBuildDagMap hashtable_build_dag_map_
 
std::vector< QueryPlanHashhashtable_cache_key_
 
HashtableCacheMetaInfo hashtable_cache_meta_info_
 
std::unordered_set< size_t > table_keys_
 
const TableIdToNodeMap table_id_to_node_map_
 
const size_t rowid_size_
 
- 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
< HashingSchemeRecycler
hash_table_layout_cache_
 

Additional Inherited Members

- Static Public Attributes inherited from HashJoin
static constexpr size_t MAX_NUM_HASH_ENTRIES = size_t(1) << 31
 

Detailed Description

Definition at line 49 of file BaselineJoinHashTable.h.

Constructor & Destructor Documentation

virtual BaselineJoinHashTable::~BaselineJoinHashTable ( )
inlinevirtual

Definition at line 139 of file BaselineJoinHashTable.h.

139 {}
BaselineJoinHashTable::BaselineJoinHashTable ( 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 std::vector< InnerOuterStringOpInfos > &  col_pairs_string_op_infos,
const int  device_count,
const RegisteredQueryHint query_hints,
const HashTableBuildDagMap hashtable_build_dag_map,
const TableIdToNodeMap table_id_to_node_map 
)
protected

Definition at line 121 of file BaselineJoinHashTable.cpp.

References CHECK_GT, device_count_, and HashJoin::hash_tables_for_device_.

Referenced by getInstance().

134  : condition_(condition)
135  , join_type_(join_type)
136  , query_infos_(query_infos)
137  , memory_level_(memory_level)
138  , executor_(executor)
139  , column_cache_(column_cache)
140  , inner_outer_pairs_(inner_outer_pairs)
141  , inner_outer_string_op_infos_pairs_(col_pairs_string_op_infos)
142  , device_count_(device_count)
143  , query_hints_(query_hints)
144  , needs_dict_translation_(false)
145  , hashtable_build_dag_map_(hashtable_build_dag_map)
146  , table_id_to_node_map_(table_id_to_node_map)
147  , rowid_size_(sizeof(int32_t)) {
149  hash_tables_for_device_.resize(std::max(device_count_, 1));
150 }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:377
HashTableBuildDagMap hashtable_build_dag_map_
const TableIdToNodeMap table_id_to_node_map_
RegisteredQueryHint query_hints_
#define CHECK_GT(x, y)
Definition: Logger.h:305
const std::vector< InputTableInfo > & query_infos_
std::vector< InnerOuter > inner_outer_pairs_
std::vector< InnerOuterStringOpInfos > inner_outer_string_op_infos_pairs_
ColumnCacheMap & column_cache_
const Data_Namespace::MemoryLevel memory_level_
const std::shared_ptr< Analyzer::BinOper > condition_

+ Here is the caller graph for this function:

Member Function Documentation

std::pair< size_t, size_t > BaselineJoinHashTable::approximateTupleCount ( const std::vector< ColumnsForDevice > &  columns_per_device) const
protectedvirtual

Definition at line 524 of file BaselineJoinHashTable.cpp.

References approximate_distinct_tuples(), approximate_distinct_tuples_on_device(), threading_serial::async(), Bitmap, CHECK, CHECK_EQ, CPU, Data_Namespace::CPU_LEVEL, cpu_threads(), device_count_, executor_, getEffectiveMemoryLevel(), getQueryEngineCudaStreamForDevice(), GPU, Data_Namespace::GPU_LEVEL, hll_size(), hll_unify(), inner_outer_pairs_, transfer_flat_object_to_gpu(), transfer_vector_of_flat_objects_to_gpu(), and UNREACHABLE.

Referenced by reifyWithLayout().

525  {
526  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
527  CountDistinctDescriptor count_distinct_desc{
529  0,
530  11,
531  true,
532  effective_memory_level == Data_Namespace::MemoryLevel::GPU_LEVEL
535  1};
536  const auto padded_size_bytes = count_distinct_desc.bitmapPaddedSizeBytes();
537 
538  CHECK(!columns_per_device.empty() && !columns_per_device.front().join_columns.empty());
539 
540  if (effective_memory_level == Data_Namespace::MemoryLevel::CPU_LEVEL) {
541  int thread_count = cpu_threads();
542  std::vector<uint8_t> hll_buffer_all_cpus(thread_count * padded_size_bytes);
543  auto hll_result = &hll_buffer_all_cpus[0];
544 
545  approximate_distinct_tuples(hll_result,
546  count_distinct_desc.bitmap_sz_bits,
547  padded_size_bytes,
548  columns_per_device.front().join_columns,
549  columns_per_device.front().join_column_types,
550  thread_count);
551  for (int i = 1; i < thread_count; ++i) {
552  hll_unify(hll_result,
553  hll_result + i * padded_size_bytes,
554  size_t(1) << count_distinct_desc.bitmap_sz_bits);
555  }
556  return std::make_pair(hll_size(hll_result, count_distinct_desc.bitmap_sz_bits), 0);
557  }
558 #ifdef HAVE_CUDA
559  auto data_mgr = executor_->getDataMgr();
560  std::vector<std::vector<uint8_t>> host_hll_buffers(device_count_);
561  for (auto& host_hll_buffer : host_hll_buffers) {
562  host_hll_buffer.resize(count_distinct_desc.bitmapPaddedSizeBytes());
563  }
564  std::vector<std::future<void>> approximate_distinct_device_threads;
565  for (int device_id = 0; device_id < device_count_; ++device_id) {
566  approximate_distinct_device_threads.emplace_back(std::async(
568  [device_id,
569  &columns_per_device,
570  &count_distinct_desc,
571  data_mgr,
572  &host_hll_buffers] {
573  auto allocator = std::make_unique<CudaAllocator>(
574  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
575  auto device_hll_buffer =
576  allocator->alloc(count_distinct_desc.bitmapPaddedSizeBytes());
577  data_mgr->getCudaMgr()->zeroDeviceMem(
578  device_hll_buffer,
579  count_distinct_desc.bitmapPaddedSizeBytes(),
580  device_id,
582  const auto& columns_for_device = columns_per_device[device_id];
583  auto join_columns_gpu = transfer_vector_of_flat_objects_to_gpu(
584  columns_for_device.join_columns, *allocator);
585  auto join_column_types_gpu = transfer_vector_of_flat_objects_to_gpu(
586  columns_for_device.join_column_types, *allocator);
587  const auto key_handler =
588  GenericKeyHandler(columns_for_device.join_columns.size(),
589  true,
590  join_columns_gpu,
591  join_column_types_gpu,
592  nullptr,
593  nullptr);
594  const auto key_handler_gpu =
595  transfer_flat_object_to_gpu(key_handler, *allocator);
597  reinterpret_cast<uint8_t*>(device_hll_buffer),
598  count_distinct_desc.bitmap_sz_bits,
599  key_handler_gpu,
600  columns_for_device.join_columns[0].num_elems);
601 
602  auto& host_hll_buffer = host_hll_buffers[device_id];
603  allocator->copyFromDevice(&host_hll_buffer[0],
604  device_hll_buffer,
605  count_distinct_desc.bitmapPaddedSizeBytes());
606  }));
607  }
608  for (auto& child : approximate_distinct_device_threads) {
609  child.get();
610  }
611  CHECK_EQ(Data_Namespace::MemoryLevel::GPU_LEVEL, effective_memory_level);
612  auto& result_hll_buffer = host_hll_buffers.front();
613  auto hll_result = reinterpret_cast<int32_t*>(&result_hll_buffer[0]);
614  for (int device_id = 1; device_id < device_count_; ++device_id) {
615  auto& host_hll_buffer = host_hll_buffers[device_id];
616  hll_unify(hll_result,
617  reinterpret_cast<int32_t*>(&host_hll_buffer[0]),
618  size_t(1) << count_distinct_desc.bitmap_sz_bits);
619  }
620  return std::make_pair(hll_size(hll_result, count_distinct_desc.bitmap_sz_bits), 0);
621 #else
622  UNREACHABLE();
623  return {0, 0};
624 #endif // HAVE_CUDA
625 }
#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
std::vector< InnerOuter > inner_outer_pairs_
void approximate_distinct_tuples(uint8_t *hll_buffer_all_cpus, 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 int thread_count)
future< Result > async(Fn &&fn, Args &&...args)
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
void approximate_distinct_tuples_on_device(uint8_t *hll_buffer, const uint32_t b, const GenericKeyHandler *key_handler, const int64_t num_elems)
#define CHECK(condition)
Definition: Logger.h:291
T * transfer_vector_of_flat_objects_to_gpu(const std::vector< T > &vec, DeviceAllocator &allocator)
int cpu_threads()
Definition: thread_count.h:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Value * BaselineJoinHashTable::codegenKey ( const CompilationOptions co)
protectedvirtual

Definition at line 1013 of file BaselineJoinHashTable.cpp.

References AUTOMATIC_IR_METADATA, CHECK, HashJoin::codegenColOrStringOper(), executor_, get_int_type(), get_max_rte_scan_table(), getKeyComponentCount(), getKeyComponentWidth(), inner_outer_pairs_, inner_outer_string_op_infos_pairs_, LL_BUILDER, LL_CONTEXT, LL_INT, and self_join_not_covered_by_left_deep_tree().

Referenced by codegenMatchingSet(), and codegenSlot().

1013  {
1014  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
1015  const auto key_component_width = getKeyComponentWidth();
1016  CHECK(key_component_width == 4 || key_component_width == 8);
1017  const auto key_size_lv = LL_INT(getKeyComponentCount() * key_component_width);
1018  llvm::Value* key_buff_lv{nullptr};
1019  switch (key_component_width) {
1020  case 4:
1021  key_buff_lv =
1022  LL_BUILDER.CreateAlloca(llvm::Type::getInt32Ty(LL_CONTEXT), key_size_lv);
1023  break;
1024  case 8:
1025  key_buff_lv =
1026  LL_BUILDER.CreateAlloca(llvm::Type::getInt64Ty(LL_CONTEXT), key_size_lv);
1027  break;
1028  default:
1029  CHECK(false);
1030  }
1031 
1032  CodeGenerator code_generator(executor_);
1033  for (size_t i = 0; i < getKeyComponentCount(); ++i) {
1034  const auto key_comp_dest_lv = LL_BUILDER.CreateGEP(
1035  key_buff_lv->getType()->getScalarType()->getPointerElementType(),
1036  key_buff_lv,
1037  LL_INT(i));
1038  const auto& inner_outer_pair = inner_outer_pairs_[i];
1039  const auto outer_col = inner_outer_pair.second;
1040  const auto key_col_var = dynamic_cast<const Analyzer::ColumnVar*>(outer_col);
1041  const auto val_col_var =
1042  dynamic_cast<const Analyzer::ColumnVar*>(inner_outer_pair.first);
1043  if (key_col_var && val_col_var &&
1045  key_col_var,
1046  val_col_var,
1047  get_max_rte_scan_table(executor_->cgen_state_->scan_idx_to_hash_pos_))) {
1048  throw std::runtime_error(
1049  "Query execution fails because the query contains not supported self-join "
1050  "pattern. We suspect the query requires multiple left-deep join tree due to "
1051  "the join condition of the self-join and is not supported for now. Please "
1052  "consider rewriting table order in "
1053  "FROM clause.");
1054  }
1055  auto key_lv = HashJoin::codegenColOrStringOper(
1056  outer_col, inner_outer_string_op_infos_pairs_[i].second, code_generator, co);
1057  const auto key_lv_ext =
1058  LL_BUILDER.CreateSExt(key_lv, get_int_type(key_component_width * 8, LL_CONTEXT));
1059  LL_BUILDER.CreateStore(key_lv_ext, key_comp_dest_lv);
1060  }
1061  return key_buff_lv;
1062 }
bool self_join_not_covered_by_left_deep_tree(const Analyzer::ColumnVar *key_side, const Analyzer::ColumnVar *val_side, const int max_rte_covered)
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)
Definition: HashJoin.cpp:564
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
const int get_max_rte_scan_table(std::unordered_map< int, llvm::Value * > &scan_idx_to_hash_pos)
std::vector< InnerOuter > inner_outer_pairs_
std::vector< InnerOuterStringOpInfos > inner_outer_string_op_infos_pairs_
#define LL_INT(v)
#define LL_CONTEXT
#define AUTOMATIC_IR_METADATA(CGENSTATE)
#define LL_BUILDER
#define CHECK(condition)
Definition: Logger.h:291
virtual size_t getKeyComponentCount() const
virtual size_t getKeyComponentWidth() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HashJoinMatchingSet BaselineJoinHashTable::codegenMatchingSet ( const CompilationOptions co,
const size_t  index 
)
overridevirtual

Implements HashJoin.

Definition at line 931 of file BaselineJoinHashTable.cpp.

References AUTOMATIC_IR_METADATA, CHECK, HashJoin::codegenHashTableLoad(), codegenKey(), HashJoin::codegenMatchingSet(), executor_, get_int_type(), getComponentBufferSize(), HashJoin::getHashTableForDevice(), getHashType(), getKeyComponentCount(), getKeyComponentWidth(), LL_BUILDER, LL_CONTEXT, LL_INT, offsetBufferOff(), OneToMany, and to_string().

933  {
934  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
935  const auto hash_table = getHashTableForDevice(size_t(0));
936  CHECK(hash_table);
937  const auto key_component_width = getKeyComponentWidth();
938  CHECK(key_component_width == 4 || key_component_width == 8);
939  auto key_buff_lv = codegenKey(co);
941  auto hash_ptr = HashJoin::codegenHashTableLoad(index, executor_);
942  const auto composite_dict_ptr_type =
943  llvm::Type::getIntNPtrTy(LL_CONTEXT, key_component_width * 8);
944  const auto composite_key_dict =
945  hash_ptr->getType()->isPointerTy()
946  ? LL_BUILDER.CreatePointerCast(hash_ptr, composite_dict_ptr_type)
947  : LL_BUILDER.CreateIntToPtr(hash_ptr, composite_dict_ptr_type);
948  const auto key_component_count = getKeyComponentCount();
949  const auto key = executor_->cgen_state_->emitExternalCall(
950  "get_composite_key_index_" + std::to_string(key_component_width * 8),
952  {key_buff_lv,
953  LL_INT(key_component_count),
954  composite_key_dict,
955  LL_INT(hash_table->getEntryCount())});
956  auto one_to_many_ptr = hash_ptr;
957  if (one_to_many_ptr->getType()->isPointerTy()) {
958  one_to_many_ptr =
959  LL_BUILDER.CreatePtrToInt(hash_ptr, llvm::Type::getInt64Ty(LL_CONTEXT));
960  } else {
961  CHECK(one_to_many_ptr->getType()->isIntegerTy(64));
962  }
963  const auto composite_key_dict_size = offsetBufferOff();
964  one_to_many_ptr =
965  LL_BUILDER.CreateAdd(one_to_many_ptr, LL_INT(composite_key_dict_size));
967  {one_to_many_ptr, key, LL_INT(int64_t(0)), LL_INT(hash_table->getEntryCount() - 1)},
968  false,
969  false,
970  false,
972  executor_);
973 }
size_t offsetBufferOff() const noexceptoverride
virtual HashJoinMatchingSet codegenMatchingSet(const CompilationOptions &, const size_t)=0
static llvm::Value * codegenHashTableLoad(const size_t table_idx, Executor *executor)
Definition: HashJoin.cpp:259
size_t getComponentBufferSize() const noexceptoverride
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::string to_string(char const *&&v)
virtual llvm::Value * codegenKey(const CompilationOptions &)
HashType getHashType() const noexceptoverride
#define LL_INT(v)
#define LL_CONTEXT
#define AUTOMATIC_IR_METADATA(CGENSTATE)
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:295
#define LL_BUILDER
#define CHECK(condition)
Definition: Logger.h:291
virtual size_t getKeyComponentCount() const
virtual size_t getKeyComponentWidth() const

+ Here is the call graph for this function:

llvm::Value * BaselineJoinHashTable::codegenSlot ( const CompilationOptions co,
const size_t  index 
)
overridevirtual

Implements HashJoin.

Definition at line 913 of file BaselineJoinHashTable.cpp.

References AUTOMATIC_IR_METADATA, CHECK, codegenKey(), executor_, get_int_type(), HashJoin::getHashTableForDevice(), getHashType(), getKeyComponentCount(), getKeyComponentWidth(), hashPtr(), LL_BUILDER, LL_CONTEXT, LL_INT, OneToOne, and to_string().

914  {
915  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
917  const auto key_component_width = getKeyComponentWidth();
918  CHECK(key_component_width == 4 || key_component_width == 8);
919  auto key_buff_lv = codegenKey(co);
920  const auto hash_ptr = hashPtr(index);
921  const auto key_ptr_lv =
922  LL_BUILDER.CreatePointerCast(key_buff_lv, llvm::Type::getInt8PtrTy(LL_CONTEXT));
923  const auto key_size_lv = LL_INT(getKeyComponentCount() * key_component_width);
924  const auto hash_table = getHashTableForDevice(size_t(0));
925  return executor_->cgen_state_->emitExternalCall(
926  "baseline_hash_join_idx_" + std::to_string(key_component_width * 8),
928  {hash_ptr, key_ptr_lv, key_size_lv, LL_INT(hash_table->getEntryCount())});
929 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::string to_string(char const *&&v)
virtual llvm::Value * codegenKey(const CompilationOptions &)
HashType getHashType() const noexceptoverride
#define LL_INT(v)
#define LL_CONTEXT
#define AUTOMATIC_IR_METADATA(CGENSTATE)
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:295
#define LL_BUILDER
llvm::Value * hashPtr(const size_t index)
#define CHECK(condition)
Definition: Logger.h:291
virtual size_t getKeyComponentCount() const
virtual size_t getKeyComponentWidth() const

+ Here is the call graph for this function:

void BaselineJoinHashTable::copyCpuHashTableToGpu ( std::shared_ptr< BaselineHashTable > &  cpu_hash_table,
const int  device_id,
Data_Namespace::DataMgr data_mgr 
)
protected

Definition at line 727 of file BaselineJoinHashTable.cpp.

References BaselineJoinHashTableBuilder::allocateDeviceMemory(), CHECK, CHECK_LT, CPU, executor_, BaselineJoinHashTableBuilder::getHashTable(), getQueryEngineCudaStreamForDevice(), HashJoin::hash_tables_for_device_, and query_hints_.

Referenced by initHashTableForDevice(), and reifyWithLayout().

730  {
732 
733  builder.allocateDeviceMemory(
734  cpu_hash_table->getHashTableEntryInfo(), device_id, executor_, query_hints_);
735  auto gpu_target_hash_table = builder.getHashTable();
736  CHECK(gpu_target_hash_table);
737  const auto gpu_buff = gpu_target_hash_table->getGpuBuffer();
738  if (gpu_buff) {
739  auto allocator = std::make_unique<CudaAllocator>(
740  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
741  allocator->copyToDevice(
742  gpu_buff,
743  cpu_hash_table->getCpuBuffer(),
744  cpu_hash_table->getHashTableBufferSize(ExecutorDeviceType::CPU));
745  }
746  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
747  hash_tables_for_device_[device_id] = std::move(gpu_target_hash_table);
748 }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:377
RegisteredQueryHint query_hints_
void allocateDeviceMemory(const BaselineHashTableEntryInfo hash_table_entry_info, const int device_id, const Executor *executor, const RegisteredQueryHint &query_hint)
#define CHECK_LT(x, y)
Definition: Logger.h:303
std::unique_ptr< BaselineHashTable > getHashTable()
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
#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 BaselineJoinHashTable::countBufferOff ( ) const
overridevirtualnoexcept

Implements HashJoin.

Definition at line 979 of file BaselineJoinHashTable.cpp.

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

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

979  {
982  } else {
983  return getKeyBufferSize();
984  }
985 }
size_t offsetBufferOff() const noexceptoverride
size_t getKeyBufferSize() const noexcept
size_t getComponentBufferSize() const noexceptoverride
HashType getHashType() const noexceptoverride
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:175

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 627 of file BaselineJoinHashTable.cpp.

References column_cache_, executor_, HashJoin::fetchJoinColumn(), get_column_descriptor_maybe(), get_effective_memory_level(), get_join_column_type_kind(), inline_fixed_encoding_null_val(), inner_outer_pairs_, isBitwiseEq(), memory_level_, and needs_dict_translation_.

Referenced by reifyWithLayout().

630  {
631  const auto effective_memory_level =
633 
634  std::vector<JoinColumn> join_columns;
635  std::vector<std::shared_ptr<Chunk_NS::Chunk>> chunks_owner;
636  std::vector<JoinColumnTypeInfo> join_column_types;
637  std::vector<JoinBucketInfo> join_bucket_info;
638  std::vector<std::shared_ptr<void>> malloc_owner;
639  for (const auto& inner_outer_pair : inner_outer_pairs_) {
640  const auto inner_col = inner_outer_pair.first;
641  const auto inner_cd = get_column_descriptor_maybe(inner_col->getColumnKey());
642  if (inner_cd && inner_cd->isVirtualCol) {
644  }
645  join_columns.emplace_back(fetchJoinColumn(inner_col,
646  fragments,
647  effective_memory_level,
648  device_id,
649  chunks_owner,
650  dev_buff_owner,
651  malloc_owner,
652  executor_,
653  &column_cache_));
654  const auto& ti = inner_col->get_type_info();
655  join_column_types.emplace_back(JoinColumnTypeInfo{static_cast<size_t>(ti.get_size()),
656  0,
657  0,
659  isBitwiseEq(),
660  0,
662  }
663  return {join_columns, join_column_types, chunks_owner, join_bucket_info, malloc_owner};
664 }
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
Data_Namespace::MemoryLevel get_effective_memory_level(const Data_Namespace::MemoryLevel memory_level, const bool needs_dict_translation)
std::vector< InnerOuter > inner_outer_pairs_
const ColumnDescriptor * get_column_descriptor_maybe(const shared::ColumnKey &column_key)
Definition: Execute.h:241
ColumnCacheMap & column_cache_
const Data_Namespace::MemoryLevel memory_level_
ColumnType get_join_column_type_kind(const SQLTypeInfo &ti)
bool isBitwiseEq() const override
int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO &ti)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ChunkKey BaselineJoinHashTable::genChunkKey ( const std::vector< Fragmenter_Namespace::FragmentInfo > &  fragments) const
protected

Definition at line 1141 of file BaselineJoinHashTable.cpp.

Referenced by reifyWithLayout().

1142  {
1143  std::vector<int> fragment_ids;
1144  std::for_each(
1145  fragments.cbegin(), fragments.cend(), [&fragment_ids](const auto& fragment) {
1146  fragment_ids.push_back(fragment.fragmentId);
1147  });
1148  return fragment_ids;
1149 }

+ Here is the caller graph for this function:

static QueryPlanHash BaselineJoinHashTable::getAlternativeCacheKey ( AlternativeCacheKeyForBaselineHashJoin info)
inlinestaticprotected

Definition at line 232 of file BaselineJoinHashTable.h.

References hash_value(), BaselineJoinHashTable::AlternativeCacheKeyForBaselineHashJoin::inner_outer_pairs, BaselineJoinHashTable::AlternativeCacheKeyForBaselineHashJoin::inner_outer_string_op_infos_pairs, BaselineJoinHashTable::AlternativeCacheKeyForBaselineHashJoin::join_type, BaselineJoinHashTable::AlternativeCacheKeyForBaselineHashJoin::num_elements, BaselineJoinHashTable::AlternativeCacheKeyForBaselineHashJoin::optype, and toString().

Referenced by reifyWithLayout().

233  {
234  auto hash = boost::hash_value(::toString(info.optype));
235  for (InnerOuter inner_outer : info.inner_outer_pairs) {
236  auto inner_col = inner_outer.first;
237  auto rhs_col_var = dynamic_cast<const Analyzer::ColumnVar*>(inner_outer.second);
238  auto outer_col = rhs_col_var ? rhs_col_var : inner_col;
239  boost::hash_combine(hash, inner_col->toString());
240  if (inner_col->get_type_info().is_string()) {
241  boost::hash_combine(hash, outer_col->toString());
242  }
243  }
244  if (info.inner_outer_string_op_infos_pairs.size()) {
245  boost::hash_combine(hash, ::toString(info.inner_outer_string_op_infos_pairs));
246  }
247  boost::hash_combine(hash, info.num_elements);
248  boost::hash_combine(hash, info.join_type);
249  return hash;
250  }
std::string toString(const ExecutorDeviceType device_type, const int device_id=0, bool raw=false) const override
std::pair< const Analyzer::ColumnVar *, const Analyzer::Expr * > InnerOuter
Definition: HashJoin.h:105
std::size_t hash_value(RexAbstractInput const &rex_ab_input)
Definition: RelAlgDag.cpp:3500

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t BaselineJoinHashTable::getComponentBufferSize ( ) const
overrideprotectedvirtualnoexcept

Implements HashJoin.

Definition at line 1008 of file BaselineJoinHashTable.cpp.

References HashJoin::getHashTableForDevice().

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

1008  {
1009  const auto hash_table = getHashTableForDevice(size_t(0));
1010  return hash_table->getEntryCount() * sizeof(int32_t);
1011 }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:295

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int BaselineJoinHashTable::getDeviceCount ( ) const
inlineoverridevirtualnoexcept

Implements HashJoin.

Definition at line 92 of file BaselineJoinHashTable.h.

References device_count_.

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

Definition at line 717 of file BaselineJoinHashTable.cpp.

References Data_Namespace::CPU_LEVEL, executor_, inner_outer_string_op_infos_pairs_, memory_level_, needs_dict_translation_, and needs_dictionary_translation().

Referenced by approximateTupleCount(), and reifyWithLayout().

718  {
720  inner_outer_pairs, inner_outer_string_op_infos_pairs_, executor_)) {
723  }
724  return memory_level_;
725 }
bool needs_dictionary_translation(const std::vector< InnerOuter > &inner_outer_pairs, const std::vector< InnerOuterStringOpInfos > &inner_outer_string_op_infos_pairs, const Executor *executor)
std::vector< InnerOuterStringOpInfos > inner_outer_string_op_infos_pairs_
const Data_Namespace::MemoryLevel memory_level_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static HashingSchemeRecycler* BaselineJoinHashTable::getHashingSchemeCache ( )
inlinestatic

Definition at line 132 of file BaselineJoinHashTable.h.

References CHECK, and hash_table_layout_cache_.

132  {
134  return hash_table_layout_cache_.get();
135  }
#define CHECK(condition)
Definition: Logger.h:291
static std::unique_ptr< HashingSchemeRecycler > hash_table_layout_cache_
std::string BaselineJoinHashTable::getHashJoinType ( ) const
inlinefinalvirtual

Implements HashJoin.

Definition at line 100 of file BaselineJoinHashTable.h.

100 { return "Baseline"; }
static HashtableRecycler* BaselineJoinHashTable::getHashTableCache ( )
inlinestatic

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

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

+ Here is the caller graph for this function:

HashType BaselineJoinHashTable::getHashType ( ) const
overridevirtualnoexcept

Implements HashJoin.

Definition at line 1093 of file BaselineJoinHashTable.cpp.

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

Referenced by codegenMatchingSet(), codegenSlot(), countBufferOff(), payloadBufferOff(), and toString().

1093  {
1094  auto hash_table = getHashTableForDevice(size_t(0));
1095  CHECK(hash_table);
1096  if (layout_override_) {
1097  return *layout_override_;
1098  } else {
1099  return hash_table->getLayout();
1100  }
1101 }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:295
std::optional< HashType > layout_override_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

shared::TableKey BaselineJoinHashTable::getInnerTableId ( ) const
overridevirtualnoexcept

Implements HashJoin.

Definition at line 1078 of file BaselineJoinHashTable.cpp.

References CHECK, and inner_outer_pairs_.

Referenced by initHashTableForDevice(), reify(), and reifyWithLayout().

1078  {
1079  try {
1081  } catch (...) {
1082  CHECK(false);
1083  }
1084  return {0, 0};
1085 }
std::vector< InnerOuter > inner_outer_pairs_
#define CHECK(condition)
Definition: Logger.h:291
shared::TableKey getInnerTableId() const noexceptoverride

+ Here is the caller graph for this function:

shared::TableKey BaselineJoinHashTable::getInnerTableId ( const std::vector< InnerOuter > &  inner_outer_pairs)
staticprotected

Definition at line 1103 of file BaselineJoinHashTable.cpp.

References CHECK.

1104  {
1105  CHECK(!inner_outer_pairs.empty());
1106  const auto first_inner_col = inner_outer_pairs.front().first;
1107  return first_inner_col->getTableKey();
1108 }
#define CHECK(condition)
Definition: Logger.h:291
int BaselineJoinHashTable::getInnerTableRteIdx ( ) const
overridevirtualnoexcept

Implements HashJoin.

Definition at line 1087 of file BaselineJoinHashTable.cpp.

References CHECK, and inner_outer_pairs_.

1087  {
1088  CHECK(!inner_outer_pairs_.empty());
1089  const auto first_inner_col = inner_outer_pairs_.front().first;
1090  return first_inner_col->get_rte_idx();
1091 }
std::vector< InnerOuter > inner_outer_pairs_
#define CHECK(condition)
Definition: Logger.h:291
std::shared_ptr< BaselineJoinHashTable > BaselineJoinHashTable::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 HashType  preferred_hash_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 
)
static

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

Definition at line 41 of file BaselineJoinHashTable.cpp.

References BaselineJoinHashTable(), RegisteredQueryHint::force_one_to_many_hash_join, HashJoin::getHashTypeString(), logger::INFO, LOG, HashJoin::normalizeColumnPairs(), OneToMany, VLOG, and VLOGGING.

Referenced by HashJoin::getInstance().

52  {
53  decltype(std::chrono::steady_clock::now()) ts1, ts2;
54 
55  auto hash_type = preferred_hash_type;
56  if (query_hints.force_one_to_many_hash_join) {
57  LOG(INFO) << "A user's query hint forced the join operation to use OneToMany hash "
58  "join layout";
59  hash_type = HashType::OneToMany;
60  }
61 
62  if (VLOGGING(1)) {
63  VLOG(1) << "Building keyed hash table " << getHashTypeString(hash_type)
64  << " for qual: " << condition->toString();
65  ts1 = std::chrono::steady_clock::now();
66  }
67  auto inner_outer_pairs =
68  HashJoin::normalizeColumnPairs(condition.get(), executor->getTemporaryTables());
69  const auto& inner_outer_cols = inner_outer_pairs.first;
70  const auto& col_pairs_string_op_infos = inner_outer_pairs.second;
71  auto join_hash_table = std::shared_ptr<BaselineJoinHashTable>(
72  new BaselineJoinHashTable(condition,
73  join_type,
74  query_infos,
75  memory_level,
76  column_cache,
77  executor,
78  inner_outer_cols,
79  col_pairs_string_op_infos,
80  device_count,
81  query_hints,
82  hashtable_build_dag_map,
83  table_id_to_node_map));
84  try {
85  join_hash_table->reify(hash_type);
86  } catch (const TableMustBeReplicated& e) {
87  // Throw a runtime error to abort the query
88  join_hash_table->freeHashBufferMemory();
89  throw std::runtime_error(e.what());
90  } catch (const HashJoinFail& e) {
91  // HashJoinFail exceptions log an error and trigger a retry with a join loop (if
92  // possible)
93  join_hash_table->freeHashBufferMemory();
94  throw HashJoinFail(std::string("Could not build a 1-to-1 correspondence for columns "
95  "involved in equijoin | ") +
96  e.what());
97  } catch (const ColumnarConversionNotSupported& e) {
98  throw HashJoinFail(std::string("Could not build hash tables for equijoin | ") +
99  e.what());
100  } catch (const OutOfMemory& e) {
101  throw HashJoinFail(
102  std::string("Ran out of memory while building hash tables for equijoin | ") +
103  e.what());
104  } catch (const JoinHashTableTooBig& e) {
105  throw e;
106  } catch (const std::exception& e) {
107  throw std::runtime_error(
108  std::string("Fatal error while attempting to build hash tables for join: ") +
109  e.what());
110  }
111  if (VLOGGING(1)) {
112  ts2 = std::chrono::steady_clock::now();
113  VLOG(1) << "Built keyed hash table "
114  << getHashTypeString(join_hash_table->getHashType()) << " in "
115  << std::chrono::duration_cast<std::chrono::milliseconds>(ts2 - ts1).count()
116  << " ms";
117  }
118  return join_hash_table;
119 }
#define LOG(tag)
Definition: Logger.h:285
BaselineJoinHashTable(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 std::vector< InnerOuterStringOpInfos > &col_pairs_string_op_infos, const int device_count, const RegisteredQueryHint &query_hints, const HashTableBuildDagMap &hashtable_build_dag_map, const TableIdToNodeMap &table_id_to_node_map)
#define VLOGGING(n)
Definition: Logger.h:289
static std::string getHashTypeString(HashType ht) noexcept
Definition: HashJoin.h:179
static std::pair< std::vector< InnerOuter >, std::vector< InnerOuterStringOpInfos > > normalizeColumnPairs(const Analyzer::BinOper *condition, const TemporaryTables *temporary_tables)
Definition: HashJoin.cpp:1015
#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 BaselineJoinHashTable::getKeyBufferSize ( ) const
protectednoexcept

Definition at line 995 of file BaselineJoinHashTable.cpp.

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

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

995  {
996  const auto key_component_width = getKeyComponentWidth();
997  CHECK(key_component_width == 4 || key_component_width == 8);
998  const auto key_component_count = getKeyComponentCount();
999  auto hash_table = getHashTableForDevice(size_t(0));
1000  CHECK(hash_table);
1001  if (layoutRequiresAdditionalBuffers(hash_table->getLayout())) {
1002  return hash_table->getEntryCount() * key_component_count * key_component_width;
1003  } else {
1004  return hash_table->getEntryCount() * (key_component_count + 1) * key_component_width;
1005  }
1006 }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:295
#define CHECK(condition)
Definition: Logger.h:291
virtual size_t getKeyComponentCount() const
virtual size_t getKeyComponentWidth() const
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:175

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t BaselineJoinHashTable::getKeyComponentCount ( ) const
protectedvirtual

Definition at line 713 of file BaselineJoinHashTable.cpp.

References inner_outer_pairs_.

Referenced by codegenKey(), codegenMatchingSet(), codegenSlot(), getKeyBufferSize(), initHashTableForDevice(), reifyWithLayout(), toSet(), and toString().

713  {
714  return inner_outer_pairs_.size();
715 }
std::vector< InnerOuter > inner_outer_pairs_

+ Here is the caller graph for this function:

size_t BaselineJoinHashTable::getKeyComponentWidth ( ) const
protectedvirtual

Definition at line 698 of file BaselineJoinHashTable.cpp.

References CHECK_EQ, and inner_outer_pairs_.

Referenced by codegenKey(), codegenMatchingSet(), codegenSlot(), getKeyBufferSize(), reifyWithLayout(), toSet(), and toString().

698  {
699  // todo: relax the assumption that all keys have the same width
700  // (i.e., 3 join keys having different integer types: (smallint, int, bigint)
701  // current: 3 * 8 = 24 bytes / ideal: 2 + 4 + 8 = 14 bytes)
702  for (const auto& inner_outer_pair : inner_outer_pairs_) {
703  const auto inner_col = inner_outer_pair.first;
704  const auto& inner_col_ti = inner_col->get_type_info();
705  if (inner_col_ti.get_logical_size() > 4) {
706  CHECK_EQ(8, inner_col_ti.get_logical_size());
707  return 8;
708  }
709  }
710  return 4;
711 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< InnerOuter > inner_outer_pairs_

+ Here is the caller graph for this function:

Data_Namespace::MemoryLevel BaselineJoinHashTable::getMemoryLevel ( ) const
inlineoverridevirtualnoexcept

Implements HashJoin.

Definition at line 88 of file BaselineJoinHashTable.h.

References memory_level_.

88  {
89  return memory_level_;
90  };
const Data_Namespace::MemoryLevel memory_level_
const RegisteredQueryHint& BaselineJoinHashTable::getRegisteredQueryHint ( )
inline

Definition at line 137 of file BaselineJoinHashTable.h.

References query_hints_.

137 { return query_hints_; }
RegisteredQueryHint query_hints_
size_t BaselineJoinHashTable::getShardCountForCondition ( const Analyzer::BinOper condition,
const Executor executor,
const std::vector< InnerOuter > &  inner_outer_pairs 
)
static

Definition at line 152 of file BaselineJoinHashTable.cpp.

References get_shard_count().

Referenced by RangeJoinHashTable::getInstance(), reify(), shardCount(), BoundingBoxIntersectJoinHashTable::shardCount(), and Executor::skipFragmentPair().

155  {
156  for (const auto& inner_outer_pair : inner_outer_pairs) {
157  const auto pair_shard_count = get_shard_count(inner_outer_pair, executor);
158  if (pair_shard_count) {
159  return pair_shard_count;
160  }
161  }
162  return 0;
163 }
size_t get_shard_count(const Analyzer::BinOper *join_condition, const Executor *executor)
Definition: HashJoin.cpp:1084

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Value * BaselineJoinHashTable::hashPtr ( const size_t  index)
protected

Definition at line 1064 of file BaselineJoinHashTable.cpp.

References AUTOMATIC_IR_METADATA, HashJoin::codegenHashTableLoad(), executor_, LL_BUILDER, and LL_CONTEXT.

Referenced by codegenSlot().

1064  {
1065  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
1066  auto hash_ptr = HashJoin::codegenHashTableLoad(index, executor_);
1067  const auto pi8_type = llvm::Type::getInt8PtrTy(LL_CONTEXT);
1068  return hash_ptr->getType()->isPointerTy()
1069  ? LL_BUILDER.CreatePointerCast(hash_ptr, pi8_type)
1070  : LL_BUILDER.CreateIntToPtr(hash_ptr, pi8_type);
1071 }
static llvm::Value * codegenHashTableLoad(const size_t table_idx, Executor *executor)
Definition: HashJoin.cpp:259
#define LL_CONTEXT
#define AUTOMATIC_IR_METADATA(CGENSTATE)
#define LL_BUILDER

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int BaselineJoinHashTable::initHashTableForDevice ( const std::vector< JoinColumn > &  join_columns,
const std::vector< JoinColumnTypeInfo > &  join_column_types,
const std::vector< JoinBucketInfo > &  join_buckets,
const HashType  layout,
const Data_Namespace::MemoryLevel  effective_memory_level,
const BaselineHashTableEntryInfo  hash_table_entry_info,
const int  device_id 
)
protectedvirtual

Definition at line 773 of file BaselineJoinHashTable.cpp.

References BASELINE_HT, CHECK, CHECK_EQ, CHECK_LT, copyCpuHashTableToGpu(), CPU, DataRecyclerUtil::CPU_DEVICE_IDENTIFIER, cpu_hash_table_buff_mutex_, Data_Namespace::CPU_LEVEL, DEBUG_TIMER, decomposeStrDictTranslationMaps(), executor_, HashJoin::getCompositeKeyInfo(), BaselineJoinHashTableBuilder::getHashTable(), getInnerTableId(), getKeyComponentCount(), getQueryEngineCudaStreamForDevice(), Data_Namespace::GPU_LEVEL, hash_table_layout_cache_, HashJoin::hash_tables_for_device_, hashtable_cache_key_, HT_HASHING_SCHEME, BaselineJoinHashTableBuilder::initHashTableOnCpu(), BaselineJoinHashTableBuilder::initHashTableOnGpu(), inner_outer_pairs_, inner_outer_string_op_infos_pairs_, HashtableRecycler::isSafeToCacheHashtable(), join_type_, memory_level_, needs_dict_translation_, putHashTableOnCpuToCache(), query_hints_, str_proxy_translation_maps_, table_id_to_node_map_, transfer_vector_of_flat_objects_to_gpu(), and UNREACHABLE.

Referenced by reifyForDevice().

780  {
781  auto timer = DEBUG_TIMER(__func__);
782  const auto key_component_count = getKeyComponentCount();
783  int err = 0;
784  decltype(std::chrono::steady_clock::now()) ts1, ts2;
785  ts1 = std::chrono::steady_clock::now();
786  auto allow_hashtable_recycling =
787  HashtableRecycler::isSafeToCacheHashtable(table_id_to_node_map_,
791  if (effective_memory_level == Data_Namespace::CPU_LEVEL) {
792  std::lock_guard<std::mutex> cpu_hash_table_buff_lock(cpu_hash_table_buff_mutex_);
793 
794  const auto composite_key_info = HashJoin::getCompositeKeyInfo(
795  inner_outer_pairs_, executor_, inner_outer_string_op_infos_pairs_);
796 
797  CHECK(!join_columns.empty());
798 
800  CHECK_EQ(device_id, 0);
801  }
802  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
803  std::shared_ptr<HashTable> hash_table{nullptr};
804  const auto str_proxy_translation_map_ptrs_and_offsets =
807 
808  const auto key_handler =
809  GenericKeyHandler(key_component_count,
810  true,
811  &join_columns[0],
812  &join_column_types[0],
813  &str_proxy_translation_map_ptrs_and_offsets.first[0],
814  &str_proxy_translation_map_ptrs_and_offsets.second[0]);
815  err = builder.initHashTableOnCpu(&key_handler,
816  composite_key_info,
817  join_columns,
818  join_column_types,
819  join_bucket_info,
820  str_proxy_translation_map_ptrs_and_offsets,
821  hash_table_entry_info,
822  join_type_,
823  executor_,
824  query_hints_);
825  hash_tables_for_device_[device_id] = builder.getHashTable();
826  ts2 = std::chrono::steady_clock::now();
827  auto hashtable_build_time =
828  std::chrono::duration_cast<std::chrono::milliseconds>(ts2 - ts1).count();
829  if (!err && allow_hashtable_recycling && hash_tables_for_device_[device_id] &&
830  hash_tables_for_device_[device_id]->getHashTableBufferSize(
832  // add ht-related items to cache iff we have a valid hashtable
835  hash_tables_for_device_[device_id],
837  hashtable_build_time);
838 
839  hash_table_layout_cache_->putItemToCache(
840  hashtable_cache_key_[device_id],
841  hash_tables_for_device_[device_id]->getLayout(),
844  0,
845  0,
846  {});
847  }
848  // Transfer the hash table on the GPU if we've only built it on CPU
849  // but the query runs on GPU (join on dictionary encoded columns).
850  // Don't transfer the buffer if there was an error since we'll bail anyway.
851  if (memory_level_ == Data_Namespace::GPU_LEVEL && !err) {
852 #ifdef HAVE_CUDA
853  auto cpu_hash_table = std::dynamic_pointer_cast<BaselineHashTable>(
854  hash_tables_for_device_[device_id]);
855  if (cpu_hash_table->getEntryCount()) {
856  copyCpuHashTableToGpu(cpu_hash_table, device_id, executor_->getDataMgr());
857  }
858 #else
859  CHECK(false);
860 #endif
861  }
862  } else {
863 #ifdef HAVE_CUDA
865 
866  auto data_mgr = executor_->getDataMgr();
867  CudaAllocator allocator(
868  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
869  auto join_column_types_gpu =
870  transfer_vector_of_flat_objects_to_gpu(join_column_types, allocator);
871  auto join_columns_gpu =
872  transfer_vector_of_flat_objects_to_gpu(join_columns, allocator);
873  const auto key_handler = GenericKeyHandler(key_component_count,
874  true,
875  join_columns_gpu,
876  join_column_types_gpu,
877  nullptr,
878  nullptr);
879 
880  err = builder.initHashTableOnGpu(&key_handler,
881  join_columns,
882  join_type_,
883  hash_table_entry_info,
884  device_id,
885  executor_,
886  query_hints_);
887  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
888  hash_tables_for_device_[device_id] = builder.getHashTable();
889  if (!err && allow_hashtable_recycling && hash_tables_for_device_[device_id]) {
890  // add layout to cache iff we have a valid hashtable
891  hash_table_layout_cache_->putItemToCache(
892  hashtable_cache_key_[device_id],
893  hash_tables_for_device_[device_id]->getLayout(),
896  0,
897  0,
898  {});
899  }
900 #else
901  UNREACHABLE();
902 #endif
903  }
904  return err;
905 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
void putHashTableOnCpuToCache(QueryPlanHash key, CacheItemType item_type, std::shared_ptr< HashTable > hashtable_ptr, DeviceIdentifier device_identifier, size_t hashtable_building_time)
std::vector< QueryPlanHash > hashtable_cache_key_
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:377
#define UNREACHABLE()
Definition: Logger.h:338
const TableIdToNodeMap table_id_to_node_map_
RegisteredQueryHint query_hints_
int initHashTableOnGpu(KEY_HANDLER *key_handler, const std::vector< JoinColumn > &join_columns, const JoinType join_type, const BaselineHashTableEntryInfo hash_table_entry_info, const int device_id, const Executor *executor, const RegisteredQueryHint &query_hint)
std::vector< InnerOuter > inner_outer_pairs_
std::vector< InnerOuterStringOpInfos > inner_outer_string_op_infos_pairs_
#define CHECK_LT(x, y)
Definition: Logger.h:303
std::unique_ptr< BaselineHashTable > getHashTable()
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)
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
const Data_Namespace::MemoryLevel memory_level_
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:412
virtual size_t getKeyComponentCount() const
void copyCpuHashTableToGpu(std::shared_ptr< BaselineHashTable > &cpu_hash_table, const int device_id, Data_Namespace::DataMgr *data_mgr)
std::vector< const StringDictionaryProxy::IdMap * > str_proxy_translation_maps_
T * transfer_vector_of_flat_objects_to_gpu(const std::vector< T > &vec, DeviceAllocator &allocator)
static std::unique_ptr< HashingSchemeRecycler > hash_table_layout_cache_
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
StrProxyTranslationMapsPtrsAndOffsets decomposeStrDictTranslationMaps(const std::vector< const StringDictionaryProxy::IdMap * > &str_proxy_translation_maps)
shared::TableKey getInnerTableId() const noexceptoverride
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:

+ Here is the caller graph for this function:

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

Definition at line 1110 of file BaselineJoinHashTable.cpp.

References CHECK, DEBUG_TIMER, hash_table_cache_, and VLOG.

Referenced by reifyWithLayout().

1113  {
1114  auto timer = DEBUG_TIMER(__func__);
1115  VLOG(1) << "Checking CPU hash table cache.";
1117  return hash_table_cache_->getItemFromCache(key, item_type, device_identifier);
1118 }
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 caller graph for this function:

static void BaselineJoinHashTable::invalidateCache ( )
inlinestatic

Definition at line 102 of file BaselineJoinHashTable.h.

References CHECK, hash_table_cache_, and hash_table_layout_cache_.

102  {
104  hash_table_cache_->clearCache();
105 
107  hash_table_layout_cache_->clearCache();
108  }
static std::unique_ptr< HashtableRecycler > hash_table_cache_
#define CHECK(condition)
Definition: Logger.h:291
static std::unique_ptr< HashingSchemeRecycler > hash_table_layout_cache_
bool BaselineJoinHashTable::isBitwiseEq ( ) const
overrideprotectedvirtual

Implements HashJoin.

Definition at line 1137 of file BaselineJoinHashTable.cpp.

References condition_, and kBW_EQ.

Referenced by fetchColumnsForDevice().

1137  {
1138  return condition_->get_optype() == kBW_EQ;
1139 }
Definition: sqldefs.h:30
const std::shared_ptr< Analyzer::BinOper > condition_

+ Here is the caller graph for this function:

static void BaselineJoinHashTable::markCachedItemAsDirty ( size_t  table_key)
inlinestatic

Definition at line 110 of file BaselineJoinHashTable.h.

References BASELINE_HT, CHECK, DataRecyclerUtil::CPU_DEVICE_IDENTIFIER, hash_table_cache_, hash_table_layout_cache_, and HT_HASHING_SCHEME.

110  {
113  auto candidate_table_keys =
114  hash_table_cache_->getMappedQueryPlanDagsWithTableKey(table_key);
115  if (candidate_table_keys.has_value()) {
116  hash_table_layout_cache_->markCachedItemAsDirty(
117  table_key,
118  *candidate_table_keys,
121  hash_table_cache_->markCachedItemAsDirty(table_key,
122  *candidate_table_keys,
125  }
126  }
static std::unique_ptr< HashtableRecycler > hash_table_cache_
#define CHECK(condition)
Definition: Logger.h:291
static std::unique_ptr< HashingSchemeRecycler > hash_table_layout_cache_
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
size_t BaselineJoinHashTable::offsetBufferOff ( ) const
overridevirtualnoexcept

Implements HashJoin.

Definition at line 975 of file BaselineJoinHashTable.cpp.

References getKeyBufferSize().

Referenced by codegenMatchingSet(), countBufferOff(), toSet(), and toString().

975  {
976  return getKeyBufferSize();
977 }
size_t getKeyBufferSize() const noexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t BaselineJoinHashTable::payloadBufferOff ( ) const
overridevirtualnoexcept

Implements HashJoin.

Definition at line 987 of file BaselineJoinHashTable.cpp.

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

Referenced by toSet(), and toString().

987  {
990  } else {
991  return getKeyBufferSize();
992  }
993 }
size_t getKeyBufferSize() const noexcept
size_t getComponentBufferSize() const noexceptoverride
HashType getHashType() const noexceptoverride
static bool layoutRequiresAdditionalBuffers(HashType layout) noexcept
Definition: HashJoin.h:175
size_t countBufferOff() const noexceptoverride

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1120 of file BaselineJoinHashTable.cpp.

References CHECK, CPU, and hash_table_cache_.

Referenced by initHashTableForDevice().

1125  {
1127  CHECK(hashtable_ptr && !hashtable_ptr->getGpuBuffer());
1128  hash_table_cache_->putItemToCache(
1129  key,
1130  hashtable_ptr,
1131  item_type,
1132  device_identifier,
1133  hashtable_ptr->getHashTableBufferSize(ExecutorDeviceType::CPU),
1134  hashtable_building_time);
1135 }
static std::unique_ptr< HashtableRecycler > hash_table_cache_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

void BaselineJoinHashTable::reify ( const HashType  preferred_layout)
protected

Definition at line 259 of file BaselineJoinHashTable.cpp.

References CHECK_EQ, CHECK_LT, HashJoin::checkHashJoinReplicationConstraint(), condition_, DEBUG_TIMER, device_count_, executor_, HashJoin::freeHashBufferMemory(), getInnerTableId(), getShardCountForCondition(), inner_outer_pairs_, inner_outer_string_op_infos_pairs_, ManyToMany, OneToMany, reifyWithLayout(), and VLOG.

259  {
260  auto timer = DEBUG_TIMER(__func__);
266  executor_);
267 
268  auto layout = preferred_layout;
269  if (condition_->is_bbox_intersect_oper()) {
270  CHECK_EQ(inner_outer_pairs_.size(), size_t(1));
271 
272  if (inner_outer_pairs_[0].second->get_type_info().is_array()) {
273  layout = HashType::ManyToMany;
274  } else {
275  layout = HashType::OneToMany;
276  }
277  try {
278  reifyWithLayout(layout);
279  return;
280  } catch (const std::exception& e) {
281  VLOG(1) << "Caught exception while building baseline hash table for bounding box "
282  "intersection: "
283  << e.what();
284  throw;
285  }
286  }
287 
288  // Automatically prefer One-To-Many layouts when string operations are involved as these
289  // tend to be cardinality-reducing operations.
290  // Todo(todd): Ostensibly only string ops on the rhs/inner expression cause rhs dups and
291  // so we may be too conservative here, but validate
292 
293  for (const auto& inner_outer_string_op_infos : inner_outer_string_op_infos_pairs_) {
294  if (inner_outer_string_op_infos.first.size() ||
295  inner_outer_string_op_infos.second.size()) {
296  layout = HashType::OneToMany;
297  break;
298  }
299  }
300 
301  try {
302  reifyWithLayout(layout);
303  } catch (const std::exception& e) {
304  VLOG(1) << "Caught exception while building baseline hash table: " << e.what();
305  // In perfect hash we CHECK that the layout is not OnetoMany here, but for baseline
306  // we are catching all exceptions, so should determine if that is safe first
307  // before we would CHECK and not throw an exception here
308  if (layout == HashType::OneToMany) {
309  throw(e);
310  }
313  }
314 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
static void checkHashJoinReplicationConstraint(const shared::TableKey &table_key, const size_t shard_count, const Executor *executor)
Definition: HashJoin.cpp:796
void freeHashBufferMemory()
Definition: HashJoin.h:337
std::vector< InnerOuter > inner_outer_pairs_
std::vector< InnerOuterStringOpInfos > inner_outer_string_op_infos_pairs_
virtual void reifyWithLayout(const HashType layout)
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define DEBUG_TIMER(name)
Definition: Logger.h:412
static size_t getShardCountForCondition(const Analyzer::BinOper *condition, const Executor *executor, const std::vector< InnerOuter > &inner_outer_pairs)
shared::TableKey getInnerTableId() const noexceptoverride
#define VLOG(n)
Definition: Logger.h:388
const std::shared_ptr< Analyzer::BinOper > condition_

+ Here is the call graph for this function:

void BaselineJoinHashTable::reifyForDevice ( const ColumnsForDevice columns_for_device,
const HashType  layout,
const int  device_id,
const BaselineHashTableEntryInfo  hash_table_entry_info,
const logger::ThreadLocalIds  parent_thread_local_ids 
)
protectedvirtual

Definition at line 666 of file BaselineJoinHashTable.cpp.

References DEBUG_TIMER_NEW_THREAD, get_effective_memory_level(), initHashTableForDevice(), ColumnsForDevice::join_buckets, ColumnsForDevice::join_column_types, ColumnsForDevice::join_columns, memory_level_, needs_dict_translation_, logger::ThreadLocalIds::setNewThreadId(), logger::ThreadLocalIds::thread_id_, and to_string().

Referenced by reifyWithLayout().

671  {
672  logger::LocalIdsScopeGuard lisg = parent_thread_local_ids.setNewThreadId();
673  DEBUG_TIMER_NEW_THREAD(parent_thread_local_ids.thread_id_);
674  const auto effective_memory_level =
676  const auto err = initHashTableForDevice(columns_for_device.join_columns,
677  columns_for_device.join_column_types,
678  columns_for_device.join_buckets,
679  layout,
680  effective_memory_level,
681  hash_table_entries_info,
682  device_id);
683  if (err) {
684  throw HashJoinFail(
685  std::string("Unrecognized error when initializing baseline hash table (") +
686  std::to_string(err) + std::string(")"));
687  }
688 }
Data_Namespace::MemoryLevel get_effective_memory_level(const Data_Namespace::MemoryLevel memory_level, const bool needs_dict_translation)
#define DEBUG_TIMER_NEW_THREAD(parent_thread_id)
Definition: Logger.h:417
std::string to_string(char const *&&v)
virtual int initHashTableForDevice(const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const std::vector< JoinBucketInfo > &join_buckets, const HashType layout, const Data_Namespace::MemoryLevel effective_memory_level, const BaselineHashTableEntryInfo hash_table_entry_info, const int device_id)
const std::vector< JoinColumnTypeInfo > join_column_types
Definition: HashJoin.h:111
LocalIdsScopeGuard setNewThreadId() const
Definition: Logger.cpp:538
const Data_Namespace::MemoryLevel memory_level_
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BaselineJoinHashTable::reifyWithLayout ( const HashType  layout)
protectedvirtual

Definition at line 316 of file BaselineJoinHashTable.cpp.

References gpu_enabled::accumulate(), approximateTupleCount(), threading_serial::async(), BASELINE_HT, HashJoin::canAccessHashTable(), CHECK, CHECK_EQ, condition_, copyCpuHashTableToGpu(), DataRecyclerUtil::CPU_DEVICE_IDENTIFIER, Data_Namespace::CPU_LEVEL, device_count_, executor_, fetchColumnsForDevice(), genChunkKey(), get_entries_per_device(), get_inner_query_info(), getAlternativeCacheKey(), DataRecyclerUtil::getAlternativeTableKeys(), HashJoin::getCompositeKeyInfo(), getEffectiveMemoryLevel(), HashtableRecycler::getHashtableAccessPathInfo(), getInnerTableId(), getKeyComponentCount(), getKeyComponentWidth(), Fragmenter_Namespace::TableInfo::getNumTuplesUpperBound(), getQueryEngineCudaStreamForDevice(), Data_Namespace::GPU_LEVEL, hash_table_cache_, HashJoin::hash_tables_for_device_, hashtable_build_dag_map_, hashtable_cache_key_, hashtable_cache_meta_info_, InputTableInfo::info, initHashTableOnCpuFromCache(), inner_outer_pairs_, inner_outer_string_op_infos_pairs_, HashtableRecycler::isInvalidHashTableCacheKey(), HashtableRecycler::isSafeToCacheHashtable(), join_type_, HashJoin::MAX_NUM_HASH_ENTRIES, memory_level_, needs_dict_translation_, HashJoin::normalizeColumnPairs(), OneToMany, only_shards_for_device(), query_infos_, reifyForDevice(), rowid_size_, shardCount(), str_proxy_translation_maps_, str_proxy_translation_mutex_, shared::TableKey::table_id, table_id_to_node_map_, table_keys_, logger::thread_local_ids(), HashJoin::translateCompositeStrDictProxies(), UNREACHABLE, and WINDOW_FUNCTION_FRAMING.

Referenced by reify().

316  {
317  const auto& query_info = get_inner_query_info(getInnerTableId(), query_infos_).info;
318  if (query_info.fragments.empty()) {
319  return;
320  }
321 
322  const auto total_entries = 2 * query_info.getNumTuplesUpperBound();
323  if (total_entries > HashJoin::MAX_NUM_HASH_ENTRIES) {
324  throw TooManyHashEntries();
325  }
326 
327  std::vector<std::unique_ptr<CudaAllocator>> dev_buff_owners;
328  std::vector<std::vector<Fragmenter_Namespace::FragmentInfo>> fragments_per_device;
329  std::vector<ColumnsForDevice> columns_per_device;
330  const auto shard_count = shardCount();
331  auto entries_per_device =
332  get_entries_per_device(total_entries, shard_count, device_count_, memory_level_);
333  auto data_mgr = executor_->getDataMgr();
334  // cached hash table lookup logic is similar with perfect join hash table
335  // first, prepare fragment lists per device
336  std::vector<ChunkKey> chunk_key_per_device;
337  for (int device_id = 0; device_id < device_count_; ++device_id) {
338  fragments_per_device.emplace_back(
339  shard_count
340  ? only_shards_for_device(query_info.fragments, device_id, device_count_)
341  : query_info.fragments);
343  dev_buff_owners.emplace_back(std::make_unique<CudaAllocator>(
344  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id)));
345  }
346  const auto chunk_key = genChunkKey(fragments_per_device[device_id]);
347  chunk_key_per_device.emplace_back(std::move(chunk_key));
348  }
349 
350  // prepare per-device cache key
351  auto inner_outer_pairs =
352  HashJoin::normalizeColumnPairs(condition_.get(), executor_->getTemporaryTables());
353  const auto& inner_outer_cols = inner_outer_pairs.first;
354  const auto& col_pairs_string_op_infos = inner_outer_pairs.second;
355  auto hashtable_access_path_info =
357  col_pairs_string_op_infos,
358  condition_->get_optype(),
359  join_type_,
362  shard_count,
363  fragments_per_device,
364  executor_);
365  hashtable_cache_key_ = hashtable_access_path_info.hashed_query_plan_dag;
366  hashtable_cache_meta_info_ = hashtable_access_path_info.meta_info;
367  table_keys_ = hashtable_access_path_info.table_keys;
368 
369  // the actual chunks fetched per device can be different but they constitute the same
370  // table in the same db, so we can exploit this to create an alternative table key
371  if (table_keys_.empty()) {
372  const auto& inner_table_key = getInnerTableId();
373  table_keys_ =
374  DataRecyclerUtil::getAlternativeTableKeys(chunk_key_per_device, inner_table_key);
375  }
376  CHECK(!table_keys_.empty());
377 
378  if (HashtableRecycler::isInvalidHashTableCacheKey(hashtable_cache_key_) &&
379  getInnerTableId().table_id > 0) {
380  // sometimes we cannot retrieve query plan dag, so try to recycler cache
381  // with the old-passioned cache key if we deal with hashtable of non-temporary table
382  for (int device_id = 0; device_id < device_count_; ++device_id) {
383  const auto num_tuples = std::accumulate(fragments_per_device[device_id].begin(),
384  fragments_per_device[device_id].end(),
385  size_t(0),
386  [](const auto& sum, const auto& fragment) {
387  return sum + fragment.getNumTuples();
388  });
389  AlternativeCacheKeyForBaselineHashJoin cache_key{inner_outer_pairs_,
391  num_tuples,
392  condition_->get_optype(),
393  join_type_,
394  chunk_key_per_device[device_id]};
395  hashtable_cache_key_[device_id] = getAlternativeCacheKey(cache_key);
396  }
397  }
398 
399  // register a mapping between cache key and input tables of the hash table
400  const auto invalid_cache_key =
401  HashtableRecycler::isInvalidHashTableCacheKey(hashtable_cache_key_);
402  if (!invalid_cache_key) {
403  if (!shard_count) {
404  hash_table_cache_->addQueryPlanDagForTableKeys(hashtable_cache_key_.front(),
405  table_keys_);
406  } else {
407  std::for_each(hashtable_cache_key_.cbegin(),
408  hashtable_cache_key_.cend(),
409  [this](QueryPlanHash key) {
410  hash_table_cache_->addQueryPlanDagForTableKeys(key, table_keys_);
411  });
412  }
413  }
414 
415  // now, let's try to check whether we have a cached hash table for this join qual
416  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
417 
418  // todo (yoonmin) : support dictionary proxy cache for join including string op(s)
419  if (effective_memory_level == Data_Namespace::CPU_LEVEL) {
420  std::unique_lock<std::mutex> str_proxy_translation_lock(str_proxy_translation_mutex_);
421  if (str_proxy_translation_maps_.empty()) {
422  const auto composite_key_info = HashJoin::getCompositeKeyInfo(
425  composite_key_info, inner_outer_string_op_infos_pairs_, executor_);
427  }
428  }
429 
430  auto allow_hashtable_recycling =
435  bool has_invalid_cached_hash_table = false;
436  if (effective_memory_level == Data_Namespace::CPU_LEVEL &&
438  allow_hashtable_recycling, invalid_cache_key, join_type_)) {
439  // build a hash table on CPU, and we have a chance to recycle the cached one if
440  // available
441  for (int device_id = 0; device_id < device_count_; ++device_id) {
442  auto hash_table =
443  initHashTableOnCpuFromCache(hashtable_cache_key_[device_id],
446  if (hash_table) {
447  hash_tables_for_device_[device_id] = hash_table;
448  } else {
449  has_invalid_cached_hash_table = true;
450  break;
451  }
452  }
453 
454  if (has_invalid_cached_hash_table) {
455  hash_tables_for_device_.clear();
456  hash_tables_for_device_.resize(device_count_);
457  } else {
459 #ifdef HAVE_CUDA
460  for (int device_id = 0; device_id < device_count_; ++device_id) {
461  auto cpu_hash_table = std::dynamic_pointer_cast<BaselineHashTable>(
462  hash_tables_for_device_[device_id]);
463  if (cpu_hash_table->getEntryCount()) {
464  copyCpuHashTableToGpu(cpu_hash_table, device_id, data_mgr);
465  }
466  }
467 #else
468  UNREACHABLE();
469 #endif
470  }
471  return;
472  }
473  }
474 
475  // we have no cached hash table for this qual
476  // so, start building the hash table by fetching columns for devices
477  for (int device_id = 0; device_id < device_count_; ++device_id) {
478  const auto columns_for_device =
479  fetchColumnsForDevice(fragments_per_device[device_id],
480  device_id,
482  ? dev_buff_owners[device_id].get()
483  : nullptr);
484  columns_per_device.push_back(columns_for_device);
485  }
486 
487  auto hashtable_layout_type = layout;
488  if (hashtable_layout_type == HashType::OneToMany) {
489  CHECK(!columns_per_device.front().join_columns.empty());
490  size_t tuple_count;
491  std::tie(tuple_count, std::ignore) = approximateTupleCount(columns_per_device);
492  const auto entry_count = 2 * std::max(tuple_count, size_t(1));
493  // reset entries per device with one to many info
494  entries_per_device =
495  get_entries_per_device(entry_count, shard_count, device_count_, memory_level_);
496  }
497  std::vector<std::future<void>> init_threads;
498  for (int device_id = 0; device_id < device_count_; ++device_id) {
499  BaselineHashTableEntryInfo hash_table_entry_info(
500  entries_per_device,
501  columns_per_device[device_id].join_columns.front().num_elems,
502  rowid_size_,
505  hashtable_layout_type,
507  init_threads.push_back(std::async(std::launch::async,
509  this,
510  columns_per_device[device_id],
511  hashtable_layout_type,
512  device_id,
513  hash_table_entry_info,
515  }
516  for (auto& init_thread : init_threads) {
517  init_thread.wait();
518  }
519  for (auto& init_thread : init_threads) {
520  init_thread.get();
521  }
522 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Fragmenter_Namespace::TableInfo info
Definition: InputMetadata.h:35
std::vector< QueryPlanHash > hashtable_cache_key_
static bool isInvalidHashTableCacheKey(const std::vector< QueryPlanHash > &cache_keys)
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) const
static bool canAccessHashTable(bool allow_hash_table_recycling, bool invalid_cache_key, JoinType join_type)
Definition: HashJoin.cpp:1049
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:377
#define UNREACHABLE()
Definition: Logger.h:338
const InputTableInfo & get_inner_query_info(const shared::TableKey &inner_table_key, const std::vector< InputTableInfo > &query_infos)
HashTableBuildDagMap hashtable_build_dag_map_
const TableIdToNodeMap table_id_to_node_map_
std::unordered_set< size_t > table_keys_
virtual ColumnsForDevice fetchColumnsForDevice(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, DeviceAllocator *dev_buff_owner)
const std::vector< InputTableInfo > & query_infos_
std::shared_ptr< HashTable > initHashTableOnCpuFromCache(QueryPlanHash key, CacheItemType item_type, DeviceIdentifier device_identifier)
std::vector< InnerOuter > inner_outer_pairs_
future< Result > async(Fn &&fn, Args &&...args)
static QueryPlanHash getAlternativeCacheKey(AlternativeCacheKeyForBaselineHashJoin &info)
std::vector< InnerOuterStringOpInfos > inner_outer_string_op_infos_pairs_
static std::unique_ptr< HashtableRecycler > hash_table_cache_
std::vector< Fragmenter_Namespace::FragmentInfo > only_shards_for_device(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, const int device_count)
static constexpr size_t MAX_NUM_HASH_ENTRIES
Definition: HashJoin.h:136
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
virtual std::pair< size_t, size_t > approximateTupleCount(const std::vector< ColumnsForDevice > &) const
static std::vector< const StringDictionaryProxy::IdMap * > translateCompositeStrDictProxies(const CompositeKeyInfo &composite_key_info, const std::vector< InnerOuterStringOpInfos > &string_op_infos_for_keys, const Executor *executor)
Definition: HashJoin.cpp:528
HashtableCacheMetaInfo hashtable_cache_meta_info_
static std::unordered_set< size_t > getAlternativeTableKeys(const std::vector< ChunkKey > &chunk_keys, const shared::TableKey &inner_table_key)
Definition: DataRecycler.h:154
size_t 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)
virtual void reifyForDevice(const ColumnsForDevice &columns_for_device, const HashType layout, const int device_id, const BaselineHashTableEntryInfo hash_table_entry_info, const logger::ThreadLocalIds parent_thread_local_ids)
size_t QueryPlanHash
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
const Data_Namespace::MemoryLevel memory_level_
#define CHECK(condition)
Definition: Logger.h:291
static bool isSafeToCacheHashtable(const TableIdToNodeMap &table_id_to_node_map, bool need_dict_translation, const std::vector< InnerOuterStringOpInfos > &inner_outer_string_op_info_pairs, const shared::TableKey &table_key)
static std::pair< std::vector< InnerOuter >, std::vector< InnerOuterStringOpInfos > > normalizeColumnPairs(const Analyzer::BinOper *condition, const TemporaryTables *temporary_tables)
Definition: HashJoin.cpp:1015
virtual size_t getKeyComponentCount() const
void copyCpuHashTableToGpu(std::shared_ptr< BaselineHashTable > &cpu_hash_table, const int device_id, Data_Namespace::DataMgr *data_mgr)
ChunkKey genChunkKey(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments) const
std::vector< const StringDictionaryProxy::IdMap * > str_proxy_translation_maps_
virtual size_t getKeyComponentWidth() const
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)
shared::TableKey getInnerTableId() const noexceptoverride
ThreadLocalIds thread_local_ids()
Definition: Logger.cpp:880
const std::shared_ptr< Analyzer::BinOper > condition_
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:

+ Here is the caller graph for this function:

size_t BaselineJoinHashTable::shardCount ( ) const
protected

Definition at line 690 of file BaselineJoinHashTable.cpp.

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

Referenced by reifyWithLayout().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::set< DecodedJoinHashBufferEntry > BaselineJoinHashTable::toSet ( const ExecutorDeviceType  device_type,
const int  device_id 
) const
overridevirtual

Implements HashJoin.

Definition at line 209 of file BaselineJoinHashTable.cpp.

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

211  {
212  auto buffer = getJoinHashBuffer(device_type, device_id);
213  auto hash_table = getHashTableForDevice(device_id);
214  CHECK(hash_table);
215  auto buffer_size = hash_table->getHashTableBufferSize(device_type);
216 #ifdef HAVE_CUDA
217  std::unique_ptr<int8_t[]> buffer_copy;
218  if (device_type == ExecutorDeviceType::GPU) {
219  buffer_copy = std::make_unique<int8_t[]>(buffer_size);
220  auto data_mgr = executor_->getDataMgr();
221  auto device_allocator = std::make_unique<CudaAllocator>(
222  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
223  device_allocator->copyFromDevice(buffer_copy.get(), buffer, buffer_size);
224  }
225  auto ptr1 = buffer_copy ? buffer_copy.get() : buffer;
226 #else
227  auto ptr1 = buffer;
228 #endif // HAVE_CUDA
229  auto ptr2 = ptr1 + offsetBufferOff();
230  auto ptr3 = ptr1 + countBufferOff();
231  auto ptr4 = ptr1 + payloadBufferOff();
232  const auto layout = hash_table->getLayout();
233  return HashTable::toSet(getKeyComponentCount() + (layout == HashType::OneToOne ? 1 : 0),
235  hash_table->getEntryCount(),
236  ptr1,
237  ptr2,
238  ptr3,
239  ptr4,
240  buffer_size);
241 }
size_t offsetBufferOff() const noexceptoverride
size_t payloadBufferOff() const noexceptoverride
int8_t * getJoinHashBuffer(const ExecutorDeviceType device_type, const int device_id) const
Definition: HashJoin.h:314
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:295
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7
#define CHECK(condition)
Definition: Logger.h:291
virtual size_t getKeyComponentCount() const
virtual size_t getKeyComponentWidth() const
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
size_t countBufferOff() const noexceptoverride

+ Here is the call graph for this function:

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

Implements HashJoin.

Definition at line 165 of file BaselineJoinHashTable.cpp.

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

Referenced by getAlternativeCacheKey().

167  {
168  auto buffer = getJoinHashBuffer(device_type, device_id);
169  if (!buffer) {
170  return "EMPTY";
171  }
172  CHECK_LT(static_cast<size_t>(device_id), hash_tables_for_device_.size());
173  auto hash_table = hash_tables_for_device_[device_id];
174  CHECK(hash_table);
175  auto buffer_size = hash_table->getHashTableBufferSize(device_type);
176 #ifdef HAVE_CUDA
177  std::unique_ptr<int8_t[]> buffer_copy;
178  if (device_type == ExecutorDeviceType::GPU) {
179  buffer_copy = std::make_unique<int8_t[]>(buffer_size);
180 
181  auto data_mgr = executor_->getDataMgr();
182  auto device_allocator = std::make_unique<CudaAllocator>(
183  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
184  device_allocator->copyFromDevice(buffer_copy.get(), buffer, buffer_size);
185  }
186  auto ptr1 = buffer_copy ? buffer_copy.get() : buffer;
187 #else
188  auto ptr1 = buffer;
189 #endif // HAVE_CUDA
190  auto ptr2 = ptr1 + offsetBufferOff();
191  auto ptr3 = ptr1 + countBufferOff();
192  auto ptr4 = ptr1 + payloadBufferOff();
193  CHECK(hash_table);
194  const auto layout = getHashType();
195  return HashTable::toString(
196  "keyed",
197  getHashTypeString(layout),
198  getKeyComponentCount() + (layout == HashType::OneToOne ? 1 : 0),
200  hash_table->getEntryCount(),
201  ptr1,
202  ptr2,
203  ptr3,
204  ptr4,
205  buffer_size,
206  raw);
207 }
size_t offsetBufferOff() const noexceptoverride
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:377
size_t payloadBufferOff() const noexceptoverride
HashType getHashType() const noexceptoverride
int8_t * getJoinHashBuffer(const ExecutorDeviceType device_type, const int device_id) const
Definition: HashJoin.h:314
#define CHECK_LT(x, y)
Definition: Logger.h:303
static std::string getHashTypeString(HashType ht) noexcept
Definition: HashJoin.h:179
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
virtual size_t getKeyComponentCount() const
virtual size_t getKeyComponentWidth() const
size_t countBufferOff() const noexceptoverride

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

ColumnCacheMap& BaselineJoinHashTable::column_cache_
protected

Definition at line 257 of file BaselineJoinHashTable.h.

Referenced by fetchColumnsForDevice().

const std::shared_ptr<Analyzer::BinOper> BaselineJoinHashTable::condition_
protected

Definition at line 252 of file BaselineJoinHashTable.h.

Referenced by isBitwiseEq(), reify(), reifyWithLayout(), and shardCount().

std::mutex BaselineJoinHashTable::cpu_hash_table_buff_mutex_
protected

Definition at line 258 of file BaselineJoinHashTable.h.

Referenced by initHashTableForDevice().

const int BaselineJoinHashTable::device_count_
protected
std::unique_ptr< HashtableRecycler > BaselineJoinHashTable::hash_table_cache_
staticprotected
std::unique_ptr< HashingSchemeRecycler > BaselineJoinHashTable::hash_table_layout_cache_
staticprotected
Initial value:
=
std::make_unique<HashingSchemeRecycler>()

Definition at line 279 of file BaselineJoinHashTable.h.

Referenced by getHashingSchemeCache(), initHashTableForDevice(), invalidateCache(), and markCachedItemAsDirty().

HashTableBuildDagMap BaselineJoinHashTable::hashtable_build_dag_map_
protected

Definition at line 270 of file BaselineJoinHashTable.h.

Referenced by reifyWithLayout().

std::vector<QueryPlanHash> BaselineJoinHashTable::hashtable_cache_key_
protected

Definition at line 272 of file BaselineJoinHashTable.h.

Referenced by initHashTableForDevice(), and reifyWithLayout().

HashtableCacheMetaInfo BaselineJoinHashTable::hashtable_cache_meta_info_
protected

Definition at line 273 of file BaselineJoinHashTable.h.

Referenced by reifyWithLayout().

std::vector<InnerOuterStringOpInfos> BaselineJoinHashTable::inner_outer_string_op_infos_pairs_
protected
const JoinType BaselineJoinHashTable::join_type_
protected

Definition at line 253 of file BaselineJoinHashTable.h.

Referenced by initHashTableForDevice(), and reifyWithLayout().

std::optional<HashType> BaselineJoinHashTable::layout_override_
protected

Definition at line 268 of file BaselineJoinHashTable.h.

Referenced by getHashType().

bool BaselineJoinHashTable::needs_dict_translation_
mutableprotected
RegisteredQueryHint BaselineJoinHashTable::query_hints_
protected
const std::vector<InputTableInfo>& BaselineJoinHashTable::query_infos_
protected

Definition at line 254 of file BaselineJoinHashTable.h.

Referenced by reifyWithLayout().

const size_t BaselineJoinHashTable::rowid_size_
protected

Definition at line 276 of file BaselineJoinHashTable.h.

Referenced by reifyWithLayout().

std::vector<const StringDictionaryProxy::IdMap*> BaselineJoinHashTable::str_proxy_translation_maps_
protected

Definition at line 260 of file BaselineJoinHashTable.h.

Referenced by initHashTableForDevice(), and reifyWithLayout().

std::mutex BaselineJoinHashTable::str_proxy_translation_mutex_
protected

Definition at line 259 of file BaselineJoinHashTable.h.

Referenced by reifyWithLayout().

const TableIdToNodeMap BaselineJoinHashTable::table_id_to_node_map_
protected

Definition at line 275 of file BaselineJoinHashTable.h.

Referenced by initHashTableForDevice(), and reifyWithLayout().

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

Definition at line 274 of file BaselineJoinHashTable.h.

Referenced by reifyWithLayout().


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