22 #include "../Analyzer/Analyzer.h"
28 std::vector<int64_t> agg_init_vals;
30 const bool is_group_by{query_mem_desc.
isGroupBy()};
31 for (
size_t target_idx = 0, agg_col_idx = 0; target_idx < targets.size();
32 ++target_idx, ++agg_col_idx) {
34 const auto agg_info = targets[target_idx];
35 const auto& agg_ti = agg_info.sql_type;
36 if (!agg_info.is_agg || agg_info.agg_kind ==
kSAMPLE) {
37 if (agg_info.agg_kind ==
kSAMPLE && agg_ti.is_string() &&
39 agg_init_vals.push_back(
47 agg_init_vals.push_back(0);
49 if (agg_info.is_varlen_projection) {
52 if (agg_ti.is_array() ||
53 (agg_ti.is_string() && agg_ti.get_compression() ==
kENCODING_NONE)) {
54 agg_init_vals.push_back(0);
56 if (agg_ti.is_geometry()) {
57 agg_init_vals.push_back(0);
58 for (
auto i = 1; i < agg_ti.get_physical_coord_cols(); ++i) {
59 agg_init_vals.push_back(0);
60 agg_init_vals.push_back(0);
72 init_ti.set_notnull(
false);
74 agg_init_vals.push_back(
77 is_group_by || float_argument_input,
78 (float_argument_input ?
sizeof(
float) : chosen_bytes)));
79 if (
kAVG == agg_info.agg_kind) {
81 agg_init_vals.push_back(0);
90 return std::make_pair(std::numeric_limits<int8_t>::max(),
91 std::numeric_limits<int8_t>::min());
93 return std::make_pair(std::numeric_limits<int16_t>::max(),
94 std::numeric_limits<int16_t>::min());
96 return std::make_pair(std::numeric_limits<int32_t>::max(),
97 std::numeric_limits<int32_t>::min());
99 return std::make_pair(std::numeric_limits<int64_t>::max(),
100 std::numeric_limits<int64_t>::min());
107 switch (byte_width) {
109 return std::make_pair(std::numeric_limits<uint8_t>::max(),
110 std::numeric_limits<uint8_t>::min());
112 return std::make_pair(std::numeric_limits<uint16_t>::max(),
113 std::numeric_limits<uint16_t>::min());
115 return std::make_pair(std::numeric_limits<uint32_t>::max(),
116 std::numeric_limits<uint32_t>::min());
118 return std::make_pair(std::numeric_limits<uint64_t>::max(),
119 std::numeric_limits<uint64_t>::min());
128 const bool enable_compaction,
129 const unsigned min_byte_width_to_compact) {
130 CHECK(!ti.
is_string() || (shared::is_any<kSINGLE_VALUE, kSAMPLE, kMODE>(agg))) << agg;
131 const auto byte_width =
134 unsigned(min_byte_width_to_compact))
143 switch (byte_width) {
146 return *
reinterpret_cast<const int32_t*
>(may_alias_ptr(&null_float));
150 return *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&null_double));
159 switch (byte_width) {
161 const float zero_float{0.};
163 ? *
reinterpret_cast<const int32_t*
>(may_alias_ptr(&zero_float))
167 const double zero_double{0.};
169 ? *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&zero_double))
185 switch (byte_width) {
188 return ti.
get_notnull() ? std::numeric_limits<int8_t>::max()
193 return ti.
get_notnull() ? std::numeric_limits<int16_t>::max()
197 const float max_float = std::numeric_limits<float>::max();
198 const float null_float =
202 ? *
reinterpret_cast<const int32_t*
>(may_alias_ptr(&max_float))
203 : *reinterpret_cast<const int32_t*>(
204 may_alias_ptr(&null_float)))
205 : (ti.
get_notnull() ? std::numeric_limits<int32_t>::max()
209 const double max_double = std::numeric_limits<double>::max();
212 may_alias_ptr(&max_double))
213 : *reinterpret_cast<const int64_t*>(
214 may_alias_ptr(&null_double)))
215 : (ti.
get_notnull() ? std::numeric_limits<int64_t>::max()
225 switch (byte_width) {
228 return ti.
get_notnull() ? std::numeric_limits<int8_t>::min()
233 return ti.
get_notnull() ? std::numeric_limits<int16_t>::min()
237 const float min_float = -std::numeric_limits<float>::max();
238 const float null_float =
242 ? *
reinterpret_cast<const int32_t*
>(may_alias_ptr(&min_float))
243 : *reinterpret_cast<const int32_t*>(
244 may_alias_ptr(&null_float)))
245 : (ti.
get_notnull() ? std::numeric_limits<int32_t>::min()
249 const double min_double = -std::numeric_limits<double>::max();
252 may_alias_ptr(&min_double))
253 : *reinterpret_cast<const int64_t*>(
254 may_alias_ptr(&null_double)))
255 : (ti.
get_notnull() ? std::numeric_limits<int64_t>::min()
268 const std::vector<Analyzer::Expr*>& targets,
269 const std::list<std::shared_ptr<Analyzer::Expr>>& quals,
271 std::vector<TargetInfo> target_infos;
272 target_infos.reserve(targets.size());
273 const auto agg_col_count = query_mem_desc.
getSlotCount();
274 for (
size_t target_idx = 0, agg_col_idx = 0;
275 target_idx < targets.size() && agg_col_idx < agg_col_count;
276 ++target_idx, ++agg_col_idx) {
277 const auto target_expr = targets[target_idx];
279 auto arg_expr =
agg_arg(target_expr);
284 shared::is_any<kMIN, kMAX, kSUM, kSUM_IF, kAVG, kAPPROX_QUANTILE, kMODE>(
291 target_infos.push_back(target);
298 return agg_expr ? agg_expr->
get_arg() :
nullptr;
302 const std::list<std::shared_ptr<Analyzer::Expr>>& quals) {
303 for (
const auto& qual : quals) {
308 bool is_negated{
false};
309 if (uoper->get_optype() ==
kNOT) {
310 uoper = std::dynamic_pointer_cast<
Analyzer::UOper>(uoper->get_own_operand());
313 if (uoper && (uoper->get_optype() ==
kISNOTNULL ||
314 (is_negated && uoper->get_optype() ==
kISNULL))) {
315 if (*uoper->get_own_operand() == *expr) {
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
size_t getSlotCount() const
bool constrained_not_null(const Analyzer::Expr *expr, const std::list< std::shared_ptr< Analyzer::Expr >> &quals)
unsigned compact_byte_width(unsigned qw, unsigned low_bound)
bool isLogicalSizedColumnsAllowed() const
Macros and functions for groupby buffer compaction.
int64_t get_agg_initial_val(const SQLAgg agg, const SQLTypeInfo &ti, const bool enable_compaction, const unsigned min_byte_width_to_compact)
bool takes_float_argument(const TargetInfo &target_info)
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
const SQLTypeInfo get_compact_type(const TargetInfo &target)
size_t get_bit_width(const SQLTypeInfo &ti)
size_t getCompactByteWidth() const
int get_logical_size() const
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
QueryDescriptionType getQueryDescriptionType() const
std::pair< uint64_t, uint64_t > inline_uint_max_min(const size_t byte_width)
Descriptor for the result set buffer layout.
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
std::pair< int64_t, int64_t > inline_int_max_min(const size_t byte_width)
HOST DEVICE bool get_notnull() const
std::vector< int64_t > init_agg_val_vec(const std::vector< TargetInfo > &targets, const QueryMemoryDescriptor &query_mem_desc)
void set_notnull(TargetInfo &target, const bool not_null)