OmniSciDB  ca0c39ec8f
 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 int 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 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, std::string_view table2, std::string_view column2, 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 int 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 int table_id, const size_t shard_count, const Executor *executor)
 
static std::pair< InnerOuter,
InnerOuterStringOpInfos
normalizeColumnPair (const Analyzer::Expr *lhs, const Analyzer::Expr *rhs, const Catalog_Namespace::Catalog &cat, const TemporaryTables *temporary_tables, const bool is_overlaps_join=false)
 
template<typename T >
static const T * getHashJoinColumn (const Analyzer::Expr *expr)
 
static std::pair< std::vector
< InnerOuter >, std::vector
< InnerOuterStringOpInfos > > 
normalizeColumnPairs (const Analyzer::BinOper *condition, const Catalog_Namespace::Catalog &cat, 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

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 124 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 1028 of file HashJoin.cpp.

References g_enable_data_recycler, g_use_hashtable_cache, and INVALID.

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

1030  {
1031  return g_enable_data_recycler && g_use_hashtable_cache && !invalid_cache_key &&
1032  allow_hash_table_recycling && join_type != JoinType::INVALID;
1033 }
bool g_enable_data_recycler
Definition: Execute.cpp:146
bool g_use_hashtable_cache
Definition: Execute.cpp:147

+ Here is the caller graph for this function:

void HashJoin::checkHashJoinReplicationConstraint ( const int  table_id,
const size_t  shard_count,
const Executor executor 
)
static

Definition at line 771 of file HashJoin.cpp.

References CHECK, g_cluster, and table_is_replicated().

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

773  {
774  if (!g_cluster) {
775  return;
776  }
777  if (table_id >= 0) {
778  CHECK(executor);
779  const auto inner_td = executor->getCatalog()->getMetadataForTable(table_id);
780  CHECK(inner_td);
781  if (!shard_count && !table_is_replicated(inner_td)) {
782  throw TableMustBeReplicated(inner_td->tableName);
783  }
784  }
785 }
bool table_is_replicated(const TableDescriptor *td)
#define CHECK(condition)
Definition: Logger.h:222
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 539 of file HashJoin.cpp.

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

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

543  {
544  if (!string_op_infos.empty()) {
545  const auto coerced_col_var =
546  dynamic_cast<const Analyzer::ColumnVar*>(col_or_string_oper);
547  CHECK(coerced_col_var);
548  std::vector<llvm::Value*> codegen_val_vec{
549  code_generator.codegenPseudoStringOper(coerced_col_var, string_op_infos, co)};
550  return codegen_val_vec[0];
551  }
552  return code_generator.codegen(col_or_string_oper, true, co)[0];
553 }
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:222

+ 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 257 of file HashJoin.cpp.

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

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

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

+ 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 OverlapsJoinHashTable, BaselineJoinHashTable, and PerfectJoinHashTable.

Referenced by PerfectJoinHashTable::codegenMatchingSet(), BaselineJoinHashTable::codegenMatchingSet(), OverlapsJoinHashTable::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 206 of file HashJoin.cpp.

References AUTOMATIC_IR_METADATA, and CHECK.

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

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

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

447  {
448  auto const fragment_id = [](auto const& frag_info) { return frag_info.fragmentId; };
449  std::vector<int> frag_ids(fragments.size());
450  std::transform(fragments.cbegin(), fragments.cend(), frag_ids.begin(), fragment_id);
451  std::sort(frag_ids.begin(), frag_ids.end());
452  return frag_ids;
453 }
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:296

+ 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 58 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 OverlapsJoinHashTable::fetchColumnsForDevice(), PerfectJoinHashTable::fetchColumnsForDevice(), and BaselineJoinHashTable::fetchColumnsForDevice().

67  {
68  static std::mutex fragment_fetch_mutex;
69  std::lock_guard<std::mutex> fragment_fetch_lock(fragment_fetch_mutex);
70  try {
71  JoinColumn join_column = ColumnFetcher::makeJoinColumn(executor,
72  *hash_col,
73  fragment_info,
74  effective_memory_level,
75  device_id,
76  dev_buff_owner,
77  /*thread_idx=*/0,
78  chunks_owner,
79  malloc_owner,
80  *column_cache);
81  if (effective_memory_level == Data_Namespace::GPU_LEVEL) {
82  CHECK(dev_buff_owner);
83  auto device_col_chunks_buff = dev_buff_owner->alloc(join_column.col_chunks_buff_sz);
84  dev_buff_owner->copyToDevice(device_col_chunks_buff,
85  join_column.col_chunks_buff,
86  join_column.col_chunks_buff_sz);
87  join_column.col_chunks_buff = device_col_chunks_buff;
88  }
89  return join_column;
90  } catch (...) {
91  throw FailedToFetchColumn();
92  }
93 }
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:222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void HashJoin::freeHashBufferMemory ( )
inline

Definition at line 311 of file HashJoin.h.

References hash_tables_for_device_.

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

311  {
312  auto empty_hash_tables =
314  hash_tables_for_device_.swap(empty_hash_tables);
315  }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:351

+ 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 455 of file HashJoin.cpp.

References CHECK, CHECK_EQ, and kENCODING_DICT.

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

458  {
459  CHECK(executor);
460  std::vector<const void*> sd_inner_proxy_per_key;
461  std::vector<void*> sd_outer_proxy_per_key;
462  std::vector<ChunkKey> cache_key_chunks; // used for the cache key
463  const auto db_id = executor->getCatalog()->getCurrentDB().dbId;
464  const bool has_string_op_infos = inner_outer_string_op_infos_pairs.size();
465  if (has_string_op_infos) {
466  CHECK_EQ(inner_outer_pairs.size(), inner_outer_string_op_infos_pairs.size());
467  }
468  size_t string_op_info_pairs_idx = 0;
469  for (const auto& inner_outer_pair : inner_outer_pairs) {
470  const auto inner_col = inner_outer_pair.first;
471  const auto outer_col = inner_outer_pair.second;
472  const auto& inner_ti = inner_col->get_type_info();
473  const auto& outer_ti = outer_col->get_type_info();
474  ChunkKey cache_key_chunks_for_column{
475  db_id, inner_col->get_table_id(), inner_col->get_column_id()};
476  if (inner_ti.is_string() &&
477  (!(inner_ti.get_comp_param() == outer_ti.get_comp_param()) ||
478  (has_string_op_infos &&
479  (inner_outer_string_op_infos_pairs[string_op_info_pairs_idx].first.size() ||
480  inner_outer_string_op_infos_pairs[string_op_info_pairs_idx].second.size())))) {
481  CHECK(outer_ti.is_string());
482  CHECK(inner_ti.get_compression() == kENCODING_DICT &&
483  outer_ti.get_compression() == kENCODING_DICT);
484  const auto sd_inner_proxy = executor->getStringDictionaryProxy(
485  inner_ti.get_comp_param(), executor->getRowSetMemoryOwner(), true);
486  auto sd_outer_proxy = executor->getStringDictionaryProxy(
487  outer_ti.get_comp_param(), executor->getRowSetMemoryOwner(), true);
488  CHECK(sd_inner_proxy && sd_outer_proxy);
489  sd_inner_proxy_per_key.push_back(sd_inner_proxy);
490  sd_outer_proxy_per_key.push_back(sd_outer_proxy);
491  cache_key_chunks_for_column.push_back(sd_outer_proxy->getGeneration());
492  } else {
493  sd_inner_proxy_per_key.emplace_back();
494  sd_outer_proxy_per_key.emplace_back();
495  }
496  cache_key_chunks.push_back(cache_key_chunks_for_column);
497  string_op_info_pairs_idx++;
498  }
499  return {sd_inner_proxy_per_key, sd_outer_proxy_per_key, cache_key_chunks};
500 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::vector< int > ChunkKey
Definition: types.h:36
#define CHECK(condition)
Definition: Logger.h:222

+ 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 788 of file HashJoin.cpp.

References CHECK, and heavydb.dtypes::T.

788  {
789  auto* target_expr = expr;
790  if (auto cast_expr = dynamic_cast<const Analyzer::UOper*>(expr)) {
791  target_expr = cast_expr->get_operand();
792  }
793  CHECK(target_expr);
794  return dynamic_cast<const T*>(target_expr);
795 }
#define CHECK(condition)
Definition: Logger.h:222
virtual std::string HashJoin::getHashJoinType ( ) const
pure virtual
HashTable* HashJoin::getHashTableForDevice ( const size_t  device_id) const
inline

Definition at line 269 of file HashJoin.h.

References CHECK_LT, and hash_tables_for_device_.

Referenced by OverlapsJoinHashTable::codegenManyKey(), BaselineJoinHashTable::codegenMatchingSet(), BaselineJoinHashTable::codegenSlot(), BaselineJoinHashTable::getComponentBufferSize(), OverlapsJoinHashTable::getEmittedKeysCount(), OverlapsJoinHashTable::getEntryCount(), BaselineJoinHashTable::getHashType(), OverlapsJoinHashTable::getHashType(), getJoinHashBufferSize(), BaselineJoinHashTable::getKeyBufferSize(), BaselineJoinHashTable::toSet(), and OverlapsJoinHashTable::toSet().

269  {
270  CHECK_LT(device_id, hash_tables_for_device_.size());
271  return hash_tables_for_device_[device_id].get();
272  }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:351
#define CHECK_LT(x, y)
Definition: Logger.h:232

+ Here is the caller graph for this function:

virtual HashType HashJoin::getHashType ( ) const
pure virtualnoexcept
static std::string HashJoin::getHashTypeString ( HashType  ht)
inlinestaticnoexcept

Definition at line 154 of file HashJoin.h.

Referenced by BaselineJoinHashTableBuilder::allocateDeviceMemory(), BaselineJoinHashTable::getInstance(), PerfectJoinHashTable::getInstance(), OverlapsJoinHashTable::getInstance(), RangeJoinHashTable::reifyWithLayout(), OverlapsJoinHashTable::reifyWithLayout(), HashingSchemeRecycler::toString(), PerfectJoinHashTable::toString(), BaselineJoinHashTable::toString(), and OverlapsJoinHashTable::toString().

154  {
155  const char* HashTypeStrings[3] = {"OneToOne", "OneToMany", "ManyToMany"};
156  return HashTypeStrings[static_cast<int>(ht)];
157  };

+ Here is the caller graph for this function:

virtual int HashJoin::getInnerTableId ( ) const
pure virtualnoexcept

Implemented in OverlapsJoinHashTable, BaselineJoinHashTable, and PerfectJoinHashTable.

Referenced by OverlapsJoinHashTable::getInnerTableId(), RangeJoinHashTable::getInstance(), OverlapsJoinHashTable::getInstance(), RangeJoinHashTable::reifyWithLayout(), and OverlapsJoinHashTable::reifyWithLayout().

+ Here is the caller graph for this function:

static int HashJoin::getInnerTableId ( const std::vector< InnerOuter > &  inner_outer_pairs)
inlinestatic

Definition at line 238 of file HashJoin.h.

References CHECK.

238  {
239  CHECK(!inner_outer_pairs.empty());
240  const auto first_inner_col = inner_outer_pairs.front().first;
241  return first_inner_col->get_table_id();
242  }
#define CHECK(condition)
Definition: Logger.h:222
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 283 of file HashJoin.cpp.

References CHECK, CHECK_EQ, CHECK_GT, coalesce_singleton_equi_join(), CPU, DEBUG_TIMER, g_enable_overlaps_hashjoin, BaselineJoinHashTable::getInstance(), PerfectJoinHashTable::getInstance(), OverlapsJoinHashTable::getInstance(), GPU, Data_Namespace::GPU_LEVEL, VLOG, and VLOGGING.

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

294  {
295  auto timer = DEBUG_TIMER(__func__);
296  std::shared_ptr<HashJoin> join_hash_table;
297  CHECK_GT(device_count, 0);
298  if (!g_enable_overlaps_hashjoin && qual_bin_oper->is_overlaps_oper()) {
299  throw std::runtime_error(
300  "Overlaps hash join disabled, attempting to fall back to loop join");
301  }
302  if (qual_bin_oper->is_overlaps_oper()) {
303  VLOG(1) << "Trying to build geo hash table:";
304  join_hash_table = OverlapsJoinHashTable::getInstance(qual_bin_oper,
305  query_infos,
306  memory_level,
307  join_type,
308  device_count,
309  column_cache,
310  executor,
311  hashtable_build_dag_map,
312  query_hint,
313  table_id_to_node_map);
314  } else if (dynamic_cast<const Analyzer::ExpressionTuple*>(
315  qual_bin_oper->get_left_operand())) {
316  VLOG(1) << "Trying to build keyed hash table:";
317  join_hash_table = BaselineJoinHashTable::getInstance(qual_bin_oper,
318  query_infos,
319  memory_level,
320  join_type,
321  preferred_hash_type,
322  device_count,
323  column_cache,
324  executor,
325  hashtable_build_dag_map,
326  table_id_to_node_map);
327  } else {
328  try {
329  VLOG(1) << "Trying to build perfect hash table:";
330  join_hash_table = PerfectJoinHashTable::getInstance(qual_bin_oper,
331  query_infos,
332  memory_level,
333  join_type,
334  preferred_hash_type,
335  device_count,
336  column_cache,
337  executor,
338  hashtable_build_dag_map,
339  table_id_to_node_map);
340  } catch (TooManyHashEntries&) {
341  const auto join_quals = coalesce_singleton_equi_join(qual_bin_oper);
342  CHECK_EQ(join_quals.size(), size_t(1));
343  const auto join_qual =
344  std::dynamic_pointer_cast<Analyzer::BinOper>(join_quals.front());
345  VLOG(1) << "Trying to build keyed hash table after perfect hash table:";
346  join_hash_table = BaselineJoinHashTable::getInstance(join_qual,
347  query_infos,
348  memory_level,
349  join_type,
350  preferred_hash_type,
351  device_count,
352  column_cache,
353  executor,
354  hashtable_build_dag_map,
355  table_id_to_node_map);
356  }
357  }
358  CHECK(join_hash_table);
359  if (VLOGGING(2)) {
360  if (join_hash_table->getMemoryLevel() == Data_Namespace::MemoryLevel::GPU_LEVEL) {
361  for (int device_id = 0; device_id < join_hash_table->getDeviceCount();
362  ++device_id) {
363  if (join_hash_table->getJoinHashBufferSize(ExecutorDeviceType::GPU, device_id) <=
364  1000) {
365  VLOG(2) << "Built GPU hash table: "
366  << join_hash_table->toString(ExecutorDeviceType::GPU, device_id);
367  }
368  }
369  } else {
370  if (join_hash_table->getJoinHashBufferSize(ExecutorDeviceType::CPU) <= 1000) {
371  VLOG(2) << "Built CPU hash table: "
372  << join_hash_table->toString(ExecutorDeviceType::CPU);
373  }
374  }
375  }
376  return join_hash_table;
377 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::list< std::shared_ptr< Analyzer::Expr > > coalesce_singleton_equi_join(const std::shared_ptr< Analyzer::BinOper > &join_qual)
static std::shared_ptr< OverlapsJoinHashTable > getInstance(const std::shared_ptr< Analyzer::BinOper > condition, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, const JoinType join_type, const int device_count, ColumnCacheMap &column_cache, Executor *executor, const HashTableBuildDagMap &hashtable_build_dag_map, const RegisteredQueryHint &query_hint, const TableIdToNodeMap &table_id_to_node_map)
Make hash table from an in-flight SQL query&#39;s parse tree etc.
#define CHECK_GT(x, y)
Definition: Logger.h:234
bool g_enable_overlaps_hashjoin
Definition: Execute.cpp:102
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 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:220
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 TableIdToNodeMap &table_id_to_node_map)
Make hash table from an in-flight SQL query&#39;s parse tree etc.
#define CHECK(condition)
Definition: Logger.h:222
#define DEBUG_TIMER(name)
Definition: Logger.h:371
#define VLOG(n)
Definition: Logger.h:316

+ 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 288 of file HashJoin.h.

References CHECK, CHECK_LT, CPU, and hash_tables_for_device_.

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

289  {
290  // TODO: just make device_id a size_t
291  CHECK_LT(size_t(device_id), hash_tables_for_device_.size());
292  if (!hash_tables_for_device_[device_id]) {
293  return nullptr;
294  }
295  CHECK(hash_tables_for_device_[device_id]);
296  auto hash_table = hash_tables_for_device_[device_id].get();
297 #ifdef HAVE_CUDA
298  if (device_type == ExecutorDeviceType::CPU) {
299  return hash_table->getCpuBuffer();
300  } else {
301  CHECK(hash_table);
302  const auto gpu_buff = hash_table->getGpuBuffer();
303  return gpu_buff;
304  }
305 #else
306  CHECK(device_type == ExecutorDeviceType::CPU);
307  return hash_table->getCpuBuffer();
308 #endif
309  }
std::vector< std::shared_ptr< HashTable > > hash_tables_for_device_
Definition: HashJoin.h:351
#define CHECK_LT(x, y)
Definition: Logger.h:232
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

size_t HashJoin::getJoinHashBufferSize ( const ExecutorDeviceType  device_type)
inline

Definition at line 274 of file HashJoin.h.

References CHECK, and CPU.

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

274  {
275  CHECK(device_type == ExecutorDeviceType::CPU);
276  return getJoinHashBufferSize(device_type, 0);
277  }
size_t getJoinHashBufferSize(const ExecutorDeviceType device_type)
Definition: HashJoin.h:274
#define CHECK(condition)
Definition: Logger.h:222

+ 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 279 of file HashJoin.h.

References getHashTableForDevice().

280  {
281  auto hash_table = getHashTableForDevice(device_id);
282  if (!hash_table) {
283  return 0;
284  }
285  return hash_table->getHashTableBufferSize(device_type);
286  }
HashTable * getHashTableForDevice(const size_t device_id) const
Definition: HashJoin.h:269

+ Here is the call 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 380 of file HashJoin.cpp.

References CHECK.

Referenced by translateInnerToOuterStrDictProxies().

382  {
383  const auto inner_col = cols.first;
384  CHECK(inner_col);
385  const auto inner_ti = inner_col->get_type_info();
386  const auto outer_col = dynamic_cast<const Analyzer::ColumnVar*>(cols.second);
387  std::pair<const StringDictionaryProxy*, StringDictionaryProxy*>
388  inner_outer_str_dict_proxies{nullptr, nullptr};
389  if (inner_ti.is_string() && outer_col) {
390  CHECK(outer_col->get_type_info().is_string());
391  inner_outer_str_dict_proxies.first =
392  executor->getStringDictionaryProxy(inner_col->get_comp_param(), true);
393  CHECK(inner_outer_str_dict_proxies.first);
394  inner_outer_str_dict_proxies.second =
395  executor->getStringDictionaryProxy(outer_col->get_comp_param(), true);
396  CHECK(inner_outer_str_dict_proxies.second);
397  if (!has_string_ops &&
398  *inner_outer_str_dict_proxies.first == *inner_outer_str_dict_proxies.second) {
399  // Dictionaries are the same - don't need to translate
400  CHECK(inner_col->get_comp_param() == outer_col->get_comp_param());
401  inner_outer_str_dict_proxies.first = nullptr;
402  inner_outer_str_dict_proxies.second = nullptr;
403  }
404  }
405  return inner_outer_str_dict_proxies;
406 }
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

std::shared_ptr< HashJoin > HashJoin::getSyntheticInstance ( std::string_view  table1,
std::string_view  column1,
std::string_view  table2,
std::string_view  column2,
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 667 of file HashJoin.cpp.

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

676  {
677  auto a1 = getSyntheticColumnVar(table1, column1, 0, executor);
678  auto a2 = getSyntheticColumnVar(table2, column2, 1, executor);
679 
680  auto qual_bin_oper = std::make_shared<Analyzer::BinOper>(kBOOLEAN, kEQ, kONE, a1, a2);
681 
682  std::set<const Analyzer::ColumnVar*> cvs =
683  AllColumnVarsVisitor().visit(qual_bin_oper.get());
684  auto query_infos = getSyntheticInputTableInfo(cvs, executor);
685  setupSyntheticCaching(cvs, executor);
687 
688  auto hash_table = HashJoin::getInstance(qual_bin_oper,
689  query_infos,
690  memory_level,
692  preferred_hash_type,
693  device_count,
694  column_cache,
695  executor,
696  {},
697  query_hint,
698  {});
699  return hash_table;
700 }
std::vector< InputTableInfo > getSyntheticInputTableInfo(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:640
Definition: sqldefs.h:29
T visit(const Analyzer::Expr *expr) const
void setupSyntheticCaching(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:626
static RegisteredQueryHint defaults()
Definition: QueryHint.h:269
Definition: sqldefs.h:70
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:283
std::shared_ptr< Analyzer::ColumnVar > getSyntheticColumnVar(std::string_view table, std::string_view column, int rte_idx, Executor *executor)
Definition: HashJoin.cpp:555

+ 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 703 of file HashJoin.cpp.

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

709  {
710  std::set<const Analyzer::ColumnVar*> cvs =
711  AllColumnVarsVisitor().visit(qual_bin_oper.get());
712  auto query_infos = getSyntheticInputTableInfo(cvs, executor);
713  setupSyntheticCaching(cvs, executor);
715 
716  auto hash_table = HashJoin::getInstance(qual_bin_oper,
717  query_infos,
718  memory_level,
720  preferred_hash_type,
721  device_count,
722  column_cache,
723  executor,
724  {},
725  query_hint,
726  {});
727  return hash_table;
728 }
std::vector< InputTableInfo > getSyntheticInputTableInfo(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:640
T visit(const Analyzer::Expr *expr) const
void setupSyntheticCaching(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:626
static RegisteredQueryHint defaults()
Definition: QueryHint.h:269
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:283

+ 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 730 of file HashJoin.cpp.

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

736  {
737  std::set<const Analyzer::ColumnVar*> cvs;
738  for (auto& qual : qual_bin_opers) {
739  auto cv = AllColumnVarsVisitor().visit(qual.get());
740  cvs.insert(cv.begin(), cv.end());
741  }
742  auto query_infos = getSyntheticInputTableInfo(cvs, executor);
743  setupSyntheticCaching(cvs, executor);
745  std::shared_ptr<HashJoin> hash_table;
746  std::string error_msg;
747  for (auto& qual : qual_bin_opers) {
748  try {
749  auto candidate_hash_table = HashJoin::getInstance(qual,
750  query_infos,
751  memory_level,
753  preferred_hash_type,
754  device_count,
755  column_cache,
756  executor,
757  {},
758  query_hint,
759  {});
760  if (candidate_hash_table) {
761  hash_table = candidate_hash_table;
762  }
763  } catch (HashJoinFail& e) {
764  error_msg = e.what();
765  continue;
766  }
767  }
768  return std::make_pair(error_msg, hash_table);
769 }
std::vector< InputTableInfo > getSyntheticInputTableInfo(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:640
T visit(const Analyzer::Expr *expr) const
void setupSyntheticCaching(std::set< const Analyzer::ColumnVar * > cvs, Executor *executor)
Definition: HashJoin.cpp:626
static RegisteredQueryHint defaults()
Definition: QueryHint.h:269
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:283

+ 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 Catalog_Namespace::Catalog cat,
const TemporaryTables temporary_tables,
const bool  is_overlaps_join = false 
)
static

Definition at line 797 of file HashJoin.cpp.

References cat(), 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().

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

Definition at line 991 of file HashJoin.cpp.

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

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

993  {
994  std::pair<std::vector<InnerOuter>, std::vector<InnerOuterStringOpInfos>> result;
995  const auto lhs_tuple_expr =
996  dynamic_cast<const Analyzer::ExpressionTuple*>(condition->get_left_operand());
997  const auto rhs_tuple_expr =
998  dynamic_cast<const Analyzer::ExpressionTuple*>(condition->get_right_operand());
999 
1000  CHECK_EQ(static_cast<bool>(lhs_tuple_expr), static_cast<bool>(rhs_tuple_expr));
1001  if (lhs_tuple_expr) {
1002  const auto& lhs_tuple = lhs_tuple_expr->getTuple();
1003  const auto& rhs_tuple = rhs_tuple_expr->getTuple();
1004  CHECK_EQ(lhs_tuple.size(), rhs_tuple.size());
1005  for (size_t i = 0; i < lhs_tuple.size(); ++i) {
1006  const auto col_pair = normalizeColumnPair(lhs_tuple[i].get(),
1007  rhs_tuple[i].get(),
1008  cat,
1009  temporary_tables,
1010  condition->is_overlaps_oper());
1011  result.first.emplace_back(col_pair.first);
1012  result.second.emplace_back(col_pair.second);
1013  }
1014  } else {
1015  CHECK(!lhs_tuple_expr && !rhs_tuple_expr);
1016  const auto col_pair = normalizeColumnPair(condition->get_left_operand(),
1017  condition->get_right_operand(),
1018  cat,
1019  temporary_tables,
1020  condition->is_overlaps_oper());
1021  result.first.emplace_back(col_pair.first);
1022  result.second.emplace_back(col_pair.second);
1023  }
1024 
1025  return result;
1026 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::string cat(Ts &&...args)
const Expr * get_right_operand() const
Definition: Analyzer.h:451
static std::pair< InnerOuter, InnerOuterStringOpInfos > normalizeColumnPair(const Analyzer::Expr *lhs, const Analyzer::Expr *rhs, const Catalog_Namespace::Catalog &cat, const TemporaryTables *temporary_tables, const bool is_overlaps_join=false)
Definition: HashJoin.cpp:797
#define CHECK(condition)
Definition: Logger.h:222
const Expr * get_left_operand() const
Definition: Analyzer.h:450
bool is_overlaps_oper() const
Definition: Analyzer.h:448

+ 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
std::string HashJoin::toStringFlat32 ( const ExecutorDeviceType  device_type,
const int  device_id 
) const
virtual

Definition at line 121 of file HashJoin.cpp.

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

Definition at line 116 of file HashJoin.cpp.

117  {
118  return toStringFlat<int64_t>(this, device_type, device_id);
119 }
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 503 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().

506  {
507  const auto& inner_proxies = composite_key_info.sd_inner_proxy_per_key;
508  const auto& outer_proxies = composite_key_info.sd_outer_proxy_per_key;
509  const size_t num_proxies = inner_proxies.size();
510  CHECK_EQ(num_proxies, outer_proxies.size());
511  std::vector<const StringDictionaryProxy::IdMap*> proxy_translation_maps;
512  proxy_translation_maps.reserve(num_proxies);
513  for (size_t proxy_pair_idx = 0; proxy_pair_idx < num_proxies; ++proxy_pair_idx) {
514  const bool translate_proxies =
515  inner_proxies[proxy_pair_idx] && outer_proxies[proxy_pair_idx];
516  if (translate_proxies) {
517  const auto inner_proxy =
518  reinterpret_cast<const StringDictionaryProxy*>(inner_proxies[proxy_pair_idx]);
519  auto outer_proxy =
520  reinterpret_cast<StringDictionaryProxy*>(outer_proxies[proxy_pair_idx]);
521  CHECK(inner_proxy);
522  CHECK(outer_proxy);
523 
524  CHECK_NE(inner_proxy->getDictId(), outer_proxy->getDictId());
525  proxy_translation_maps.emplace_back(
526  executor->getJoinIntersectionStringProxyTranslationMap(
527  inner_proxy,
528  outer_proxy,
529  string_op_infos_for_keys[proxy_pair_idx].first,
530  string_op_infos_for_keys[proxy_pair_idx].second,
531  executor->getRowSetMemoryOwner()));
532  } else {
533  proxy_translation_maps.emplace_back(nullptr);
534  }
535  }
536  return proxy_translation_maps;
537 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::vector< const void * > sd_inner_proxy_per_key
Definition: HashJoin.h:117
std::vector< void * > sd_outer_proxy_per_key
Definition: HashJoin.h:118
#define CHECK_NE(x, y)
Definition: Logger.h:231
#define CHECK(condition)
Definition: Logger.h:222

+ 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 408 of file HashJoin.cpp.

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

Referenced by PerfectJoinHashTable::reify().

412  {
413  const bool has_string_ops = inner_outer_string_op_infos.first.size() ||
414  inner_outer_string_op_infos.second.size();
415  const auto inner_outer_proxies =
416  HashJoin::getStrDictProxies(cols, executor, has_string_ops);
417  const bool translate_dictionary =
418  inner_outer_proxies.first && inner_outer_proxies.second;
419  if (translate_dictionary) {
420  const auto inner_dict_id = inner_outer_proxies.first->getDictId();
421  const auto outer_dict_id = inner_outer_proxies.second->getDictId();
422  CHECK(has_string_ops || inner_dict_id != outer_dict_id);
423  const auto id_map = executor->getJoinIntersectionStringProxyTranslationMap(
424  inner_outer_proxies.first,
425  inner_outer_proxies.second,
426  inner_outer_string_op_infos.first,
427  inner_outer_string_op_infos.second,
428  executor->getRowSetMemoryOwner());
429  if (!inner_outer_string_op_infos.second.empty()) {
430  // String op was applied to lhs table,
431  // need to expand column range appropriately
432  col_range = ExpressionRange::makeIntRange(
433  std::min(col_range.getIntMin(),
434  static_cast<int64_t>(
435  inner_outer_proxies.second->transientEntryCount() + 1) *
436  -1),
437  col_range.getIntMax(),
438  0,
439  col_range.hasNulls());
440  }
441  return id_map;
442  }
443  return nullptr;
444 }
static std::pair< const StringDictionaryProxy *, StringDictionaryProxy * > getStrDictProxies(const InnerOuter &cols, const Executor *executor, const bool has_string_ops)
Definition: HashJoin.cpp:380
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:222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation


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