OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OutputBufferInitialization.h File Reference
#include "Shared/SqlTypesLayout.h"
#include <list>
#include <memory>
#include <utility>
#include <vector>
+ Include dependency graph for OutputBufferInitialization.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 Analyzer
 

Functions

std::pair< int64_t, int64_t > inline_int_max_min (const size_t byte_width)
 
std::pair< uint64_t, uint64_t > inline_uint_max_min (const size_t byte_width)
 
int64_t get_agg_initial_val (const SQLAgg agg, const SQLTypeInfo &ti, const bool enable_compaction, const unsigned min_byte_width_to_compact)
 
std::vector< int64_t > init_agg_val_vec (const std::vector< Analyzer::Expr * > &targets, const std::list< std::shared_ptr< Analyzer::Expr >> &quals, const QueryMemoryDescriptor &query_mem_desc)
 
std::vector< int64_t > init_agg_val_vec (const std::vector< TargetInfo > &targets, const QueryMemoryDescriptor &query_mem_desc)
 
const Analyzer::Expragg_arg (const Analyzer::Expr *expr)
 
bool constrained_not_null (const Analyzer::Expr *expr, const std::list< std::shared_ptr< Analyzer::Expr >> &quals)
 
void set_notnull (TargetInfo &target, const bool not_null)
 

Detailed Description

Author
Alex Suhan alex@.nosp@m.mapd.nosp@m..com

Definition in file OutputBufferInitialization.h.

Function Documentation

const Analyzer::Expr* agg_arg ( const Analyzer::Expr expr)

Definition at line 294 of file OutputBufferInitialization.cpp.

References Analyzer::AggExpr::get_arg().

Referenced by TargetExprCodegen::codegen(), TargetExprCodegen::codegenAggregate(), get_compact_type(), anonymous_namespace{GroupByAndAggregate.cpp}::get_keyless_info(), get_target_info(), init_agg_val_vec(), TargetExprCodegenBuilder::operator()(), and set_compact_type().

294  {
295  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
296  return agg_expr ? agg_expr->get_arg() : nullptr;
297 }
Expr * get_arg() const
Definition: Analyzer.h:1238

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool constrained_not_null ( const Analyzer::Expr expr,
const std::list< std::shared_ptr< Analyzer::Expr >> &  quals 
)

Definition at line 299 of file OutputBufferInitialization.cpp.

References kISNOTNULL, kISNULL, and kNOT.

Referenced by anonymous_namespace{GroupByAndAggregate.cpp}::get_keyless_info(), init_agg_val_vec(), and TargetExprCodegenBuilder::operator()().

300  {
301  for (const auto& qual : quals) {
302  auto uoper = std::dynamic_pointer_cast<Analyzer::UOper>(qual);
303  if (!uoper) {
304  continue;
305  }
306  bool is_negated{false};
307  if (uoper->get_optype() == kNOT) {
308  uoper = std::dynamic_pointer_cast<Analyzer::UOper>(uoper->get_own_operand());
309  is_negated = true;
310  }
311  if (uoper && (uoper->get_optype() == kISNOTNULL ||
312  (is_negated && uoper->get_optype() == kISNULL))) {
313  if (*uoper->get_own_operand() == *expr) {
314  return true;
315  }
316  }
317  }
318  return false;
319 }
Definition: sqldefs.h:39

+ Here is the caller graph for this function:

int64_t get_agg_initial_val ( const SQLAgg  agg,
const SQLTypeInfo ti,
const bool  enable_compaction,
const unsigned  min_byte_width_to_compact 
)

Definition at line 126 of file OutputBufferInitialization.cpp.

References CHECK, compact_byte_width(), get_bit_width(), SQLTypeInfo::get_logical_size(), SQLTypeInfo::get_notnull(), inline_fp_null_val(), inline_int_null_val(), SQLTypeInfo::is_fp(), SQLTypeInfo::is_string(), kAPPROX_COUNT_DISTINCT, kAPPROX_QUANTILE, kAVG, kCOUNT, kMAX, kMIN, kSAMPLE, kSINGLE_VALUE, and kSUM.

Referenced by anonymous_namespace{TargetExprBuilder.cpp}::get_initial_agg_val(), anonymous_namespace{GroupByAndAggregate.cpp}::get_keyless_info(), and init_agg_val_vec().

129  {
130  CHECK(!ti.is_string() || (agg == kSINGLE_VALUE || agg == kSAMPLE));
131  const auto byte_width =
132  enable_compaction
133  ? compact_byte_width(static_cast<unsigned>(get_bit_width(ti) >> 3),
134  unsigned(min_byte_width_to_compact))
135  : sizeof(int64_t);
136  CHECK(ti.get_logical_size() < 0 ||
137  byte_width >= static_cast<unsigned>(ti.get_logical_size()));
138  switch (agg) {
139  case kSUM: {
140  if (!ti.get_notnull()) {
141  if (ti.is_fp()) {
142  switch (byte_width) {
143  case 4: {
144  const float null_float = inline_fp_null_val(ti);
145  return *reinterpret_cast<const int32_t*>(may_alias_ptr(&null_float));
146  }
147  case 8: {
148  const double null_double = inline_fp_null_val(ti);
149  return *reinterpret_cast<const int64_t*>(may_alias_ptr(&null_double));
150  }
151  default:
152  CHECK(false);
153  }
154  } else {
155  return inline_int_null_val(ti);
156  }
157  }
158  switch (byte_width) {
159  case 4: {
160  const float zero_float{0.};
161  return ti.is_fp()
162  ? *reinterpret_cast<const int32_t*>(may_alias_ptr(&zero_float))
163  : 0;
164  }
165  case 8: {
166  const double zero_double{0.};
167  return ti.is_fp()
168  ? *reinterpret_cast<const int64_t*>(may_alias_ptr(&zero_double))
169  : 0;
170  }
171  default:
172  CHECK(false);
173  }
174  }
175  case kAVG:
176  case kCOUNT:
178  return 0;
179  case kAPPROX_QUANTILE:
180  return {}; // Init value is a quantile::TDigest* set elsewhere.
181  case kMIN: {
182  switch (byte_width) {
183  case 1: {
184  CHECK(!ti.is_fp());
185  return ti.get_notnull() ? std::numeric_limits<int8_t>::max()
186  : inline_int_null_val(ti);
187  }
188  case 2: {
189  CHECK(!ti.is_fp());
190  return ti.get_notnull() ? std::numeric_limits<int16_t>::max()
191  : inline_int_null_val(ti);
192  }
193  case 4: {
194  const float max_float = std::numeric_limits<float>::max();
195  const float null_float =
196  ti.is_fp() ? static_cast<float>(inline_fp_null_val(ti)) : 0.;
197  return ti.is_fp()
198  ? (ti.get_notnull()
199  ? *reinterpret_cast<const int32_t*>(may_alias_ptr(&max_float))
200  : *reinterpret_cast<const int32_t*>(
201  may_alias_ptr(&null_float)))
202  : (ti.get_notnull() ? std::numeric_limits<int32_t>::max()
203  : inline_int_null_val(ti));
204  }
205  case 8: {
206  const double max_double = std::numeric_limits<double>::max();
207  const double null_double{ti.is_fp() ? inline_fp_null_val(ti) : 0.};
208  return ti.is_fp() ? (ti.get_notnull() ? *reinterpret_cast<const int64_t*>(
209  may_alias_ptr(&max_double))
210  : *reinterpret_cast<const int64_t*>(
211  may_alias_ptr(&null_double)))
212  : (ti.get_notnull() ? std::numeric_limits<int64_t>::max()
213  : inline_int_null_val(ti));
214  }
215  default:
216  CHECK(false);
217  }
218  }
219  case kSINGLE_VALUE:
220  case kSAMPLE:
221  case kMAX: {
222  switch (byte_width) {
223  case 1: {
224  CHECK(!ti.is_fp());
225  return ti.get_notnull() ? std::numeric_limits<int8_t>::min()
226  : inline_int_null_val(ti);
227  }
228  case 2: {
229  CHECK(!ti.is_fp());
230  return ti.get_notnull() ? std::numeric_limits<int16_t>::min()
231  : inline_int_null_val(ti);
232  }
233  case 4: {
234  const float min_float = -std::numeric_limits<float>::max();
235  const float null_float =
236  ti.is_fp() ? static_cast<float>(inline_fp_null_val(ti)) : 0.;
237  return (ti.is_fp())
238  ? (ti.get_notnull()
239  ? *reinterpret_cast<const int32_t*>(may_alias_ptr(&min_float))
240  : *reinterpret_cast<const int32_t*>(
241  may_alias_ptr(&null_float)))
242  : (ti.get_notnull() ? std::numeric_limits<int32_t>::min()
243  : inline_int_null_val(ti));
244  }
245  case 8: {
246  const double min_double = -std::numeric_limits<double>::max();
247  const double null_double{ti.is_fp() ? inline_fp_null_val(ti) : 0.};
248  return ti.is_fp() ? (ti.get_notnull() ? *reinterpret_cast<const int64_t*>(
249  may_alias_ptr(&min_double))
250  : *reinterpret_cast<const int64_t*>(
251  may_alias_ptr(&null_double)))
252  : (ti.get_notnull() ? std::numeric_limits<int64_t>::min()
253  : inline_int_null_val(ti));
254  }
255  default:
256  CHECK(false);
257  }
258  }
259  default:
260  abort();
261  }
262 }
unsigned compact_byte_width(unsigned qw, unsigned low_bound)
bool is_fp() const
Definition: sqltypes.h:508
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
Definition: sqldefs.h:73
size_t get_bit_width(const SQLTypeInfo &ti)
int get_logical_size() const
Definition: sqltypes.h:340
Definition: sqldefs.h:75
Definition: sqldefs.h:76
#define CHECK(condition)
Definition: Logger.h:209
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
bool is_string() const
Definition: sqltypes.h:504
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336
Definition: sqldefs.h:74
Definition: sqldefs.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<int64_t> init_agg_val_vec ( const std::vector< Analyzer::Expr * > &  targets,
const std::list< std::shared_ptr< Analyzer::Expr >> &  quals,
const QueryMemoryDescriptor query_mem_desc 
)

Definition at line 264 of file OutputBufferInitialization.cpp.

References agg_arg(), constrained_not_null(), g_bigint_count, get_target_info(), QueryMemoryDescriptor::getQueryDescriptionType(), QueryMemoryDescriptor::getSlotCount(), init_agg_val_vec(), kAPPROX_QUANTILE, kAVG, kMAX, kMIN, kSUM, NonGroupedAggregate, and set_notnull().

267  {
268  std::vector<TargetInfo> target_infos;
269  target_infos.reserve(targets.size());
270  const auto agg_col_count = query_mem_desc.getSlotCount();
271  for (size_t target_idx = 0, agg_col_idx = 0;
272  target_idx < targets.size() && agg_col_idx < agg_col_count;
273  ++target_idx, ++agg_col_idx) {
274  const auto target_expr = targets[target_idx];
275  auto target = get_target_info(target_expr, g_bigint_count);
276  auto arg_expr = agg_arg(target_expr);
277  if (arg_expr) {
278  if (query_mem_desc.getQueryDescriptionType() ==
280  target.is_agg &&
281  (target.agg_kind == kMIN || target.agg_kind == kMAX ||
282  target.agg_kind == kSUM || target.agg_kind == kAVG ||
283  target.agg_kind == kAPPROX_QUANTILE)) {
284  set_notnull(target, false);
285  } else if (constrained_not_null(arg_expr, quals)) {
286  set_notnull(target, true);
287  }
288  }
289  target_infos.push_back(target);
290  }
291  return init_agg_val_vec(target_infos, query_mem_desc);
292 }
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
bool constrained_not_null(const Analyzer::Expr *expr, const std::list< std::shared_ptr< Analyzer::Expr >> &quals)
TargetInfo get_target_info(const PointerType target_expr, const bool bigint_count)
Definition: TargetInfo.h:92
Definition: sqldefs.h:73
bool g_bigint_count
Definition: sqldefs.h:75
QueryDescriptionType getQueryDescriptionType() const
Definition: sqldefs.h:74
std::vector< int64_t > init_agg_val_vec(const std::vector< TargetInfo > &targets, const QueryMemoryDescriptor &query_mem_desc)
Definition: sqldefs.h:72
void set_notnull(TargetInfo &target, const bool not_null)

+ Here is the call graph for this function:

std::vector<int64_t> init_agg_val_vec ( const std::vector< TargetInfo > &  targets,
const QueryMemoryDescriptor query_mem_desc 
)

Definition at line 26 of file OutputBufferInitialization.cpp.

References CHECK_GT, CHECK_LT, get_agg_initial_val(), get_compact_type(), QueryMemoryDescriptor::getCompactByteWidth(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getSlotCount(), i, QueryMemoryDescriptor::isGroupBy(), QueryMemoryDescriptor::isLogicalSizedColumnsAllowed(), kAVG, kENCODING_NONE, kSAMPLE, and takes_float_argument().

Referenced by init_agg_val_vec().

27  {
28  std::vector<int64_t> agg_init_vals;
29  agg_init_vals.reserve(query_mem_desc.getSlotCount());
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) {
33  CHECK_LT(agg_col_idx, query_mem_desc.getSlotCount());
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() &&
38  agg_ti.get_compression() != kENCODING_NONE) {
39  agg_init_vals.push_back(
40  get_agg_initial_val(agg_info.agg_kind,
41  agg_ti,
42  is_group_by,
43  query_mem_desc.getCompactByteWidth()));
44  continue;
45  }
46  if (query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx) > 0) {
47  agg_init_vals.push_back(0);
48  }
49  if (agg_info.is_varlen_projection) {
50  continue;
51  }
52  if (agg_ti.is_array() ||
53  (agg_ti.is_string() && agg_ti.get_compression() == kENCODING_NONE)) {
54  agg_init_vals.push_back(0);
55  }
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);
61  }
62  }
63  continue;
64  }
65  CHECK_GT(query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx), 0);
66  const bool float_argument_input = takes_float_argument(agg_info);
67  const auto chosen_bytes = query_mem_desc.isLogicalSizedColumnsAllowed()
68  ? query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx)
69  : query_mem_desc.getCompactByteWidth();
70  auto init_ti = get_compact_type(agg_info);
71  if (!is_group_by) {
72  init_ti.set_notnull(false);
73  }
74  agg_init_vals.push_back(
75  get_agg_initial_val(agg_info.agg_kind,
76  init_ti,
77  is_group_by || float_argument_input,
78  (float_argument_input ? sizeof(float) : chosen_bytes)));
79  if (kAVG == agg_info.agg_kind) {
80  ++agg_col_idx;
81  agg_init_vals.push_back(0);
82  }
83  }
84  return agg_init_vals;
85 }
bool isLogicalSizedColumnsAllowed() const
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)
Definition: TargetInfo.h:157
#define CHECK_GT(x, y)
Definition: Logger.h:221
const SQLTypeInfo get_compact_type(const TargetInfo &target)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:219
Definition: sqldefs.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::pair<int64_t, int64_t> inline_int_max_min ( const size_t  byte_width)

Definition at line 87 of file OutputBufferInitialization.cpp.

Referenced by CgenState::inlineIntMaxMin(), and SqliteMemDatabase::runSelect().

87  {
88  switch (byte_width) {
89  case 1:
90  return std::make_pair(std::numeric_limits<int8_t>::max(),
91  std::numeric_limits<int8_t>::min());
92  case 2:
93  return std::make_pair(std::numeric_limits<int16_t>::max(),
94  std::numeric_limits<int16_t>::min());
95  case 4:
96  return std::make_pair(std::numeric_limits<int32_t>::max(),
97  std::numeric_limits<int32_t>::min());
98  case 8:
99  return std::make_pair(std::numeric_limits<int64_t>::max(),
100  std::numeric_limits<int64_t>::min());
101  default:
102  abort();
103  }
104 }

+ Here is the caller graph for this function:

std::pair<uint64_t, uint64_t> inline_uint_max_min ( const size_t  byte_width)

Definition at line 106 of file OutputBufferInitialization.cpp.

Referenced by CgenState::inlineIntMaxMin().

106  {
107  switch (byte_width) {
108  case 1:
109  return std::make_pair(std::numeric_limits<uint8_t>::max(),
110  std::numeric_limits<uint8_t>::min());
111  case 2:
112  return std::make_pair(std::numeric_limits<uint16_t>::max(),
113  std::numeric_limits<uint16_t>::min());
114  case 4:
115  return std::make_pair(std::numeric_limits<uint32_t>::max(),
116  std::numeric_limits<uint32_t>::min());
117  case 8:
118  return std::make_pair(std::numeric_limits<uint64_t>::max(),
119  std::numeric_limits<uint64_t>::min());
120  default:
121  abort();
122  }
123 }

+ Here is the caller graph for this function:

void set_notnull ( TargetInfo target,
const bool  not_null 
)
inline

Definition at line 390 of file QueryMemoryDescriptor.h.

References get_compact_type(), set_compact_type(), and TargetInfo::skip_null_val.

Referenced by init_agg_val_vec(), and target_exprs_to_infos().

390  {
391  target.skip_null_val = !not_null;
392  auto new_type = get_compact_type(target);
393  new_type.set_notnull(not_null);
394  set_compact_type(target, new_type);
395 }
void set_compact_type(TargetInfo &target, const SQLTypeInfo &new_type)
bool skip_null_val
Definition: TargetInfo.h:53
const SQLTypeInfo get_compact_type(const TargetInfo &target)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: