OmniSciDB  16c4e035a1
 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::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 466 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:35
Definition: sqldefs.h:36
Definition: sqldefs.h:30
Definition: sqldefs.h:34
double getFpMax() const
double getFpMin() const
void setFpMax(const double fp_max)
Definition: sqldefs.h:33
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: sqltypes.h:215
#define CHECK(condition)
Definition: Logger.h:211
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51

+ 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:35
Definition: sqldefs.h:36
Definition: sqldefs.h:30
void setIntMin(const int64_t int_min)
Definition: sqldefs.h:34
void setIntMax(const int64_t int_max)
int64_t getIntMax() const
Definition: sqldefs.h:33

+ 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:193
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:194

+ 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 388 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().

392  {
393  const auto& lhs =
394  getExpressionRange(expr->get_left_operand(), query_infos, executor, simple_quals);
395  const auto& rhs =
396  getExpressionRange(expr->get_right_operand(), query_infos, executor, simple_quals);
397  switch (expr->get_optype()) {
398  case kPLUS:
399  return lhs + rhs;
400  case kMINUS:
401  return lhs - rhs;
402  case kMULTIPLY:
403  return lhs * rhs;
404  case kDIVIDE: {
405  const auto& lhs_type = expr->get_left_operand()->get_type_info();
406  if (lhs_type.is_decimal() && lhs.getType() != ExpressionRangeType::Invalid) {
407  CHECK(lhs.getType() == ExpressionRangeType::Integer);
408  const auto adjusted_lhs = ExpressionRange::makeIntRange(
409  scale_up_interval_endpoint(lhs.getIntMin(), lhs_type),
410  scale_up_interval_endpoint(lhs.getIntMax(), lhs_type),
411  0,
412  lhs.hasNulls());
413  return adjusted_lhs / rhs;
414  }
415  return lhs / rhs;
416  }
417  default:
418  break;
419  }
421 }
const Expr * get_right_operand() const
Definition: Analyzer.h:442
Definition: sqldefs.h:41
int64_t scale_up_interval_endpoint(const int64_t endpoint, const SQLTypeInfo &ti)
SQLOps get_optype() const
Definition: Analyzer.h:438
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:77
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
Definition: sqldefs.h:40
#define CHECK(condition)
Definition: Logger.h:211
const Expr * get_left_operand() const
Definition: Analyzer.h:441
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 423 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().

423  {
424  if (constant_expr->get_is_null()) {
426  }
427  const auto constant_type = constant_expr->get_type_info().get_type();
428  const auto datum = constant_expr->get_constval();
429  switch (constant_type) {
430  case kTINYINT: {
431  const int64_t v = datum.tinyintval;
432  return ExpressionRange::makeIntRange(v, v, 0, false);
433  }
434  case kSMALLINT: {
435  const int64_t v = datum.smallintval;
436  return ExpressionRange::makeIntRange(v, v, 0, false);
437  }
438  case kINT: {
439  const int64_t v = datum.intval;
440  return ExpressionRange::makeIntRange(v, v, 0, false);
441  }
442  case kBIGINT:
443  case kNUMERIC:
444  case kDECIMAL: {
445  const int64_t v = datum.bigintval;
446  return ExpressionRange::makeIntRange(v, v, 0, false);
447  }
448  case kTIME:
449  case kTIMESTAMP:
450  case kDATE: {
451  const int64_t v = datum.bigintval;
452  return ExpressionRange::makeIntRange(v, v, 0, false);
453  }
454  case kFLOAT: {
455  return ExpressionRange::makeFloatRange(datum.floatval, datum.floatval, false);
456  }
457  case kDOUBLE: {
458  return ExpressionRange::makeDoubleRange(datum.doubleval, datum.doubleval, false);
459  }
460  default:
461  break;
462  }
464 }
Definition: sqltypes.h:49
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:53
Definition: sqltypes.h:45
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 642 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().

646  {
647  const int rte_idx = col_expr->get_rte_idx();
648  CHECK_GE(rte_idx, 0);
649  CHECK_LT(static_cast<size_t>(rte_idx), query_infos.size());
650  bool is_outer_join_proj = rte_idx > 0 && executor->containsLeftDeepOuterJoin();
651  if (col_expr->get_table_id() > 0) {
652  auto col_range = executor->getColRange(
653  PhysicalInput{col_expr->get_column_id(), col_expr->get_table_id()});
654  if (is_outer_join_proj) {
655  col_range.setHasNulls();
656  }
657  return apply_simple_quals(col_expr, col_range, simple_quals);
658  }
659  return getLeafColumnRange(col_expr, query_infos, executor, is_outer_join_proj);
660 }
int get_table_id() const
Definition: Analyzer.h:193
#define CHECK_GE(x, y)
Definition: Logger.h:224
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:221
int get_rte_idx() const
Definition: Analyzer.h:195
int get_column_id() const
Definition: Analyzer.h:194

+ Here is the call graph for this function:

ExpressionRange getExpressionRange ( const Analyzer::LikeExpr like_expr)

Definition at line 662 of file ExpressionRange.cpp.

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

662  {
663  const auto& ti = like_expr->get_type_info();
664  CHECK(ti.is_boolean());
665  const auto& arg_ti = like_expr->get_arg()->get_type_info();
667  arg_ti.get_notnull() ? 0 : inline_int_null_val(ti), 1, 0, false);
668 }
const Expr * get_arg() const
Definition: Analyzer.h:951
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77
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:211
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 670 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.

672  {
673  const auto& expr_pair_list = case_expr->get_expr_pair_list();
674  auto expr_range = ExpressionRange::makeInvalidRange();
675  bool has_nulls = false;
676  for (const auto& expr_pair : expr_pair_list) {
677  CHECK_EQ(expr_pair.first->get_type_info().get_type(), kBOOLEAN);
678  const auto crt_range =
679  getExpressionRange(expr_pair.second.get(), query_infos, executor);
680  if (crt_range.getType() == ExpressionRangeType::Null) {
681  has_nulls = true;
682  continue;
683  }
684  if (crt_range.getType() == ExpressionRangeType::Invalid) {
686  }
687  expr_range = (expr_range.getType() != ExpressionRangeType::Invalid)
688  ? expr_range || crt_range
689  : crt_range;
690  }
691  if (has_nulls && !(expr_range.getType() == ExpressionRangeType::Invalid)) {
692  expr_range.setHasNulls();
693  }
694  const auto else_expr = case_expr->get_else_expr();
695  CHECK(else_expr);
696  const auto else_null_expr = dynamic_cast<const Analyzer::Constant*>(else_expr);
697  if (else_null_expr && else_null_expr->get_is_null()) {
698  expr_range.setHasNulls();
699  return expr_range;
700  }
701  return expr_range || getExpressionRange(else_expr, query_infos, executor);
702 }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
const Expr * get_else_expr() const
Definition: Analyzer.h:1307
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:211
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:1304

+ 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 769 of file ExpressionRange.cpp.

References 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, kDOUBLE, kENCODING_DICT, kFLOAT, kUNNEST, ExpressionRange::makeDoubleRange(), ExpressionRange::makeFloatRange(), ExpressionRange::makeIntRange(), ExpressionRange::makeInvalidRange(), ExpressionRange::makeNullRange(), Analyzer::Expr::toString(), and VLOG.

773  {
774  if (u_expr->get_optype() == kUNNEST) {
775  return getExpressionRange(u_expr->get_operand(), query_infos, executor, simple_quals);
776  }
777  if (u_expr->get_optype() != kCAST) {
779  }
780  const auto& ti = u_expr->get_type_info();
781  if (ti.is_string() && ti.get_compression() == kENCODING_DICT) {
782  const auto sdp = executor->getStringDictionaryProxy(
783  ti.get_comp_param(), executor->getRowSetMemoryOwner(), true);
784  CHECK(sdp);
785  const auto const_operand =
786  dynamic_cast<const Analyzer::Constant*>(u_expr->get_operand());
787  if (!const_operand) {
788  // casted subquery result. return invalid for now, but we could attempt to pull the
789  // range from the subquery result in the future
790  CHECK(u_expr->get_operand());
791  VLOG(1) << "Unable to determine expression range for dictionary encoded expression "
792  << u_expr->get_operand()->toString() << ", proceeding with invalid range.";
794  }
795 
796  if (const_operand->get_is_null()) {
798  }
799  CHECK(const_operand->get_constval().stringval);
800  const int64_t v = sdp->getIdOfString(*const_operand->get_constval().stringval);
801  return ExpressionRange::makeIntRange(v, v, 0, false);
802  }
803  const auto arg_range =
804  getExpressionRange(u_expr->get_operand(), query_infos, executor, simple_quals);
805  const auto& arg_ti = u_expr->get_operand()->get_type_info();
806  // Timestamp to Date OR Date/Timestamp casts with different precision
807  if ((ti.is_timestamp() && (arg_ti.get_dimension() != ti.get_dimension())) ||
808  ((arg_ti.is_timestamp() && ti.is_date()))) {
809  return getDateTimePrecisionCastRange(arg_range, arg_ti, ti);
810  }
811  switch (arg_range.getType()) {
814  if (ti.is_fp()) {
815  return ti.get_type() == kDOUBLE
817  arg_range.getFpMin(), arg_range.getFpMax(), arg_range.hasNulls())
818  : ExpressionRange::makeFloatRange(arg_range.getFpMin(),
819  arg_range.getFpMax(),
820  arg_range.hasNulls());
821  }
822  if (ti.is_integer()) {
823  return ExpressionRange::makeIntRange(std::floor(arg_range.getFpMin()),
824  std::ceil(arg_range.getFpMax()),
825  0,
826  arg_range.hasNulls());
827  }
828  break;
829  }
831  if (ti.is_decimal()) {
832  CHECK_EQ(int64_t(0), arg_range.getBucket());
833  const int64_t scale = exp_to_scale(ti.get_scale() - arg_ti.get_scale());
834  return ExpressionRange::makeIntRange(arg_range.getIntMin() * scale,
835  arg_range.getIntMax() * scale,
836  0,
837  arg_range.hasNulls());
838  }
839  if (arg_ti.is_decimal()) {
840  CHECK_EQ(int64_t(0), arg_range.getBucket());
841  const int64_t scale = exp_to_scale(arg_ti.get_scale());
842  const int64_t scale_half = scale / 2;
843  if (ti.is_fp()) {
844  return fpRangeFromDecimal(arg_range, scale, ti);
845  }
846  return ExpressionRange::makeIntRange((arg_range.getIntMin() - scale_half) / scale,
847  (arg_range.getIntMax() + scale_half) / scale,
848  0,
849  arg_range.hasNulls());
850  }
851  if (ti.is_integer() || ti.is_time()) {
852  return arg_range;
853  }
854  if (ti.get_type() == kFLOAT) {
856  arg_range.getIntMin(), arg_range.getIntMax(), arg_range.hasNulls());
857  }
858  if (ti.get_type() == kDOUBLE) {
860  arg_range.getIntMin(), arg_range.getIntMax(), arg_range.hasNulls());
861  }
862  break;
863  }
865  break;
866  default:
867  CHECK(false);
868  }
870 }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
static ExpressionRange makeNullRange()
Definition: sqldefs.h:49
static ExpressionRange makeFloatRange(const float fp_min, const float fp_max, const bool has_nulls)
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:77
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)
virtual std::string toString() const =0
const Expr * get_operand() const
Definition: Analyzer.h:370
#define CHECK(condition)
Definition: Logger.h:211
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:369
#define VLOG(n)
Definition: Logger.h:305
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 872 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().

876  {
877  const int32_t extract_field{extract_expr->get_field()};
878  const auto arg_range = getExpressionRange(
879  extract_expr->get_from_expr(), query_infos, executor, simple_quals);
880  const bool has_nulls =
881  arg_range.getType() == ExpressionRangeType::Invalid || arg_range.hasNulls();
882  const auto& extract_expr_ti = extract_expr->get_from_expr()->get_type_info();
883  switch (extract_field) {
884  case kYEAR: {
885  if (arg_range.getType() == ExpressionRangeType::Invalid) {
887  }
888  CHECK(arg_range.getType() == ExpressionRangeType::Integer);
889  const int64_t year_range_min =
890  extract_expr_ti.is_high_precision_timestamp()
891  ? ExtractFromTime(
892  kYEAR,
893  arg_range.getIntMin() /
894  get_timestamp_precision_scale(extract_expr_ti.get_dimension()))
895  : ExtractFromTime(kYEAR, arg_range.getIntMin());
896  const int64_t year_range_max =
897  extract_expr_ti.is_high_precision_timestamp()
898  ? ExtractFromTime(
899  kYEAR,
900  arg_range.getIntMax() /
901  get_timestamp_precision_scale(extract_expr_ti.get_dimension()))
902  : ExtractFromTime(kYEAR, arg_range.getIntMax());
904  year_range_min, year_range_max, 0, arg_range.hasNulls());
905  }
906  case kEPOCH:
907  case kDATEEPOCH:
908  return arg_range;
909  case kQUARTERDAY:
910  case kQUARTER:
911  return ExpressionRange::makeIntRange(1, 4, 0, has_nulls);
912  case kMONTH:
913  return ExpressionRange::makeIntRange(1, 12, 0, has_nulls);
914  case kDAY:
915  return ExpressionRange::makeIntRange(1, 31, 0, has_nulls);
916  case kHOUR:
917  return ExpressionRange::makeIntRange(0, 23, 0, has_nulls);
918  case kMINUTE:
919  return ExpressionRange::makeIntRange(0, 59, 0, has_nulls);
920  case kSECOND:
921  return ExpressionRange::makeIntRange(0, 60, 0, has_nulls);
922  case kMILLISECOND:
923  return ExpressionRange::makeIntRange(0, 999, 0, has_nulls);
924  case kMICROSECOND:
925  return ExpressionRange::makeIntRange(0, 999999, 0, has_nulls);
926  case kNANOSECOND:
927  return ExpressionRange::makeIntRange(0, 999999999, 0, has_nulls);
928  case kDOW:
929  return ExpressionRange::makeIntRange(0, 6, 0, has_nulls);
930  case kISODOW:
931  return ExpressionRange::makeIntRange(1, 7, 0, has_nulls);
932  case kDOY:
933  return ExpressionRange::makeIntRange(1, 366, 0, has_nulls);
934  case kWEEK:
935  case kWEEK_SUNDAY:
936  case kWEEK_SATURDAY:
937  return ExpressionRange::makeIntRange(1, 53, 0, has_nulls);
938  default:
939  CHECK(false);
940  }
942 }
const Expr * get_from_expr() const
Definition: Analyzer.h:1352
ExtractField get_field() const
Definition: Analyzer.h:1351
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:77
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:211
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 944 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().

948  {
949  const auto arg_range = getExpressionRange(
950  datetrunc_expr->get_from_expr(), query_infos, executor, simple_quals);
951  if (arg_range.getType() == ExpressionRangeType::Invalid) {
953  }
954  const auto& datetrunc_expr_ti = datetrunc_expr->get_from_expr()->get_type_info();
955  const int64_t min_ts = DateTimeTranslator::getDateTruncConstantValue(
956  arg_range.getIntMin(), datetrunc_expr->get_field(), datetrunc_expr_ti);
957  const int64_t max_ts = DateTimeTranslator::getDateTruncConstantValue(
958  arg_range.getIntMax(), datetrunc_expr->get_field(), datetrunc_expr_ti);
959  const int64_t bucket =
960  datetrunc_expr_ti.is_high_precision_timestamp()
961  ? get_conservative_datetrunc_bucket(datetrunc_expr->get_field()) *
963  datetrunc_expr_ti.get_dimension())
964  : get_conservative_datetrunc_bucket(datetrunc_expr->get_field());
965 
966  return ExpressionRange::makeIntRange(min_ts, max_ts, bucket, arg_range.hasNulls());
967 }
DatetruncField get_field() const
Definition: Analyzer.h:1476
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:77
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:1477
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 969 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(), INT32_MAX, Integer, Invalid, Analyzer::WidthBucketExpr::is_constant_expr(), ExpressionRange::makeIntRange(), run_benchmark_import::res, and width_bucket_expr().

973  {
974  auto target_value_expr = width_bucket_expr->get_target_value();
975  auto target_value_range = getExpressionRange(target_value_expr, query_infos, executor);
976  auto target_ti = target_value_expr->get_type_info();
977  if (width_bucket_expr->is_constant_expr() &&
978  target_value_range.getType() != ExpressionRangeType::Invalid) {
979  auto const_target_value = dynamic_cast<const Analyzer::Constant*>(target_value_expr);
980  if (const_target_value) {
981  if (const_target_value->get_is_null()) {
982  // null constant, return default width_bucket range
984  0, width_bucket_expr->get_partition_count_val(), 0, true);
985  } else {
986  CHECK(target_value_range.getFpMax() == target_value_range.getFpMin());
987  auto target_value_bucket =
988  width_bucket_expr->compute_bucket(target_value_range.getFpMax(), target_ti);
990  target_value_bucket, target_value_bucket, 0, target_value_range.hasNulls());
991  }
992  }
993  // compute possible bucket range based on lower and upper bound constants
994  // to elucidate a target bucket range
995  const auto target_value_range_with_qual =
996  getExpressionRange(target_value_expr, query_infos, executor, simple_quals);
997  auto compute_bucket_range = [&width_bucket_expr](const ExpressionRange& target_range,
998  SQLTypeInfo ti) {
999  // we casted bucket bound exprs to double
1000  auto lower_bound_bucket =
1001  width_bucket_expr->compute_bucket<double>(target_range.getFpMin(), ti);
1002  auto upper_bound_bucket =
1003  width_bucket_expr->compute_bucket<double>(target_range.getFpMax(), ti);
1005  lower_bound_bucket, upper_bound_bucket, 0, target_range.hasNulls());
1006  };
1007  auto res_range = compute_bucket_range(target_value_range_with_qual, target_ti);
1008  // check target_value expression's col range to be not nullable iff it has its filter
1009  // expression i.e., in simple_quals
1010  // todo (yoonmin) : need to search simple_quals to cover more cases?
1011  if (target_value_range.getFpMin() < target_value_range_with_qual.getFpMin() ||
1012  target_value_range.getFpMax() > target_value_range_with_qual.getFpMax()) {
1013  res_range.setNulls(false);
1014  }
1015  return res_range;
1016  } else {
1017  // we cannot determine a possibility of skipping oob check safely
1018  const bool has_nulls = target_value_range.getType() == ExpressionRangeType::Invalid ||
1019  target_value_range.hasNulls();
1020  auto partition_expr_range = getExpressionRange(
1021  width_bucket_expr->get_partition_count(), query_infos, executor, simple_quals);
1022  auto res = ExpressionRange::makeIntRange(0, INT32_MAX, 0, has_nulls);
1023  switch (partition_expr_range.getType()) {
1025  res.setIntMax(partition_expr_range.getIntMax() + 1);
1026  break;
1027  }
1030  res.setIntMax(static_cast<int64_t>(partition_expr_range.getFpMax()) + 1);
1031  break;
1032  }
1033  default:
1034  break;
1035  }
1036  return res;
1037  }
1038 }
const Expr * get_partition_count() const
Definition: Analyzer.h:1091
bool is_constant_expr() const
Definition: Analyzer.h:1166
#define INT32_MAX
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
RUNTIME_EXPORT ALWAYS_INLINE DEVICE double width_bucket_expr(const double target_value, const bool reversed, const double lower_bound, const double upper_bound, const int32_t partition_count)
int32_t get_partition_count_val() const
Definition: Analyzer.cpp:3430
const Expr * get_target_value() const
Definition: Analyzer.h:1088
#define CHECK(condition)
Definition: Logger.h:211
int32_t compute_bucket(T target_const_val, SQLTypeInfo &ti) const
Definition: Analyzer.h:1129

+ 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 332 of file ExpressionRange.cpp.

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

336  {
337  const auto& expr_ti = expr->get_type_info();
338  if (!ExpressionRange::typeSupportsRange(expr_ti)) {
340  }
341  auto bin_oper_expr = dynamic_cast<const Analyzer::BinOper*>(expr);
342  if (bin_oper_expr) {
343  return getExpressionRange(bin_oper_expr, query_infos, executor, simple_quals);
344  }
345  auto constant_expr = dynamic_cast<const Analyzer::Constant*>(expr);
346  if (constant_expr) {
347  return getExpressionRange(constant_expr);
348  }
349  auto column_var_expr = dynamic_cast<const Analyzer::ColumnVar*>(expr);
350  if (column_var_expr) {
351  return getExpressionRange(column_var_expr, query_infos, executor, simple_quals);
352  }
353  auto like_expr = dynamic_cast<const Analyzer::LikeExpr*>(expr);
354  if (like_expr) {
355  return getExpressionRange(like_expr);
356  }
357  auto case_expr = dynamic_cast<const Analyzer::CaseExpr*>(expr);
358  if (case_expr) {
359  return getExpressionRange(case_expr, query_infos, executor);
360  }
361  auto u_expr = dynamic_cast<const Analyzer::UOper*>(expr);
362  if (u_expr) {
363  return getExpressionRange(u_expr, query_infos, executor, simple_quals);
364  }
365  auto extract_expr = dynamic_cast<const Analyzer::ExtractExpr*>(expr);
366  if (extract_expr) {
367  return getExpressionRange(extract_expr, query_infos, executor, simple_quals);
368  }
369  auto datetrunc_expr = dynamic_cast<const Analyzer::DatetruncExpr*>(expr);
370  if (datetrunc_expr) {
371  return getExpressionRange(datetrunc_expr, query_infos, executor, simple_quals);
372  }
373  auto width_bucket_expr = dynamic_cast<const Analyzer::WidthBucketExpr*>(expr);
374  if (width_bucket_expr) {
375  return getExpressionRange(width_bucket_expr, query_infos, executor, simple_quals);
376  }
378 }
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:77
RUNTIME_EXPORT ALWAYS_INLINE DEVICE double width_bucket_expr(const double target_value, const bool reversed, const double lower_bound, const double upper_bound, const int32_t partition_count)
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 536 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(), i, 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().

539  {
540  bool has_nulls = is_outer_join_proj;
541  int col_id = col_expr->get_column_id();
542  const auto& col_phys_ti = col_expr->get_type_info().is_array()
543  ? col_expr->get_type_info().get_elem_type()
544  : col_expr->get_type_info();
545  const auto col_ti = get_logical_type_info(col_phys_ti);
546  switch (col_ti.get_type()) {
547  case kTEXT:
548  case kCHAR:
549  case kVARCHAR:
550  CHECK_EQ(kENCODING_DICT, col_ti.get_compression());
551  case kBOOLEAN:
552  case kTINYINT:
553  case kSMALLINT:
554  case kINT:
555  case kBIGINT:
556  case kDECIMAL:
557  case kNUMERIC:
558  case kDATE:
559  case kTIMESTAMP:
560  case kTIME:
561  case kFLOAT:
562  case kDOUBLE: {
563  std::optional<size_t> ti_idx;
564  for (size_t i = 0; i < query_infos.size(); ++i) {
565  if (col_expr->get_table_id() == query_infos[i].table_id) {
566  ti_idx = i;
567  break;
568  }
569  }
570  CHECK(ti_idx);
571  const auto& query_info = query_infos[*ti_idx].info;
572  const auto& fragments = query_info.fragments;
573  const auto cd = executor->getColumnDescriptor(col_expr);
574  if (cd && cd->isVirtualCol) {
575  CHECK(cd->columnName == "rowid");
576  CHECK_EQ(kBIGINT, col_ti.get_type());
577  const int64_t num_tuples = query_info.getNumTuples();
579  0, std::max(num_tuples - 1, int64_t(0)), 0, has_nulls);
580  }
581  if (query_info.getNumTuples() == 0) {
582  // The column doesn't contain any values, synthesize an empty range.
583  if (col_ti.is_fp()) {
584  return col_ti.get_type() == kFLOAT
585  ? ExpressionRange::makeFloatRange(0, -1, false)
586  : ExpressionRange::makeDoubleRange(0, -1, false);
587  }
588  return ExpressionRange::makeIntRange(0, -1, 0, false);
589  }
590  std::vector<size_t> nonempty_fragment_indices;
591  for (size_t i = 0; i < fragments.size(); ++i) {
592  const auto& fragment = fragments[i];
593  if (!fragment.isEmptyPhysicalFragment()) {
594  nonempty_fragment_indices.push_back(i);
595  }
596  }
597  FIND_STAT_FRAG(min);
598  FIND_STAT_FRAG(max);
599  const auto& min_frag = fragments[*min_frag_index];
600  const auto min_it = min_frag.getChunkMetadataMap().find(col_id);
601  if (min_it == min_frag.getChunkMetadataMap().end()) {
603  }
604  const auto& max_frag = fragments[*max_frag_index];
605  const auto max_it = max_frag.getChunkMetadataMap().find(col_id);
606  CHECK(max_it != max_frag.getChunkMetadataMap().end());
607  for (const auto& fragment : fragments) {
608  const auto it = fragment.getChunkMetadataMap().find(col_id);
609  if (it != fragment.getChunkMetadataMap().end()) {
610  if (it->second->chunkStats.has_nulls) {
611  has_nulls = true;
612  break;
613  }
614  }
615  }
616  if (col_ti.is_fp()) {
617  const auto min_val = extract_min_stat_fp_type(min_it->second->chunkStats, col_ti);
618  const auto max_val = extract_max_stat_fp_type(max_it->second->chunkStats, col_ti);
619  return col_ti.get_type() == kFLOAT
620  ? ExpressionRange::makeFloatRange(min_val, max_val, has_nulls)
621  : ExpressionRange::makeDoubleRange(min_val, max_val, has_nulls);
622  }
623  const auto min_val = extract_min_stat_int_type(min_it->second->chunkStats, col_ti);
624  const auto max_val = extract_max_stat_int_type(max_it->second->chunkStats, col_ti);
625  if (max_val < min_val) {
626  // The column doesn't contain any non-null values, synthesize an empty range.
627  CHECK_GT(min_val, 0);
628  return ExpressionRange::makeIntRange(0, -1, 0, has_nulls);
629  }
630  const int64_t bucket =
631  col_ti.get_type() == kDATE ? get_conservative_datetrunc_bucket(dtDAY) : 0;
632  return ExpressionRange::makeIntRange(min_val, max_val, bucket, has_nulls);
633  }
634  default:
635  break;
636  }
638 }
int get_table_id() const
Definition: Analyzer.h:193
#define CHECK_EQ(x, y)
Definition: Logger.h:219
#define FIND_STAT_FRAG(stat_name)
Definition: sqltypes.h:49
double extract_max_stat_fp_type(const ChunkStats &stats, const SQLTypeInfo &ti)
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1064
#define CHECK_GT(x, y)
Definition: Logger.h:223
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:77
static ExpressionRange makeIntRange(const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
Definition: sqltypes.h:52
Definition: sqltypes.h:53
Definition: sqltypes.h:41
bool g_enable_watchdog false
Definition: Execute.cpp:76
#define CHECK(condition)
Definition: Logger.h:211
Definition: sqltypes.h:45
int get_column_id() const
Definition: Analyzer.h:194
static ExpressionRange makeInvalidRange()
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:861
bool is_array() const
Definition: sqltypes.h:527

+ Here is the call graph for this function:

+ Here is the caller graph for this function: