OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{LogicalIR.cpp} Namespace Reference

Functions

bool contains_unsafe_division (const Analyzer::Expr *expr)
 
bool should_defer_eval (const std::shared_ptr< Analyzer::Expr > expr)
 
Likelihood get_likelihood (const Analyzer::Expr *expr)
 
Weight get_weight (const Analyzer::Expr *expr, int depth=0)
 
bool is_qualified_bin_oper (const Analyzer::Expr *expr)
 

Function Documentation

bool anonymous_namespace{LogicalIR.cpp}::contains_unsafe_division ( const Analyzer::Expr expr)

Definition at line 26 of file LogicalIR.cpp.

References decimal_to_int_type(), Analyzer::Expr::find_expr(), Analyzer::Constant::get_constval(), Analyzer::BinOper::get_right_operand(), kBIGINT, kBOOLEAN, kDIVIDE, kDOUBLE, kFLOAT, kINT, kSMALLINT, kTINYINT, and run_benchmark_import::type.

Referenced by CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::prioritizeQuals(), and should_defer_eval().

26  {
27  auto is_div = [](const Analyzer::Expr* e) -> bool {
28  auto bin_oper = dynamic_cast<const Analyzer::BinOper*>(e);
29  if (bin_oper && bin_oper->get_optype() == kDIVIDE) {
30  auto rhs = bin_oper->get_right_operand();
31  auto rhs_constant = dynamic_cast<const Analyzer::Constant*>(rhs);
32  if (!rhs_constant || rhs_constant->get_is_null()) {
33  return true;
34  }
35  const auto& datum = rhs_constant->get_constval();
36  const auto& ti = rhs_constant->get_type_info();
37  const auto type = ti.is_decimal() ? decimal_to_int_type(ti) : ti.get_type();
38  if ((type == kBOOLEAN && datum.boolval == 0) ||
39  (type == kTINYINT && datum.tinyintval == 0) ||
40  (type == kSMALLINT && datum.smallintval == 0) ||
41  (type == kINT && datum.intval == 0) ||
42  (type == kBIGINT && datum.bigintval == 0LL) ||
43  (type == kFLOAT && datum.floatval == 0.0) ||
44  (type == kDOUBLE && datum.doubleval == 0.0)) {
45  return true;
46  }
47  }
48  return false;
49  };
50  std::list<const Analyzer::Expr*> binoper_list;
51  expr->find_expr(is_div, binoper_list);
52  return !binoper_list.empty();
53 }
const Expr * get_right_operand() const
Definition: Analyzer.h:456
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:561
Datum get_constval() const
Definition: Analyzer.h:348
Definition: sqltypes.h:72
virtual void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const
Definition: Analyzer.h:163

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Likelihood anonymous_namespace{LogicalIR.cpp}::get_likelihood ( const Analyzer::Expr expr)

Definition at line 79 of file LogicalIR.cpp.

References Analyzer::BinOper::get_left_operand(), NullableValue< T >::isInvalid(), kAND, kNOT, and kOR.

Referenced by CodeGenerator::codegenLogicalShortCircuit(), and CodeGenerator::prioritizeQuals().

79  {
80  Likelihood truth{1.0};
81  auto likelihood_expr = dynamic_cast<const Analyzer::LikelihoodExpr*>(expr);
82  if (likelihood_expr) {
83  return Likelihood(likelihood_expr->get_likelihood());
84  }
85  auto u_oper = dynamic_cast<const Analyzer::UOper*>(expr);
86  if (u_oper) {
87  Likelihood oper_likelihood = get_likelihood(u_oper->get_operand());
88  if (oper_likelihood.isInvalid()) {
89  return Likelihood();
90  }
91  if (u_oper->get_optype() == kNOT) {
92  return truth - oper_likelihood;
93  }
94  return oper_likelihood;
95  }
96  auto bin_oper = dynamic_cast<const Analyzer::BinOper*>(expr);
97  if (bin_oper) {
98  auto lhs = bin_oper->get_left_operand();
99  auto rhs = bin_oper->get_right_operand();
100  Likelihood lhs_likelihood = get_likelihood(lhs);
101  Likelihood rhs_likelihood = get_likelihood(rhs);
102  if (lhs_likelihood.isInvalid() && rhs_likelihood.isInvalid()) {
103  return Likelihood();
104  }
105  const auto optype = bin_oper->get_optype();
106  if (optype == kOR) {
107  auto both_false = (truth - lhs_likelihood) * (truth - rhs_likelihood);
108  return truth - both_false;
109  }
110  if (optype == kAND) {
111  return lhs_likelihood * rhs_likelihood;
112  }
113  return (lhs_likelihood + rhs_likelihood) / 2.0;
114  }
115 
116  return Likelihood();
117 }
Definition: sqldefs.h:40
Likelihood get_likelihood(const Analyzer::Expr *expr)
Definition: LogicalIR.cpp:79
bool isInvalid() const
Definition: NullableValue.h:33
Definition: sqldefs.h:39
NullableValue< float > Likelihood
Definition: NullableValue.h:99
const Expr * get_left_operand() const
Definition: Analyzer.h:455
Definition: sqldefs.h:41

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Weight anonymous_namespace{LogicalIR.cpp}::get_weight ( const Analyzer::Expr expr,
int  depth = 0 
)

Definition at line 119 of file LogicalIR.cpp.

References Analyzer::BinOper::get_left_operand().

Referenced by CodeGenerator::codegenLogicalShortCircuit().

119  {
120  auto like_expr = dynamic_cast<const Analyzer::LikeExpr*>(expr);
121  if (like_expr) {
122  // heavy weight expr, start valid weight propagation
123  return Weight((like_expr->get_is_simple()) ? 200 : 1000);
124  }
125  auto regexp_expr = dynamic_cast<const Analyzer::RegexpExpr*>(expr);
126  if (regexp_expr) {
127  // heavy weight expr, start valid weight propagation
128  return Weight(2000);
129  }
130  auto u_oper = dynamic_cast<const Analyzer::UOper*>(expr);
131  if (u_oper) {
132  auto weight = get_weight(u_oper->get_operand(), depth + 1);
133  return weight + 1;
134  }
135  auto bin_oper = dynamic_cast<const Analyzer::BinOper*>(expr);
136  if (bin_oper) {
137  auto lhs = bin_oper->get_left_operand();
138  auto rhs = bin_oper->get_right_operand();
139  auto lhs_weight = get_weight(lhs, depth + 1);
140  auto rhs_weight = get_weight(rhs, depth + 1);
141  if (rhs->get_type_info().is_array()) {
142  // heavy weight expr, start valid weight propagation
143  rhs_weight = rhs_weight + Weight(100);
144  }
145  auto weight = lhs_weight + rhs_weight;
146  return weight + 1;
147  }
148 
149  if (depth > 4) {
150  return Weight(1);
151  }
152 
153  return Weight();
154 }
Weight get_weight(const Analyzer::Expr *expr, int depth=0)
Definition: LogicalIR.cpp:119
const Expr * get_left_operand() const
Definition: Analyzer.h:455
NullableValue< uint64_t > Weight

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{LogicalIR.cpp}::is_qualified_bin_oper ( const Analyzer::Expr expr)

Definition at line 356 of file LogicalIR.cpp.

References Analyzer::BinOper::get_qualifier(), and kONE.

Referenced by CodeGenerator::codegenLogical().

356  {
357  const auto bin_oper = dynamic_cast<const Analyzer::BinOper*>(expr);
358  return bin_oper && bin_oper->get_qualifier() != kONE;
359 }
Definition: sqldefs.h:74
SQLQualifier get_qualifier() const
Definition: Analyzer.h:454

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{LogicalIR.cpp}::should_defer_eval ( const std::shared_ptr< Analyzer::Expr expr)

Definition at line 55 of file LogicalIR.cpp.

References contains_unsafe_division(), Analyzer::BinOper::get_right_operand(), Analyzer::Expr::get_type_info(), and SQLTypeInfo::is_array().

Referenced by CodeGenerator::prioritizeQuals().

55  {
56  if (std::dynamic_pointer_cast<Analyzer::LikeExpr>(expr)) {
57  return true;
58  }
59  if (std::dynamic_pointer_cast<Analyzer::RegexpExpr>(expr)) {
60  return true;
61  }
62  if (std::dynamic_pointer_cast<Analyzer::FunctionOper>(expr)) {
63  return true;
64  }
65  if (!std::dynamic_pointer_cast<Analyzer::BinOper>(expr)) {
66  return false;
67  }
68  const auto bin_expr = std::static_pointer_cast<Analyzer::BinOper>(expr);
69  if (contains_unsafe_division(bin_expr.get())) {
70  return true;
71  }
72  if (bin_expr->is_bbox_intersect_oper()) {
73  return false;
74  }
75  const auto rhs = bin_expr->get_right_operand();
76  return rhs->get_type_info().is_array();
77 }
const Expr * get_right_operand() const
Definition: Analyzer.h:456
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
bool contains_unsafe_division(const Analyzer::Expr *expr)
Definition: LogicalIR.cpp:26
bool is_array() const
Definition: sqltypes.h:585

+ Here is the call graph for this function:

+ Here is the caller graph for this function: