OmniSciDB  baf940c279
anonymous_namespace{GroupByAndAggregate.cpp} Namespace Reference

Functions

int32_t get_agg_count (const std::vector< Analyzer::Expr *> &target_exprs)
 
bool expr_is_rowid (const Analyzer::Expr *expr, const Catalog_Namespace::Catalog &cat)
 
bool has_count_distinct (const RelAlgExecutionUnit &ra_exe_unit)
 
bool is_column_range_too_big_for_perfect_hash (const ColRangeInfo &col_range_info, const int64_t max_entry_count)
 
bool cardinality_estimate_less_than_column_range (const int64_t cardinality_estimate, const ColRangeInfo &col_range_info)
 
void add_transient_string_literals_for_expression (const Analyzer::Expr *expr, Executor *executor, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 

Function Documentation

◆ add_transient_string_literals_for_expression()

void anonymous_namespace{GroupByAndAggregate.cpp}::add_transient_string_literals_for_expression ( const Analyzer::Expr expr,
Executor executor,
std::shared_ptr< RowSetMemoryOwner row_set_mem_owner 
)

Definition at line 516 of file GroupByAndAggregate.cpp.

References CHECK, CHECK_EQ, Analyzer::CaseExpr::get_domain(), Analyzer::UOper::get_optype(), Analyzer::Expr::get_type_info(), kCAST, and kENCODING_DICT.

Referenced by GroupByAndAggregate::addTransientStringLiterals().

519  {
520  if (!expr) {
521  return;
522  }
523 
524  const auto array_expr = dynamic_cast<const Analyzer::ArrayExpr*>(expr);
525  if (array_expr) {
526  for (size_t i = 0; i < array_expr->getElementCount(); i++) {
528  array_expr->getElement(i), executor, row_set_mem_owner);
529  }
530  return;
531  }
532 
533  const auto cast_expr = dynamic_cast<const Analyzer::UOper*>(expr);
534  const auto& expr_ti = expr->get_type_info();
535  if (cast_expr && cast_expr->get_optype() == kCAST && expr_ti.is_string()) {
536  CHECK_EQ(kENCODING_DICT, expr_ti.get_compression());
537  auto sdp = executor->getStringDictionaryProxy(
538  expr_ti.get_comp_param(), row_set_mem_owner, true);
539  CHECK(sdp);
540  const auto str_lit_expr =
541  dynamic_cast<const Analyzer::Constant*>(cast_expr->get_operand());
542  if (str_lit_expr && str_lit_expr->get_constval().stringval) {
543  sdp->getOrAddTransient(*str_lit_expr->get_constval().stringval);
544  }
545  return;
546  }
547  const auto case_expr = dynamic_cast<const Analyzer::CaseExpr*>(expr);
548  if (!case_expr) {
549  return;
550  }
551  Analyzer::DomainSet domain_set;
552  case_expr->get_domain(domain_set);
553  if (domain_set.empty()) {
554  return;
555  }
556  if (expr_ti.is_string()) {
557  CHECK_EQ(kENCODING_DICT, expr_ti.get_compression());
558  auto sdp = executor->getStringDictionaryProxy(
559  expr_ti.get_comp_param(), row_set_mem_owner, true);
560  CHECK(sdp);
561  for (const auto domain_expr : domain_set) {
562  const auto cast_expr = dynamic_cast<const Analyzer::UOper*>(domain_expr);
563  const auto str_lit_expr =
564  cast_expr && cast_expr->get_optype() == kCAST
565  ? dynamic_cast<const Analyzer::Constant*>(cast_expr->get_operand())
566  : dynamic_cast<const Analyzer::Constant*>(domain_expr);
567  if (str_lit_expr && str_lit_expr->get_constval().stringval) {
568  sdp->getOrAddTransient(*str_lit_expr->get_constval().stringval);
569  }
570  }
571  }
572 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
void get_domain(DomainSet &domain_set) const override
Definition: Analyzer.cpp:3096
Definition: sqldefs.h:49
std::list< const Expr * > DomainSet
Definition: Analyzer.h:61
void add_transient_string_literals_for_expression(const Analyzer::Expr *expr, Executor *executor, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
#define CHECK(condition)
Definition: Logger.h:197
SQLOps get_optype() const
Definition: Analyzer.h:370
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cardinality_estimate_less_than_column_range()

bool anonymous_namespace{GroupByAndAggregate.cpp}::cardinality_estimate_less_than_column_range ( const int64_t  cardinality_estimate,
const ColRangeInfo col_range_info 
)

Definition at line 115 of file GroupByAndAggregate.cpp.

References ColRangeInfo::max, and ColRangeInfo::min.

Referenced by GroupByAndAggregate::getColRangeInfo().

116  {
117  try {
118  // the cardinality estimate is the size of the baseline hash table. further penalize
119  // the baseline hash table by a factor of 2x due to overhead in computing baseline
120  // hash. This has the overall effect of penalizing baseline hash over perfect hash by
121  // 4x; i.e. if the cardinality of the filtered data is less than 25% of the entry
122  // count of the column, we use baseline hash on the filtered set
123  return checked_int64_t(cardinality_estimate) * 2 <
124  static_cast<int64_t>(checked_int64_t(col_range_info.max) -
125  checked_int64_t(col_range_info.min));
126  } catch (...) {
127  return false;
128  }
129 }
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void > > checked_int64_t
+ Here is the caller graph for this function:

◆ expr_is_rowid()

bool anonymous_namespace{GroupByAndAggregate.cpp}::expr_is_rowid ( const Analyzer::Expr expr,
const Catalog_Namespace::Catalog cat 
)

Definition at line 81 of file GroupByAndAggregate.cpp.

References cat(), CHECK_EQ, and get_column_descriptor_maybe().

Referenced by GroupByAndAggregate::getColRangeInfo().

81  {
82  const auto col = dynamic_cast<const Analyzer::ColumnVar*>(expr);
83  if (!col) {
84  return false;
85  }
86  const auto cd =
87  get_column_descriptor_maybe(col->get_column_id(), col->get_table_id(), cat);
88  if (!cd || !cd->isVirtualCol) {
89  return false;
90  }
91  CHECK_EQ("rowid", cd->columnName);
92  return true;
93 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::string cat(Ts &&... args)
const ColumnDescriptor * get_column_descriptor_maybe(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:183
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_agg_count()

int32_t anonymous_namespace{GroupByAndAggregate.cpp}::get_agg_count ( const std::vector< Analyzer::Expr *> &  target_exprs)

Definition at line 55 of file GroupByAndAggregate.cpp.

References agg_count(), CHECK, Analyzer::Expr::get_type_info(), kAVG, kENCODING_NONE, and kSAMPLE.

Referenced by GroupByAndAggregate::codegen().

55  {
56  int32_t agg_count{0};
57  for (auto target_expr : target_exprs) {
58  CHECK(target_expr);
59  const auto agg_expr = dynamic_cast<Analyzer::AggExpr*>(target_expr);
60  if (!agg_expr || agg_expr->get_aggtype() == kSAMPLE) {
61  const auto& ti = target_expr->get_type_info();
62  // TODO(pavan): or if is_geometry()
63  if (ti.is_array() || (ti.is_string() && ti.get_compression() == kENCODING_NONE)) {
64  agg_count += 2;
65  } else if (ti.is_geometry()) {
66  agg_count += ti.get_physical_coord_cols() * 2;
67  } else {
68  ++agg_count;
69  }
70  continue;
71  }
72  if (agg_expr && agg_expr->get_aggtype() == kAVG) {
73  agg_count += 2;
74  } else {
75  ++agg_count;
76  }
77  }
78  return agg_count;
79 }
ALWAYS_INLINE uint64_t agg_count(uint64_t *agg, const int64_t)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
#define CHECK(condition)
Definition: Logger.h:197
Definition: sqldefs.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ has_count_distinct()

bool anonymous_namespace{GroupByAndAggregate.cpp}::has_count_distinct ( const RelAlgExecutionUnit ra_exe_unit)

Definition at line 95 of file GroupByAndAggregate.cpp.

References g_bigint_count, get_target_info(), is_distinct_target(), and RelAlgExecutionUnit::target_exprs.

Referenced by GroupByAndAggregate::getColRangeInfo().

95  {
96  for (const auto& target_expr : ra_exe_unit.target_exprs) {
97  const auto agg_info = get_target_info(target_expr, g_bigint_count);
98  if (agg_info.is_agg && is_distinct_target(agg_info)) {
99  return true;
100  }
101  }
102  return false;
103 }
std::vector< Analyzer::Expr * > target_exprs
TargetInfo get_target_info(const PointerType target_expr, const bool bigint_count)
Definition: TargetInfo.h:78
bool g_bigint_count
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:129
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_column_range_too_big_for_perfect_hash()

bool anonymous_namespace{GroupByAndAggregate.cpp}::is_column_range_too_big_for_perfect_hash ( const ColRangeInfo col_range_info,
const int64_t  max_entry_count 
)

Definition at line 105 of file GroupByAndAggregate.cpp.

References ColRangeInfo::max, and ColRangeInfo::min.

Referenced by GroupByAndAggregate::getColRangeInfo().

106  {
107  try {
108  return static_cast<int64_t>(checked_int64_t(col_range_info.max) -
109  checked_int64_t(col_range_info.min)) >= max_entry_count;
110  } catch (...) {
111  return true;
112  }
113 }
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void > > checked_int64_t
+ Here is the caller graph for this function: