OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExpressionRange.cpp File Reference
#include "ExpressionRange.h"
#include "DateTimeTranslator.h"
#include "DateTimeUtils.h"
#include "DateTruncate.h"
#include "Descriptors/InputDescriptors.h"
#include "Execute.h"
#include "ExtractFromTime.h"
#include "GroupByAndAggregate.h"
#include "QueryPhysicalInputsCollector.h"
#include <algorithm>
#include <cfenv>
#include <cmath>
+ Include dependency graph for ExpressionRange.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{ExpressionRange.cpp}
 

Macros

#define DEF_OPERATOR(fname, op)
 
#define FIND_STAT_FRAG(stat_name)
 

Functions

void apply_fp_qual (const Datum const_datum, const SQLTypes const_type, const SQLOps sql_op, ExpressionRange &qual_range)
 
void apply_int_qual (const Datum const_datum, const SQLTypes const_type, const SQLOps sql_op, ExpressionRange &qual_range)
 
void apply_hpt_qual (const Datum const_datum, const SQLTypes const_type, const int32_t const_dimen, const int32_t col_dimen, const SQLOps sql_op, ExpressionRange &qual_range)
 
ExpressionRange apply_simple_quals (const Analyzer::ColumnVar *col_expr, const ExpressionRange &col_range, const boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
 
ExpressionRange getExpressionRange (const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
 
ExpressionRange getExpressionRange (const Analyzer::Constant *expr)
 
ExpressionRange getExpressionRange (const Analyzer::ColumnVar *col_expr, const std::vector< InputTableInfo > &query_infos, const Executor *executor, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
 
ExpressionRange getExpressionRange (const Analyzer::StringOper *string_oper_expr, const Executor *executor)
 
ExpressionRange getExpressionRange (const Analyzer::LikeExpr *like_expr)
 
ExpressionRange getExpressionRange (const Analyzer::CaseExpr *case_expr, const std::vector< InputTableInfo > &query_infos, const Executor *)
 
ExpressionRange getExpressionRange (const Analyzer::UOper *u_expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
 
ExpressionRange getExpressionRange (const Analyzer::ExtractExpr *extract_expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
 
ExpressionRange getExpressionRange (const Analyzer::DatetruncExpr *datetrunc_expr, const std::vector< InputTableInfo > &query_infos, const Executor *executor, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
 
ExpressionRange getExpressionRange (const Analyzer::WidthBucketExpr *width_bucket_expr, const std::vector< InputTableInfo > &query_infos, const Executor *executor, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
 
ExpressionRange getExpressionRange (const Analyzer::Expr *expr, const std::vector< InputTableInfo > &query_infos, const Executor *executor, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
 
int64_t anonymous_namespace{ExpressionRange.cpp}::scale_up_interval_endpoint (const int64_t endpoint, const SQLTypeInfo &ti)
 
int64_t anonymous_namespace{ExpressionRange.cpp}::get_conservative_datetrunc_bucket (const DatetruncField datetrunc_field)
 
ExpressionRange getLeafColumnRange (const Analyzer::ColumnVar *col_expr, const std::vector< InputTableInfo > &query_infos, const Executor *executor, const bool is_outer_join_proj)
 
ExpressionRange anonymous_namespace{ExpressionRange.cpp}::fpRangeFromDecimal (const ExpressionRange &arg_range, const int64_t scale, const SQLTypeInfo &target_ti)
 
ExpressionRange anonymous_namespace{ExpressionRange.cpp}::getDateTimePrecisionCastRange (const ExpressionRange &arg_range, const SQLTypeInfo &oper_ti, const SQLTypeInfo &target_ti)
 

Macro Definition Documentation

#define DEF_OPERATOR (   fname,
  op 
)

Definition at line 31 of file ExpressionRange.cpp.

#define FIND_STAT_FRAG (   stat_name)

Definition at line 452 of file ExpressionRange.cpp.

Referenced by getLeafColumnRange().

Function Documentation

void apply_fp_qual ( const Datum  const_datum,
const SQLTypes  const_type,
const SQLOps  sql_op,
ExpressionRange qual_range 
)

Definition at line 74 of file ExpressionRange.cpp.

References kEQ, kGE, kGT, kLE, and kLT.

Referenced by apply_simple_quals().

77  {
78  double const_val = get_value_from_datum<double>(const_datum, const_type);
79  switch (sql_op) {
80  case kGT:
81  case kGE:
82  qual_range.setFpMin(std::max(qual_range.getFpMin(), const_val));
83  break;
84  case kLT:
85  case kLE:
86  qual_range.setFpMax(std::min(qual_range.getFpMax(), const_val));
87  break;
88  case kEQ:
89  qual_range.setFpMin(std::max(qual_range.getFpMin(), const_val));
90  qual_range.setFpMax(std::min(qual_range.getFpMax(), const_val));
91  break;
92  default: // there may be other operators, but don't do anything with them
93  break;
94  }
95 }
Definition: sqldefs.h:34
Definition: sqldefs.h:35
Definition: sqldefs.h:29
Definition: sqldefs.h:33
double getFpMax() const
double getFpMin() const
void setFpMax(const double fp_max)
Definition: sqldefs.h:32
void setFpMin(const double fp_min)

+ Here is the caller graph for this function:

void apply_hpt_qual ( const Datum  const_datum,
const SQLTypes  const_type,
const int32_t  const_dimen,
const int32_t  col_dimen,
const SQLOps  sql_op,
ExpressionRange qual_range 
)

Definition at line 124 of file ExpressionRange.cpp.

References apply_int_qual(), Datum::bigintval, CHECK, and DateTimeUtils::get_timestamp_precision_scale().

Referenced by apply_simple_quals().

129  {
130  CHECK(const_dimen != col_dimen);
131  Datum datum{0};
132  if (const_dimen > col_dimen) {
133  datum.bigintval =
134  get_value_from_datum<int64_t>(const_datum, const_type) /
135  DateTimeUtils::get_timestamp_precision_scale(const_dimen - col_dimen);
136  } else {
137  datum.bigintval =
138  get_value_from_datum<int64_t>(const_datum, const_type) *
139  DateTimeUtils::get_timestamp_precision_scale(col_dimen - const_dimen);
140  }
141  apply_int_qual(datum, const_type, sql_op, qual_range);
142 }
void apply_int_qual(const Datum const_datum, const SQLTypes const_type, const SQLOps sql_op, ExpressionRange &qual_range)
int64_t bigintval
Definition: Datum.h:49
#define CHECK(condition)
Definition: Logger.h:222
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
Definition: Datum.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void apply_int_qual ( const Datum  const_datum,
const SQLTypes  const_type,
const SQLOps  sql_op,
ExpressionRange qual_range 
)

Definition at line 97 of file ExpressionRange.cpp.

References ExpressionRange::getIntMax(), ExpressionRange::getIntMin(), kEQ, kGE, kGT, kLE, kLT, ExpressionRange::setIntMax(), and ExpressionRange::setIntMin().

Referenced by apply_hpt_qual(), and apply_simple_quals().

100  {
101  int64_t const_val = get_value_from_datum<int64_t>(const_datum, const_type);
102  switch (sql_op) {
103  case kGT:
104  qual_range.setIntMin(std::max(qual_range.getIntMin(), const_val + 1));
105  break;
106  case kGE:
107  qual_range.setIntMin(std::max(qual_range.getIntMin(), const_val));
108  break;
109  case kLT:
110  qual_range.setIntMax(std::min(qual_range.getIntMax(), const_val - 1));
111  break;
112  case kLE:
113  qual_range.setIntMax(std::min(qual_range.getIntMax(), const_val));
114  break;
115  case kEQ:
116  qual_range.setIntMin(std::max(qual_range.getIntMin(), const_val));
117  qual_range.setIntMax(std::min(qual_range.getIntMax(), const_val));
118  break;
119  default: // there may be other operators, but don't do anything with them
120  break;
121  }
122 }
int64_t getIntMin() const
Definition: sqldefs.h:34
Definition: sqldefs.h:35
Definition: sqldefs.h:29
void setIntMin(const int64_t int_min)
Definition: sqldefs.h:33
void setIntMax(const int64_t int_max)
int64_t getIntMax() const
Definition: sqldefs.h:32

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExpressionRange apply_simple_quals ( const Analyzer::ColumnVar col_expr,
const ExpressionRange col_range,
const boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>>  simple_quals 
)

Definition at line 144 of file ExpressionRange.cpp.

References apply_fp_qual(), apply_hpt_qual(), apply_int_qual(), Double, Float, Analyzer::ColumnVar::get_column_id(), Analyzer::ColumnVar::get_table_id(), and ExpressionRange::getType().

Referenced by getExpressionRange().

147  {
148  if (!simple_quals) {
149  return col_range;
150  }
151  ExpressionRange qual_range(col_range);
152  for (auto const& itr : simple_quals.get()) {
153  auto qual_bin_oper = dynamic_cast<Analyzer::BinOper*>(itr.get());
154  if (!qual_bin_oper) {
155  continue;
156  }
157  const Analyzer::Expr* left_operand = qual_bin_oper->get_left_operand();
158  auto qual_col = dynamic_cast<const Analyzer::ColumnVar*>(left_operand);
159  if (!qual_col) {
160  // Check for possibility that column is wrapped in a cast
161  // Presumes that only simple casts (i.e. timestamp to timestamp or int to int) have
162  // been passed through by BinOper::normalize_simple_predicate
163  auto u_expr = dynamic_cast<const Analyzer::UOper*>(left_operand);
164  if (!u_expr) {
165  continue;
166  }
167  qual_col = dynamic_cast<const Analyzer::ColumnVar*>(u_expr->get_operand());
168  if (!qual_col) {
169  continue;
170  }
171  }
172  if (qual_col->get_table_id() != col_expr->get_table_id() ||
173  qual_col->get_column_id() != col_expr->get_column_id()) {
174  continue;
175  }
176  const Analyzer::Expr* right_operand = qual_bin_oper->get_right_operand();
177  auto qual_const = dynamic_cast<const Analyzer::Constant*>(right_operand);
178  if (!qual_const) {
179  continue;
180  }
181  if (qual_range.getType() == ExpressionRangeType::Float ||
182  qual_range.getType() == ExpressionRangeType::Double) {
183  apply_fp_qual(qual_const->get_constval(),
184  qual_const->get_type_info().get_type(),
185  qual_bin_oper->get_optype(),
186  qual_range);
187  } else if ((qual_col->get_type_info().is_timestamp() ||
188  qual_const->get_type_info().is_timestamp()) &&
189  (qual_col->get_type_info().get_dimension() !=
190  qual_const->get_type_info().get_dimension())) {
191  apply_hpt_qual(qual_const->get_constval(),
192  qual_const->get_type_info().get_type(),
193  qual_const->get_type_info().get_dimension(),
194  qual_col->get_type_info().get_dimension(),
195  qual_bin_oper->get_optype(),
196  qual_range);
197  } else {
198  apply_int_qual(qual_const->get_constval(),
199  qual_const->get_type_info().get_type(),
200  qual_bin_oper->get_optype(),
201  qual_range);
202  }
203  }
204  return qual_range;
205 }
int get_table_id() const
Definition: Analyzer.h:201
void apply_hpt_qual(const Datum const_datum, const SQLTypes const_type, const int32_t const_dimen, const int32_t col_dimen, const SQLOps sql_op, ExpressionRange &qual_range)
void apply_int_qual(const Datum const_datum, const SQLTypes const_type, const SQLOps sql_op, ExpressionRange &qual_range)
void apply_fp_qual(const Datum const_datum, const SQLTypes const_type, const SQLOps sql_op, ExpressionRange &qual_range)
int get_column_id() const
Definition: Analyzer.h:202

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::BinOper expr,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor,
boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>>  simple_quals 
)

Definition at line 374 of file ExpressionRange.cpp.

References CHECK, Analyzer::BinOper::get_left_operand(), Analyzer::BinOper::get_optype(), Analyzer::BinOper::get_right_operand(), Analyzer::Expr::get_type_info(), Integer, Invalid, kDIVIDE, kMINUS, kMULTIPLY, kPLUS, ExpressionRange::makeIntRange(), ExpressionRange::makeInvalidRange(), and anonymous_namespace{ExpressionRange.cpp}::scale_up_interval_endpoint().

Referenced by CodeGenerator::checkExpressionRanges(), CodeGenerator::codegen(), anonymous_namespace{RelAlgExecutor.cpp}::decide_approx_count_distinct_implementation(), anonymous_namespace{GroupByAndAggregate.cpp}::get_expr_range_info(), anonymous_namespace{GroupByAndAggregate.cpp}::get_keyless_info(), getExpressionRange(), PerfectJoinHashTable::getInstance(), anonymous_namespace{QueryMemoryDescriptor.cpp}::pick_baseline_key_width(), and QueryRewriter::rewriteConstrainedByInImpl().

378  {
379  const auto& lhs =
380  getExpressionRange(expr->get_left_operand(), query_infos, executor, simple_quals);
381  const auto& rhs =
382  getExpressionRange(expr->get_right_operand(), query_infos, executor, simple_quals);
383  switch (expr->get_optype()) {
384  case kPLUS:
385  return lhs + rhs;
386  case kMINUS:
387  return lhs - rhs;
388  case kMULTIPLY:
389  return lhs * rhs;
390  case kDIVIDE: {
391  const auto& lhs_type = expr->get_left_operand()->get_type_info();
392  if (lhs_type.is_decimal() && lhs.getType() != ExpressionRangeType::Invalid) {
393  CHECK(lhs.getType() == ExpressionRangeType::Integer);
394  const auto adjusted_lhs = ExpressionRange::makeIntRange(
395  scale_up_interval_endpoint(lhs.getIntMin(), lhs_type),
396  scale_up_interval_endpoint(lhs.getIntMax(), lhs_type),
397  0,
398  lhs.hasNulls());
399  return adjusted_lhs / rhs;
400  }
401  return lhs / rhs;
402  }
403  default:
404  break;
405  }
407 }
const Expr * get_right_operand() const
Definition: Analyzer.h:451
Definition: sqldefs.h:40
int64_t scale_up_interval_endpoint(const int64_t endpoint, const SQLTypeInfo &ti)
SQLOps get_optype() const
Definition: Analyzer.h:447
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
Definition: sqldefs.h:39
#define CHECK(condition)
Definition: Logger.h:222
const Expr * get_left_operand() const
Definition: Analyzer.h:450
static ExpressionRange makeInvalidRange()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::Constant expr)

Definition at line 409 of file ExpressionRange.cpp.

References Analyzer::Constant::get_constval(), Analyzer::Constant::get_is_null(), SQLTypeInfo::get_type(), Analyzer::Expr::get_type_info(), kBIGINT, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, ExpressionRange::makeDoubleRange(), ExpressionRange::makeFloatRange(), ExpressionRange::makeIntRange(), and ExpressionRange::makeInvalidRange().

409  {
410  if (constant_expr->get_is_null()) {
412  }
413  const auto constant_type = constant_expr->get_type_info().get_type();
414  const auto datum = constant_expr->get_constval();
415  switch (constant_type) {
416  case kTINYINT: {
417  const int64_t v = datum.tinyintval;
418  return ExpressionRange::makeIntRange(v, v, 0, false);
419  }
420  case kSMALLINT: {
421  const int64_t v = datum.smallintval;
422  return ExpressionRange::makeIntRange(v, v, 0, false);
423  }
424  case kINT: {
425  const int64_t v = datum.intval;
426  return ExpressionRange::makeIntRange(v, v, 0, false);
427  }
428  case kBIGINT:
429  case kNUMERIC:
430  case kDECIMAL: {
431  const int64_t v = datum.bigintval;
432  return ExpressionRange::makeIntRange(v, v, 0, false);
433  }
434  case kTIME:
435  case kTIMESTAMP:
436  case kDATE: {
437  const int64_t v = datum.bigintval;
438  return ExpressionRange::makeIntRange(v, v, 0, false);
439  }
440  case kFLOAT: {
441  return ExpressionRange::makeFloatRange(datum.floatval, datum.floatval, false);
442  }
443  case kDOUBLE: {
444  return ExpressionRange::makeDoubleRange(datum.doubleval, datum.doubleval, false);
445  }
446  default:
447  break;
448  }
450 }
Definition: sqltypes.h:64
static ExpressionRange makeFloatRange(const float fp_min, const float fp_max, const bool has_nulls)
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
static ExpressionRange makeDoubleRange(const double fp_min, const double fp_max, const bool has_nulls)
Definition: sqltypes.h:68
Definition: sqltypes.h:60
static ExpressionRange makeInvalidRange()

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::ColumnVar col_expr,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor,
boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>>  simple_quals 
)

Definition at line 635 of file ExpressionRange.cpp.

References apply_simple_quals(), CHECK_GE, CHECK_LT, Analyzer::ColumnVar::get_column_id(), Analyzer::ColumnVar::get_rte_idx(), Analyzer::ColumnVar::get_table_id(), and getLeafColumnRange().

639  {
640  const int rte_idx = col_expr->get_rte_idx();
641  CHECK_GE(rte_idx, 0);
642  CHECK_LT(static_cast<size_t>(rte_idx), query_infos.size());
643  bool is_outer_join_proj = rte_idx > 0 && executor->containsLeftDeepOuterJoin();
644  if (col_expr->get_table_id() > 0) {
645  auto col_range = executor->getColRange(
646  PhysicalInput{col_expr->get_column_id(), col_expr->get_table_id()});
647  if (is_outer_join_proj) {
648  col_range.setHasNulls();
649  }
650  return apply_simple_quals(col_expr, col_range, simple_quals);
651  }
652  return getLeafColumnRange(col_expr, query_infos, executor, is_outer_join_proj);
653 }
int get_table_id() const
Definition: Analyzer.h:201
#define CHECK_GE(x, y)
Definition: Logger.h:235
ExpressionRange apply_simple_quals(const Analyzer::ColumnVar *col_expr, const ExpressionRange &col_range, const boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
ExpressionRange getLeafColumnRange(const Analyzer::ColumnVar *col_expr, const std::vector< InputTableInfo > &query_infos, const Executor *executor, const bool is_outer_join_proj)
#define CHECK_LT(x, y)
Definition: Logger.h:232
int get_rte_idx() const
Definition: Analyzer.h:203
int get_column_id() const
Definition: Analyzer.h:202

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::StringOper string_oper_expr,
const Executor executor 
)

Definition at line 655 of file ExpressionRange.cpp.

References CHECK, Analyzer::Expr::get_type_info(), Analyzer::StringOper::getArg(), Analyzer::StringOper::getChainedStringOpExprs(), ExpressionRange::makeIntRange(), ExpressionRange::makeInvalidRange(), remove_cast(), and RowSetMemoryOwner::SOURCE_UNION.

656  {
657  auto chained_string_op_exprs = string_oper_expr->getChainedStringOpExprs();
658  if (chained_string_op_exprs.empty()) {
659  throw std::runtime_error(
660  "StringOper getExpressionRange() Expected folded string operator but found "
661  "operator unfolded.");
662  }
663  // Consider encapsulating below in an Analyzer::StringOper method to dedup
664  std::vector<StringOps_Namespace::StringOpInfo> string_op_infos;
665  for (const auto& chained_string_op_expr : chained_string_op_exprs) {
666  auto chained_string_op =
667  dynamic_cast<const Analyzer::StringOper*>(chained_string_op_expr.get());
668  CHECK(chained_string_op);
669  StringOps_Namespace::StringOpInfo string_op_info(chained_string_op->get_kind(),
670  chained_string_op->get_type_info(),
671  chained_string_op->getLiteralArgs());
672  string_op_infos.emplace_back(string_op_info);
673  }
674 
675  const auto string_oper_col_var_expr = remove_cast(string_oper_expr->getArg(0));
676  CHECK(string_oper_col_var_expr);
677  const auto string_oper_col_var =
678  dynamic_cast<const Analyzer::ColumnVar*>(string_oper_col_var_expr);
679  CHECK(string_oper_col_var);
680  const auto string_oper_col_var_ti = string_oper_col_var->get_type_info();
681  if (string_oper_col_var_ti.is_none_encoded_string()) {
682  // If here the translation is done on the fly so unless this
683  // was the result of a previous step, we won't have the translated
684  // dictionary yet. Just throw an invalid range.
686  }
687  CHECK(string_oper_col_var_ti.is_dict_encoded_string());
688 
689  const auto expr_ti = string_oper_expr->get_type_info();
690  if (expr_ti.is_string()) {
691  CHECK(expr_ti.is_dict_encoded_string());
692  const auto dict_id = expr_ti.get_comp_param();
693 
694  const auto translation_map = executor->getStringProxyTranslationMap(
695  dict_id,
696  dict_id,
698  string_op_infos,
699  executor->getRowSetMemoryOwner(),
700  true);
701 
702  // Todo(todd): Track null presence in StringDictionaryProxy::IdMap
703  return ExpressionRange::makeIntRange(translation_map->rangeStart(),
704  translation_map->rangeEnd() - 1,
705  0 /* bucket */,
706  true /* assume has nulls */);
707 
708  } else {
709  // Todo: Get min/max range stats
711  }
712 }
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4255
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
Expression class for string functions The &quot;arg&quot; constructor parameter must be an expression that reso...
Definition: Analyzer.h:1464
#define CHECK(condition)
Definition: Logger.h:222
static ExpressionRange makeInvalidRange()
std::vector< std::shared_ptr< Analyzer::Expr > > getChainedStringOpExprs() const
Definition: Analyzer.h:1547
const Expr * getArg(const size_t i) const
Definition: Analyzer.h:1535

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::LikeExpr like_expr)

Definition at line 714 of file ExpressionRange.cpp.

References CHECK, Analyzer::LikeExpr::get_arg(), Analyzer::Expr::get_type_info(), inline_int_null_val(), and ExpressionRange::makeIntRange().

714  {
715  const auto& ti = like_expr->get_type_info();
716  CHECK(ti.is_boolean());
717  const auto& arg_ti = like_expr->get_arg()->get_type_info();
719  arg_ti.get_notnull() ? 0 : inline_int_null_val(ti), 1, 0, false);
720 }
const Expr * get_arg() const
Definition: Analyzer.h:904
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
#define CHECK(condition)
Definition: Logger.h:222
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::CaseExpr case_expr,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor 
)

Definition at line 722 of file ExpressionRange.cpp.

References CHECK, CHECK_EQ, Analyzer::CaseExpr::get_else_expr(), Analyzer::CaseExpr::get_expr_pair_list(), getExpressionRange(), Invalid, kBOOLEAN, ExpressionRange::makeInvalidRange(), and Null.

724  {
725  const auto& expr_pair_list = case_expr->get_expr_pair_list();
726  auto expr_range = ExpressionRange::makeInvalidRange();
727  bool has_nulls = false;
728  for (const auto& expr_pair : expr_pair_list) {
729  CHECK_EQ(expr_pair.first->get_type_info().get_type(), kBOOLEAN);
730  const auto crt_range =
731  getExpressionRange(expr_pair.second.get(), query_infos, executor);
732  if (crt_range.getType() == ExpressionRangeType::Null) {
733  has_nulls = true;
734  continue;
735  }
736  if (crt_range.getType() == ExpressionRangeType::Invalid) {
738  }
739  expr_range = (expr_range.getType() != ExpressionRangeType::Invalid)
740  ? expr_range || crt_range
741  : crt_range;
742  }
743  if (has_nulls && !(expr_range.getType() == ExpressionRangeType::Invalid)) {
744  expr_range.setHasNulls();
745  }
746  const auto else_expr = case_expr->get_else_expr();
747  CHECK(else_expr);
748  const auto else_null_expr = dynamic_cast<const Analyzer::Constant*>(else_expr);
749  if (else_null_expr && else_null_expr->get_is_null()) {
750  expr_range.setHasNulls();
751  return expr_range;
752  }
753  return expr_range || getExpressionRange(else_expr, query_infos, executor);
754 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const Expr * get_else_expr() const
Definition: Analyzer.h:1260
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
#define CHECK(condition)
Definition: Logger.h:222
static ExpressionRange makeInvalidRange()
const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > & get_expr_pair_list() const
Definition: Analyzer.h:1257

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::UOper u_expr,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor,
boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>>  simple_quals 
)

Definition at line 827 of file ExpressionRange.cpp.

References gpu_enabled::accumulate(), CHECK, CHECK_EQ, Double, exp_to_scale(), Float, anonymous_namespace{ExpressionRange.cpp}::fpRangeFromDecimal(), Analyzer::UOper::get_operand(), Analyzer::UOper::get_optype(), Analyzer::Expr::get_type_info(), anonymous_namespace{ExpressionRange.cpp}::getDateTimePrecisionCastRange(), getExpressionRange(), Integer, Invalid, kCAST, kDATE, kDOUBLE, kENCODING_DICT, kFLOAT, kTIME, kUNNEST, ExpressionRange::makeDoubleRange(), ExpressionRange::makeFloatRange(), ExpressionRange::makeIntRange(), ExpressionRange::makeInvalidRange(), ExpressionRange::makeNullRange(), Analyzer::Expr::toString(), TRANSIENT_DICT_ID, and VLOG.

831  {
832  if (u_expr->get_optype() == kUNNEST) {
833  return getExpressionRange(u_expr->get_operand(), query_infos, executor, simple_quals);
834  }
835  if (u_expr->get_optype() != kCAST) {
837  }
838  const auto& ti = u_expr->get_type_info();
839  if (ti.is_string() && ti.get_compression() == kENCODING_DICT) {
840  const auto sdp = executor->getStringDictionaryProxy(
841  ti.get_comp_param(), executor->getRowSetMemoryOwner(), true);
842  CHECK(sdp);
843  const auto colvar_operand =
844  dynamic_cast<const Analyzer::ColumnVar*>(u_expr->get_operand());
845  if (colvar_operand) {
846  const auto& colvar_ti = colvar_operand->get_type_info();
847  if (!(colvar_ti.is_none_encoded_string() &&
848  ti.get_comp_param() == TRANSIENT_DICT_ID)) {
849  VLOG(1)
850  << "Unable to determine expression range for dictionary encoded expression "
851  << u_expr->get_operand()->toString() << ", proceeding with invalid range.";
853  }
854  CHECK_EQ(ti.get_comp_param(), TRANSIENT_DICT_ID);
855  CHECK_EQ(sdp->storageEntryCount(), 0UL);
856  const int64_t transient_entries = static_cast<int64_t>(sdp->transientEntryCount());
857  int64_t const tuples_upper_bound = static_cast<int64_t>(
858  std::accumulate(query_infos.cbegin(),
859  query_infos.cend(),
860  size_t(0),
861  [](auto max, auto const& query_info) {
862  return std::max(max, query_info.info.getNumTuples());
863  }));
864  const int64_t conservative_range_min = -1L - transient_entries - tuples_upper_bound;
865  return ExpressionRange::makeIntRange(conservative_range_min, -2L, 0, true);
866  }
867  const auto const_operand =
868  dynamic_cast<const Analyzer::Constant*>(u_expr->get_operand());
869  if (!const_operand) {
870  // casted subquery result. return invalid for now, but we could attempt to pull the
871  // range from the subquery result in the future
872  CHECK(u_expr->get_operand());
873  VLOG(1) << "Unable to determine expression range for dictionary encoded expression "
874  << u_expr->get_operand()->toString() << ", proceeding with invalid range.";
876  }
877 
878  if (const_operand->get_is_null()) {
880  }
881  CHECK(const_operand->get_constval().stringval);
882  const int64_t v = sdp->getIdOfString(*const_operand->get_constval().stringval);
883  return ExpressionRange::makeIntRange(v, v, 0, false);
884  }
885  const auto arg_range =
886  getExpressionRange(u_expr->get_operand(), query_infos, executor, simple_quals);
887  const auto& arg_ti = u_expr->get_operand()->get_type_info();
888  // Timestamp to Date OR Date/Timestamp casts with different precision
889  if ((ti.is_timestamp() && (arg_ti.get_dimension() != ti.get_dimension())) ||
890  ((arg_ti.is_timestamp() && ti.is_any(kDATE, kTIME)))) {
891  return getDateTimePrecisionCastRange(arg_range, arg_ti, ti);
892  }
893  switch (arg_range.getType()) {
896  if (ti.is_fp()) {
897  return ti.get_type() == kDOUBLE
899  arg_range.getFpMin(), arg_range.getFpMax(), arg_range.hasNulls())
900  : ExpressionRange::makeFloatRange(arg_range.getFpMin(),
901  arg_range.getFpMax(),
902  arg_range.hasNulls());
903  }
904  if (ti.is_integer()) {
905  return ExpressionRange::makeIntRange(std::floor(arg_range.getFpMin()),
906  std::ceil(arg_range.getFpMax()),
907  0,
908  arg_range.hasNulls());
909  }
910  break;
911  }
913  if (ti.is_decimal()) {
914  CHECK_EQ(int64_t(0), arg_range.getBucket());
915  const int64_t scale = exp_to_scale(ti.get_scale() - arg_ti.get_scale());
916  return ExpressionRange::makeIntRange(arg_range.getIntMin() * scale,
917  arg_range.getIntMax() * scale,
918  0,
919  arg_range.hasNulls());
920  }
921  if (arg_ti.is_decimal()) {
922  CHECK_EQ(int64_t(0), arg_range.getBucket());
923  const int64_t scale = exp_to_scale(arg_ti.get_scale());
924  const int64_t scale_half = scale / 2;
925  if (ti.is_fp()) {
926  return fpRangeFromDecimal(arg_range, scale, ti);
927  }
928  return ExpressionRange::makeIntRange((arg_range.getIntMin() - scale_half) / scale,
929  (arg_range.getIntMax() + scale_half) / scale,
930  0,
931  arg_range.hasNulls());
932  }
933  if (ti.is_integer() || ti.is_time()) {
934  return arg_range;
935  }
936  if (ti.get_type() == kFLOAT) {
938  arg_range.getIntMin(), arg_range.getIntMax(), arg_range.hasNulls());
939  }
940  if (ti.get_type() == kDOUBLE) {
942  arg_range.getIntMin(), arg_range.getIntMax(), arg_range.hasNulls());
943  }
944  break;
945  }
947  break;
948  default:
949  CHECK(false);
950  }
952 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
static ExpressionRange makeNullRange()
Definition: sqltypes.h:64
Definition: sqldefs.h:48
static ExpressionRange makeFloatRange(const float fp_min, const float fp_max, const bool has_nulls)
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
static ExpressionRange makeDoubleRange(const double fp_min, const double fp_max, const bool has_nulls)
Definition: sqltypes.h:68
virtual std::string toString() const =0
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:309
const Expr * get_operand() const
Definition: Analyzer.h:379
#define CHECK(condition)
Definition: Logger.h:222
uint64_t exp_to_scale(const unsigned exp)
static ExpressionRange makeInvalidRange()
ExpressionRange getDateTimePrecisionCastRange(const ExpressionRange &arg_range, const SQLTypeInfo &oper_ti, const SQLTypeInfo &target_ti)
SQLOps get_optype() const
Definition: Analyzer.h:378
#define VLOG(n)
Definition: Logger.h:316
ExpressionRange fpRangeFromDecimal(const ExpressionRange &arg_range, const int64_t scale, const SQLTypeInfo &target_ti)

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::ExtractExpr extract_expr,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor,
boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>>  simple_quals 
)

Definition at line 954 of file ExpressionRange.cpp.

References CHECK, ExtractFromTime(), Analyzer::ExtractExpr::get_field(), Analyzer::ExtractExpr::get_from_expr(), DateTimeUtils::get_timestamp_precision_scale(), Analyzer::Expr::get_type_info(), getExpressionRange(), ExpressionRange::getType(), Integer, Invalid, kDATEEPOCH, kDAY, kDOW, kDOY, kEPOCH, kHOUR, kISODOW, kMICROSECOND, kMILLISECOND, kMINUTE, kMONTH, kNANOSECOND, kQUARTER, kQUARTERDAY, kSECOND, kWEEK, kWEEK_SATURDAY, kWEEK_SUNDAY, kYEAR, ExpressionRange::makeIntRange(), and ExpressionRange::makeInvalidRange().

958  {
959  const int32_t extract_field{extract_expr->get_field()};
960  const auto arg_range = getExpressionRange(
961  extract_expr->get_from_expr(), query_infos, executor, simple_quals);
962  const bool has_nulls =
963  arg_range.getType() == ExpressionRangeType::Invalid || arg_range.hasNulls();
964  const auto& extract_expr_ti = extract_expr->get_from_expr()->get_type_info();
965  switch (extract_field) {
966  case kYEAR: {
967  if (arg_range.getType() == ExpressionRangeType::Invalid) {
969  }
970  CHECK(arg_range.getType() == ExpressionRangeType::Integer);
971  const int64_t year_range_min =
972  extract_expr_ti.is_high_precision_timestamp()
973  ? ExtractFromTime(
974  kYEAR,
975  arg_range.getIntMin() /
976  get_timestamp_precision_scale(extract_expr_ti.get_dimension()))
977  : ExtractFromTime(kYEAR, arg_range.getIntMin());
978  const int64_t year_range_max =
979  extract_expr_ti.is_high_precision_timestamp()
980  ? ExtractFromTime(
981  kYEAR,
982  arg_range.getIntMax() /
983  get_timestamp_precision_scale(extract_expr_ti.get_dimension()))
984  : ExtractFromTime(kYEAR, arg_range.getIntMax());
986  year_range_min, year_range_max, 0, arg_range.hasNulls());
987  }
988  case kEPOCH:
989  case kDATEEPOCH:
990  return arg_range;
991  case kQUARTERDAY:
992  case kQUARTER:
993  return ExpressionRange::makeIntRange(1, 4, 0, has_nulls);
994  case kMONTH:
995  return ExpressionRange::makeIntRange(1, 12, 0, has_nulls);
996  case kDAY:
997  return ExpressionRange::makeIntRange(1, 31, 0, has_nulls);
998  case kHOUR:
999  return ExpressionRange::makeIntRange(0, 23, 0, has_nulls);
1000  case kMINUTE:
1001  return ExpressionRange::makeIntRange(0, 59, 0, has_nulls);
1002  case kSECOND:
1003  return ExpressionRange::makeIntRange(0, 60, 0, has_nulls);
1004  case kMILLISECOND:
1005  return ExpressionRange::makeIntRange(0, 999, 0, has_nulls);
1006  case kMICROSECOND:
1007  return ExpressionRange::makeIntRange(0, 999999, 0, has_nulls);
1008  case kNANOSECOND:
1009  return ExpressionRange::makeIntRange(0, 999999999, 0, has_nulls);
1010  case kDOW:
1011  return ExpressionRange::makeIntRange(0, 6, 0, has_nulls);
1012  case kISODOW:
1013  return ExpressionRange::makeIntRange(1, 7, 0, has_nulls);
1014  case kDOY:
1015  return ExpressionRange::makeIntRange(1, 366, 0, has_nulls);
1016  case kWEEK:
1017  case kWEEK_SUNDAY:
1018  case kWEEK_SATURDAY:
1019  return ExpressionRange::makeIntRange(1, 53, 0, has_nulls);
1020  default:
1021  CHECK(false);
1022  }
1024 }
const Expr * get_from_expr() const
Definition: Analyzer.h:1305
ExtractField get_field() const
Definition: Analyzer.h:1304
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
DEVICE int64_t ExtractFromTime(ExtractField field, const int64_t timeval)
ExpressionRangeType getType() const
#define CHECK(condition)
Definition: Logger.h:222
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
static ExpressionRange makeInvalidRange()

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::DatetruncExpr datetrunc_expr,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor,
boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>>  simple_quals 
)

Definition at line 1026 of file ExpressionRange.cpp.

References anonymous_namespace{ExpressionRange.cpp}::get_conservative_datetrunc_bucket(), Analyzer::DatetruncExpr::get_field(), Analyzer::DatetruncExpr::get_from_expr(), DateTimeUtils::get_timestamp_precision_scale(), Analyzer::Expr::get_type_info(), DateTimeTranslator::getDateTruncConstantValue(), getExpressionRange(), Invalid, ExpressionRange::makeIntRange(), and ExpressionRange::makeInvalidRange().

1030  {
1031  const auto arg_range = getExpressionRange(
1032  datetrunc_expr->get_from_expr(), query_infos, executor, simple_quals);
1033  if (arg_range.getType() == ExpressionRangeType::Invalid) {
1035  }
1036  const auto& datetrunc_expr_ti = datetrunc_expr->get_from_expr()->get_type_info();
1037  const int64_t min_ts = DateTimeTranslator::getDateTruncConstantValue(
1038  arg_range.getIntMin(), datetrunc_expr->get_field(), datetrunc_expr_ti);
1039  const int64_t max_ts = DateTimeTranslator::getDateTruncConstantValue(
1040  arg_range.getIntMax(), datetrunc_expr->get_field(), datetrunc_expr_ti);
1041  const int64_t bucket =
1042  datetrunc_expr_ti.is_high_precision_timestamp()
1043  ? get_conservative_datetrunc_bucket(datetrunc_expr->get_field()) *
1045  datetrunc_expr_ti.get_dimension())
1046  : get_conservative_datetrunc_bucket(datetrunc_expr->get_field());
1047 
1048  return ExpressionRange::makeIntRange(min_ts, max_ts, bucket, arg_range.hasNulls());
1049 }
DatetruncField get_field() const
Definition: Analyzer.h:1429
int64_t get_conservative_datetrunc_bucket(const DatetruncField datetrunc_field)
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
const Expr * get_from_expr() const
Definition: Analyzer.h:1430
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
static ExpressionRange makeInvalidRange()
static int64_t getDateTruncConstantValue(const int64_t &timeval, const DatetruncField &field, const SQLTypeInfo &ti)

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::WidthBucketExpr width_bucket_expr,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor,
boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>>  simple_quals 
)

Definition at line 1051 of file ExpressionRange.cpp.

References CHECK, Analyzer::WidthBucketExpr::compute_bucket(), Double, Float, Analyzer::WidthBucketExpr::get_partition_count(), Analyzer::WidthBucketExpr::get_partition_count_val(), Analyzer::WidthBucketExpr::get_target_value(), getExpressionRange(), ExpressionRange::getFpMax(), ExpressionRange::getFpMin(), ExpressionRange::hasNulls(), Integer, Invalid, Analyzer::WidthBucketExpr::is_constant_expr(), ExpressionRange::makeIntRange(), run_benchmark_import::res, and width_bucket_expr().

1055  {
1056  auto target_value_expr = width_bucket_expr->get_target_value();
1057  auto target_value_range = getExpressionRange(target_value_expr, query_infos, executor);
1058  auto target_ti = target_value_expr->get_type_info();
1059  if (width_bucket_expr->is_constant_expr() &&
1060  target_value_range.getType() != ExpressionRangeType::Invalid) {
1061  auto const_target_value = dynamic_cast<const Analyzer::Constant*>(target_value_expr);
1062  if (const_target_value) {
1063  if (const_target_value->get_is_null()) {
1064  // null constant, return default width_bucket range
1066  0, width_bucket_expr->get_partition_count_val(), 0, true);
1067  } else {
1068  CHECK(target_value_range.getFpMax() == target_value_range.getFpMin());
1069  auto target_value_bucket =
1070  width_bucket_expr->compute_bucket(target_value_range.getFpMax(), target_ti);
1072  target_value_bucket, target_value_bucket, 0, target_value_range.hasNulls());
1073  }
1074  }
1075  // compute possible bucket range based on lower and upper bound constants
1076  // to elucidate a target bucket range
1077  const auto target_value_range_with_qual =
1078  getExpressionRange(target_value_expr, query_infos, executor, simple_quals);
1079  auto compute_bucket_range = [&width_bucket_expr](const ExpressionRange& target_range,
1080  SQLTypeInfo ti) {
1081  // we casted bucket bound exprs to double
1082  auto lower_bound_bucket =
1083  width_bucket_expr->compute_bucket<double>(target_range.getFpMin(), ti);
1084  auto upper_bound_bucket =
1085  width_bucket_expr->compute_bucket<double>(target_range.getFpMax(), ti);
1087  lower_bound_bucket, upper_bound_bucket, 0, target_range.hasNulls());
1088  };
1089  auto res_range = compute_bucket_range(target_value_range_with_qual, target_ti);
1090  // check target_value expression's col range to be not nullable iff it has its filter
1091  // expression i.e., in simple_quals
1092  // todo (yoonmin) : need to search simple_quals to cover more cases?
1093  if (target_value_range.getFpMin() < target_value_range_with_qual.getFpMin() ||
1094  target_value_range.getFpMax() > target_value_range_with_qual.getFpMax()) {
1095  res_range.setNulls(false);
1096  }
1097  return res_range;
1098  } else {
1099  // we cannot determine a possibility of skipping oob check safely
1100  const bool has_nulls = target_value_range.getType() == ExpressionRangeType::Invalid ||
1101  target_value_range.hasNulls();
1102  auto partition_expr_range = getExpressionRange(
1103  width_bucket_expr->get_partition_count(), query_infos, executor, simple_quals);
1104  auto res = ExpressionRange::makeIntRange(0, INT32_MAX, 0, has_nulls);
1105  switch (partition_expr_range.getType()) {
1107  res.setIntMax(partition_expr_range.getIntMax() + 1);
1108  break;
1109  }
1112  res.setIntMax(static_cast<int64_t>(partition_expr_range.getFpMax()) + 1);
1113  break;
1114  }
1115  default:
1116  break;
1117  }
1118  return res;
1119  }
1120 }
const Expr * get_partition_count() const
Definition: Analyzer.h:1044
bool is_constant_expr() const
Definition: Analyzer.h:1119
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
bool hasNulls() const
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
double getFpMax() const
double getFpMin() const
int32_t get_partition_count_val() const
Definition: Analyzer.cpp:3705
const Expr * get_target_value() const
Definition: Analyzer.h:1041
#define CHECK(condition)
Definition: Logger.h:222
int32_t compute_bucket(T target_const_val, SQLTypeInfo &ti) const
Definition: Analyzer.h:1082
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int32_t width_bucket_expr(const double target_value, const bool reversed, const double lower_bound, const double upper_bound, const int32_t partition_count)

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::Expr expr,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor,
boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>>  simple_quals 
)

Definition at line 335 of file ExpressionRange.cpp.

References Analyzer::Expr::get_type_info(), getExpressionRange(), ExpressionRange::makeInvalidRange(), and ExpressionRange::typeSupportsRange().

339  {
342  } else if (auto bin_oper_expr = dynamic_cast<const Analyzer::BinOper*>(expr)) {
343  return getExpressionRange(bin_oper_expr, query_infos, executor, simple_quals);
344  } else if (auto constant_expr = dynamic_cast<const Analyzer::Constant*>(expr)) {
345  return getExpressionRange(constant_expr);
346  } else if (auto column_var_expr = dynamic_cast<const Analyzer::ColumnVar*>(expr)) {
347  return getExpressionRange(column_var_expr, query_infos, executor, simple_quals);
348  } else if (auto string_oper_expr = dynamic_cast<const Analyzer::StringOper*>(expr)) {
349  return getExpressionRange(string_oper_expr, executor);
350  } else if (auto like_expr = dynamic_cast<const Analyzer::LikeExpr*>(expr)) {
351  return getExpressionRange(like_expr);
352  } else if (auto case_expr = dynamic_cast<const Analyzer::CaseExpr*>(expr)) {
353  return getExpressionRange(case_expr, query_infos, executor);
354  } else if (auto u_expr = dynamic_cast<const Analyzer::UOper*>(expr)) {
355  return getExpressionRange(u_expr, query_infos, executor, simple_quals);
356  } else if (auto extract_expr = dynamic_cast<const Analyzer::ExtractExpr*>(expr)) {
357  return getExpressionRange(extract_expr, query_infos, executor, simple_quals);
358  } else if (auto datetrunc_expr = dynamic_cast<const Analyzer::DatetruncExpr*>(expr)) {
359  return getExpressionRange(datetrunc_expr, query_infos, executor, simple_quals);
360  } else if (auto width_expr = dynamic_cast<const Analyzer::WidthBucketExpr*>(expr)) {
361  return getExpressionRange(width_expr, query_infos, executor, simple_quals);
362  }
364 }
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
static bool typeSupportsRange(const SQLTypeInfo &ti)
static ExpressionRange makeInvalidRange()

+ Here is the call graph for this function:

ExpressionRange getLeafColumnRange ( const Analyzer::ColumnVar col_expr,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor,
const bool  is_outer_join_proj 
)

Definition at line 522 of file ExpressionRange.cpp.

References CHECK, CHECK_EQ, CHECK_GT, dtDAY, extract_max_stat_fp_type(), extract_max_stat_int_type(), extract_min_stat_fp_type(), extract_min_stat_int_type(), FIND_STAT_FRAG, Analyzer::ColumnVar::get_column_id(), anonymous_namespace{ExpressionRange.cpp}::get_conservative_datetrunc_bucket(), SQLTypeInfo::get_elem_type(), get_logical_type_info(), Analyzer::ColumnVar::get_table_id(), Analyzer::Expr::get_type_info(), SQLTypeInfo::is_array(), kBIGINT, kBOOLEAN, kCHAR, kDATE, kDECIMAL, kDOUBLE, kENCODING_DICT, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, ExpressionRange::makeDoubleRange(), ExpressionRange::makeFloatRange(), ExpressionRange::makeIntRange(), and ExpressionRange::makeInvalidRange().

Referenced by Executor::computeColRangesCache(), and getExpressionRange().

525  {
526  bool has_nulls = is_outer_join_proj;
527  int col_id = col_expr->get_column_id();
528  const auto& col_phys_ti = col_expr->get_type_info().is_array()
529  ? col_expr->get_type_info().get_elem_type()
530  : col_expr->get_type_info();
531  const auto col_ti = get_logical_type_info(col_phys_ti);
532  switch (col_ti.get_type()) {
533  case kTEXT:
534  case kCHAR:
535  case kVARCHAR:
536  CHECK_EQ(kENCODING_DICT, col_ti.get_compression());
537  case kBOOLEAN:
538  case kTINYINT:
539  case kSMALLINT:
540  case kINT:
541  case kBIGINT:
542  case kDECIMAL:
543  case kNUMERIC:
544  case kDATE:
545  case kTIMESTAMP:
546  case kTIME:
547  case kFLOAT:
548  case kDOUBLE: {
549  std::optional<size_t> ti_idx;
550  for (size_t i = 0; i < query_infos.size(); ++i) {
551  if (col_expr->get_table_id() == query_infos[i].table_id) {
552  ti_idx = i;
553  break;
554  }
555  }
556  CHECK(ti_idx);
557  const auto& query_info = query_infos[*ti_idx].info;
558  const auto& fragments = query_info.fragments;
559  const auto cd = executor->getColumnDescriptor(col_expr);
560  if (cd && cd->isVirtualCol) {
561  CHECK(cd->columnName == "rowid");
562  CHECK_EQ(kBIGINT, col_ti.get_type());
563  const int64_t num_tuples = query_info.getNumTuples();
565  0, std::max(num_tuples - 1, int64_t(0)), 0, has_nulls);
566  }
567  if (query_info.getNumTuples() == 0) {
568  // The column doesn't contain any values, synthesize an empty range.
569  if (col_ti.is_fp()) {
570  return col_ti.get_type() == kFLOAT
571  ? ExpressionRange::makeFloatRange(0, -1, false)
572  : ExpressionRange::makeDoubleRange(0, -1, false);
573  }
574  return ExpressionRange::makeIntRange(0, -1, 0, false);
575  }
576  std::vector<size_t> nonempty_fragment_indices;
577  for (size_t i = 0; i < fragments.size(); ++i) {
578  const auto& fragment = fragments[i];
579  if (!fragment.isEmptyPhysicalFragment()) {
580  nonempty_fragment_indices.push_back(i);
581  }
582  }
583  FIND_STAT_FRAG(min);
584  FIND_STAT_FRAG(max);
585  const auto& min_frag = fragments[*min_frag_index];
586  const auto min_it = min_frag.getChunkMetadataMap().find(col_id);
587  if (min_it == min_frag.getChunkMetadataMap().end()) {
589  }
590  const auto& max_frag = fragments[*max_frag_index];
591  const auto max_it = max_frag.getChunkMetadataMap().find(col_id);
592  CHECK(max_it != max_frag.getChunkMetadataMap().end());
593  for (const auto& fragment : fragments) {
594  const auto it = fragment.getChunkMetadataMap().find(col_id);
595  if (it != fragment.getChunkMetadataMap().end()) {
596  if (it->second->chunkStats.has_nulls) {
597  has_nulls = true;
598  break;
599  }
600  }
601  }
602 
603  // Detect FSI placeholder metadata. If we let this through it will be treated as an
604  // empty range, when it really implies an unknown range.
605  if (min_it->second->isPlaceholder() || max_it->second->isPlaceholder()) {
607  }
608 
609  if (col_ti.is_fp()) {
610  const auto min_val = extract_min_stat_fp_type(min_it->second->chunkStats, col_ti);
611  const auto max_val = extract_max_stat_fp_type(max_it->second->chunkStats, col_ti);
612  return col_ti.get_type() == kFLOAT
613  ? ExpressionRange::makeFloatRange(min_val, max_val, has_nulls)
614  : ExpressionRange::makeDoubleRange(min_val, max_val, has_nulls);
615  }
616  const auto min_val = extract_min_stat_int_type(min_it->second->chunkStats, col_ti);
617  const auto max_val = extract_max_stat_int_type(max_it->second->chunkStats, col_ti);
618  if (max_val < min_val) {
619  // The column doesn't contain any non-null values, synthesize an empty range.
620  CHECK_GT(min_val, 0);
621  return ExpressionRange::makeIntRange(0, -1, 0, has_nulls);
622  }
623  const int64_t bucket =
624  col_ti.get_type() == kDATE ? get_conservative_datetrunc_bucket(dtDAY) : 0;
625  return ExpressionRange::makeIntRange(min_val, max_val, bucket, has_nulls);
626  }
627  default:
628  break;
629  }
631 }
int get_table_id() const
Definition: Analyzer.h:201
#define CHECK_EQ(x, y)
Definition: Logger.h:230
#define FIND_STAT_FRAG(stat_name)
Definition: sqltypes.h:64
double extract_max_stat_fp_type(const ChunkStats &stats, const SQLTypeInfo &ti)
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1198
#define CHECK_GT(x, y)
Definition: Logger.h:234
int64_t extract_max_stat_int_type(const ChunkStats &stats, const SQLTypeInfo &ti)
static ExpressionRange makeFloatRange(const float fp_min, const float fp_max, const bool has_nulls)
int64_t get_conservative_datetrunc_bucket(const DatetruncField datetrunc_field)
double extract_min_stat_fp_type(const ChunkStats &stats, const SQLTypeInfo &ti)
int64_t extract_min_stat_int_type(const ChunkStats &stats, const SQLTypeInfo &ti)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
Definition: sqltypes.h:67
Definition: sqltypes.h:68
Definition: sqltypes.h:56
bool g_enable_watchdog false
Definition: Execute.cpp:79
#define CHECK(condition)
Definition: Logger.h:222
Definition: sqltypes.h:60
int get_column_id() const
Definition: Analyzer.h:202
static ExpressionRange makeInvalidRange()
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:956
bool is_array() const
Definition: sqltypes.h:583

+ Here is the call graph for this function:

+ Here is the caller graph for this function: