OmniSciDB  085a039ca4
 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 (RelRexToStringConfig config=RelRexToStringConfig::defaults()) 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 RaExecutionDesc *context_data) const
 
void setOutputMetainfo (const std::vector< TargetMetaInfo > &targets_metainfo) const
 
void setQueryPlanDag (const std::string &extracted_query_plan_dag) const
 
std::string getQueryPlanDag () const
 
size_t getQueryPlanDagHash () const
 
const std::vector
< TargetMetaInfo > & 
getOutputMetainfo () const
 
unsigned getId () const
 
void setIdInPlanTree (size_t id) const
 
std::optional< size_t > getIdInPlanTree () const
 
bool hasContextData () const
 
const RaExecutionDescgetContextData () 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 > id_in_plan_tree_
 
std::optional< size_t > hash_
 

Detailed Description

Definition at line 1578 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:223
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 156 of file RelLeftDeepInnerJoin.cpp.

References original_filter_, and original_joins_.

156  {
157  if (node == original_filter_.get()) {
158  return true;
159  }
160  for (const auto& original_join : original_joins_) {
161  if (original_join.get() == node) {
162  return true;
163  }
164  }
165  return false;
166 }
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 151 of file RelLeftDeepInnerJoin.cpp.

References CHECK.

151  {
152  CHECK(false);
153  return nullptr;
154 }
#define CHECK(condition)
Definition: Logger.h:223
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:234

+ Here is the caller graph for this function:

const RelFilter * RelLeftDeepInnerJoin::getOriginalFilter ( ) const

Definition at line 168 of file RelLeftDeepInnerJoin.cpp.

References original_filter_.

168  {
169  return original_filter_.get();
170 }
const std::shared_ptr< RelFilter > original_filter_
std::vector< std::shared_ptr< const RelJoin > > RelLeftDeepInnerJoin::getOriginalJoins ( ) const

Definition at line 172 of file RelLeftDeepInnerJoin.cpp.

References original_joins_.

173  {
174  std::vector<std::shared_ptr<const RelJoin>> original_joins;
175  original_joins.assign(original_joins_.begin(), original_joins_.end());
176  return original_joins;
177 }
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:236
#define CHECK_LE(x, y)
Definition: Logger.h:234

+ Here is the caller graph for this function:

size_t RelLeftDeepInnerJoin::size ( ) const
overridevirtual

Implements RelAlgNode.

Definition at line 143 of file RelLeftDeepInnerJoin.cpp.

References RelAlgNode::inputs_.

143  {
144  size_t total_size = 0;
145  for (const auto& input : inputs_) {
146  total_size += input->size();
147  }
148  return total_size;
149 }
RelAlgInputs inputs_
size_t RelLeftDeepInnerJoin::toHash ( ) const
overridevirtual

Implements RelAlgNode.

Definition at line 128 of file RelLeftDeepInnerJoin.cpp.

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

128  {
129  if (!hash_) {
130  hash_ = typeid(RelLeftDeepInnerJoin).hash_code();
131  boost::hash_combine(*hash_, condition_ ? condition_->toHash() : HASH_N);
132  for (auto& expr : outer_conditions_per_level_) {
133  boost::hash_combine(*hash_, expr ? expr->toHash() : HASH_N);
134  }
135  boost::hash_combine(*hash_, original_filter_ ? original_filter_->toHash() : HASH_N);
136  for (auto& node : inputs_) {
137  boost::hash_combine(*hash_, node->toHash());
138  }
139  }
140  return *hash_;
141 }
std::vector< std::unique_ptr< const RexScalar > > outer_conditions_per_level_
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)
static auto const HASH_N
const std::shared_ptr< RelFilter > original_filter_
RelAlgInputs inputs_

+ Here is the call graph for this function:

std::string RelLeftDeepInnerJoin::toString ( RelRexToStringConfig  config = RelRexToStringConfig::defaults()) const
overridevirtual

Implements RelAlgNode.

Definition at line 110 of file RelLeftDeepInnerJoin.cpp.

References condition_, RelAlgNode::inputs_, RelRexToStringConfig::skip_input_nodes, to_string(), and typeName().

110  {
111  std::string ret = ::typeName(this) + "(";
112  ret += condition_->toString(config);
113  if (!config.skip_input_nodes) {
114  for (const auto& input : inputs_) {
115  ret += " " + input->toString(config);
116  }
117  } else {
118  ret += ", input node id={";
119  for (auto& input : inputs_) {
120  ret += std::to_string(input->getId()) + " ";
121  }
122  ret += "}";
123  }
124  ret += ")";
125  return ret;
126 }
std::string to_string(char const *&&v)
std::string typeName(const T *v)
Definition: toString.h:102
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 1606 of file RelAlgDagBuilder.h.

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

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

Definition at line 1608 of file RelAlgDagBuilder.h.

Referenced by coversOriginalNode(), getOriginalFilter(), and toHash().

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

Definition at line 1609 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 1607 of file RelAlgDagBuilder.h.

Referenced by getOuterCondition(), RelLeftDeepInnerJoin(), and toHash().


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