OmniSciDB  72c90bc290
 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 25 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().

25  {
26  auto is_div = [](const Analyzer::Expr* e) -> bool {
27  auto bin_oper = dynamic_cast<const Analyzer::BinOper*>(e);
28  if (bin_oper && bin_oper->get_optype() == kDIVIDE) {
29  auto rhs = bin_oper->get_right_operand();
30  auto rhs_constant = dynamic_cast<const Analyzer::Constant*>(rhs);
31  if (!rhs_constant || rhs_constant->get_is_null()) {
32  return true;
33  }
34  const auto& datum = rhs_constant->get_constval();
35  const auto& ti = rhs_constant->get_type_info();
36  const auto type = ti.is_decimal() ? decimal_to_int_type(ti) : ti.get_type();
37  if ((type == kBOOLEAN && datum.boolval == 0) ||
38  (type == kTINYINT && datum.tinyintval == 0) ||
39  (type == kSMALLINT && datum.smallintval == 0) ||
40  (type == kINT && datum.intval == 0) ||
41  (type == kBIGINT && datum.bigintval == 0LL) ||
42  (type == kFLOAT && datum.floatval == 0.0) ||
43  (type == kDOUBLE && datum.doubleval == 0.0)) {
44  return true;
45  }
46  }
47  return false;
48  };
49  std::list<const Analyzer::Expr*> binoper_list;
50  expr->find_expr(is_div, binoper_list);
51  return !binoper_list.empty();
52 }
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 78 of file LogicalIR.cpp.

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

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

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

+ 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 118 of file LogicalIR.cpp.

References Analyzer::BinOper::get_left_operand().

Referenced by CodeGenerator::codegenLogicalShortCircuit().

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

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

Referenced by CodeGenerator::codegenLogical().

355  {
356  const auto bin_oper = dynamic_cast<const Analyzer::BinOper*>(expr);
357  return bin_oper && bin_oper->get_qualifier() != kONE;
358 }
Definition: sqldefs.h:71
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 54 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().

54  {
55  if (std::dynamic_pointer_cast<Analyzer::LikeExpr>(expr)) {
56  return true;
57  }
58  if (std::dynamic_pointer_cast<Analyzer::RegexpExpr>(expr)) {
59  return true;
60  }
61  if (std::dynamic_pointer_cast<Analyzer::FunctionOper>(expr)) {
62  return true;
63  }
64  if (!std::dynamic_pointer_cast<Analyzer::BinOper>(expr)) {
65  return false;
66  }
67  const auto bin_expr = std::static_pointer_cast<Analyzer::BinOper>(expr);
68  if (contains_unsafe_division(bin_expr.get())) {
69  return true;
70  }
71  if (bin_expr->is_bbox_intersect_oper()) {
72  return false;
73  }
74  const auto rhs = bin_expr->get_right_operand();
75  return rhs->get_type_info().is_array();
76 }
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:25
bool is_array() const
Definition: sqltypes.h:583

+ Here is the call graph for this function:

+ Here is the caller graph for this function: