OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryMemoryDescriptor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "QueryMemoryDescriptor.h"
18 
19 #include "../Execute.h"
20 #include "../ExpressionRewrite.h"
21 #include "../GroupByAndAggregate.h"
22 #include "../StreamingTopN.h"
23 #include "../UsedColumnsVisitor.h"
24 #include "ColSlotContext.h"
25 
26 #include <boost/algorithm/cxx11/any_of.hpp>
27 
29 extern bool g_enable_columnar_output;
30 extern size_t g_streaming_topn_max;
31 
32 namespace {
33 
34 bool is_int_and_no_bigger_than(const SQLTypeInfo& ti, const size_t byte_width) {
35  if (!ti.is_integer()) {
36  return false;
37  }
38  return get_bit_width(ti) <= (byte_width * 8);
39 }
40 
42  return range.getIntMin() > INT32_MIN && range.getIntMax() < EMPTY_KEY_32 - 1;
43 }
44 
45 std::vector<int64_t> target_expr_group_by_indices(
46  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby_exprs,
47  const std::vector<Analyzer::Expr*>& target_exprs) {
48  std::vector<int64_t> indices(target_exprs.size(), -1);
49  for (size_t target_idx = 0; target_idx < target_exprs.size(); ++target_idx) {
50  const auto target_expr = target_exprs[target_idx];
51  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
52  continue;
53  }
54  const auto var_expr = dynamic_cast<const Analyzer::Var*>(target_expr);
55  if (var_expr && var_expr->get_which_row() == Analyzer::Var::kGROUPBY) {
56  indices[target_idx] = var_expr->get_varno() - 1;
57  continue;
58  }
59  }
60  return indices;
61 }
62 
63 std::vector<int64_t> target_expr_proj_indices(const RelAlgExecutionUnit& ra_exe_unit) {
64  if (ra_exe_unit.input_descs.size() > 1 ||
65  !ra_exe_unit.sort_info.order_entries.empty()) {
66  return {};
67  }
68  std::vector<int64_t> target_indices(ra_exe_unit.target_exprs.size(), -1);
69  UsedColumnsVisitor columns_visitor;
70  std::unordered_set<int> used_columns;
71  for (const auto& simple_qual : ra_exe_unit.simple_quals) {
72  const auto crt_used_columns = columns_visitor.visit(simple_qual.get());
73  used_columns.insert(crt_used_columns.begin(), crt_used_columns.end());
74  }
75  for (const auto& qual : ra_exe_unit.quals) {
76  const auto crt_used_columns = columns_visitor.visit(qual.get());
77  used_columns.insert(crt_used_columns.begin(), crt_used_columns.end());
78  }
79  for (const auto& target : ra_exe_unit.target_exprs) {
80  const auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(target);
81  if (col_var) {
82  const auto cd = get_column_descriptor_maybe(col_var->getColumnKey());
83  if (!cd || !cd->isVirtualCol) {
84  continue;
85  }
86  }
87  const auto crt_used_columns = columns_visitor.visit(target);
88  used_columns.insert(crt_used_columns.begin(), crt_used_columns.end());
89  }
90  for (size_t target_idx = 0; target_idx < ra_exe_unit.target_exprs.size();
91  ++target_idx) {
92  const auto target_expr = ra_exe_unit.target_exprs[target_idx];
93  CHECK(target_expr);
94  const auto& ti = target_expr->get_type_info();
95  // TODO: add proper lazy fetch for varlen types in result set
96  if (ti.is_varlen()) {
97  continue;
98  }
99  const auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(target_expr);
100  if (!col_var) {
101  continue;
102  }
103  if (!ti.is_varlen() &&
104  used_columns.find(col_var->getColumnKey().column_id) == used_columns.end()) {
105  // setting target index to be zero so that later it can be decoded properly (in lazy
106  // fetch, the zeroth target index indicates the corresponding rowid column for the
107  // projected entry)
108  target_indices[target_idx] = 0;
109  }
110  }
111  return target_indices;
112 }
113 
115  const size_t group_col_width) {
116  if (range.getType() == ExpressionRangeType::Invalid) {
117  return sizeof(int64_t);
118  }
119  switch (range.getType()) {
121  if (group_col_width == sizeof(int64_t) && range.hasNulls()) {
122  return sizeof(int64_t);
123  }
124  return is_valid_int32_range(range) ? sizeof(int32_t) : sizeof(int64_t);
127  return sizeof(int64_t); // No compaction for floating point yet.
128  default:
129  UNREACHABLE();
130  }
131  return sizeof(int64_t);
132 }
133 
134 // TODO(miyu): make sure following setting of compact width is correct in all cases.
136  const std::vector<InputTableInfo>& query_infos,
137  const Executor* executor) {
138  int8_t compact_width{4};
139  for (const auto& groupby_expr : ra_exe_unit.groupby_exprs) {
140  const auto expr_range = getExpressionRange(groupby_expr.get(), query_infos, executor);
141  compact_width = std::max(compact_width,
143  expr_range, groupby_expr->get_type_info().get_size()));
144  }
145  return compact_width;
146 }
147 
148 bool use_streaming_top_n(const RelAlgExecutionUnit& ra_exe_unit,
149  const bool output_columnar) {
150  if (g_cluster) {
151  return false; // TODO(miyu)
152  }
153 
154  for (const auto target_expr : ra_exe_unit.target_exprs) {
155  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
156  return false;
157  }
158  if (dynamic_cast<const Analyzer::WindowFunction*>(target_expr)) {
159  return false;
160  }
161  }
162 
163  // TODO: Allow streaming top n for columnar output
164  if (!output_columnar && ra_exe_unit.sort_info.order_entries.size() == 1 &&
165  ra_exe_unit.sort_info.limit &&
167  const auto only_order_entry = ra_exe_unit.sort_info.order_entries.front();
168  CHECK_GT(only_order_entry.tle_no, int(0));
169  CHECK_LE(static_cast<size_t>(only_order_entry.tle_no),
170  ra_exe_unit.target_exprs.size());
171  const auto order_entry_expr = ra_exe_unit.target_exprs[only_order_entry.tle_no - 1];
172  const auto n = ra_exe_unit.sort_info.offset + ra_exe_unit.sort_info.limit;
173  if ((order_entry_expr->get_type_info().is_number() ||
174  order_entry_expr->get_type_info().is_time()) &&
175  n <= g_streaming_topn_max) {
176  return true;
177  }
178  }
179 
180  return false;
181 }
182 
183 template <class T>
184 inline std::vector<int8_t> get_col_byte_widths(const T& col_expr_list) {
185  std::vector<int8_t> col_widths;
186  size_t col_expr_idx = 0;
187  for (const auto& col_expr : col_expr_list) {
188  if (!col_expr) {
189  // row index
190  col_widths.push_back(sizeof(int64_t));
191  } else {
192  bool is_varlen_projection{false};
193  if constexpr (std::is_same<T, std::list<std::shared_ptr<Analyzer::Expr>>>::value) {
195  !(std::dynamic_pointer_cast<const Analyzer::GeoExpr>(col_expr) == nullptr);
196  } else {
198  !(dynamic_cast<const Analyzer::GeoExpr*>(col_expr) == nullptr);
199  }
200 
201  if (is_varlen_projection) {
202  col_widths.push_back(sizeof(int64_t));
203  ++col_expr_idx;
204  continue;
205  }
206  const auto agg_info = get_target_info(col_expr, g_bigint_count);
207  const auto chosen_type = get_compact_type(agg_info);
208  if ((chosen_type.is_string() && chosen_type.get_compression() == kENCODING_NONE) ||
209  chosen_type.is_array()) {
210  col_widths.push_back(sizeof(int64_t));
211  col_widths.push_back(sizeof(int64_t));
212  ++col_expr_idx;
213  continue;
214  }
215  if (chosen_type.is_geometry()) {
216  for (auto i = 0; i < chosen_type.get_physical_coord_cols(); ++i) {
217  col_widths.push_back(sizeof(int64_t));
218  col_widths.push_back(sizeof(int64_t));
219  }
220  ++col_expr_idx;
221  continue;
222  }
223  const auto col_expr_bitwidth = get_bit_width(chosen_type);
224  CHECK_EQ(size_t(0), col_expr_bitwidth % 8);
225  col_widths.push_back(static_cast<int8_t>(col_expr_bitwidth >> 3));
226  // for average, we'll need to keep the count as well
227  if (agg_info.agg_kind == kAVG) {
228  CHECK(agg_info.is_agg);
229  col_widths.push_back(sizeof(int64_t));
230  }
231  }
232  ++col_expr_idx;
233  }
234  return col_widths;
235 }
236 
237 } // namespace
238 
239 std::unique_ptr<QueryMemoryDescriptor> QueryMemoryDescriptor::init(
240  const Executor* executor,
241  const RelAlgExecutionUnit& ra_exe_unit,
242  const std::vector<InputTableInfo>& query_infos,
243  const ColRangeInfo& col_range_info,
244  const KeylessInfo& keyless_info,
245  const bool allow_multifrag,
246  const ExecutorDeviceType device_type,
247  const int8_t crt_min_byte_width,
248  const bool sort_on_gpu_hint,
249  const size_t shard_count,
250  const size_t max_groups_buffer_entry_count,
251  RenderInfo* render_info,
252  const CountDistinctDescriptors count_distinct_descriptors,
253  const bool must_use_baseline_sort,
254  const bool output_columnar_hint,
255  const bool streaming_top_n_hint) {
256  auto group_col_widths = get_col_byte_widths(ra_exe_unit.groupby_exprs);
257  const bool is_group_by{!group_col_widths.empty()};
258 
259  auto col_slot_context = ColSlotContext(ra_exe_unit.target_exprs, {});
260 
261  const auto min_slot_size = QueryMemoryDescriptor::pick_target_compact_width(
262  ra_exe_unit, query_infos, crt_min_byte_width);
263 
264  col_slot_context.setAllSlotsPaddedSize(min_slot_size);
265  col_slot_context.validate();
266 
267  if (!is_group_by) {
268  CHECK(!must_use_baseline_sort);
269 
270  return std::make_unique<QueryMemoryDescriptor>(
271  executor,
272  ra_exe_unit,
273  query_infos,
274  allow_multifrag,
275  false,
276  false,
277  -1,
278  ColRangeInfo{ra_exe_unit.estimator ? QueryDescriptionType::Estimator
280  0,
281  0,
282  0,
283  false},
284  col_slot_context,
285  std::vector<int8_t>{},
286  /*group_col_compact_width=*/0,
287  std::vector<int64_t>{},
288  /*entry_count=*/1,
289  count_distinct_descriptors,
290  false,
291  output_columnar_hint,
292  render_info && render_info->isInSitu(),
293  must_use_baseline_sort,
294  /*use_streaming_top_n=*/false);
295  }
296 
297  size_t entry_count = 1;
298  auto actual_col_range_info = col_range_info;
299  bool interleaved_bins_on_gpu = false;
300  bool keyless_hash = false;
301  bool streaming_top_n = false;
302  int8_t group_col_compact_width = 0;
303  int32_t idx_target_as_key = -1;
304  auto output_columnar = output_columnar_hint;
305  std::vector<int64_t> target_groupby_indices;
306 
307  switch (col_range_info.hash_type_) {
309  if (render_info) {
310  // TODO(croot): this can be removed now thanks to the more centralized
311  // NonInsituQueryClassifier code, but keeping it just in case
312  render_info->setNonInSitu();
313  }
314  // keyless hash: whether or not group columns are stored at the beginning of the
315  // output buffer
316  keyless_hash =
317  (!sort_on_gpu_hint ||
319  col_range_info.max, col_range_info.min, col_range_info.bucket)) &&
320  !col_range_info.bucket && !must_use_baseline_sort && keyless_info.keyless;
321 
322  // if keyless, then this target index indicates wheter an entry is empty or not
323  // (acts as a key)
324  idx_target_as_key = keyless_info.target_index;
325 
326  if (group_col_widths.size() > 1) {
327  // col range info max contains the expected cardinality of the output
328  entry_count = static_cast<size_t>(actual_col_range_info.max);
329  actual_col_range_info.bucket = 0;
330  } else {
331  // single column perfect hash
332  entry_count = std::max(
333  GroupByAndAggregate::getBucketedCardinality(col_range_info), int64_t(1));
334  const size_t interleaved_max_threshold{512};
335 
336  if (must_use_baseline_sort) {
337  target_groupby_indices = target_expr_group_by_indices(ra_exe_unit.groupby_exprs,
338  ra_exe_unit.target_exprs);
339  col_slot_context =
340  ColSlotContext(ra_exe_unit.target_exprs, target_groupby_indices);
341  }
342 
343  bool has_varlen_sample_agg = false;
344  for (const auto& target_expr : ra_exe_unit.target_exprs) {
345  if (target_expr->get_contains_agg()) {
346  const auto agg_expr = dynamic_cast<Analyzer::AggExpr*>(target_expr);
347  CHECK(agg_expr);
348  if (agg_expr->get_aggtype() == kSAMPLE &&
349  agg_expr->get_type_info().is_varlen()) {
350  has_varlen_sample_agg = true;
351  break;
352  }
353  }
354  }
355 
356  interleaved_bins_on_gpu = keyless_hash && !has_varlen_sample_agg &&
357  (entry_count <= interleaved_max_threshold) &&
358  (device_type == ExecutorDeviceType::GPU) &&
360  count_distinct_descriptors) &&
361  !output_columnar;
362  }
363  break;
364  }
366  if (render_info) {
367  // TODO(croot): this can be removed now thanks to the more centralized
368  // NonInsituQueryClassifier code, but keeping it just in case
369  render_info->setNonInSitu();
370  }
371  entry_count = shard_count
372  ? (max_groups_buffer_entry_count + shard_count - 1) / shard_count
373  : max_groups_buffer_entry_count;
374  target_groupby_indices = target_expr_group_by_indices(ra_exe_unit.groupby_exprs,
375  ra_exe_unit.target_exprs);
376  col_slot_context = ColSlotContext(ra_exe_unit.target_exprs, target_groupby_indices);
377 
378  group_col_compact_width =
379  output_columnar ? 8
380  : pick_baseline_key_width(ra_exe_unit, query_infos, executor);
381 
382  actual_col_range_info =
384  break;
385  }
387  CHECK(!must_use_baseline_sort);
388 
389  if (streaming_top_n_hint && use_streaming_top_n(ra_exe_unit, output_columnar)) {
390  streaming_top_n = true;
391  entry_count = ra_exe_unit.sort_info.offset + ra_exe_unit.sort_info.limit;
392  } else {
393  if (ra_exe_unit.use_bump_allocator) {
394  output_columnar = false;
395  entry_count = 0;
396  } else {
397  entry_count = ra_exe_unit.scan_limit
398  ? static_cast<size_t>(ra_exe_unit.scan_limit)
399  : max_groups_buffer_entry_count;
400  }
401  }
402 
403  target_groupby_indices = executor->plan_state_->allow_lazy_fetch_
404  ? target_expr_proj_indices(ra_exe_unit)
405  : std::vector<int64_t>{};
406 
407  col_slot_context = ColSlotContext(ra_exe_unit.target_exprs, target_groupby_indices);
408  break;
409  }
410  default:
411  UNREACHABLE() << "Unknown query type";
412  }
413 
414  return std::make_unique<QueryMemoryDescriptor>(executor,
415  ra_exe_unit,
416  query_infos,
417  allow_multifrag,
418  keyless_hash,
419  interleaved_bins_on_gpu,
420  idx_target_as_key,
421  actual_col_range_info,
422  col_slot_context,
423  group_col_widths,
424  group_col_compact_width,
425  target_groupby_indices,
426  entry_count,
427  count_distinct_descriptors,
428  sort_on_gpu_hint,
429  output_columnar,
430  render_info && render_info->isInSitu(),
431  must_use_baseline_sort,
432  streaming_top_n);
433 }
434 
435 namespace {
436 template <SQLAgg... agg_types>
437 bool any_of(std::vector<Analyzer::Expr*> const& target_exprs) {
438  return boost::algorithm::any_of(target_exprs, [=](Analyzer::Expr const* expr) {
439  auto const* const agg = dynamic_cast<Analyzer::AggExpr const*>(expr);
440  return agg && (... || (agg_types == agg->get_aggtype()));
441  });
442 }
443 } // namespace
444 
446  const Executor* executor,
447  const RelAlgExecutionUnit& ra_exe_unit,
448  const std::vector<InputTableInfo>& query_infos,
449  const bool allow_multifrag,
450  const bool keyless_hash,
451  const bool interleaved_bins_on_gpu,
452  const int32_t idx_target_as_key,
453  const ColRangeInfo& col_range_info,
454  const ColSlotContext& col_slot_context,
455  const std::vector<int8_t>& group_col_widths,
456  const int8_t group_col_compact_width,
457  const std::vector<int64_t>& target_groupby_indices,
458  const size_t entry_count,
459  const CountDistinctDescriptors count_distinct_descriptors,
460  const bool sort_on_gpu_hint,
461  const bool output_columnar_hint,
462  const bool render_output,
463  const bool must_use_baseline_sort,
464  const bool use_streaming_top_n)
465  : executor_(executor)
466  , allow_multifrag_(allow_multifrag)
467  , query_desc_type_(col_range_info.hash_type_)
468  , keyless_hash_(keyless_hash)
469  , interleaved_bins_on_gpu_(interleaved_bins_on_gpu)
470  , idx_target_as_key_(idx_target_as_key)
471  , group_col_widths_(group_col_widths)
472  , group_col_compact_width_(group_col_compact_width)
473  , target_groupby_indices_(target_groupby_indices)
474  , entry_count_(entry_count)
475  , min_val_(col_range_info.min)
476  , max_val_(col_range_info.max)
477  , bucket_(col_range_info.bucket)
478  , has_nulls_(col_range_info.has_nulls)
479  , count_distinct_descriptors_(count_distinct_descriptors)
480  , output_columnar_(false)
481  , render_output_(render_output)
482  , must_use_baseline_sort_(must_use_baseline_sort)
483  , is_table_function_(false)
484  , use_streaming_top_n_(use_streaming_top_n)
485  , force_4byte_float_(false)
486  , col_slot_context_(col_slot_context) {
490 
491  sort_on_gpu_ = sort_on_gpu_hint && canOutputColumnar() && !keyless_hash_;
492  if (sort_on_gpu_) {
493  CHECK(!ra_exe_unit.use_bump_allocator);
494  output_columnar_ = true;
495  } else {
496  switch (query_desc_type_) {
498  output_columnar_ = output_columnar_hint;
499  break;
501  output_columnar_ = output_columnar_hint &&
504  !any_of<kAPPROX_QUANTILE, kMODE>(ra_exe_unit.target_exprs);
505  break;
507  output_columnar_ = output_columnar_hint;
508  break;
510  output_columnar_ = output_columnar_hint &&
513  !any_of<kAPPROX_QUANTILE, kMODE>(ra_exe_unit.target_exprs);
514  break;
515  default:
516  output_columnar_ = false;
517  break;
518  }
519  }
520 
522  // TODO(adb): Ensure fixed size buffer allocations are correct with all logical column
523  // sizes
524  CHECK(!ra_exe_unit.use_bump_allocator);
527  }
528 
529 #ifdef HAVE_CUDA
530  // Check Streaming Top N heap usage, bail if > max slab size, CUDA ONLY
531  if (use_streaming_top_n_ && executor->getDataMgr()->gpusPresent()) {
532  const auto thread_count = executor->blockSize() * executor->gridSize();
533  const auto total_buff_size =
535  if (total_buff_size > executor_->maxGpuSlabSize()) {
536  throw StreamingTopNOOM(total_buff_size);
537  }
538  }
539 #endif
540 }
541 
543  : executor_(nullptr)
544  , allow_multifrag_(false)
545  , query_desc_type_(QueryDescriptionType::Projection)
546  , keyless_hash_(false)
547  , interleaved_bins_on_gpu_(false)
548  , idx_target_as_key_(0)
549  , group_col_compact_width_(0)
550  , entry_count_(0)
551  , min_val_(0)
552  , max_val_(0)
553  , bucket_(0)
554  , has_nulls_(false)
555  , sort_on_gpu_(false)
556  , output_columnar_(false)
557  , render_output_(false)
558  , must_use_baseline_sort_(false)
559  , is_table_function_(false)
560  , use_streaming_top_n_(false)
561  , force_4byte_float_(false) {}
562 
564  const size_t entry_count,
565  const QueryDescriptionType query_desc_type,
566  const bool is_table_function)
567  : executor_(executor)
568  , allow_multifrag_(false)
569  , query_desc_type_(query_desc_type)
570  , keyless_hash_(false)
571  , interleaved_bins_on_gpu_(false)
572  , idx_target_as_key_(0)
573  , group_col_compact_width_(0)
574  , entry_count_(entry_count)
575  , min_val_(0)
576  , max_val_(0)
577  , bucket_(0)
578  , has_nulls_(false)
579  , sort_on_gpu_(false)
580  , output_columnar_(false)
581  , render_output_(false)
582  , must_use_baseline_sort_(false)
583  , is_table_function_(is_table_function)
584  , use_streaming_top_n_(false)
585  , force_4byte_float_(false) {}
586 
588  const int64_t min_val,
589  const int64_t max_val,
590  const bool has_nulls,
591  const std::vector<int8_t>& group_col_widths)
592  : executor_(nullptr)
593  , allow_multifrag_(false)
594  , query_desc_type_(query_desc_type)
595  , keyless_hash_(false)
596  , interleaved_bins_on_gpu_(false)
597  , idx_target_as_key_(0)
598  , group_col_widths_(group_col_widths)
599  , group_col_compact_width_(0)
600  , entry_count_(0)
601  , min_val_(min_val)
602  , max_val_(max_val)
603  , bucket_(0)
604  , has_nulls_(false)
605  , sort_on_gpu_(false)
606  , output_columnar_(false)
607  , render_output_(false)
608  , must_use_baseline_sort_(false)
609  , is_table_function_(false)
610  , use_streaming_top_n_(false)
611  , force_4byte_float_(false) {}
612 
614  // Note that this method does not check ptr reference members (e.g. executor_) or
615  // entry_count_
616  if (query_desc_type_ != other.query_desc_type_) {
617  return false;
618  }
619  if (keyless_hash_ != other.keyless_hash_) {
620  return false;
621  }
623  return false;
624  }
625  if (idx_target_as_key_ != other.idx_target_as_key_) {
626  return false;
627  }
628  if (force_4byte_float_ != other.force_4byte_float_) {
629  return false;
630  }
631  if (group_col_widths_ != other.group_col_widths_) {
632  return false;
633  }
635  return false;
636  }
638  return false;
639  }
640  if (min_val_ != other.min_val_) {
641  return false;
642  }
643  if (max_val_ != other.max_val_) {
644  return false;
645  }
646  if (bucket_ != other.bucket_) {
647  return false;
648  }
649  if (has_nulls_ != other.has_nulls_) {
650  return false;
651  }
653  return false;
654  } else {
655  // Count distinct descriptors can legitimately differ in device only.
656  for (size_t i = 0; i < count_distinct_descriptors_.size(); ++i) {
657  auto ref_count_distinct_desc = other.count_distinct_descriptors_[i];
658  auto count_distinct_desc = count_distinct_descriptors_[i];
659  count_distinct_desc.device_type = ref_count_distinct_desc.device_type;
660  if (ref_count_distinct_desc != count_distinct_desc) {
661  return false;
662  }
663  }
664  }
665  if (sort_on_gpu_ != other.sort_on_gpu_) {
666  return false;
667  }
668  if (output_columnar_ != other.output_columnar_) {
669  return false;
670  }
671  if (col_slot_context_ != other.col_slot_context_) {
672  return false;
673  }
674  return true;
675 }
676 
677 std::unique_ptr<QueryExecutionContext> QueryMemoryDescriptor::getQueryExecutionContext(
678  const RelAlgExecutionUnit& ra_exe_unit,
679  const Executor* executor,
680  const ExecutorDeviceType device_type,
681  const ExecutorDispatchMode dispatch_mode,
682  const int device_id,
683  const shared::TableKey& outer_table_key,
684  const int64_t num_rows,
685  const std::vector<std::vector<const int8_t*>>& col_buffers,
686  const std::vector<std::vector<uint64_t>>& frag_offsets,
687  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
688  const bool output_columnar,
689  const bool sort_on_gpu,
690  const size_t thread_idx,
691  RenderInfo* render_info) const {
692  auto timer = DEBUG_TIMER(__func__);
693  if (frag_offsets.empty()) {
694  return nullptr;
695  }
696  return std::unique_ptr<QueryExecutionContext>(
697  new QueryExecutionContext(ra_exe_unit,
698  *this,
699  executor,
700  device_type,
701  dispatch_mode,
702  device_id,
703  outer_table_key,
704  num_rows,
705  col_buffers,
706  frag_offsets,
707  row_set_mem_owner,
708  output_columnar,
709  sort_on_gpu,
710  thread_idx,
711  render_info));
712 }
713 
715  const RelAlgExecutionUnit& ra_exe_unit,
716  const std::vector<InputTableInfo>& query_infos,
717  const int8_t crt_min_byte_width) {
718  if (g_bigint_count) {
719  return sizeof(int64_t);
720  }
721  int8_t compact_width{0};
722  auto col_it = ra_exe_unit.input_col_descs.begin();
723  auto const end = ra_exe_unit.input_col_descs.end();
724  int unnest_array_col_id{std::numeric_limits<int>::min()};
725  for (const auto& groupby_expr : ra_exe_unit.groupby_exprs) {
726  const auto uoper = dynamic_cast<Analyzer::UOper*>(groupby_expr.get());
727  if (uoper && uoper->get_optype() == kUNNEST) {
728  const auto& arg_ti = uoper->get_operand()->get_type_info();
729  CHECK(arg_ti.is_array());
730  const auto& elem_ti = arg_ti.get_elem_type();
731  if (elem_ti.is_string() && elem_ti.get_compression() == kENCODING_DICT) {
732  unnest_array_col_id = (*col_it)->getColId();
733  } else {
734  compact_width = crt_min_byte_width;
735  break;
736  }
737  }
738  if (col_it != end) {
739  ++col_it;
740  }
741  }
742  if (!compact_width &&
743  (ra_exe_unit.groupby_exprs.size() != 1 || !ra_exe_unit.groupby_exprs.front())) {
744  compact_width = crt_min_byte_width;
745  }
746  if (!compact_width) {
747  col_it = ra_exe_unit.input_col_descs.begin();
748  std::advance(col_it, ra_exe_unit.groupby_exprs.size());
749  for (const auto target : ra_exe_unit.target_exprs) {
750  const auto& ti = target->get_type_info();
751  const auto agg = dynamic_cast<const Analyzer::AggExpr*>(target);
752  if (agg && agg->get_arg()) {
753  compact_width = crt_min_byte_width;
754  break;
755  }
756 
757  if (agg) {
758  CHECK_EQ(kCOUNT, agg->get_aggtype());
759  CHECK(!agg->get_is_distinct());
760  if (col_it != end) {
761  ++col_it;
762  }
763  continue;
764  }
765 
766  if (is_int_and_no_bigger_than(ti, 4) ||
767  (ti.is_string() && ti.get_compression() == kENCODING_DICT)) {
768  if (col_it != end) {
769  ++col_it;
770  }
771  continue;
772  }
773 
774  const auto uoper = dynamic_cast<Analyzer::UOper*>(target);
775  if (uoper && uoper->get_optype() == kUNNEST &&
776  (*col_it)->getColId() == unnest_array_col_id) {
777  const auto arg_ti = uoper->get_operand()->get_type_info();
778  CHECK(arg_ti.is_array());
779  const auto& elem_ti = arg_ti.get_elem_type();
780  if (elem_ti.is_string() && elem_ti.get_compression() == kENCODING_DICT) {
781  if (col_it != end) {
782  ++col_it;
783  }
784  continue;
785  }
786  }
787 
788  compact_width = crt_min_byte_width;
789  break;
790  }
791  }
792  if (!compact_width) {
793  size_t total_tuples{0};
794  for (const auto& qi : query_infos) {
795  total_tuples += qi.info.getNumTuples();
796  }
797  return total_tuples <= static_cast<size_t>(std::numeric_limits<uint32_t>::max()) ||
798  unnest_array_col_id != std::numeric_limits<int>::min()
799  ? 4
800  : crt_min_byte_width;
801  } else {
802  // TODO(miyu): relax this condition to allow more cases just w/o padding
803  for (auto wid : get_col_byte_widths(ra_exe_unit.target_exprs)) {
804  compact_width = std::max(compact_width, wid);
805  }
806  return compact_width;
807  }
808 }
809 
812 }
813 
816  size_t total_bytes{0};
817  if (keyless_hash_) {
818  // ignore, there's no group column in the output buffer
820  } else {
821  total_bytes += group_col_widths_.size() * getEffectiveKeyWidth();
822  total_bytes = align_to_int64(total_bytes);
823  }
824  total_bytes += getColsSize();
825  return align_to_int64(total_bytes);
826 }
827 
829  return (interleaved_bins_on_gpu_ ? executor_->warpSize() : 1);
830 }
831 
834 }
835 
844 }
845 
851  const size_t num_entries_per_column) const {
852  return col_slot_context_.getTotalBytesOfColumnarBuffers(num_entries_per_column);
853 }
854 
865  const size_t projection_count) const {
866  constexpr size_t row_index_width = sizeof(int64_t);
867  return getTotalBytesOfColumnarBuffers(projection_count) +
868  row_index_width * projection_count;
869 }
870 
871 size_t QueryMemoryDescriptor::getColOnlyOffInBytes(const size_t col_idx) const {
872  return col_slot_context_.getColOnlyOffInBytes(col_idx);
873 }
874 
875 /*
876  * Returns the memory offset in bytes for a specific agg column in the output
877  * memory buffer. Depending on the query type, there may be some extra portion
878  * of memory prepended at the beginning of the buffer. A brief description of
879  * the memory layout is as follows:
880  * 1. projections: index column (64bit) + all target columns
881  * 2. group by: all group columns (64-bit each) + all agg columns
882  * 2a. if keyless, there is no prepending group column stored at the beginning
883  */
884 size_t QueryMemoryDescriptor::getColOffInBytes(const size_t col_idx) const {
885  const auto warp_count = getWarpCount();
886  if (output_columnar_) {
887  CHECK_EQ(size_t(1), warp_count);
888  size_t offset{0};
889  if (!keyless_hash_) {
891  }
892  if (is_table_function_) {
893  for (size_t index = 0; index < col_idx; ++index) {
894  int8_t column_width = getPaddedSlotWidthBytes(index);
895  if (column_width > 0) {
896  offset += align_to_int64(column_width * entry_count_);
897  } else {
898  int64_t flatbuffer_size = getFlatBufferSize(index);
899  CHECK_GT(flatbuffer_size, 0);
900  offset += align_to_int64(flatbuffer_size);
901  }
902  }
903  } else {
904  for (size_t index = 0; index < col_idx; ++index) {
906  }
907  }
908  return offset;
909  }
910 
911  size_t offset{0};
912  if (keyless_hash_) {
913  // ignore, there's no group column in the output buffer
915  } else {
916  offset += group_col_widths_.size() * getEffectiveKeyWidth();
917  offset = align_to_int64(offset);
918  }
919  offset += getColOnlyOffInBytes(col_idx);
920  return offset;
921 }
922 
923 /*
924  * Returns the memory offset for a particular group column in the prepended group
925  * columns portion of the memory.
926  */
928  const size_t group_idx) const {
930  CHECK(group_idx < getGroupbyColCount());
931  size_t offset{0};
932  for (size_t col_idx = 0; col_idx < group_idx; col_idx++) {
933  // TODO(Saman): relax that int64_bit part immediately
934  offset += align_to_int64(
935  std::max(groupColWidth(col_idx), static_cast<int8_t>(sizeof(int64_t))) *
936  getEntryCount());
937  }
938  return offset;
939 }
940 
941 /*
942  * Returns total amount of memory prepended at the beginning of the output memory
943  * buffer.
944  */
947  size_t buffer_size{0};
948  for (size_t group_idx = 0; group_idx < getGroupbyColCount(); group_idx++) {
949  buffer_size += align_to_int64(
950  std::max(groupColWidth(group_idx), static_cast<int8_t>(sizeof(int64_t))) *
951  getEntryCount());
952  }
953  return buffer_size;
954 }
955 
956 size_t QueryMemoryDescriptor::getColOffInBytesInNextBin(const size_t col_idx) const {
957  auto warp_count = getWarpCount();
958  if (output_columnar_) {
959  CHECK_EQ(size_t(1), group_col_widths_.size());
960  CHECK_EQ(size_t(1), warp_count);
961  return getPaddedSlotWidthBytes(col_idx);
962  }
963 
964  return warp_count * getRowSize();
965 }
966 
967 size_t QueryMemoryDescriptor::getNextColOffInBytes(const int8_t* col_ptr,
968  const size_t bin,
969  const size_t col_idx) const {
971  size_t offset{0};
972  auto warp_count = getWarpCount();
973  const auto chosen_bytes = getPaddedSlotWidthBytes(col_idx);
974  const auto total_slot_count = getSlotCount();
975  if (col_idx + 1 == total_slot_count) {
976  if (output_columnar_) {
977  return (entry_count_ - bin) * chosen_bytes;
978  } else {
979  return static_cast<size_t>(align_to_int64(col_ptr + chosen_bytes) - col_ptr);
980  }
981  }
982 
983  const auto next_chosen_bytes = getPaddedSlotWidthBytes(col_idx + 1);
984  if (output_columnar_) {
985  CHECK_EQ(size_t(1), group_col_widths_.size());
986  CHECK_EQ(size_t(1), warp_count);
987 
988  offset = align_to_int64(entry_count_ * chosen_bytes);
989 
990  offset += bin * (next_chosen_bytes - chosen_bytes);
991  return offset;
992  }
993 
994  if (next_chosen_bytes == sizeof(int64_t)) {
995  return static_cast<size_t>(align_to_int64(col_ptr + chosen_bytes) - col_ptr);
996  } else {
997  return chosen_bytes;
998  }
999 }
1000 
1002  const size_t col_idx) const {
1003  const auto chosen_bytes = getPaddedSlotWidthBytes(col_idx);
1004  const auto total_slot_count = getSlotCount();
1005  if (col_idx + 1 == total_slot_count) {
1006  return static_cast<size_t>(align_to_int64(col_ptr + chosen_bytes) - col_ptr);
1007  }
1008 
1009  const auto next_chosen_bytes = getPaddedSlotWidthBytes(col_idx + 1);
1010 
1011  if (next_chosen_bytes == sizeof(int64_t)) {
1012  return static_cast<size_t>(align_to_int64(col_ptr + chosen_bytes) - col_ptr);
1013  } else {
1014  return chosen_bytes;
1015  }
1016 }
1017 
1019  const RelAlgExecutionUnit& ra_exe_unit,
1020  const unsigned thread_count,
1021  const ExecutorDeviceType device_type) const {
1022  if (use_streaming_top_n_) {
1023  const size_t n = ra_exe_unit.sort_info.offset + ra_exe_unit.sort_info.limit;
1024  return streaming_top_n::get_heap_size(getRowSize(), n, thread_count);
1025  }
1026  return getBufferSizeBytes(device_type, entry_count_);
1027 }
1028 
1042  const size_t entry_count) const {
1043  if (keyless_hash_ && !output_columnar_) {
1044  CHECK_GE(group_col_widths_.size(), size_t(1));
1045  auto row_bytes = align_to_int64(getColsSize());
1046 
1047  return (interleavedBins(device_type) ? executor_->warpSize() : 1) * entry_count *
1048  row_bytes;
1049  }
1050 
1051  constexpr size_t row_index_width = sizeof(int64_t);
1052  size_t total_bytes{0};
1053  if (output_columnar_) {
1054  switch (query_desc_type_) {
1056  total_bytes = row_index_width * entry_count + getTotalBytesOfColumnarBuffers();
1057  break;
1059  total_bytes = getTotalBytesOfColumnarBuffers();
1060  break;
1061  default:
1062  total_bytes = sizeof(int64_t) * group_col_widths_.size() * entry_count +
1064  break;
1065  }
1066  } else {
1067  total_bytes = getRowSize() * entry_count;
1068  }
1069  return total_bytes;
1070 }
1071 
1073  const ExecutorDeviceType device_type) const {
1074  return getBufferSizeBytes(device_type, entry_count_);
1075 }
1076 
1078  output_columnar_ = val;
1081  }
1082 }
1083 
1084 /*
1085  * Indicates the query types that are currently allowed to use the logical
1086  * sized columns instead of padded sized ones.
1087  */
1089  // In distributed mode, result sets are serialized using rowwise iterators, so we use
1090  // consistent slot widths for now
1091  return output_columnar_ && !g_cluster &&
1093  query_desc_type_ == QueryDescriptionType::TableFunction);
1094 }
1095 
1097  size_t total_slot_count = col_slot_context_.getSlotCount();
1098 
1099  if (target_groupby_indices_.empty()) {
1100  return total_slot_count;
1101  }
1102  return total_slot_count - std::count_if(target_groupby_indices_.begin(),
1104  [](const int64_t i) { return i >= 0; });
1105 }
1106 
1109  getGroupbyColCount() == 1);
1110 }
1111 
1114 }
1115 
1117  if (g_cluster) {
1118  return true;
1119  }
1121  return true;
1122  }
1123  if (executor_->isCPUOnly() || render_output_ ||
1128  getGroupbyColCount() > 1)) {
1129  return true;
1130  }
1133 }
1134 
1136  return device_type == ExecutorDeviceType::GPU && !render_output_ &&
1138 }
1139 
1141  return interleaved_bins_on_gpu_ && device_type == ExecutorDeviceType::GPU;
1142 }
1143 
1144 // TODO(Saman): an implementation detail, so move this out of QMD
1146  const ExecutorDeviceType device_type) const {
1147  if (device_type == ExecutorDeviceType::GPU) {
1148  return executor_->cudaMgr()->isArchVoltaOrGreaterForAll();
1149  }
1150  return false;
1151 }
1152 
1154  return col_slot_context_.getColCount();
1155 }
1156 
1159 }
1160 
1161 const int8_t QueryMemoryDescriptor::getPaddedSlotWidthBytes(const size_t slot_idx) const {
1162  return col_slot_context_.getSlotInfo(slot_idx).padded_size;
1163 }
1164 
1166  const int8_t bytes) {
1167  col_slot_context_.setPaddedSlotWidthBytes(slot_idx, bytes);
1168 }
1169 
1171  const size_t slot_idx) const {
1172  return col_slot_context_.getSlotInfo(slot_idx).logical_size;
1173 }
1174 
1176  const size_t col_idx) const {
1177  const auto& col_slots = col_slot_context_.getSlotsForCol(col_idx);
1178  CHECK_EQ(col_slots.size(), size_t(1));
1179  return col_slots.front();
1180 }
1181 
1182 void QueryMemoryDescriptor::useConsistentSlotWidthSize(const int8_t slot_width_size) {
1183  col_slot_context_.setAllSlotsSize(slot_width_size);
1184 }
1185 
1187  // Note: Actual row size may include padding (see ResultSetBufferAccessors.h)
1189 }
1190 
1192  const int8_t actual_min_byte_width) const {
1193  return col_slot_context_.getMinPaddedByteSize(actual_min_byte_width);
1194 }
1195 
1197  const std::vector<std::tuple<int8_t, int8_t>>& slots_for_col) {
1198  col_slot_context_.addColumn(slots_for_col);
1199 }
1200 
1201 void QueryMemoryDescriptor::addColSlotInfoFlatBuffer(const int64_t flatbuffer_size) {
1202  col_slot_context_.addColumnFlatBuffer(flatbuffer_size);
1203 }
1204 
1207 }
1208 
1211 }
1212 
1217 }
1218 
1220  switch (query_desc_type_) {
1222  return "Perfect Hash";
1224  return "Baseline Hash";
1226  return "Projection";
1228  return "Table Function";
1230  return "Non-grouped Aggregate";
1232  return "Estimator";
1233  default:
1234  UNREACHABLE();
1235  }
1236  return "";
1237 }
1238 
1239 std::string QueryMemoryDescriptor::toString() const {
1240  auto str = reductionKey();
1241  str += "\tAllow Multifrag: " + ::toString(allow_multifrag_) + "\n";
1242  str += "\tInterleaved Bins on GPU: " + ::toString(interleaved_bins_on_gpu_) + "\n";
1243  str += "\tBlocks Share Memory: " + ::toString(blocksShareMemory()) + "\n";
1244  str += "\tThreads Share Memory: " + ::toString(threadsShareMemory()) + "\n";
1245  str += "\tUses Fast Group Values: " + ::toString(usesGetGroupValueFast()) + "\n";
1246  str +=
1247  "\tLazy Init Groups (GPU): " + ::toString(lazyInitGroups(ExecutorDeviceType::GPU)) +
1248  "\n";
1249  str += "\tEntry Count: " + std::to_string(entry_count_) + "\n";
1250  str += "\tMin Val (perfect hash only): " + std::to_string(min_val_) + "\n";
1251  str += "\tMax Val (perfect hash only): " + std::to_string(max_val_) + "\n";
1252  str += "\tBucket Val (perfect hash only): " + std::to_string(bucket_) + "\n";
1253  str += "\tSort on GPU: " + ::toString(sort_on_gpu_) + "\n";
1254  str += "\tUse Streaming Top N: " + ::toString(use_streaming_top_n_) + "\n";
1255  str += "\tOutput Columnar: " + ::toString(output_columnar_) + "\n";
1256  str += "\tRender Output: " + ::toString(render_output_) + "\n";
1257  str += "\tUse Baseline Sort: " + ::toString(must_use_baseline_sort_) + "\n";
1258  str += "\tIs Table Function: " + ::toString(is_table_function_) + "\n";
1259  return str;
1260 }
1261 
1263  std::string str;
1264  str += "Query Memory Descriptor State\n";
1265  str += "\tQuery Type: " + queryDescTypeToString() + "\n";
1266  str +=
1267  "\tKeyless Hash: " + ::toString(keyless_hash_) +
1268  (keyless_hash_ ? ", target index for key: " + std::to_string(getTargetIdxForKey())
1269  : "") +
1270  "\n";
1271  str += "\tEffective key width: " + std::to_string(getEffectiveKeyWidth()) + "\n";
1272  str += "\tNumber of group columns: " + std::to_string(getGroupbyColCount()) + "\n";
1273  const auto group_indices_size = targetGroupbyIndicesSize();
1274  if (group_indices_size) {
1275  std::vector<std::string> group_indices_strings;
1276  for (size_t target_idx = 0; target_idx < group_indices_size; ++target_idx) {
1277  group_indices_strings.push_back(std::to_string(getTargetGroupbyIndex(target_idx)));
1278  }
1279  str += "\tTarget group by indices: " +
1280  boost::algorithm::join(group_indices_strings, ",") + "\n";
1281  }
1282  str += "\t" + col_slot_context_.toString();
1283  return str;
1284 }
1285 
1286 std::vector<TargetInfo> target_exprs_to_infos(
1287  const std::vector<Analyzer::Expr*>& targets,
1289  std::vector<TargetInfo> target_infos;
1290  for (const auto target_expr : targets) {
1291  auto target = get_target_info(target_expr, g_bigint_count);
1292  if (query_mem_desc.getQueryDescriptionType() ==
1294  set_notnull(target, false);
1295  target.sql_type.set_notnull(false);
1296  }
1297  target_infos.push_back(target);
1298  }
1299  return target_infos;
1300 }
1301 
1303  int64_t buffer_element_size{0};
1304  for (size_t i = 0; i < col_slot_context_.getSlotCount(); i++) {
1305  try {
1306  const auto slot_element_size = col_slot_context_.varlenOutputElementSize(i);
1307  if (slot_element_size < 0) {
1308  return std::nullopt;
1309  }
1310  buffer_element_size += slot_element_size;
1311  } catch (...) {
1312  continue;
1313  }
1314  }
1315  return buffer_element_size;
1316 }
1317 
1318 size_t QueryMemoryDescriptor::varlenOutputRowSizeToSlot(const size_t slot_idx) const {
1319  int64_t buffer_element_size{0};
1321  for (size_t i = 0; i < slot_idx; i++) {
1322  try {
1323  const auto slot_element_size = col_slot_context_.varlenOutputElementSize(i);
1324  if (slot_element_size < 0) {
1325  continue;
1326  }
1327  buffer_element_size += slot_element_size;
1328  } catch (...) {
1329  continue;
1330  }
1331  }
1332  return buffer_element_size;
1333 }
size_t varlenOutputRowSizeToSlot(const size_t slot_idx) const
int8_t getMinPaddedByteSize(const int8_t actual_min_byte_width) const
std::vector< Analyzer::Expr * > target_exprs
static bool many_entries(const int64_t max_val, const int64_t min_val, const int64_t bucket)
void addColSlotInfoFlatBuffer(const int64_t flatbuffer_size)
int64_t getIntMin() const
SQLAgg
Definition: sqldefs.h:73
#define CHECK_EQ(x, y)
Definition: Logger.h:301
size_t getBufferSizeBytes(const RelAlgExecutionUnit &ra_exe_unit, const unsigned thread_count, const ExecutorDeviceType device_type) const
bool g_enable_smem_group_by
static int64_t getBucketedCardinality(const ColRangeInfo &col_range_info)
void alignPaddedSlots(const bool sort_on_gpu)
std::vector< int64_t > target_expr_proj_indices(const RelAlgExecutionUnit &ra_exe_unit)
int8_t logical_size
size_t getTotalBytesOfColumnarProjections(const size_t projection_count) const
int64_t getTargetGroupbyIndex(const size_t target_idx) const
ExecutorDeviceType
void sort_on_gpu(int64_t *val_buff, int32_t *idx_buff, const uint64_t entry_count, const bool desc, const uint32_t chosen_bytes, ThrustAllocator &alloc, const int device_id)
std::string toString() const
bool isLogicalSizedColumnsAllowed() const
void setPaddedSlotWidthBytes(const size_t slot_idx, const int8_t bytes)
std::vector< int8_t > get_col_byte_widths(const T &col_expr_list)
int8_t pick_baseline_key_component_width(const ExpressionRange &range, const size_t group_col_width)
const std::list< Analyzer::OrderEntry > order_entries
std::string join(T const &container, std::string const &delim)
std::vector< InputDescriptor > input_descs
static std::unique_ptr< QueryMemoryDescriptor > init(const Executor *executor, const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &query_infos, const ColRangeInfo &col_range_info, const KeylessInfo &keyless_info, const bool allow_multifrag, const ExecutorDeviceType device_type, const int8_t crt_min_byte_width, const bool sort_on_gpu_hint, const size_t shard_count, const size_t max_groups_buffer_entry_count, RenderInfo *render_info, const CountDistinctDescriptors count_distinct_descriptors, const bool must_use_baseline_sort, const bool output_columnar_hint, const bool streaming_top_n_hint)
#define UNREACHABLE()
Definition: Logger.h:337
void setOutputColumnar(const bool val)
const SortAlgorithm algorithm
#define CHECK_GE(x, y)
Definition: Logger.h:306
size_t getAllSlotsPaddedSize() const
size_t getAllSlotsAlignedPaddedSize() const
size_t getNextColOffInBytes(const int8_t *col_ptr, const size_t bin, const size_t col_idx) const
size_t getEffectiveKeyWidth() const
bool use_streaming_top_n(const RelAlgExecutionUnit &ra_exe_unit, const bool output_columnar)
size_t g_streaming_topn_max
Definition: ResultSet.cpp:51
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
T visit(const Analyzer::Expr *expr) const
#define CHECK_GT(x, y)
Definition: Logger.h:305
void setAllSlotsSize(const int8_t slot_width_size)
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.h:88
std::string to_string(char const *&&v)
void useConsistentSlotWidthSize(const int8_t slot_width_size)
const SlotSize & getSlotInfo(const size_t slot_idx) const
size_t getColOnlyOffInBytes(const size_t col_idx) const
ExecutorDispatchMode
size_t getColOnlyOffInBytes(const size_t slot_idx) const
const SQLTypeInfo get_compact_type(const TargetInfo &target)
bool is_varlen_projection(const Analyzer::Expr *target_expr, const SQLTypeInfo &ti)
const size_t limit
bool g_enable_columnar_output
Definition: Execute.cpp:99
int8_t groupColWidth(const size_t key_idx) const
size_t get_bit_width(const SQLTypeInfo &ti)
void addColumnFlatBuffer(const int64_t flatbuffer_size)
std::vector< CountDistinctDescriptor > CountDistinctDescriptors
Definition: CountDistinct.h:34
size_t getCompactByteWidth() const
Provides column info and slot info for the output buffer and some metadata helpers.
size_t getGroupbyColCount() const
bool is_integer() const
Definition: sqltypes.h:582
const ColumnDescriptor * get_column_descriptor_maybe(const shared::ColumnKey &column_key)
Definition: Execute.h:220
bool lazyInitGroups(const ExecutorDeviceType) const
size_t targetGroupbyIndicesSize() const
size_t getPrependedGroupBufferSizeInBytes() const
size_t getTotalBytesOfColumnarBuffers() const
executor_(executor)
std::vector< int64_t > target_groupby_indices_
static int8_t pick_target_compact_width(const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &query_infos, const int8_t crt_min_byte_width)
bool g_bigint_count
CountDistinctDescriptors count_distinct_descriptors_
int32_t get_varno() const
Definition: Analyzer.h:288
bool is_valid_int32_range(const ExpressionRange &range)
void validate() const
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
bool hasNulls() const
int64_t varlenOutputElementSize(const size_t slot_idx) const
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
QueryDescriptionType getQueryDescriptionType() const
std::vector< int64_t > target_expr_group_by_indices(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby_exprs, const std::vector< Analyzer::Expr * > &target_exprs)
std::optional< size_t > varlenOutputBufferElemSize() const
void addColumn(const std::vector< std::tuple< int8_t, int8_t >> &slots_for_col)
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK_LE(x, y)
Definition: Logger.h:304
size_t getNextColOffInBytesRowOnly(const int8_t *col_ptr, const size_t col_idx) const
const Expr * get_operand() const
Definition: Analyzer.h:384
QueryDescriptionType query_desc_type_
int8_t padded_size
Definition: sqldefs.h:78
int8_t updateActualMinByteWidth(const int8_t actual_min_byte_width) const
size_t getTotalBytesOfColumnarBuffers(const size_t entry_count) const
bool operator==(const QueryMemoryDescriptor &other) const
Descriptor for the result set buffer layout.
bool is_int_and_no_bigger_than(const SQLTypeInfo &ti, const size_t byte_width)
std::list< std::shared_ptr< Analyzer::Expr > > quals
ExpressionRangeType getType() const
size_t get_heap_size(const size_t row_size, const size_t n, const size_t thread_count)
int64_t getIntMax() const
bool isWarpSyncRequired(const ExecutorDeviceType) const
std::string toString() const
size_t getSlotCount() const
void setAllSlotsPaddedSizeToLogicalSize()
bool interleavedBins(const ExecutorDeviceType) const
bool g_enable_watchdog false
Definition: Execute.cpp:79
#define CHECK(condition)
Definition: Logger.h:291
#define DEBUG_TIMER(name)
Definition: Logger.h:411
size_t getColCount() const
std::vector< int8_t > group_col_widths_
#define EMPTY_KEY_32
QueryDescriptionType
Definition: Types.h:29
bool g_cluster
void setPaddedSlotWidthBytes(const size_t slot_idx, const int8_t bytes)
std::vector< TargetInfo > target_exprs_to_infos(const std::vector< Analyzer::Expr * > &targets, const QueryMemoryDescriptor &query_mem_desc)
const std::vector< size_t > & getSlotsForCol(const size_t col_idx) const
std::string queryDescTypeToString() const
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)
std::list< std::shared_ptr< const InputColDescriptor > > input_col_descs
constexpr double n
Definition: Utm.h:38
void addColSlotInfo(const std::vector< std::tuple< int8_t, int8_t >> &slots_for_col)
const size_t offset
static bool countDescriptorsLogicallyEmpty(const CountDistinctDescriptors &count_distinct_descriptors)
void setAllUnsetSlotsPaddedSize(const int8_t padded_size)
int64_t getFlatBufferSize(const size_t slot_idx) const
const int8_t getSlotIndexForSingleSlotCol(const size_t col_idx) const
const int8_t getLogicalSlotWidthBytes(const size_t slot_idx) const
Definition: sqldefs.h:74
size_t getColOffInBytes(const size_t col_idx) const
size_t getColOffInBytesInNextBin(const size_t col_idx) const
std::unique_ptr< QueryExecutionContext > getQueryExecutionContext(const RelAlgExecutionUnit &, const Executor *executor, const ExecutorDeviceType device_type, const ExecutorDispatchMode dispatch_mode, const int device_id, const shared::TableKey &outer_table_key, const int64_t num_rows, const std::vector< std::vector< const int8_t * >> &col_buffers, const std::vector< std::vector< uint64_t >> &frag_offsets, std::shared_ptr< RowSetMemoryOwner >, const bool output_columnar, const bool sort_on_gpu, const size_t thread_idx, RenderInfo *) const
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)
int8_t pick_baseline_key_width(const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &query_infos, const Executor *executor)
std::string reductionKey() const
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals
void set_notnull(TargetInfo &target, const bool not_null)
int32_t getTargetIdxForKey() const
size_t getPrependedGroupColOffInBytes(const size_t group_idx) const