OmniSciDB  a667adc9c8
 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 519 of file GroupByAndAggregate.cpp.

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

Referenced by GroupByAndAggregate::addTransientStringLiterals().

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

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

Referenced by GroupByAndAggregate::getColRangeInfo().

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

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

Referenced by GroupByAndAggregate::getColRangeInfo().

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

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

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

Referenced by GroupByAndAggregate::codegen().

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

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

Referenced by GroupByAndAggregate::getColRangeInfo().

98  {
99  for (const auto& target_expr : ra_exe_unit.target_exprs) {
100  const auto agg_info = get_target_info(target_expr, g_bigint_count);
101  if (agg_info.is_agg && is_distinct_target(agg_info)) {
102  return true;
103  }
104  }
105  return false;
106 }
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 108 of file GroupByAndAggregate.cpp.

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

Referenced by GroupByAndAggregate::getColRangeInfo().

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