OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryPlanDagChecker.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2021 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "QueryPlanDagChecker.h"
18 
21 }
22 
25 }
26 
28  const RelAlgTranslator& rel_alg_translator) {
29  QueryPlanDagChecker checker(rel_alg_translator);
30  checker.check(rel_alg_node);
31  return checker.getCheckResult();
32 }
33 
34 void QueryPlanDagChecker::check(const RelAlgNode* rel_alg_node) {
35  RelRexDagVisitor::visit(rel_alg_node);
36 }
37 
38 void QueryPlanDagChecker::visit(const RelLogicalValues* rel_alg_node) {
40  return;
41 }
42 
43 void QueryPlanDagChecker::visit(const RelModify* rel_alg_node) {
45  return;
46 }
47 
48 void QueryPlanDagChecker::visit(const RelTableFunction* rel_alg_node) {
50  return;
51 }
52 
53 void QueryPlanDagChecker::visit(const RelProject* rel_alg_node) {
54  if (rel_alg_node->isDeleteViaSelect() || rel_alg_node->isUpdateViaSelect() ||
55  rel_alg_node->isVarlenUpdateRequired()) {
57  return;
58  }
59  RelRexDagVisitor::visit(rel_alg_node);
60 }
61 
62 void QueryPlanDagChecker::visit(const RelCompound* rel_alg_node) {
63  if (rel_alg_node->isDeleteViaSelect() || rel_alg_node->isUpdateViaSelect() ||
64  rel_alg_node->isVarlenUpdateRequired()) {
66  return;
67  }
68  // SINGLE_VALUE / SAMPLE query
69  if (rel_alg_node->isAggregate() && rel_alg_node->size() > 0) {
70  for (size_t i = 0; i < rel_alg_node->size(); ++i) {
71  auto target_expr = rel_alg_node->getTargetExpr(i);
72  auto agg_expr = dynamic_cast<const RexAgg*>(target_expr);
73  if (agg_expr && (agg_expr->getKind() == SQLAgg::kSINGLE_VALUE ||
74  agg_expr->getKind() == SQLAgg::kSAMPLE ||
75  agg_expr->getKind() == SQLAgg::kAPPROX_QUANTILE)) {
77  return;
78  }
79  }
80  }
81  RelRexDagVisitor::visit(rel_alg_node);
82 }
83 
84 void QueryPlanDagChecker::visit(const RelLogicalUnion* rel_alg_node) {
86  return;
87 }
88 
89 void QueryPlanDagChecker::visit(const RelScan* rel_alg_node) {
92  return;
93  }
94  RelRexDagVisitor::visit(rel_alg_node);
95 }
96 
97 void QueryPlanDagChecker::visit(RexOperator const* rex_node) {
98  // prevent too heavy IN clause containing more than 20 values to check
99  if (rex_node->getOperator() == SQLOps::kOR && rex_node->size() > 20) {
101  return;
102  }
103  for (size_t i = 0; i < rex_node->size(); ++i) {
104  if (rex_node->getOperand(i)) {
106  }
107  }
108 }
109 
111  if (not_supported_functions_.count(rex_node->getName())) {
113  if (rex_node->getName() == "DATETIME") {
114  const auto arg = rel_alg_translator_.translateScalarRex(rex_node->getOperand(0));
115  const auto arg_lit = std::dynamic_pointer_cast<Analyzer::Constant>(arg);
116  if (arg_lit && !arg_lit->get_is_null() && arg_lit->get_type_info().is_string()) {
117  if (*arg_lit->get_constval().stringval != "NOW"sv) {
118  reset();
119  }
120  }
121  }
122  }
123  if (getCheckResult()) {
124  return;
125  }
126  for (size_t i = 0; i < rex_node->size(); ++i) {
127  if (rex_node->getOperand(i)) {
129  }
130  }
131 }
132 
135 }
void check(const RelAlgNode *)
const Rex * getTargetExpr(const size_t i) const
void visit(RelAlgNode const *)
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
size_t size() const override
size_t size() const
const RexScalar * getOperand(const size_t idx) const
std::string storageType
Definition: sqldefs.h:38
const RelAlgTranslator & rel_alg_translator_
static bool isNotSupportedDag(const RelAlgNode *rel_alg_node, const RelAlgTranslator &rel_alg_translator)
SQLOps getOperator() const
void visit(const RelLogicalValues *) override
auto const isDeleteViaSelect() const
bool isAggregate() const
const std::unordered_set< std::string > not_supported_functions_
auto const isUpdateViaSelect() const
const std::string & getName() const
auto const isVarlenUpdateRequired() const
static constexpr char const * FOREIGN_TABLE
const TableDescriptor * getTableDescriptor() const