OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HashJoin Class Referenceabstract

#include <HashJoin.h>

+ Inheritance diagram for HashJoin:

Public Member Functions

virtual std::string toString (const ExecutorDeviceType device_type, const int device_id=0, bool raw=false) const =0
 
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
 
virtual DecodedJoinHashBufferSet toSet (const ExecutorDeviceType device_type, const int device_id) const =0
 
virtual llvm::Value * codegenSlot (const CompilationOptions &, const size_t)=0
 
virtual HashJoinMatchingSet codegenMatchingSet (const CompilationOptions &, const size_t)=0
 
virtual shared::TableKey getInnerTableId () const noexcept=0
 
virtual int getInnerTableRteIdx () const noexcept=0
 
virtual HashType getHashType () const noexcept=0
 
virtual Data_Namespace::MemoryLevel getMemoryLevel () const noexcept=0
 
virtual int getDeviceCount () const noexcept=0
 
virtual size_t offsetBufferOff () const noexcept=0
 
virtual size_t countBufferOff () const noexcept=0
 
virtual size_t payloadBufferOff () const noexcept=0
 
virtual std::string getHashJoinType () const =0
 
virtual bool isBitwiseEq () const =0
 
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 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)
 

Static Public Attributes

static constexpr size_t MAX_NUM_HASH_ENTRIES = size_t(1) << 31
 

Protected Member Functions

virtual size_t getComponentBufferSize () const noexcept=0
 

Static Protected Member Functions

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

std::vector< std::shared_ptr
< HashTable > > 
hash_tables_for_device_
 

Detailed Description

Definition at line 134 of file HashJoin.h.

Member Function Documentation

bool HashJoin::canAccessHashTable ( bool  allow_hash_table_recycling,
bool  invalid_cache_key,
JoinType  join_type 
)
static

Definition at line 1049 of file HashJoin.cpp.

References g_enable_data_recycler, g_use_hashtable_cache, and INVALID.

Referenced by PerfectJoinHashTable::reify(), and BaselineJoinHashTable::reifyWithLayout().

1051  {
1052  return g_enable_data_recycler && g_use_hashtable_cache && !invalid_cache_key &&
1053  allow_hash_table_recycling && join_type != JoinType::INVALID;
1054 }
bool g_enable_data_recycler
Definition: Execute.cpp:154
bool g_use_hashtable_cache
Definition: Execute.cpp:155

+ Here is the caller graph for this function:

void HashJoin::checkHashJoinReplicationConstraint ( const shared::TableKey table_key,
const size_t  shard_count,
const Executor executor 
)
static

Definition at line 796 of file HashJoin.cpp.

References CHECK, g_cluster, Catalog_Namespace::get_metadata_for_table(), shared::TableKey::table_id, and table_is_replicated().

Referenced by RangeJoinHashTable::getInstance(), BaselineJoinHashTable::reify(), and PerfectJoinHashTable::reify().

798  {
799  if (!g_cluster) {
800  return;
801  }
802  if (table_key.table_id >= 0) {
803  CHECK(executor);
804  const auto inner_td = Catalog_Namespace::get_metadata_for_table(table_key);
805  CHECK(inner_td);
806  if (!shard_count && !table_is_replicated(inner_td)) {
807  throw TableMustBeReplicated(inner_td->tableName);
808  }
809  }
810 }
const TableDescriptor * get_metadata_for_table(const ::shared::TableKey &table_key, bool populate_fragmenter)
bool table_is_replicated(const TableDescriptor *td)
#define CHECK(condition)
Definition: Logger.h:291
bool g_cluster

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Value * HashJoin::codegenColOrStringOper ( const Analyzer::Expr col_or_string_oper,
const std::vector< StringOps_Namespace::StringOpInfo > &  string_op_infos,
CodeGenerator code_generator,
const CompilationOptions co 
)
staticprotected

Definition at line 564 of file HashJoin.cpp.

References CHECK, CodeGenerator::codegen(), and CodeGenerator::codegenPseudoStringOper().

Referenced by BaselineJoinHashTable::codegenKey(), PerfectJoinHashTable::codegenMatchingSet(), and PerfectJoinHashTable::codegenSlot().

568  {
569  if (!string_op_infos.empty()) {
570  const auto coerced_col_var =
571  dynamic_cast<const Analyzer::ColumnVar*>(col_or_string_oper);
572  CHECK(coerced_col_var);
573  std::vector<llvm::Value*> codegen_val_vec{
574  code_generator.codegenPseudoStringOper(coerced_col_var, string_op_infos, co)};
575  return codegen_val_vec[0];
576  }
577  return code_generator.codegen(col_or_string_oper, true, co)[0];
578 }
llvm::Value * codegenPseudoStringOper(const Analyzer::ColumnVar *, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos, const CompilationOptions &)
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
Definition: IRCodegen.cpp:30
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Value * HashJoin::codegenHashTableLoad ( const size_t  table_idx,
Executor executor 
)
static

Definition at line 259 of file HashJoin.cpp.

References AUTOMATIC_IR_METADATA, CHECK, CHECK_LT, and get_arg_by_name().

Referenced by PerfectJoinHashTable::codegenHashTableLoad(), BaselineJoinHashTable::codegenMatchingSet(), BoundingBoxIntersectJoinHashTable::codegenMatchingSet(), RangeJoinHashTable::codegenMatchingSetWithOffset(), and BaselineJoinHashTable::hashPtr().

259  {
260  AUTOMATIC_IR_METADATA(executor->cgen_state_.get());
261  llvm::Value* hash_ptr = nullptr;
262  const auto total_table_count =
263  executor->plan_state_->join_info_.join_hash_tables_.size();
264  CHECK_LT(table_idx, total_table_count);
265  if (total_table_count > 1) {
266  auto hash_tables_ptr =
267  get_arg_by_name(executor->cgen_state_->row_func_, "join_hash_tables");
268  auto hash_pptr =
269  table_idx > 0
270  ? executor->cgen_state_->ir_builder_.CreateGEP(
271  hash_tables_ptr->getType()->getScalarType()->getPointerElementType(),
272  hash_tables_ptr,
273  executor->cgen_state_->llInt(static_cast<int64_t>(table_idx)))
274  : hash_tables_ptr;
275  hash_ptr = executor->cgen_state_->ir_builder_.CreateLoad(
276  hash_pptr->getType()->getPointerElementType(), hash_pptr);
277  } else {
278  hash_ptr = get_arg_by_name(executor->cgen_state_->row_func_, "join_hash_tables");
279  }
280  CHECK(hash_ptr);
281  return hash_ptr;
282 }
llvm::Value * get_arg_by_name(llvm::Function *func, const std::string &name)
Definition: Execute.h:168
#define AUTOMATIC_IR_METADATA(CGENSTATE)
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual HashJoinMatchingSet HashJoin::codegenMatchingSet ( const CompilationOptions ,
const size_t   
)
pure virtual

Implemented in BoundingBoxIntersectJoinHashTable, BaselineJoinHashTable, and PerfectJoinHashTable.

Referenced by PerfectJoinHashTable::codegenMatchingSet(), BaselineJoinHashTable::codegenMatchingSet(), BoundingBoxIntersectJoinHashTable::codegenMatchingSet(), and RangeJoinHashTable::codegenMatchingSetWithOffset().

+ Here is the caller graph for this function:

HashJoinMatchingSet HashJoin::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

Definition at line 208 of file HashJoin.cpp.

References AUTOMATIC_IR_METADATA, and CHECK.

215  {
216  AUTOMATIC_IR_METADATA(executor->cgen_state_.get());
217  using namespace std::string_literals;
218 
219  std::string fname(is_bucketized ? "bucketized_hash_join_idx"s : "hash_join_idx"s);
220 
221  if (is_bw_eq) {
222  fname += "_bitwise";
223  }
224  if (is_sharded) {
225  fname += "_sharded";
226  }
227  if (!is_bw_eq && col_is_nullable) {
228  fname += "_nullable";
229  }
230 
231  const auto slot_lv = executor->cgen_state_->emitCall(fname, hash_join_idx_args_in);
232  const auto slot_valid_lv = executor->cgen_state_->ir_builder_.CreateICmpSGE(
233  slot_lv, executor->cgen_state_->llInt(int64_t(0)));
234 
235  auto pos_ptr = hash_join_idx_args_in[0];
236  CHECK(pos_ptr);
237 
238  auto count_ptr = executor->cgen_state_->ir_builder_.CreateAdd(
239  pos_ptr, executor->cgen_state_->llInt(sub_buff_size));
240  auto hash_join_idx_args = hash_join_idx_args_in;
241  hash_join_idx_args[0] = executor->cgen_state_->ir_builder_.CreatePtrToInt(
242  count_ptr, llvm::Type::getInt64Ty(executor->cgen_state_->context_));
243 
244  const auto row_count_lv = executor->cgen_state_->ir_builder_.CreateSelect(
245  slot_valid_lv,
246  executor->cgen_state_->emitCall(fname, hash_join_idx_args),
247  executor->cgen_state_->llInt(int64_t(0)));
248  auto rowid_base_i32 = executor->cgen_state_->ir_builder_.CreateIntToPtr(
249  executor->cgen_state_->ir_builder_.CreateAdd(
250  pos_ptr, executor->cgen_state_->llInt(2 * sub_buff_size)),
251  llvm::Type::getInt32PtrTy(executor->cgen_state_->context_));
252  auto rowid_ptr_i32 = executor->cgen_state_->ir_builder_.CreateGEP(
253  rowid_base_i32->getType()->getScalarType()->getPointerElementType(),
254  rowid_base_i32,
255  slot_lv);
256  return {rowid_ptr_i32, row_count_lv, slot_lv};
257 }
#define AUTOMATIC_IR_METADATA(CGENSTATE)
#define CHECK(condition)
Definition: Logger.h:291
virtual llvm::Value* HashJoin::codegenSlot ( const CompilationOptions ,
const size_t   
)
pure virtual
std::vector< int > HashJoin::collectFragmentIds ( const std::vector< Fragmenter_Namespace::FragmentInfo > &  fragments)
static

Definition at line 461 of file HashJoin.cpp.

References gpu_enabled::sort(), and shared::transform().

Referenced by BoundingBoxIntersectJoinHashTable::generateCacheKey(), HashtableRecycler::getHashtableAccessPathInfo(), RangeJoinHashTable::reifyWithLayout(), and BoundingBoxIntersectJoinHashTable::reifyWithLayout().

462  {
463  auto const fragment_id = [](auto const& frag_info) { return frag_info.fragmentId; };
464  std::vector<int> frag_ids(fragments.size());
465  std::transform(fragments.cbegin(), fragments.cend(), frag_ids.begin(), fragment_id);
466  std::sort(frag_ids.begin(), frag_ids.end());
467  return frag_ids;
468 }
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:320

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual size_t HashJoin::countBufferOff ( ) const
pure virtualnoexcept
JoinColumn HashJoin::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 
)

fetchJoinColumn() calls ColumnFetcher::makeJoinColumn(), then copies the JoinColumn's col_chunks_buff memory onto the GPU if required by the effective_memory_level parameter. The dev_buff_owner parameter will manage the GPU memory.

Definition at line 60 of file HashJoin.cpp.

References Allocator::alloc(), CHECK, JoinColumn::col_chunks_buff, JoinColumn::col_chunks_buff_sz, DeviceAllocator::copyToDevice(), Data_Namespace::GPU_LEVEL, and ColumnFetcher::makeJoinColumn().

Referenced by BoundingBoxIntersectJoinHashTable::fetchColumnsForDevice(), PerfectJoinHashTable::fetchColumnsForDevice(), and BaselineJoinHashTable::fetchColumnsForDevice().

69  {
70  static std::mutex fragment_fetch_mutex;
71  std::lock_guard<std::mutex> fragment_fetch_lock(fragment_fetch_mutex);
72  try {
73  JoinColumn join_column = ColumnFetcher::makeJoinColumn(executor,
74  *hash_col,
75  fragment_info,
76  effective_memory_level,
77  device_id,
78  dev_buff_owner,
79  /*thread_idx=*/0,
80  chunks_owner,
81  malloc_owner,
82  *column_cache);
83  if (effective_memory_level == Data_Namespace::GPU_LEVEL) {
84  CHECK(dev_buff_owner);
85  auto device_col_chunks_buff = dev_buff_owner->alloc(join_column.col_chunks_buff_sz);
86  dev_buff_owner->copyToDevice(device_col_chunks_buff,
87  join_column.col_chunks_buff,
88  join_column.col_chunks_buff_sz);
89  join_column.col_chunks_buff = device_col_chunks_buff;
90  }
91  return join_column;
92  } catch (...) {
93  throw FailedToFetchColumn();
94  }
95 }
static JoinColumn makeJoinColumn(Executor *executor, const Analyzer::ColumnVar &hash_col, const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const Data_Namespace::MemoryLevel effective_mem_lvl, const int device_id, DeviceAllocator *device_allocator, const size_t thread_idx, std::vector< std::shared_ptr< Chunk_NS::Chunk >> &chunks_owner, std::vector< std::shared_ptr< void >> &malloc_owner, ColumnCacheMap &column_cache)
Creates a JoinColumn struct containing an array of JoinChunk structs.
virtual int8_t * alloc(const size_t num_bytes)=0
virtual void copyToDevice(void *device_dst, const void *host_src, const size_t num_bytes) const =0
size_t col_chunks_buff_sz
const int8_t * col_chunks_buff
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HashJoin::freeHashBufferMemory ( )
inline

Definition at line 337 of file HashJoin.h.

References hash_tables_for_device_.

Referenced by BaselineJoinHashTable::reify(), and PerfectJoinHashTable::reify().

337  {
338  auto empty_hash_tables =
340  hash_tables_for_device_.swap(empty_hash_tables);
341  }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:377

+ Here is the caller graph for this function:

static std::string HashJoin::generateTooManyHashEntriesErrMsg ( size_t  num_entries,
size_t  threshold,
MemoryLevel  memory_level 
)
inlinestatic

Definition at line 165 of file HashJoin.h.

References toString().

Referenced by PerfectJoinHashTable::getInstance().

167  {
168  std::ostringstream oss;
169  oss << "Hash tables with more than " << threshold
170  << " entries (# hash entries: " << num_entries << ") on "
171  << ::toString(memory_level) << " not supported yet";
172  return oss.str();
173  }
virtual std::string toString(const ExecutorDeviceType device_type, const int device_id=0, bool raw=false) const =0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual size_t HashJoin::getComponentBufferSize ( ) const
protectedpure virtualnoexcept
CompositeKeyInfo HashJoin::getCompositeKeyInfo ( const std::vector< InnerOuter > &  inner_outer_pairs,
const Executor executor,
const std::vector< InnerOuterStringOpInfos > &  inner_outer_string_op_infos_pairs = {} 
)
static

Definition at line 470 of file HashJoin.cpp.

References CHECK, CHECK_EQ, and kENCODING_DICT.

Referenced by RangeJoinHashTable::approximateTupleCount(), BaselineJoinHashTable::initHashTableForDevice(), RangeJoinHashTable::initHashTableOnCpu(), BoundingBoxIntersectJoinHashTable::reify(), and BaselineJoinHashTable::reifyWithLayout().

473  {
474  CHECK(executor);
475  std::vector<const void*> sd_inner_proxy_per_key;
476  std::vector<void*> sd_outer_proxy_per_key;
477  std::vector<ChunkKey> cache_key_chunks; // used for the cache key
478  const bool has_string_op_infos = inner_outer_string_op_infos_pairs.size();
479  if (has_string_op_infos) {
480  CHECK_EQ(inner_outer_pairs.size(), inner_outer_string_op_infos_pairs.size());
481  }
482  size_t string_op_info_pairs_idx = 0;
483  for (const auto& inner_outer_pair : inner_outer_pairs) {
484  const auto inner_col = inner_outer_pair.first;
485  const auto outer_col = inner_outer_pair.second;
486  const auto& inner_ti = inner_col->get_type_info();
487  const auto& outer_ti = outer_col->get_type_info();
488  if (inner_ti.is_string() && outer_ti.is_string() &&
489  inner_ti.is_dict_encoded_string() != outer_ti.is_dict_encoded_string()) {
490  throw std::runtime_error(
491  "Detected a join between dictionary-encoded and none-encoded text columns. "
492  "Please consider applying dictionary-encoding for the other column.");
493  }
494  const auto& inner_column_key = inner_col->getColumnKey();
495  ChunkKey cache_key_chunks_for_column{
496  inner_column_key.db_id, inner_column_key.table_id, inner_column_key.column_id};
497  if (inner_ti.is_string() &&
498  (!(inner_ti.getStringDictKey() == outer_ti.getStringDictKey()) ||
499  (has_string_op_infos &&
500  (inner_outer_string_op_infos_pairs[string_op_info_pairs_idx].first.size() ||
501  inner_outer_string_op_infos_pairs[string_op_info_pairs_idx].second.size())))) {
502  CHECK(outer_ti.is_string());
503  StringDictionaryProxy* sd_inner_proxy{nullptr};
504  StringDictionaryProxy* sd_outer_proxy{nullptr};
505  if (inner_ti.get_compression() == kENCODING_DICT) {
506  sd_inner_proxy = executor->getStringDictionaryProxy(
507  inner_ti.getStringDictKey(), executor->getRowSetMemoryOwner(), true);
508  sd_inner_proxy_per_key.push_back(sd_inner_proxy);
509  }
510  if (outer_ti.get_compression() == kENCODING_DICT) {
511  sd_outer_proxy = executor->getStringDictionaryProxy(
512  outer_ti.getStringDictKey(), executor->getRowSetMemoryOwner(), true);
513  sd_outer_proxy_per_key.push_back(sd_outer_proxy);
514  cache_key_chunks_for_column.push_back(sd_outer_proxy->getGeneration());
515  }
516  } else {
517  sd_inner_proxy_per_key.emplace_back();
518  sd_outer_proxy_per_key.emplace_back();
519  cache_key_chunks_for_column.push_back({-1});
520  }
521  cache_key_chunks.push_back(cache_key_chunks_for_column);
522  string_op_info_pairs_idx++;
523  }
524  return {sd_inner_proxy_per_key, sd_outer_proxy_per_key, cache_key_chunks};
525 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< int > ChunkKey
Definition: types.h:36
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

virtual int HashJoin::getDeviceCount ( ) const
pure virtualnoexcept
template<typename T >
const T * HashJoin::getHashJoinColumn ( const Analyzer::Expr expr)
static

Definition at line 813 of file HashJoin.cpp.

References CHECK, and heavydb.dtypes::T.

813  {
814  auto* target_expr = expr;
815  if (auto cast_expr = dynamic_cast<const Analyzer::UOper*>(expr)) {
816  target_expr = cast_expr->get_operand();
817  }
818  CHECK(target_expr);
819  return dynamic_cast<const T*>(target_expr);
820 }
#define CHECK(condition)
Definition: Logger.h:291
virtual std::string HashJoin::getHashJoinType ( ) const
pure virtual
HashTable* HashJoin::getHashTableForDevice ( const size_t  device_id) const
inline
virtual HashType HashJoin::getHashType ( ) const
pure virtualnoexcept
static std::string HashJoin::getHashTypeString ( HashType  ht)
inlinestaticnoexcept

Definition at line 179 of file HashJoin.h.

Referenced by BaselineJoinHashTable::getInstance(), PerfectJoinHashTable::getInstance(), BoundingBoxIntersectJoinHashTable::getInstance(), RangeJoinHashTable::reifyWithLayout(), BoundingBoxIntersectJoinHashTable::reifyWithLayout(), HashingSchemeRecycler::toString(), PerfectJoinHashTable::toString(), BaselineJoinHashTable::toString(), and BoundingBoxIntersectJoinHashTable::toString().

179  {
180  const char* HashTypeStrings[3] = {"OneToOne", "OneToMany", "ManyToMany"};
181  return HashTypeStrings[static_cast<int>(ht)];
182  };

+ Here is the caller graph for this function:

virtual shared::TableKey HashJoin::getInnerTableId ( ) const
pure virtualnoexcept
static shared::TableKey HashJoin::getInnerTableId ( const std::vector< InnerOuter > &  inner_outer_pairs)
inlinestatic

Definition at line 265 of file HashJoin.h.

References CHECK.

266  {
267  CHECK(!inner_outer_pairs.empty());
268  const auto first_inner_col = inner_outer_pairs.front().first;
269  return first_inner_col->getTableKey();
270  }
#define CHECK(condition)
Definition: Logger.h:291
virtual int HashJoin::getInnerTableRteIdx ( ) const
pure virtualnoexcept
std::shared_ptr< HashJoin > HashJoin::getInstance ( 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 
)
static

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

Definition at line 285 of file HashJoin.cpp.

References CHECK, CHECK_EQ, CHECK_GT, coalesce_singleton_equi_join(), CPU, DEBUG_TIMER, RegisteredQueryHint::force_baseline_hash_join, g_enable_bbox_intersect_hashjoin, BaselineJoinHashTable::getInstance(), PerfectJoinHashTable::getInstance(), BoundingBoxIntersectJoinHashTable::getInstance(), GPU, Data_Namespace::GPU_LEVEL, logger::INFO, LOG, VLOG, and VLOGGING.

Referenced by Executor::buildHashTableForQualifier(), and getSyntheticInstance().

296  {
297  auto timer = DEBUG_TIMER(__func__);
298  std::shared_ptr<HashJoin> join_hash_table;
299  CHECK_GT(device_count, 0);
300  if (!g_enable_bbox_intersect_hashjoin && qual_bin_oper->is_bbox_intersect_oper()) {
301  throw std::runtime_error(
302  "Bounding box intersection disabled, attempting to fall back to loop join");
303  }
304  if (qual_bin_oper->is_bbox_intersect_oper()) {
305  VLOG(1) << "Trying to build geo hash table:";
306  join_hash_table =
308  query_infos,
309  memory_level,
310  join_type,
311  device_count,
312  column_cache,
313  executor,
314  hashtable_build_dag_map,
315  query_hint,
316  table_id_to_node_map);
317  } else if (dynamic_cast<const Analyzer::ExpressionTuple*>(
318  qual_bin_oper->get_left_operand()) ||
319  query_hint.force_baseline_hash_join) {
320  if (query_hint.force_baseline_hash_join) {
321  LOG(INFO) << "A user's query hint forced the join operation to use the Baseline "
322  "hash join layout";
323  }
324  VLOG(1) << "Trying to build keyed hash table:";
325  join_hash_table = BaselineJoinHashTable::getInstance(qual_bin_oper,
326  query_infos,
327  memory_level,
328  join_type,
329  preferred_hash_type,
330  device_count,
331  column_cache,
332  executor,
333  hashtable_build_dag_map,
334  query_hint,
335  table_id_to_node_map);
336  } else {
337  try {
338  VLOG(1) << "Trying to build perfect hash table:";
339  join_hash_table = PerfectJoinHashTable::getInstance(qual_bin_oper,
340  query_infos,
341  memory_level,
342  join_type,
343  preferred_hash_type,
344  device_count,
345  column_cache,
346  executor,
347  hashtable_build_dag_map,
348  query_hint,
349  table_id_to_node_map);
350  } catch (JoinHashTableTooBig& e) {
351  throw e;
352  } catch (TooManyHashEntries& e) {
353  const auto join_quals = coalesce_singleton_equi_join(qual_bin_oper);
354  CHECK_EQ(join_quals.size(), size_t(1));
355  const auto join_qual =
356  std::dynamic_pointer_cast<Analyzer::BinOper>(join_quals.front());
357  VLOG(1) << "Building a perfect join hash table fails: " << e.what();
358  VLOG(1) << "Trying to re-build keyed join hash table";
359  join_hash_table = BaselineJoinHashTable::getInstance(join_qual,
360  query_infos,
361  memory_level,
362  join_type,
363  preferred_hash_type,
364  device_count,
365  column_cache,
366  executor,
367  hashtable_build_dag_map,
368  query_hint,
369  table_id_to_node_map);
370  }
371  }
372  CHECK(join_hash_table);
373  if (VLOGGING(2)) {
374  if (join_hash_table->getMemoryLevel() == Data_Namespace::MemoryLevel::GPU_LEVEL) {
375  for (int device_id = 0; device_id < join_hash_table->getDeviceCount();
376  ++device_id) {
377  if (join_hash_table->getJoinHashBufferSize(ExecutorDeviceType::GPU, device_id) <=
378  1000) {
379  VLOG(2) << "Built GPU hash table: "
380  << join_hash_table->toString(ExecutorDeviceType::GPU, device_id);
381  }
382  }
383  } else {
384  if (join_hash_table->getJoinHashBufferSize(ExecutorDeviceType::CPU) <= 1000) {
385  VLOG(2) << "Built CPU hash table: "
386  << join_hash_table->toString(ExecutorDeviceType::CPU);
387  }
388  }
389  }
390  return join_hash_table;
391 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::list< std::shared_ptr< Analyzer::Expr > > coalesce_singleton_equi_join(const std::shared_ptr< Analyzer::BinOper > &join_qual)
#define LOG(tag)
Definition: Logger.h:285
#define CHECK_GT(x, y)
Definition: Logger.h:305
static std::shared_ptr< BoundingBoxIntersectJoinHashTable > getInstance(const std::shared_ptr< Analyzer::BinOper > condition, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, const JoinType join_type, const int device_count, ColumnCacheMap &column_cache, Executor *executor, const HashTableBuildDagMap &hashtable_build_dag_map, const RegisteredQueryHint &query_hint, const TableIdToNodeMap &table_id_to_node_map)
Make hash table from an in-flight SQL query&#39;s parse tree etc.
#define VLOGGING(n)
Definition: Logger.h:289
bool g_enable_bbox_intersect_hashjoin
Definition: Execute.cpp:105
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&#39;s parse tree etc.
static std::shared_ptr< PerfectJoinHashTable > getInstance(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_hints, const TableIdToNodeMap &table_id_to_node_map)
Make hash table from an in-flight SQL query&#39;s parse tree etc.
bool force_baseline_hash_join
Definition: QueryHint.h:359
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:412
#define VLOG(n)
Definition: Logger.h:388

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t* HashJoin::getJoinHashBuffer ( const ExecutorDeviceType  device_type,
const int  device_id 
) const
inline

Definition at line 314 of file HashJoin.h.

References CHECK, CHECK_LT, CPU, and hash_tables_for_device_.

Referenced by PerfectJoinHashTable::toSet(), BaselineJoinHashTable::toSet(), BoundingBoxIntersectJoinHashTable::toSet(), PerfectJoinHashTable::toString(), BaselineJoinHashTable::toString(), BoundingBoxIntersectJoinHashTable::toString(), and anonymous_namespace{HashJoin.cpp}::toStringFlat().

315  {
316  // TODO: just make device_id a size_t
317  CHECK_LT(size_t(device_id), hash_tables_for_device_.size());
318  if (!hash_tables_for_device_[device_id]) {
319  return nullptr;
320  }
321  CHECK(hash_tables_for_device_[device_id]);
322  auto hash_table = hash_tables_for_device_[device_id].get();
323 #ifdef HAVE_CUDA
324  if (device_type == ExecutorDeviceType::CPU) {
325  return hash_table->getCpuBuffer();
326  } else {
327  CHECK(hash_table);
328  const auto gpu_buff = hash_table->getGpuBuffer();
329  return gpu_buff;
330  }
331 #else
332  CHECK(device_type == ExecutorDeviceType::CPU);
333  return hash_table->getCpuBuffer();
334 #endif
335  }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:377
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

size_t HashJoin::getJoinHashBufferSize ( const ExecutorDeviceType  device_type)
inline

Definition at line 300 of file HashJoin.h.

References CHECK, and CPU.

Referenced by PerfectJoinHashTable::toSet(), PerfectJoinHashTable::toString(), and anonymous_namespace{HashJoin.cpp}::toStringFlat().

300  {
301  CHECK(device_type == ExecutorDeviceType::CPU);
302  return getJoinHashBufferSize(device_type, 0);
303  }
size_t getJoinHashBufferSize(const ExecutorDeviceType device_type)
Definition: HashJoin.h:300
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

size_t HashJoin::getJoinHashBufferSize ( const ExecutorDeviceType  device_type,
const int  device_id 
) const
inline

Definition at line 305 of file HashJoin.h.

References getHashTableForDevice().

306  {
307  auto hash_table = getHashTableForDevice(device_id);
308  if (!hash_table) {
309  return 0;
310  }
311  return hash_table->getHashTableBufferSize(device_type);
312  }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:295

+ Here is the call graph for this function:

size_t HashJoin::getMaximumNumHashEntriesCanHold ( MemoryLevel  memory_level,
const Executor executor,
size_t  rowid_size 
)
staticnoexcept

Definition at line 1056 of file HashJoin.cpp.

References CHECK_GT, Data_Namespace::CPU_LEVEL, and MAX_NUM_HASH_ENTRIES.

Referenced by PerfectJoinHashTable::getInstance().

1058  {
1059  if (memory_level == Data_Namespace::CPU_LEVEL) {
1060  // we can hold up to 2B hash entries b/c CPU hash table buffer is allocated
1061  // to heap which is a memory region that our buffer manager does not manage
1062  // i.e., can allocate a contiguous memory larger than `max_cpu_slab_size`
1064  } else {
1065  // allocate memory buffer for hash table from data_mgr that considers
1066  // `max_gpu_slab_size` but still it can have up to 2B rows.
1067  CHECK_GT(rowid_size, static_cast<size_t>(0));
1068  return std::min(HashJoin::MAX_NUM_HASH_ENTRIES,
1069  executor->maxGpuSlabSize() / rowid_size);
1070  }
1071 }
#define CHECK_GT(x, y)
Definition: Logger.h:305
static constexpr size_t MAX_NUM_HASH_ENTRIES
Definition: HashJoin.h:136

+ Here is the caller graph for this function:

virtual Data_Namespace::MemoryLevel HashJoin::getMemoryLevel ( ) const
pure virtualnoexcept
std::pair< const StringDictionaryProxy *, StringDictionaryProxy * > HashJoin::getStrDictProxies ( const InnerOuter cols,
const Executor executor,
const bool  has_string_ops 
)
static

Definition at line 394 of file HashJoin.cpp.

References CHECK, CHECK_EQ, and Analyzer::Expr::get_type_info().

Referenced by translateInnerToOuterStrDictProxies().

396  {
397  const auto inner_col = cols.first;
398  CHECK(inner_col);
399  const auto inner_ti = inner_col->get_type_info();
400  const auto outer_col = dynamic_cast<const Analyzer::ColumnVar*>(cols.second);
401  std::pair<const StringDictionaryProxy*, StringDictionaryProxy*>
402  inner_outer_str_dict_proxies{nullptr, nullptr};
403  if (inner_ti.is_string() && outer_col) {
404  const auto& outer_ti = outer_col->get_type_info();
405  CHECK(outer_ti.is_string());
406  inner_outer_str_dict_proxies.first =
407  executor->getStringDictionaryProxy(inner_ti.getStringDictKey(), true);
408  CHECK(inner_outer_str_dict_proxies.first);
409  inner_outer_str_dict_proxies.second =
410  executor->getStringDictionaryProxy(outer_ti.getStringDictKey(), true);
411  CHECK(inner_outer_str_dict_proxies.second);
412  if (!has_string_ops &&
413  *inner_outer_str_dict_proxies.first == *inner_outer_str_dict_proxies.second) {
414  // Dictionaries are the same - don't need to translate
415  CHECK_EQ(inner_ti.getStringDictKey(), outer_ti.getStringDictKey());
416  inner_outer_str_dict_proxies.first = nullptr;
417  inner_outer_str_dict_proxies.second = nullptr;
418  }
419  }
420  return inner_outer_str_dict_proxies;
421 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< HashJoin > HashJoin::getSyntheticInstance ( 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 
)
static

Make hash table from named tables and columns (such as for testing).

Definition at line 690 of file HashJoin.cpp.

References RegisteredQueryHint::defaults(), getInstance(), getSyntheticColumnVar(), getSyntheticInputTableInfo(), INNER, kBOOLEAN, kEQ, kONE, setupSyntheticCaching(), and ScalarExprVisitor< T >::visit().

701  {
702  auto a1 = getSyntheticColumnVar(table1, column1, 0, catalog1);
703  auto a2 = getSyntheticColumnVar(table2, column2, 1, catalog2);
704 
705  auto qual_bin_oper = std::make_shared<Analyzer::BinOper>(kBOOLEAN, kEQ, kONE, a1, a2);
706 
707  std::set<const Analyzer::ColumnVar*> cvs =
708  AllColumnVarsVisitor().visit(qual_bin_oper.get());
709  auto query_infos = getSyntheticInputTableInfo(cvs, executor);
710  setupSyntheticCaching(cvs, executor);
712 
713  auto hash_table = HashJoin::getInstance(qual_bin_oper,
714  query_infos,
715  memory_level,
717  preferred_hash_type,
718  device_count,
719  column_cache,
720  executor,
721  {},
722  query_hint,
723  {});
724  return hash_table;
725 }
std::vector< InputTableInfo > getSyntheticInputTableInfo(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:667
Definition: sqldefs.h:29
T visit(const Analyzer::Expr *expr) const
void setupSyntheticCaching(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:651
static RegisteredQueryHint defaults()
Definition: QueryHint.h:364
Definition: sqldefs.h:71
std::shared_ptr< Analyzer::ColumnVar > getSyntheticColumnVar(std::string_view table, std::string_view column, int rte_idx, const Catalog_Namespace::Catalog &catalog)
Definition: HashJoin.cpp:580
static std::shared_ptr< HashJoin > getInstance(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&#39;s parse tree etc.
Definition: HashJoin.cpp:285

+ Here is the call graph for this function:

std::shared_ptr< HashJoin > HashJoin::getSyntheticInstance ( 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 
)
static

Make hash table from named tables and columns (such as for testing).

Definition at line 728 of file HashJoin.cpp.

References RegisteredQueryHint::defaults(), getInstance(), getSyntheticInputTableInfo(), INNER, setupSyntheticCaching(), and ScalarExprVisitor< T >::visit().

734  {
735  std::set<const Analyzer::ColumnVar*> cvs =
736  AllColumnVarsVisitor().visit(qual_bin_oper.get());
737  auto query_infos = getSyntheticInputTableInfo(cvs, executor);
738  setupSyntheticCaching(cvs, executor);
740 
741  auto hash_table = HashJoin::getInstance(qual_bin_oper,
742  query_infos,
743  memory_level,
745  preferred_hash_type,
746  device_count,
747  column_cache,
748  executor,
749  {},
750  query_hint,
751  {});
752  return hash_table;
753 }
std::vector< InputTableInfo > getSyntheticInputTableInfo(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:667
T visit(const Analyzer::Expr *expr) const
void setupSyntheticCaching(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:651
static RegisteredQueryHint defaults()
Definition: QueryHint.h:364
static std::shared_ptr< HashJoin > getInstance(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&#39;s parse tree etc.
Definition: HashJoin.cpp:285

+ Here is the call graph for this function:

std::pair< std::string, std::shared_ptr< HashJoin > > HashJoin::getSyntheticInstance ( std::vector< std::shared_ptr< Analyzer::BinOper >>  qual_bin_opers,
const Data_Namespace::MemoryLevel  memory_level,
const HashType  preferred_hash_type,
const int  device_count,
ColumnCacheMap column_cache,
Executor executor 
)
static

Definition at line 755 of file HashJoin.cpp.

References RegisteredQueryHint::defaults(), getInstance(), getSyntheticInputTableInfo(), INNER, setupSyntheticCaching(), and ScalarExprVisitor< T >::visit().

761  {
762  std::set<const Analyzer::ColumnVar*> cvs;
763  for (auto& qual : qual_bin_opers) {
764  auto cv = AllColumnVarsVisitor().visit(qual.get());
765  cvs.insert(cv.begin(), cv.end());
766  }
767  auto query_infos = getSyntheticInputTableInfo(cvs, executor);
768  setupSyntheticCaching(cvs, executor);
770  std::shared_ptr<HashJoin> hash_table;
771  std::string error_msg;
772  for (auto& qual : qual_bin_opers) {
773  try {
774  auto candidate_hash_table = HashJoin::getInstance(qual,
775  query_infos,
776  memory_level,
778  preferred_hash_type,
779  device_count,
780  column_cache,
781  executor,
782  {},
783  query_hint,
784  {});
785  if (candidate_hash_table) {
786  hash_table = candidate_hash_table;
787  }
788  } catch (HashJoinFail& e) {
789  error_msg = e.what();
790  continue;
791  }
792  }
793  return std::make_pair(error_msg, hash_table);
794 }
std::vector< InputTableInfo > getSyntheticInputTableInfo(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:667
T visit(const Analyzer::Expr *expr) const
void setupSyntheticCaching(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:651
static RegisteredQueryHint defaults()
Definition: QueryHint.h:364
static std::shared_ptr< HashJoin > getInstance(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&#39;s parse tree etc.
Definition: HashJoin.cpp:285

+ Here is the call graph for this function:

virtual bool HashJoin::isBitwiseEq ( ) const
pure virtual
std::pair< InnerOuter, InnerOuterStringOpInfos > HashJoin::normalizeColumnPair ( const Analyzer::Expr lhs,
const Analyzer::Expr rhs,
const TemporaryTables temporary_tables,
const bool  is_bbox_intersect = false 
)
static

Definition at line 822 of file HashJoin.cpp.

References CHECK, CHECK_GT, get_column_descriptor_maybe(), get_column_type(), SQLTypeInfo::get_precision(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_type(), Analyzer::Expr::get_type_info(), SQLTypeInfo::get_type_name(), is_constructed_point(), SQLTypeInfo::is_decimal(), SQLTypeInfo::is_integer(), SQLTypeInfo::is_string(), SQLTypeInfo::is_time(), kCAST, kENCODING_DICT, kPOINT, LHS, RHS, gpu_enabled::swap(), UNKNOWN, and ScalarExprVisitor< T >::visit().

Referenced by anonymous_namespace{PerfectJoinHashTable.cpp}::get_cols(), anonymous_namespace{HashJoin.cpp}::get_cols(), normalizeColumnPairs(), and QueryPlanDagExtractor::normalizeColumnsPair().

826  {
827  SQLTypeInfo lhs_ti = lhs->get_type_info();
828  SQLTypeInfo rhs_ti = rhs->get_type_info();
829  if (!is_bbox_intersect) {
830  if (lhs_ti.get_type() != rhs_ti.get_type()) {
831  throw HashJoinFail("Equijoin types must be identical, found: " +
832  lhs_ti.get_type_name() + ", " + rhs_ti.get_type_name());
833  }
834  if (!lhs_ti.is_integer() && !lhs_ti.is_time() && !lhs_ti.is_string() &&
835  !lhs_ti.is_decimal()) {
836  throw HashJoinFail("Cannot apply hash join to inner column type " +
837  lhs_ti.get_type_name());
838  }
839  // Decimal types should be identical.
840  if (lhs_ti.is_decimal() && (lhs_ti.get_scale() != rhs_ti.get_scale() ||
841  lhs_ti.get_precision() != rhs_ti.get_precision())) {
842  throw HashJoinFail("Equijoin with different decimal types");
843  }
844  }
845 
846  const auto lhs_cast = dynamic_cast<const Analyzer::UOper*>(lhs);
847  const auto rhs_cast = dynamic_cast<const Analyzer::UOper*>(rhs);
848  if (lhs_ti.is_string() && (static_cast<bool>(lhs_cast) != static_cast<bool>(rhs_cast) ||
849  (lhs_cast && lhs_cast->get_optype() != kCAST) ||
850  (rhs_cast && rhs_cast->get_optype() != kCAST))) {
851  throw HashJoinFail(
852  "Cannot use hash join for given expression (non-cast unary operator)");
853  }
854  // Casts to decimal are not suported.
855  if (lhs_ti.is_decimal() && (lhs_cast || rhs_cast)) {
856  throw HashJoinFail("Cannot use hash join for given expression (cast to decimal)");
857  }
858  auto lhs_col = getHashJoinColumn<Analyzer::ColumnVar>(lhs);
859  auto rhs_col = getHashJoinColumn<Analyzer::ColumnVar>(rhs);
860 
861  const auto lhs_string_oper = getHashJoinColumn<Analyzer::StringOper>(lhs);
862  const auto rhs_string_oper = getHashJoinColumn<Analyzer::StringOper>(rhs);
863 
864  auto process_string_op_infos = [](const auto& string_oper, auto& col, auto& ti) {
865  std::vector<StringOps_Namespace::StringOpInfo> string_op_infos;
866  if (string_oper) {
867  col = dynamic_cast<const Analyzer::ColumnVar*>(string_oper->getArg(0));
868  if (!col) {
869  // Todo (todd): Allow for non-colvar inputs into string operators for
870  // join predicates
871  // We now guard against non constant/colvar/stringoper inputs
872  // in Analyzer::StringOper::check_operand_types, but keeping this to not
873  // depend on that logic if and when it changes as allowing non-colvar inputs
874  // for hash joins will be additional work on top of allowing them
875  // outside of join predicates
876  throw HashJoinFail(
877  "Hash joins involving string operators currently restricted to column inputs "
878  "(i.e. not case statements).");
879  }
880  ti = col->get_type_info();
881  CHECK(ti.is_dict_encoded_string());
882  const auto chained_string_op_exprs = string_oper->getChainedStringOpExprs();
883  CHECK_GT(chained_string_op_exprs.size(), 0UL);
884  for (const auto& chained_string_op_expr : chained_string_op_exprs) {
885  auto chained_string_op =
886  dynamic_cast<const Analyzer::StringOper*>(chained_string_op_expr.get());
887  CHECK(chained_string_op);
888  StringOps_Namespace::StringOpInfo string_op_info(
889  chained_string_op->get_kind(),
890  chained_string_op->get_type_info(),
891  chained_string_op->getLiteralArgs());
892  string_op_infos.emplace_back(string_op_info);
893  }
894  }
895  return string_op_infos;
896  };
897 
898  auto outer_string_op_infos = process_string_op_infos(lhs_string_oper, lhs_col, lhs_ti);
899  auto inner_string_op_infos = process_string_op_infos(rhs_string_oper, rhs_col, rhs_ti);
900 
901  if (!lhs_col && !rhs_col) {
902  throw HashJoinFail(
903  "Cannot use hash join for given expression (both lhs and rhs are invalid)",
905  }
906 
907  const Analyzer::ColumnVar* inner_col{nullptr};
908  const Analyzer::ColumnVar* outer_col{nullptr};
909  auto outer_ti = lhs_ti;
910  auto inner_ti = rhs_ti;
911  const Analyzer::Expr* outer_expr{lhs};
912  InnerQualDecision inner_qual_decision = InnerQualDecision::UNKNOWN;
913  if (!lhs_col || (rhs_col && lhs_col->get_rte_idx() < rhs_col->get_rte_idx())) {
914  inner_qual_decision = InnerQualDecision::RHS;
915  inner_col = rhs_col;
916  outer_col = lhs_col;
917  } else {
918  inner_qual_decision = InnerQualDecision::LHS;
919  if (lhs_col && lhs_col->get_rte_idx() == 0) {
920  throw HashJoinFail(
921  "Cannot use hash join for given expression (lhs' rte idx is zero)",
922  inner_qual_decision);
923  }
924  inner_col = lhs_col;
925  outer_col = rhs_col;
926  std::swap(outer_ti, inner_ti);
927  std::swap(outer_string_op_infos, inner_string_op_infos);
928  outer_expr = rhs;
929  }
930  if (!inner_col) {
931  throw HashJoinFail("Cannot use hash join for given expression (invalid inner col)",
932  inner_qual_decision);
933  }
934  if (!outer_col) {
935  // check whether outer_col is a constant, i.e., inner_col = K;
936  const auto outer_constant_col = dynamic_cast<const Analyzer::Constant*>(outer_expr);
937  if (outer_constant_col) {
938  throw HashJoinFail(
939  "Cannot use hash join for given expression: try to join with a constant "
940  "value",
941  inner_qual_decision);
942  }
943  MaxRangeTableIndexVisitor rte_idx_visitor;
944  int outer_rte_idx = rte_idx_visitor.visit(outer_expr);
945  // The inner column candidate is not actually inner; the outer
946  // expression contains columns which are at least as deep.
947  if (inner_col->get_rte_idx() <= outer_rte_idx) {
948  throw HashJoinFail(
949  "Cannot use hash join for given expression (inner's rte <= outer's rte)",
950  inner_qual_decision);
951  }
952  }
953  // We need to fetch the actual type information from the catalog since Analyzer
954  // always reports nullable as true for inner table columns in left joins.
955  const auto& column_key = inner_col->getColumnKey();
956  const auto inner_col_cd = get_column_descriptor_maybe(column_key);
957  const auto inner_col_real_ti = get_column_type(
958  column_key.column_id, column_key.table_id, inner_col_cd, temporary_tables);
959  const auto& outer_col_ti =
960  !(dynamic_cast<const Analyzer::FunctionOper*>(lhs)) && outer_col
961  ? outer_col->get_type_info()
962  : outer_ti;
963  // Casts from decimal are not supported.
964  if ((inner_col_real_ti.is_decimal() || outer_col_ti.is_decimal()) &&
965  (lhs_cast || rhs_cast)) {
966  throw HashJoinFail("Cannot use hash join for given expression (cast from decimal)");
967  }
968  if (is_bbox_intersect) {
969  if (!inner_col_real_ti.is_array()) {
970  throw HashJoinFail(
971  "Bounding box intersection only supported for inner columns with array type");
972  }
973  auto is_bounds_array = [](const auto ti) {
974  return ti.is_fixlen_array() && ti.get_size() == 32;
975  };
976  if (!is_bounds_array(inner_col_real_ti)) {
977  throw HashJoinFail(
978  "Bounding box intersection only supported for 4-element double fixed length "
979  "arrays");
980  }
981  if (!(outer_col_ti.get_type() == kPOINT || is_bounds_array(outer_col_ti) ||
982  is_constructed_point(outer_expr))) {
983  throw HashJoinFail(
984  "Bounding box intersection only supported for geometry outer columns of type "
985  "point, "
986  "geometry columns with bounds or constructed points");
987  }
988  } else {
989  if (!(inner_col_real_ti.is_integer() || inner_col_real_ti.is_time() ||
990  inner_col_real_ti.is_decimal() ||
991  (inner_col_real_ti.is_string() &&
992  inner_col_real_ti.get_compression() == kENCODING_DICT))) {
993  throw HashJoinFail(
994  "Can only apply hash join to integer-like types and dictionary encoded "
995  "strings");
996  }
997  }
998 
999  auto normalized_inner_col = inner_col;
1000  auto normalized_outer_col = outer_col ? outer_col : outer_expr;
1001 
1002  const auto& normalized_inner_ti = normalized_inner_col->get_type_info();
1003  const auto& normalized_outer_ti = normalized_outer_col->get_type_info();
1004 
1005  if (normalized_inner_ti.is_string() != normalized_outer_ti.is_string()) {
1006  throw HashJoinFail(std::string("Could not build hash tables for incompatible types " +
1007  normalized_inner_ti.get_type_name() + " and " +
1008  normalized_outer_ti.get_type_name()));
1009  }
1010  return std::make_pair(std::make_pair(normalized_inner_col, normalized_outer_col),
1011  std::make_pair(inner_string_op_infos, outer_string_op_infos));
1012 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396
bool is_constructed_point(const Analyzer::Expr *expr)
Definition: Execute.h:1699
const SQLTypeInfo get_column_type(const int col_id, const int table_id, const ColumnDescriptor *cd, const TemporaryTables *temporary_tables)
Definition: Execute.h:254
Definition: sqldefs.h:48
T visit(const Analyzer::Expr *expr) const
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
#define CHECK_GT(x, y)
Definition: Logger.h:305
bool is_time() const
Definition: sqltypes.h:577
bool is_integer() const
Definition: sqltypes.h:565
const ColumnDescriptor * get_column_descriptor_maybe(const shared::ColumnKey &column_key)
Definition: Execute.h:241
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
int get_precision() const
Definition: sqltypes.h:394
Expression class for string functions The &quot;arg&quot; constructor parameter must be an expression that reso...
Definition: Analyzer.h:1601
std::string get_type_name() const
Definition: sqltypes.h:482
#define CHECK(condition)
Definition: Logger.h:291
InnerQualDecision
Definition: HashJoin.h:61
bool is_string() const
Definition: sqltypes.h:559
bool is_decimal() const
Definition: sqltypes.h:568
DEVICE void swap(ARGS &&...args)
Definition: gpu_enabled.h:114

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::pair< std::vector< InnerOuter >, std::vector< InnerOuterStringOpInfos > > HashJoin::normalizeColumnPairs ( const Analyzer::BinOper condition,
const TemporaryTables temporary_tables 
)
static

Definition at line 1015 of file HashJoin.cpp.

References CHECK, CHECK_EQ, Analyzer::BinOper::get_left_operand(), Analyzer::BinOper::get_right_operand(), Analyzer::BinOper::is_bbox_intersect_oper(), normalizeColumnPair(), and run_benchmark_import::result.

Referenced by anonymous_namespace{FromTableReordering.cpp}::get_join_qual_cost(), BaselineJoinHashTable::getInstance(), BoundingBoxIntersectJoinHashTable::getInstance(), BaselineJoinHashTable::reifyWithLayout(), and Executor::skipFragmentPair().

1016  {
1017  std::pair<std::vector<InnerOuter>, std::vector<InnerOuterStringOpInfos>> result;
1018  const auto lhs_tuple_expr =
1019  dynamic_cast<const Analyzer::ExpressionTuple*>(condition->get_left_operand());
1020  const auto rhs_tuple_expr =
1021  dynamic_cast<const Analyzer::ExpressionTuple*>(condition->get_right_operand());
1022 
1023  CHECK_EQ(static_cast<bool>(lhs_tuple_expr), static_cast<bool>(rhs_tuple_expr));
1024  if (lhs_tuple_expr) {
1025  const auto& lhs_tuple = lhs_tuple_expr->getTuple();
1026  const auto& rhs_tuple = rhs_tuple_expr->getTuple();
1027  CHECK_EQ(lhs_tuple.size(), rhs_tuple.size());
1028  for (size_t i = 0; i < lhs_tuple.size(); ++i) {
1029  const auto col_pair = normalizeColumnPair(lhs_tuple[i].get(),
1030  rhs_tuple[i].get(),
1031  temporary_tables,
1032  condition->is_bbox_intersect_oper());
1033  result.first.emplace_back(col_pair.first);
1034  result.second.emplace_back(col_pair.second);
1035  }
1036  } else {
1037  CHECK(!lhs_tuple_expr && !rhs_tuple_expr);
1038  const auto col_pair = normalizeColumnPair(condition->get_left_operand(),
1039  condition->get_right_operand(),
1040  temporary_tables,
1041  condition->is_bbox_intersect_oper());
1042  result.first.emplace_back(col_pair.first);
1043  result.second.emplace_back(col_pair.second);
1044  }
1045 
1046  return result;
1047 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const Expr * get_right_operand() const
Definition: Analyzer.h:456
bool is_bbox_intersect_oper() const
Definition: Analyzer.h:453
#define CHECK(condition)
Definition: Logger.h:291
static std::pair< InnerOuter, InnerOuterStringOpInfos > normalizeColumnPair(const Analyzer::Expr *lhs, const Analyzer::Expr *rhs, const TemporaryTables *temporary_tables, const bool is_bbox_intersect=false)
Definition: HashJoin.cpp:822
const Expr * get_left_operand() const
Definition: Analyzer.h:455

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual size_t HashJoin::offsetBufferOff ( ) const
pure virtualnoexcept
virtual size_t HashJoin::payloadBufferOff ( ) const
pure virtualnoexcept
virtual DecodedJoinHashBufferSet HashJoin::toSet ( const ExecutorDeviceType  device_type,
const int  device_id 
) const
pure virtual
virtual std::string HashJoin::toString ( const ExecutorDeviceType  device_type,
const int  device_id = 0,
bool  raw = false 
) const
pure virtual

Implemented in BoundingBoxIntersectJoinHashTable, BaselineJoinHashTable, and PerfectJoinHashTable.

Referenced by generateTooManyHashEntriesErrMsg().

+ Here is the caller graph for this function:

std::string HashJoin::toStringFlat32 ( const ExecutorDeviceType  device_type,
const int  device_id 
) const
virtual

Definition at line 123 of file HashJoin.cpp.

124  {
125  return toStringFlat<int32_t>(this, device_type, device_id);
126 }
std::string HashJoin::toStringFlat64 ( const ExecutorDeviceType  device_type,
const int  device_id 
) const
virtual

Definition at line 118 of file HashJoin.cpp.

119  {
120  return toStringFlat<int64_t>(this, device_type, device_id);
121 }
std::vector< const StringDictionaryProxy::IdMap * > HashJoin::translateCompositeStrDictProxies ( const CompositeKeyInfo composite_key_info,
const std::vector< InnerOuterStringOpInfos > &  string_op_infos_for_keys,
const Executor executor 
)
static

Definition at line 528 of file HashJoin.cpp.

References CHECK, CHECK_EQ, CHECK_NE, CompositeKeyInfo::sd_inner_proxy_per_key, and CompositeKeyInfo::sd_outer_proxy_per_key.

Referenced by BaselineJoinHashTable::reifyWithLayout().

531  {
532  const auto& inner_proxies = composite_key_info.sd_inner_proxy_per_key;
533  const auto& outer_proxies = composite_key_info.sd_outer_proxy_per_key;
534  const size_t num_proxies = inner_proxies.size();
535  CHECK_EQ(num_proxies, outer_proxies.size());
536  std::vector<const StringDictionaryProxy::IdMap*> proxy_translation_maps;
537  proxy_translation_maps.reserve(num_proxies);
538  for (size_t proxy_pair_idx = 0; proxy_pair_idx < num_proxies; ++proxy_pair_idx) {
539  const bool translate_proxies =
540  inner_proxies[proxy_pair_idx] && outer_proxies[proxy_pair_idx];
541  if (translate_proxies) {
542  const auto inner_proxy =
543  reinterpret_cast<const StringDictionaryProxy*>(inner_proxies[proxy_pair_idx]);
544  auto outer_proxy =
545  reinterpret_cast<StringDictionaryProxy*>(outer_proxies[proxy_pair_idx]);
546  CHECK(inner_proxy);
547  CHECK(outer_proxy);
548 
549  CHECK_NE(inner_proxy->getDictKey(), outer_proxy->getDictKey());
550  proxy_translation_maps.emplace_back(
551  executor->getJoinIntersectionStringProxyTranslationMap(
552  inner_proxy,
553  outer_proxy,
554  string_op_infos_for_keys[proxy_pair_idx].first,
555  string_op_infos_for_keys[proxy_pair_idx].second,
556  executor->getRowSetMemoryOwner()));
557  } else {
558  proxy_translation_maps.emplace_back(nullptr);
559  }
560  }
561  return proxy_translation_maps;
562 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< const void * > sd_inner_proxy_per_key
Definition: HashJoin.h:127
std::vector< void * > sd_outer_proxy_per_key
Definition: HashJoin.h:128
#define CHECK_NE(x, y)
Definition: Logger.h:302
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

const StringDictionaryProxy::IdMap * HashJoin::translateInnerToOuterStrDictProxies ( const InnerOuter cols,
const InnerOuterStringOpInfos inner_outer_string_op_infos,
ExpressionRange old_col_range,
const Executor executor 
)
static

Definition at line 423 of file HashJoin.cpp.

References CHECK, ExpressionRange::getIntMax(), ExpressionRange::getIntMin(), getStrDictProxies(), ExpressionRange::hasNulls(), ExpressionRange::makeIntRange(), and StringDictionaryProxy::TranslationMap< T >::size().

Referenced by PerfectJoinHashTable::reify().

427  {
428  const bool has_string_ops = inner_outer_string_op_infos.first.size() ||
429  inner_outer_string_op_infos.second.size();
430  const auto inner_outer_proxies =
431  HashJoin::getStrDictProxies(cols, executor, has_string_ops);
432  const bool translate_dictionary =
433  inner_outer_proxies.first && inner_outer_proxies.second;
434  if (translate_dictionary) {
435  const auto& inner_dict_id = inner_outer_proxies.first->getDictKey();
436  const auto& outer_dict_id = inner_outer_proxies.second->getDictKey();
437  CHECK(has_string_ops || inner_dict_id != outer_dict_id);
438  const auto id_map = executor->getJoinIntersectionStringProxyTranslationMap(
439  inner_outer_proxies.first,
440  inner_outer_proxies.second,
441  inner_outer_string_op_infos.first,
442  inner_outer_string_op_infos.second,
443  executor->getRowSetMemoryOwner());
444  if (!inner_outer_string_op_infos.second.empty()) {
445  // String op was applied to lhs table,
446  // need to expand column range appropriately
447  col_range = ExpressionRange::makeIntRange(
448  std::min(col_range.getIntMin(),
449  static_cast<int64_t>(
450  inner_outer_proxies.second->transientEntryCount() + 1) *
451  -1),
452  col_range.getIntMax(),
453  0,
454  col_range.hasNulls());
455  }
456  return id_map;
457  }
458  return nullptr;
459 }
static std::pair< const StringDictionaryProxy *, StringDictionaryProxy * > getStrDictProxies(const InnerOuter &cols, const Executor *executor, const bool has_string_ops)
Definition: HashJoin.cpp:394
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

constexpr size_t HashJoin::MAX_NUM_HASH_ENTRIES = size_t(1) << 31
static

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