OmniSciDB  29e35f4d58
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)
 
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 292 of file OutputBufferInitialization.cpp.

References Analyzer::AggExpr::get_arg().

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

292  {
293  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
294  return agg_expr ? agg_expr->get_arg() : nullptr;
295 }
Expr * get_arg() const
Definition: Analyzer.h:1045
+ 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 297 of file OutputBufferInitialization.cpp.

References kISNOTNULL, kISNULL, and kNOT.

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

298  {
299  for (const auto qual : quals) {
300  auto uoper = std::dynamic_pointer_cast<Analyzer::UOper>(qual);
301  if (!uoper) {
302  continue;
303  }
304  bool is_negated{false};
305  if (uoper->get_optype() == kNOT) {
306  uoper = std::dynamic_pointer_cast<Analyzer::UOper>(uoper->get_own_operand());
307  is_negated = true;
308  }
309  if (uoper && (uoper->get_optype() == kISNOTNULL ||
310  (is_negated && uoper->get_optype() == kISNULL))) {
311  if (*uoper->get_own_operand() == *expr) {
312  return true;
313  }
314  }
315  }
316  return false;
317 }
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 127 of file OutputBufferInitialization.cpp.

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

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

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

◆ init_agg_val_vec()

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

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

Referenced by init_agg_val_vec().

266  {
267  std::vector<TargetInfo> target_infos;
268  target_infos.reserve(targets.size());
269  const auto agg_col_count = query_mem_desc.getSlotCount();
270  for (size_t target_idx = 0, agg_col_idx = 0;
271  target_idx < targets.size() && agg_col_idx < agg_col_count;
272  ++target_idx, ++agg_col_idx) {
273  const auto target_expr = targets[target_idx];
274  auto target = get_target_info(target_expr, g_bigint_count);
275  auto arg_expr = agg_arg(target_expr);
276  if (arg_expr) {
277  if (query_mem_desc.getQueryDescriptionType() ==
279  target.is_agg &&
280  (target.agg_kind == kMIN || target.agg_kind == kMAX ||
281  target.agg_kind == kSUM || target.agg_kind == kAVG)) {
282  set_notnull(target, false);
283  } else if (constrained_not_null(arg_expr, quals)) {
284  set_notnull(target, true);
285  }
286  }
287  target_infos.push_back(target);
288  }
289  return init_agg_val_vec(target_infos, query_mem_desc);
290 }
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)
const int64_t const uint32_t const uint32_t const uint32_t agg_col_count
TargetInfo get_target_info(const PointerType target_expr, const bool bigint_count)
Definition: TargetInfo.h:66
Definition: sqldefs.h:73
bool g_bigint_count
Definition: sqldefs.h:75
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)
QueryDescriptionType getQueryDescriptionType() const
Definition: sqldefs.h:74
Definition: sqldefs.h:72
void set_notnull(TargetInfo &target, const bool not_null)
+ 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 88 of file OutputBufferInitialization.cpp.

Referenced by CgenState::inlineIntMaxMin().

88  {
89  switch (byte_width) {
90  case 1:
91  return std::make_pair(std::numeric_limits<int8_t>::max(),
92  std::numeric_limits<int8_t>::min());
93  case 2:
94  return std::make_pair(std::numeric_limits<int16_t>::max(),
95  std::numeric_limits<int16_t>::min());
96  case 4:
97  return std::make_pair(std::numeric_limits<int32_t>::max(),
98  std::numeric_limits<int32_t>::min());
99  case 8:
100  return std::make_pair(std::numeric_limits<int64_t>::max(),
101  std::numeric_limits<int64_t>::min());
102  default:
103  abort();
104  }
105 }
+ 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 107 of file OutputBufferInitialization.cpp.

Referenced by CgenState::inlineIntMaxMin().

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

◆ set_notnull()

void set_notnull ( TargetInfo target,
const bool  not_null 
)
inline

Definition at line 372 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().

372  {
373  target.skip_null_val = !not_null;
374  auto new_type = get_compact_type(target);
375  new_type.set_notnull(not_null);
376  set_compact_type(target, new_type);
377 }
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: