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

#include <RelAlgDagBuilder.h>

+ Inheritance diagram for RelLeftDeepInnerJoin:
+ Collaboration diagram for RelLeftDeepInnerJoin:

Public Member Functions

 RelLeftDeepInnerJoin (const std::shared_ptr< RelFilter > &filter, RelAlgInputs inputs, std::vector< std::shared_ptr< const RelJoin >> &original_joins)
 
const RexScalargetInnerCondition () const
 
const RexScalargetOuterCondition (const size_t nesting_level) const
 
const JoinType getJoinType (const size_t nesting_level) const
 
std::string toString () const override
 
size_t toHash () const override
 
size_t size () const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
bool coversOriginalNode (const RelAlgNode *node) const
 
const RelFiltergetOriginalFilter () const
 
std::vector< std::shared_ptr
< const RelJoin > > 
getOriginalJoins () const
 
- Public Member Functions inherited from RelAlgNode
 RelAlgNode (RelAlgInputs inputs={})
 
virtual ~RelAlgNode ()
 
void resetQueryExecutionState ()
 
void setContextData (const void *context_data) const
 
void setOutputMetainfo (const std::vector< TargetMetaInfo > &targets_metainfo) const
 
const std::vector
< TargetMetaInfo > & 
getOutputMetainfo () const
 
unsigned getId () const
 
bool hasContextData () const
 
const void * getContextData () const
 
const size_t inputCount () const
 
const RelAlgNodegetInput (const size_t idx) const
 
std::shared_ptr< const RelAlgNodegetAndOwnInput (const size_t idx) const
 
void addManagedInput (std::shared_ptr< const RelAlgNode > input)
 
bool hasInput (const RelAlgNode *needle) const
 
virtual void replaceInput (std::shared_ptr< const RelAlgNode > old_input, std::shared_ptr< const RelAlgNode > input)
 
void setRelNodeDagId (const size_t id) const
 
size_t getRelNodeDagId () const
 
bool isNop () const
 
void markAsNop ()
 
void clearContextData () const
 

Private Attributes

std::unique_ptr< const RexScalarcondition_
 
std::vector< std::unique_ptr
< const RexScalar > > 
outer_conditions_per_level_
 
const std::shared_ptr< RelFilteroriginal_filter_
 
const std::vector
< std::shared_ptr< const
RelJoin > > 
original_joins_
 

Additional Inherited Members

- Static Public Member Functions inherited from RelAlgNode
static void resetRelAlgFirstId () noexcept
 
- Protected Attributes inherited from RelAlgNode
RelAlgInputs inputs_
 
const unsigned id_
 
std::optional< size_t > hash_
 

Detailed Description

Definition at line 1484 of file RelAlgDagBuilder.h.

Constructor & Destructor Documentation

RelLeftDeepInnerJoin::RelLeftDeepInnerJoin ( const std::shared_ptr< RelFilter > &  filter,
RelAlgInputs  inputs,
std::vector< std::shared_ptr< const RelJoin >> &  original_joins 
)

Definition at line 24 of file RelLeftDeepInnerJoin.cpp.

References RelAlgNode::addManagedInput(), ANTI, CHECK, condition_, INNER, kAND, kBOOLEAN, LEFT, outer_conditions_per_level_, and SEMI.

Referenced by toHash().

28  : condition_(filter ? filter->getAndReleaseCondition() : nullptr)
29  , original_filter_(filter)
30  , original_joins_(original_joins) {
31  std::vector<std::unique_ptr<const RexScalar>> operands;
32  bool is_notnull = true;
33  // Accumulate join conditions from the (explicit) joins themselves and
34  // from the filter node at the root of the left-deep tree pattern.
35  outer_conditions_per_level_.resize(original_joins.size());
36  for (size_t nesting_level = 0; nesting_level < original_joins.size(); ++nesting_level) {
37  const auto& original_join = original_joins[nesting_level];
38  const auto condition_true =
39  dynamic_cast<const RexLiteral*>(original_join->getCondition());
40  if (!condition_true || !condition_true->getVal<bool>()) {
41  if (dynamic_cast<const RexOperator*>(original_join->getCondition())) {
42  is_notnull =
43  is_notnull && dynamic_cast<const RexOperator*>(original_join->getCondition())
44  ->getType()
45  .get_notnull();
46  }
47  switch (original_join->getJoinType()) {
48  case JoinType::INNER:
49  case JoinType::SEMI:
50  case JoinType::ANTI: {
51  if (original_join->getCondition()) {
52  operands.emplace_back(original_join->getAndReleaseCondition());
53  }
54  break;
55  }
56  case JoinType::LEFT: {
57  if (original_join->getCondition()) {
58  outer_conditions_per_level_[nesting_level].reset(
59  original_join->getAndReleaseCondition());
60  }
61  break;
62  }
63  default:
64  CHECK(false);
65  }
66  }
67  }
68  if (!operands.empty()) {
69  if (condition_) {
70  CHECK(dynamic_cast<const RexOperator*>(condition_.get()));
71  is_notnull =
72  is_notnull &&
73  static_cast<const RexOperator*>(condition_.get())->getType().get_notnull();
74  operands.emplace_back(std::move(condition_));
75  }
76  if (operands.size() > 1) {
77  condition_.reset(
78  new RexOperator(kAND, operands, SQLTypeInfo(kBOOLEAN, is_notnull)));
79  } else {
80  condition_ = std::move(operands.front());
81  }
82  }
83  if (!condition_) {
84  condition_.reset(new RexLiteral(true, kBOOLEAN, kBOOLEAN, 0, 0, 0, 0));
85  }
86  for (const auto& input : inputs) {
87  addManagedInput(input);
88  }
89 }
std::vector< std::unique_ptr< const RexScalar > > outer_conditions_per_level_
void addManagedInput(std::shared_ptr< const RelAlgNode > input)
const std::vector< std::shared_ptr< const RelJoin > > original_joins_
Definition: sqldefs.h:37
std::unique_ptr< const RexScalar > condition_
#define CHECK(condition)
Definition: Logger.h:209
const std::shared_ptr< RelFilter > original_filter_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Function Documentation

bool RelLeftDeepInnerJoin::coversOriginalNode ( const RelAlgNode node) const

Definition at line 145 of file RelLeftDeepInnerJoin.cpp.

References original_filter_, and original_joins_.

145  {
146  if (node == original_filter_.get()) {
147  return true;
148  }
149  for (const auto& original_join : original_joins_) {
150  if (original_join.get() == node) {
151  return true;
152  }
153  }
154  return false;
155 }
const std::vector< std::shared_ptr< const RelJoin > > original_joins_
const std::shared_ptr< RelFilter > original_filter_
std::shared_ptr< RelAlgNode > RelLeftDeepInnerJoin::deepCopy ( ) const
overridevirtual

Implements RelAlgNode.

Definition at line 140 of file RelLeftDeepInnerJoin.cpp.

References CHECK.

140  {
141  CHECK(false);
142  return nullptr;
143 }
#define CHECK(condition)
Definition: Logger.h:209
const RexScalar * RelLeftDeepInnerJoin::getInnerCondition ( ) const

Definition at line 91 of file RelLeftDeepInnerJoin.cpp.

References condition_.

Referenced by RelAlgExecutor::translateLeftDeepJoinFilter(), RelRexDagVisitor::visit(), and anonymous_namespace{QueryPhysicalInputsCollector.cpp}::RelAlgPhysicalInputsVisitor::visitLeftDeepInnerJoin().

91  {
92  return condition_.get();
93 }
std::unique_ptr< const RexScalar > condition_

+ Here is the caller graph for this function:

const JoinType RelLeftDeepInnerJoin::getJoinType ( const size_t  nesting_level) const

Definition at line 105 of file RelLeftDeepInnerJoin.cpp.

References CHECK_LE, and original_joins_.

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::left_deep_join_types().

105  {
106  CHECK_LE(nesting_level, original_joins_.size());
107  return original_joins_[original_joins_.size() - nesting_level]->getJoinType();
108 }
const std::vector< std::shared_ptr< const RelJoin > > original_joins_
#define CHECK_LE(x, y)
Definition: Logger.h:220

+ Here is the caller graph for this function:

const RelFilter * RelLeftDeepInnerJoin::getOriginalFilter ( ) const

Definition at line 157 of file RelLeftDeepInnerJoin.cpp.

References original_filter_.

157  {
158  return original_filter_.get();
159 }
const std::shared_ptr< RelFilter > original_filter_
std::vector< std::shared_ptr< const RelJoin > > RelLeftDeepInnerJoin::getOriginalJoins ( ) const

Definition at line 161 of file RelLeftDeepInnerJoin.cpp.

References original_joins_.

162  {
163  std::vector<std::shared_ptr<const RelJoin>> original_joins;
164  original_joins.assign(original_joins_.begin(), original_joins_.end());
165  return original_joins;
166 }
const std::vector< std::shared_ptr< const RelJoin > > original_joins_
const RexScalar * RelLeftDeepInnerJoin::getOuterCondition ( const size_t  nesting_level) const

Definition at line 95 of file RelLeftDeepInnerJoin.cpp.

References CHECK_GE, CHECK_LE, and outer_conditions_per_level_.

Referenced by QueryPlanDagExtractor::handleLeftDeepJoinTree(), anonymous_namespace{RelAlgExecutor.cpp}::left_deep_join_types(), RelAlgExecutor::translateLeftDeepJoinFilter(), RelRexDagVisitor::visit(), and anonymous_namespace{QueryPhysicalInputsCollector.cpp}::RelAlgPhysicalInputsVisitor::visitLeftDeepInnerJoin().

96  {
97  CHECK_GE(nesting_level, size_t(1));
98  CHECK_LE(nesting_level, outer_conditions_per_level_.size());
99  // Outer join conditions are collected depth-first while the returned condition
100  // must be consistent with the order of the loops (which is reverse depth-first).
101  return outer_conditions_per_level_[outer_conditions_per_level_.size() - nesting_level]
102  .get();
103 }
std::vector< std::unique_ptr< const RexScalar > > outer_conditions_per_level_
#define CHECK_GE(x, y)
Definition: Logger.h:222
#define CHECK_LE(x, y)
Definition: Logger.h:220

+ Here is the caller graph for this function:

size_t RelLeftDeepInnerJoin::size ( ) const
overridevirtual

Implements RelAlgNode.

Definition at line 132 of file RelLeftDeepInnerJoin.cpp.

References RelAlgNode::inputs_.

132  {
133  size_t total_size = 0;
134  for (const auto& input : inputs_) {
135  total_size += input->size();
136  }
137  return total_size;
138 }
RelAlgInputs inputs_
size_t RelLeftDeepInnerJoin::toHash ( ) const
overridevirtual

Implements RelAlgNode.

Definition at line 120 of file RelLeftDeepInnerJoin.cpp.

References condition_, RelAlgNode::hash_, RelAlgNode::inputs_, and RelLeftDeepInnerJoin().

120  {
121  if (!hash_) {
122  hash_ = typeid(RelLeftDeepInnerJoin).hash_code();
123  boost::hash_combine(*hash_,
124  condition_ ? condition_->toHash() : boost::hash_value("n"));
125  for (auto& node : inputs_) {
126  boost::hash_combine(*hash_, node->toHash());
127  }
128  }
129  return *hash_;
130 }
std::optional< size_t > hash_
std::unique_ptr< const RexScalar > condition_
RelLeftDeepInnerJoin(const std::shared_ptr< RelFilter > &filter, RelAlgInputs inputs, std::vector< std::shared_ptr< const RelJoin >> &original_joins)
RelAlgInputs inputs_

+ Here is the call graph for this function:

std::string RelLeftDeepInnerJoin::toString ( ) const
overridevirtual

Implements RelAlgNode.

Definition at line 110 of file RelLeftDeepInnerJoin.cpp.

References condition_, RelAlgNode::inputs_, and typeName().

110  {
111  std::string ret = ::typeName(this) + "(";
112  ret += ::toString(condition_);
113  for (const auto& input : inputs_) {
114  ret += " " + ::toString(input);
115  }
116  ret += ")";
117  return ret;
118 }
std::string toString() const override
std::string typeName(const T *v)
Definition: toString.h:88
std::unique_ptr< const RexScalar > condition_
RelAlgInputs inputs_

+ Here is the call graph for this function:

Member Data Documentation

std::unique_ptr<const RexScalar> RelLeftDeepInnerJoin::condition_
private

Definition at line 1511 of file RelAlgDagBuilder.h.

Referenced by getInnerCondition(), RelLeftDeepInnerJoin(), toHash(), and toString().

const std::shared_ptr<RelFilter> RelLeftDeepInnerJoin::original_filter_
private

Definition at line 1513 of file RelAlgDagBuilder.h.

Referenced by coversOriginalNode(), and getOriginalFilter().

const std::vector<std::shared_ptr<const RelJoin> > RelLeftDeepInnerJoin::original_joins_
private

Definition at line 1514 of file RelAlgDagBuilder.h.

Referenced by coversOriginalNode(), getJoinType(), and getOriginalJoins().

std::vector<std::unique_ptr<const RexScalar> > RelLeftDeepInnerJoin::outer_conditions_per_level_
private

Definition at line 1512 of file RelAlgDagBuilder.h.

Referenced by getOuterCondition(), and RelLeftDeepInnerJoin().


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