OmniSciDB  b28c0d5765
 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)
 

Function Documentation

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

Definition at line 295 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(), target_info::get_target_info_impl(), init_agg_val_vec(), TargetExprCodegenBuilder::operator()(), and set_compact_type().

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

+ 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 300 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()().

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

+ 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, kCOUNT_IF, kMAX, kMIN, kMODE, 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() || (shared::is_any<kSINGLE_VALUE, kSAMPLE, kMODE>(agg))) << agg;
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:
177  case kCOUNT_IF:
179  return 0;
180  case kAPPROX_QUANTILE:
181  case kMODE:
182  return {}; // Init value is a pointer set elsewhere.
183  case kMIN: {
184  switch (byte_width) {
185  case 1: {
186  CHECK(!ti.is_fp());
187  return ti.get_notnull() ? std::numeric_limits<int8_t>::max()
188  : inline_int_null_val(ti);
189  }
190  case 2: {
191  CHECK(!ti.is_fp());
192  return ti.get_notnull() ? std::numeric_limits<int16_t>::max()
193  : inline_int_null_val(ti);
194  }
195  case 4: {
196  const float max_float = std::numeric_limits<float>::max();
197  const float null_float =
198  ti.is_fp() ? static_cast<float>(inline_fp_null_val(ti)) : 0.;
199  return ti.is_fp()
200  ? (ti.get_notnull()
201  ? *reinterpret_cast<const int32_t*>(may_alias_ptr(&max_float))
202  : *reinterpret_cast<const int32_t*>(
203  may_alias_ptr(&null_float)))
204  : (ti.get_notnull() ? std::numeric_limits<int32_t>::max()
205  : inline_int_null_val(ti));
206  }
207  case 8: {
208  const double max_double = std::numeric_limits<double>::max();
209  const double null_double{ti.is_fp() ? inline_fp_null_val(ti) : 0.};
210  return ti.is_fp() ? (ti.get_notnull() ? *reinterpret_cast<const int64_t*>(
211  may_alias_ptr(&max_double))
212  : *reinterpret_cast<const int64_t*>(
213  may_alias_ptr(&null_double)))
214  : (ti.get_notnull() ? std::numeric_limits<int64_t>::max()
215  : inline_int_null_val(ti));
216  }
217  default:
218  CHECK(false);
219  }
220  }
221  case kSINGLE_VALUE:
222  case kSAMPLE:
223  case kMAX: {
224  switch (byte_width) {
225  case 1: {
226  CHECK(!ti.is_fp());
227  return ti.get_notnull() ? std::numeric_limits<int8_t>::min()
228  : inline_int_null_val(ti);
229  }
230  case 2: {
231  CHECK(!ti.is_fp());
232  return ti.get_notnull() ? std::numeric_limits<int16_t>::min()
233  : inline_int_null_val(ti);
234  }
235  case 4: {
236  const float min_float = -std::numeric_limits<float>::max();
237  const float null_float =
238  ti.is_fp() ? static_cast<float>(inline_fp_null_val(ti)) : 0.;
239  return (ti.is_fp())
240  ? (ti.get_notnull()
241  ? *reinterpret_cast<const int32_t*>(may_alias_ptr(&min_float))
242  : *reinterpret_cast<const int32_t*>(
243  may_alias_ptr(&null_float)))
244  : (ti.get_notnull() ? std::numeric_limits<int32_t>::min()
245  : inline_int_null_val(ti));
246  }
247  case 8: {
248  const double min_double = -std::numeric_limits<double>::max();
249  const double null_double{ti.is_fp() ? inline_fp_null_val(ti) : 0.};
250  return ti.is_fp() ? (ti.get_notnull() ? *reinterpret_cast<const int64_t*>(
251  may_alias_ptr(&min_double))
252  : *reinterpret_cast<const int64_t*>(
253  may_alias_ptr(&null_double)))
254  : (ti.get_notnull() ? std::numeric_limits<int64_t>::min()
255  : inline_int_null_val(ti));
256  }
257  default:
258  CHECK(false);
259  }
260  }
261  default:
262  abort();
263  }
264 }
unsigned compact_byte_width(unsigned qw, unsigned low_bound)
bool is_fp() const
Definition: sqltypes.h:580
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
Definition: sqldefs.h:75
size_t get_bit_width(const SQLTypeInfo &ti)
int get_logical_size() const
Definition: sqltypes.h:400
Definition: sqldefs.h:77
Definition: sqldefs.h:78
#define CHECK(condition)
Definition: Logger.h:222
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
bool is_string() const
Definition: sqltypes.h:576
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:387
Definition: sqldefs.h:76
Definition: sqldefs.h:74
Definition: sqldefs.h:83

+ 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 266 of file OutputBufferInitialization.cpp.

References agg_arg(), constrained_not_null(), g_bigint_count, get_target_info(), QueryMemoryDescriptor::getQueryDescriptionType(), QueryMemoryDescriptor::getSlotCount(), init_agg_val_vec(), NonGroupedAggregate, and set_notnull().

269  {
270  std::vector<TargetInfo> target_infos;
271  target_infos.reserve(targets.size());
272  const auto agg_col_count = query_mem_desc.getSlotCount();
273  for (size_t target_idx = 0, agg_col_idx = 0;
274  target_idx < targets.size() && agg_col_idx < agg_col_count;
275  ++target_idx, ++agg_col_idx) {
276  const auto target_expr = targets[target_idx];
277  auto target = get_target_info(target_expr, g_bigint_count);
278  auto arg_expr = agg_arg(target_expr);
279  if (arg_expr) {
280  if (query_mem_desc.getQueryDescriptionType() ==
282  target.is_agg &&
283  shared::is_any<kMIN, kMAX, kSUM, kAVG, kAPPROX_QUANTILE, kMODE>(
284  target.agg_kind)) {
285  set_notnull(target, false);
286  } else if (constrained_not_null(arg_expr, quals)) {
287  set_notnull(target, true);
288  }
289  }
290  target_infos.push_back(target);
291  }
292  return init_agg_val_vec(target_infos, query_mem_desc);
293 }
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 Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.h:88
bool g_bigint_count
QueryDescriptionType getQueryDescriptionType() 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)

+ 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(), 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:102
#define CHECK_GT(x, y)
Definition: Logger.h:234
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:232
Definition: sqldefs.h:74

+ 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 397 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().

397  {
398  target.skip_null_val = !not_null;
399  auto new_type = get_compact_type(target);
400  new_type.set_notnull(not_null);
401  set_compact_type(target, new_type);
402 }
void set_compact_type(TargetInfo &target, const SQLTypeInfo &new_type)
bool skip_null_val
Definition: TargetInfo.h:54
const SQLTypeInfo get_compact_type(const TargetInfo &target)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: