OmniSciDB  bf83d84833
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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 518 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().

521  {
522  if (!expr) {
523  return;
524  }
525 
526  const auto array_expr = dynamic_cast<const Analyzer::ArrayExpr*>(expr);
527  if (array_expr) {
528  for (size_t i = 0; i < array_expr->getElementCount(); i++) {
530  array_expr->getElement(i), executor, row_set_mem_owner);
531  }
532  return;
533  }
534 
535  const auto cast_expr = dynamic_cast<const Analyzer::UOper*>(expr);
536  const auto& expr_ti = expr->get_type_info();
537  if (cast_expr && cast_expr->get_optype() == kCAST && expr_ti.is_string()) {
538  CHECK_EQ(kENCODING_DICT, expr_ti.get_compression());
539  auto sdp = executor->getStringDictionaryProxy(
540  expr_ti.get_comp_param(), row_set_mem_owner, true);
541  CHECK(sdp);
542  const auto str_lit_expr =
543  dynamic_cast<const Analyzer::Constant*>(cast_expr->get_operand());
544  if (str_lit_expr && str_lit_expr->get_constval().stringval) {
545  sdp->getOrAddTransient(*str_lit_expr->get_constval().stringval);
546  }
547  return;
548  }
549  const auto case_expr = dynamic_cast<const Analyzer::CaseExpr*>(expr);
550  if (!case_expr) {
551  return;
552  }
553  Analyzer::DomainSet domain_set;
554  case_expr->get_domain(domain_set);
555  if (domain_set.empty()) {
556  return;
557  }
558  if (expr_ti.is_string()) {
559  CHECK_EQ(kENCODING_DICT, expr_ti.get_compression());
560  auto sdp = executor->getStringDictionaryProxy(
561  expr_ti.get_comp_param(), row_set_mem_owner, true);
562  CHECK(sdp);
563  for (const auto domain_expr : domain_set) {
564  const auto cast_expr = dynamic_cast<const Analyzer::UOper*>(domain_expr);
565  const auto str_lit_expr =
566  cast_expr && cast_expr->get_optype() == kCAST
567  ? dynamic_cast<const Analyzer::Constant*>(cast_expr->get_operand())
568  : dynamic_cast<const Analyzer::Constant*>(domain_expr);
569  if (str_lit_expr && str_lit_expr->get_constval().stringval) {
570  sdp->getOrAddTransient(*str_lit_expr->get_constval().stringval);
571  }
572  }
573  }
574 }
#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
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
void add_transient_string_literals_for_expression(const Analyzer::Expr *expr, Executor *executor, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
#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:

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

Definition at line 117 of file GroupByAndAggregate.cpp.

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

Referenced by GroupByAndAggregate::getColRangeInfo().

118  {
119  try {
120  // the cardinality estimate is the size of the baseline hash table. further penalize
121  // the baseline hash table by a factor of 2x due to overhead in computing baseline
122  // hash. This has the overall effect of penalizing baseline hash over perfect hash by
123  // 4x; i.e. if the cardinality of the filtered data is less than 25% of the entry
124  // count of the column, we use baseline hash on the filtered set
125  return checked_int64_t(cardinality_estimate) * 2 <
126  static_cast<int64_t>(checked_int64_t(col_range_info.max) -
127  checked_int64_t(col_range_info.min));
128  } catch (...) {
129  return false;
130  }
131 }
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:

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

Definition at line 83 of file GroupByAndAggregate.cpp.

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

Referenced by GroupByAndAggregate::getColRangeInfo().

83  {
84  const auto col = dynamic_cast<const Analyzer::ColumnVar*>(expr);
85  if (!col) {
86  return false;
87  }
88  const auto cd =
89  get_column_descriptor_maybe(col->get_column_id(), col->get_table_id(), cat);
90  if (!cd || !cd->isVirtualCol) {
91  return false;
92  }
93  CHECK_EQ("rowid", cd->columnName);
94  return true;
95 }
#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:216

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 57 of file GroupByAndAggregate.cpp.

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

Referenced by GroupByAndAggregate::codegen().

57  {
58  int32_t agg_count{0};
59  for (auto target_expr : target_exprs) {
60  CHECK(target_expr);
61  const auto agg_expr = dynamic_cast<Analyzer::AggExpr*>(target_expr);
62  if (!agg_expr || agg_expr->get_aggtype() == kSAMPLE) {
63  const auto& ti = target_expr->get_type_info();
64  // TODO(pavan): or if is_geometry()
65  if (ti.is_buffer()) {
66  agg_count += 2;
67  } else if (ti.is_geometry()) {
68  agg_count += ti.get_physical_coord_cols() * 2;
69  } else {
70  ++agg_count;
71  }
72  continue;
73  }
74  if (agg_expr && agg_expr->get_aggtype() == kAVG) {
75  agg_count += 2;
76  } else {
77  ++agg_count;
78  }
79  }
80  return agg_count;
81 }
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:

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

Definition at line 97 of file GroupByAndAggregate.cpp.

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

Referenced by GroupByAndAggregate::getColRangeInfo().

97  {
98  for (const auto& target_expr : ra_exe_unit.target_exprs) {
99  const auto agg_info = get_target_info(target_expr, g_bigint_count);
100  if (agg_info.is_agg && is_distinct_target(agg_info)) {
101  return true;
102  }
103  }
104  return false;
105 }
std::vector< Analyzer::Expr * > target_exprs
TargetInfo get_target_info(const PointerType target_expr, const bool bigint_count)
Definition: TargetInfo.h:79
bool g_bigint_count
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:130

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 107 of file GroupByAndAggregate.cpp.

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

Referenced by GroupByAndAggregate::getColRangeInfo().

108  {
109  try {
110  return static_cast<int64_t>(checked_int64_t(col_range_info.max) -
111  checked_int64_t(col_range_info.min)) >= max_entry_count;
112  } catch (...) {
113  return true;
114  }
115 }
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: