OmniSciDB  3a86f6ec37
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

◆ agg_arg()

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

Definition at line 291 of file OutputBufferInitialization.cpp.

References Analyzer::AggExpr::get_arg().

Referenced by TargetExprCodegen::codegen(), TargetExprCodegen::codegenAggregate(), get_compact_type(), get_target_info(), GroupByAndAggregate::getKeylessInfo(), init_agg_val_vec(), TargetExprCodegenBuilder::operator()(), and set_compact_type().

291  {
292  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
293  return agg_expr ? agg_expr->get_arg() : nullptr;
294 }
Expr * get_arg() const
Definition: Analyzer.h:1096
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constrained_not_null()

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

Definition at line 296 of file OutputBufferInitialization.cpp.

References kISNOTNULL, kISNULL, and kNOT.

Referenced by GroupByAndAggregate::getKeylessInfo(), init_agg_val_vec(), and TargetExprCodegenBuilder::operator()().

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

◆ get_agg_initial_val()

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 123 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_MEDIAN, kAVG, kCOUNT, kMAX, kMIN, kSAMPLE, kSINGLE_VALUE, and kSUM.

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

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

◆ init_agg_val_vec() [1/2]

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 261 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_MEDIAN, kAVG, kMAX, kMIN, kSUM, NonGroupedAggregate, and set_notnull().

264  {
265  std::vector<TargetInfo> target_infos;
266  target_infos.reserve(targets.size());
267  const auto agg_col_count = query_mem_desc.getSlotCount();
268  for (size_t target_idx = 0, agg_col_idx = 0;
269  target_idx < targets.size() && agg_col_idx < agg_col_count;
270  ++target_idx, ++agg_col_idx) {
271  const auto target_expr = targets[target_idx];
272  auto target = get_target_info(target_expr, g_bigint_count);
273  auto arg_expr = agg_arg(target_expr);
274  if (arg_expr) {
275  if (query_mem_desc.getQueryDescriptionType() ==
277  target.is_agg &&
278  (target.agg_kind == kMIN || target.agg_kind == kMAX ||
279  target.agg_kind == kSUM || target.agg_kind == kAVG ||
280  target.agg_kind == kAPPROX_MEDIAN)) {
281  set_notnull(target, false);
282  } else if (constrained_not_null(arg_expr, quals)) {
283  set_notnull(target, true);
284  }
285  }
286  target_infos.push_back(target);
287  }
288  return init_agg_val_vec(target_infos, query_mem_desc);
289 }
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:79
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:

◆ init_agg_val_vec() [2/2]

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(), QueryMemoryDescriptor::isGroupBy(), QueryMemoryDescriptor::isLogicalSizedColumnsAllowed(), kAVG, kENCODING_NONE, kSAMPLE, and takes_float_argument().

Referenced by Executor::compileWorkUnit(), and 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_ti.is_array() ||
50  (agg_ti.is_string() && agg_ti.get_compression() == kENCODING_NONE)) {
51  agg_init_vals.push_back(0);
52  }
53  if (agg_ti.is_geometry()) {
54  agg_init_vals.push_back(0);
55  for (auto i = 1; i < agg_ti.get_physical_coord_cols(); ++i) {
56  agg_init_vals.push_back(0);
57  agg_init_vals.push_back(0);
58  }
59  }
60  continue;
61  }
62  CHECK_GT(query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx), 0);
63  const bool float_argument_input = takes_float_argument(agg_info);
64  const auto chosen_bytes = query_mem_desc.isLogicalSizedColumnsAllowed()
65  ? query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx)
66  : query_mem_desc.getCompactByteWidth();
67  auto init_ti = get_compact_type(agg_info);
68  if (!is_group_by) {
69  init_ti.set_notnull(false);
70  }
71  agg_init_vals.push_back(
72  get_agg_initial_val(agg_info.agg_kind,
73  init_ti,
74  is_group_by || float_argument_input,
75  (float_argument_input ? sizeof(float) : chosen_bytes)));
76  if (kAVG == agg_info.agg_kind) {
77  ++agg_col_idx;
78  agg_init_vals.push_back(0);
79  }
80  }
81  return agg_init_vals;
82 }
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:134
#define CHECK_GT(x, y)
Definition: Logger.h:209
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
const SQLTypeInfo get_compact_type(const TargetInfo &target)
#define CHECK_LT(x, y)
Definition: Logger.h:207
Definition: sqldefs.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inline_int_max_min()

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

Definition at line 84 of file OutputBufferInitialization.cpp.

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

84  {
85  switch (byte_width) {
86  case 1:
87  return std::make_pair(std::numeric_limits<int8_t>::max(),
88  std::numeric_limits<int8_t>::min());
89  case 2:
90  return std::make_pair(std::numeric_limits<int16_t>::max(),
91  std::numeric_limits<int16_t>::min());
92  case 4:
93  return std::make_pair(std::numeric_limits<int32_t>::max(),
94  std::numeric_limits<int32_t>::min());
95  case 8:
96  return std::make_pair(std::numeric_limits<int64_t>::max(),
97  std::numeric_limits<int64_t>::min());
98  default:
99  abort();
100  }
101 }
+ Here is the caller graph for this function:

◆ inline_uint_max_min()

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

Definition at line 103 of file OutputBufferInitialization.cpp.

Referenced by CgenState::inlineIntMaxMin().

103  {
104  switch (byte_width) {
105  case 1:
106  return std::make_pair(std::numeric_limits<uint8_t>::max(),
107  std::numeric_limits<uint8_t>::min());
108  case 2:
109  return std::make_pair(std::numeric_limits<uint16_t>::max(),
110  std::numeric_limits<uint16_t>::min());
111  case 4:
112  return std::make_pair(std::numeric_limits<uint32_t>::max(),
113  std::numeric_limits<uint32_t>::min());
114  case 8:
115  return std::make_pair(std::numeric_limits<uint64_t>::max(),
116  std::numeric_limits<uint64_t>::min());
117  default:
118  abort();
119  }
120 }
+ Here is the caller graph for this function:

◆ set_notnull()

void set_notnull ( TargetInfo target,
const bool  not_null 
)
inline

Definition at line 371 of file QueryMemoryDescriptor.h.

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

Referenced by init_agg_val_vec(), and target_exprs_to_infos().

371  {
372  target.skip_null_val = !not_null;
373  auto new_type = get_compact_type(target);
374  new_type.set_notnull(not_null);
375  set_compact_type(target, new_type);
376 }
void set_compact_type(TargetInfo &target, const SQLTypeInfo &new_type)
bool skip_null_val
Definition: TargetInfo.h:44
const SQLTypeInfo get_compact_type(const TargetInfo &target)
+ Here is the call graph for this function:
+ Here is the caller graph for this function: