OmniSciDB  17c254d2f8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResultSet.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
25 #ifndef QUERYENGINE_RESULTSET_H
26 #define QUERYENGINE_RESULTSET_H
27 
28 #include "CardinalityEstimator.h"
29 #include "DataMgr/Chunk/Chunk.h"
31 #include "TargetValue.h"
32 
33 #include <atomic>
34 #include <functional>
35 #include <list>
36 
37 /*
38  * Stores the underlying buffer and the meta-data for a result set. The buffer
39  * format reflects the main requirements for result sets. Not all queries
40  * specify a GROUP BY clause, but since it's the most important and challenging
41  * case we'll focus on it. Note that the meta-data is stored separately from
42  * the buffer and it's not transferred to GPU.
43  *
44  * 1. It has to be efficient for reduction of partial GROUP BY query results
45  * from multiple devices / cores, the cardinalities can be high. Reduction
46  * currently happens on the host.
47  * 2. No conversions should be needed when buffers are transferred from GPU to
48  * host for reduction. This implies the buffer needs to be "flat", with no
49  * pointers to chase since they have no meaning in a different address space.
50  * 3. Must be size-efficient.
51  *
52  * There are several variations of the format of a result set buffer, but the
53  * most common is a sequence of entries which represent a row in the result or
54  * an empty slot. One entry looks as follows:
55  *
56  * +-+-+-+-+-+-+-+-+-+-+-+--?--+-+-+-+-+-+-+-+-+-+-+-+-+
57  * |key_0| ... |key_N-1| padding |value_0|...|value_N-1|
58  * +-+-+-+-+-+-+-+-+-+-+-+--?--+-+-+-+-+-+-+-+-+-+-+-+-+
59  *
60  * (key_0 ... key_N-1) is a multiple component key, unique within the buffer.
61  * It stores the tuple specified by the GROUP BY clause. All components have
62  * the same width, 4 or 8 bytes. For the 4-byte components, 4-byte padding is
63  * added if the number of components is odd. Not all entries in the buffer are
64  * valid; an empty entry contains EMPTY_KEY_{64, 32} for 8-byte / 4-byte width,
65  * respectively. An empty entry is ignored by subsequent operations on the
66  * result set (reduction, iteration, sort etc).
67  *
68  * value_0 through value_N-1 are 8-byte fields which hold the columns of the
69  * result, like aggregates and projected expressions. They're reduced between
70  * multiple partial results for identical (key_0 ... key_N-1) tuples.
71  *
72  * The order of entries is decided by the type of hash used, which depends on
73  * the range of the keys. For small enough ranges, a perfect hash is used. When
74  * a perfect hash isn't feasible, open addressing (using MurmurHash) with linear
75  * probing is used instead, with a 50% fill rate.
76  */
77 
78 struct ReductionCode;
79 
81  public:
82  ResultSetStorage(const std::vector<TargetInfo>& targets,
84  int8_t* buff,
85  const bool buff_is_provided);
86 
87  void reduce(const ResultSetStorage& that,
88  const std::vector<std::string>& serialized_varlen_buffer,
89  const ReductionCode& reduction_code) const;
90 
92  const std::vector<std::string>& serialized_varlen_buffer) const;
93 
94  int8_t* getUnderlyingBuffer() const;
95 
96  size_t getEntryCount() const { return query_mem_desc_.getEntryCount(); }
97 
98  template <class KeyType>
99  void moveEntriesToBuffer(int8_t* new_buff, const size_t new_entry_count) const;
100 
101  template <class KeyType>
102  void moveOneEntryToBuffer(const size_t entry_index,
103  int64_t* new_buff_i64,
104  const size_t new_entry_count,
105  const size_t key_count,
106  const size_t row_qw_count,
107  const int64_t* src_buff,
108  const size_t key_byte_width) const;
109 
110  void updateEntryCount(const size_t new_entry_count) {
111  query_mem_desc_.setEntryCount(new_entry_count);
112  }
113 
114  // Reduces results for a single row when using interleaved bin layouts
115  static bool reduceSingleRow(const int8_t* row_ptr,
116  const int8_t warp_count,
117  const bool is_columnar,
118  const bool replace_bitmap_ptr_with_bitmap_sz,
119  std::vector<int64_t>& agg_vals,
120  const QueryMemoryDescriptor& query_mem_desc,
121  const std::vector<TargetInfo>& targets,
122  const std::vector<int64_t>& agg_init_vals);
123 
124  private:
126  int8_t* this_buff,
127  const int8_t* that_buff,
128  const ResultSetStorage& that,
129  const size_t start_index,
130  const size_t end_index,
131  const std::vector<std::string>& serialized_varlen_buffer) const;
132 
133  void copyKeyColWise(const size_t entry_idx,
134  int8_t* this_buff,
135  const int8_t* that_buff) const;
136 
137  bool isEmptyEntry(const size_t entry_idx, const int8_t* buff) const;
138  bool isEmptyEntry(const size_t entry_idx) const;
139  bool isEmptyEntryColumnar(const size_t entry_idx, const int8_t* buff) const;
140 
141  void reduceOneEntryBaseline(int8_t* this_buff,
142  const int8_t* that_buff,
143  const size_t i,
144  const size_t that_entry_count,
145  const ResultSetStorage& that) const;
146 
147  void reduceOneEntrySlotsBaseline(int64_t* this_entry_slots,
148  const int64_t* that_buff,
149  const size_t that_entry_idx,
150  const size_t that_entry_count,
151  const ResultSetStorage& that) const;
152 
153  void initializeBaselineValueSlots(int64_t* this_entry_slots) const;
154 
155  void reduceOneSlotBaseline(int64_t* this_buff,
156  const size_t this_slot,
157  const int64_t* that_buff,
158  const size_t that_entry_count,
159  const size_t that_slot,
160  const TargetInfo& target_info,
161  const size_t target_logical_idx,
162  const size_t target_slot_idx,
163  const size_t init_agg_val_idx,
164  const ResultSetStorage& that) const;
165 
167  void reduceOneSlotSingleValue(int8_t* this_ptr1,
168  const TargetInfo& target_info,
169  const size_t target_slot_idx,
170  const size_t init_agg_val_idx,
171  const int8_t* that_ptr1) const;
172 
174  void reduceOneSlot(int8_t* this_ptr1,
175  int8_t* this_ptr2,
176  const int8_t* that_ptr1,
177  const int8_t* that_ptr2,
178  const TargetInfo& target_info,
179  const size_t target_logical_idx,
180  const size_t target_slot_idx,
181  const size_t init_agg_val_idx,
182  const ResultSetStorage& that,
183  const size_t first_slot_idx_for_target,
184  const std::vector<std::string>& serialized_varlen_buffer) const;
185 
186  void reduceOneCountDistinctSlot(int8_t* this_ptr1,
187  const int8_t* that_ptr1,
188  const size_t target_logical_idx,
189  const ResultSetStorage& that) const;
190 
191  void fillOneEntryRowWise(const std::vector<int64_t>& entry);
192 
193  void fillOneEntryColWise(const std::vector<int64_t>& entry);
194 
195  void initializeRowWise() const;
196 
197  void initializeColWise() const;
198 
199  // TODO(alex): remove the following two methods, see comment about
200  // count_distinct_sets_mapping_.
201  void addCountDistinctSetPointerMapping(const int64_t remote_ptr, const int64_t ptr);
202 
203  int64_t mappedPtr(const int64_t) const;
204 
205  size_t binSearchRowCount() const;
206 
207  const std::vector<TargetInfo> targets_;
209  int8_t* buff_;
210  const bool buff_is_provided_;
211  std::vector<int64_t> target_init_vals_;
212  // Provisional field used for multi-node until we improve the count distinct
213  // and flatten the main group by buffer and the distinct buffers in a single,
214  // contiguous buffer which we'll be able to serialize as a no-op. Used to
215  // re-route the pointers in the result set received over the wire to this
216  // machine address-space. Not efficient at all, just a placeholder!
217  std::unordered_map<int64_t, int64_t> count_distinct_sets_mapping_;
218 
219  friend class ResultSet;
220  friend class ResultSetManager;
221 };
222 
223 namespace Analyzer {
224 
225 class Expr;
226 class Estimator;
227 struct OrderEntry;
228 
229 } // namespace Analyzer
230 
231 class Executor;
232 
234  const bool is_lazily_fetched;
235  const int local_col_id;
237 };
238 
240  const int64_t value;
241  const bool valid;
242 };
243 
244 class ResultSet;
245 
247  public:
248  using value_type = std::vector<TargetValue>;
249  using difference_type = std::ptrdiff_t;
250  using pointer = std::vector<TargetValue>*;
251  using reference = std::vector<TargetValue>&;
252  using iterator_category = std::input_iterator_tag;
253 
254  bool operator==(const ResultSetRowIterator& other) const {
255  return result_set_ == other.result_set_ &&
257  }
258  bool operator!=(const ResultSetRowIterator& other) const { return !(*this == other); }
259 
260  inline value_type operator*() const;
261  inline ResultSetRowIterator& operator++(void);
263  ResultSetRowIterator iter(*this);
264  ++(*this);
265  return iter;
266  }
267 
268  size_t getCurrentRowBufferIndex() const {
269  if (crt_row_buff_idx_ == 0) {
270  throw std::runtime_error("current row buffer iteration index is undefined");
271  }
272  return crt_row_buff_idx_ - 1;
273  }
274 
275  private:
283 
285  bool translate_strings,
286  bool decimal_to_double)
287  : result_set_(rs)
288  , crt_row_buff_idx_(0)
289  , global_entry_idx_(0)
291  , fetched_so_far_(0)
292  , translate_strings_(translate_strings)
293  , decimal_to_double_(decimal_to_double){};
294 
296 
297  friend class ResultSet;
298 };
299 
300 class TSerializedRows;
301 
302 using AppendedStorage = std::vector<std::unique_ptr<ResultSetStorage>>;
303 
304 class ResultSet {
305  public:
306  ResultSet(const std::vector<TargetInfo>& targets,
307  const ExecutorDeviceType device_type,
309  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
310  const Executor* executor);
311 
312  ResultSet(const std::vector<TargetInfo>& targets,
313  const std::vector<ColumnLazyFetchInfo>& lazy_fetch_info,
314  const std::vector<std::vector<const int8_t*>>& col_buffers,
315  const std::vector<std::vector<int64_t>>& frag_offsets,
316  const std::vector<int64_t>& consistent_frag_sizes,
317  const ExecutorDeviceType device_type,
318  const int device_id,
319  const QueryMemoryDescriptor& query_mem_desc,
320  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
321  const Executor* executor);
322 
323  ResultSet(const std::shared_ptr<const Analyzer::Estimator>,
324  const ExecutorDeviceType device_type,
325  const int device_id,
326  Data_Namespace::DataMgr* data_mgr);
327 
328  ResultSet(const std::string& explanation);
329 
330  ResultSet(int64_t queue_time_ms,
331  int64_t render_time_ms,
332  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner);
333 
334  ~ResultSet();
335 
336  inline ResultSetRowIterator rowIterator(size_t from_logical_index,
337  bool translate_strings,
338  bool decimal_to_double) const {
339  ResultSetRowIterator rowIterator(this, translate_strings, decimal_to_double);
340 
341  // move to first logical position
342  ++rowIterator;
343 
344  for (size_t index = 0; index < from_logical_index; index++) {
345  ++rowIterator;
346  }
347 
348  return rowIterator;
349  }
350 
351  inline ResultSetRowIterator rowIterator(bool translate_strings,
352  bool decimal_to_double) const {
353  return rowIterator(0, translate_strings, decimal_to_double);
354  }
355 
357 
358  const ResultSetStorage* allocateStorage() const;
359 
360  const ResultSetStorage* allocateStorage(int8_t*, const std::vector<int64_t>&) const;
361 
362  const ResultSetStorage* allocateStorage(const std::vector<int64_t>&) const;
363 
364  void updateStorageEntryCount(const size_t new_entry_count) {
366  query_mem_desc_.setEntryCount(new_entry_count);
367  CHECK(storage_);
368  storage_->updateEntryCount(new_entry_count);
369  }
370 
371  std::vector<TargetValue> getNextRow(const bool translate_strings,
372  const bool decimal_to_double) const;
373 
374  size_t getCurrentRowBufferIndex() const;
375 
376  std::vector<TargetValue> getRowAt(const size_t index) const;
377 
378  TargetValue getRowAt(const size_t row_idx,
379  const size_t col_idx,
380  const bool translate_strings,
381  const bool decimal_to_double = true) const;
382 
383  // Specialized random access getter for result sets with a single column to
384  // avoid the overhead of building a std::vector<TargetValue> result with only
385  // one element. Only used by RelAlgTranslator::getInIntegerSetExpr currently.
386  OneIntegerColumnRow getOneColRow(const size_t index) const;
387 
388  std::vector<TargetValue> getRowAtNoTranslations(
389  const size_t index,
390  const std::vector<bool>& targets_to_skip = {}) const;
391 
392  bool isRowAtEmpty(const size_t index) const;
393 
394  void sort(const std::list<Analyzer::OrderEntry>& order_entries, const size_t top_n);
395 
396  void keepFirstN(const size_t n);
397 
398  void dropFirstN(const size_t n);
399 
400  void append(ResultSet& that);
401 
402  const ResultSetStorage* getStorage() const;
403 
404  size_t colCount() const;
405 
406  SQLTypeInfo getColType(const size_t col_idx) const;
407 
408  size_t rowCount(const bool force_parallel = false) const;
409 
410  void setCachedRowCount(const size_t row_count) const;
411 
412  size_t entryCount() const;
413 
414  size_t getBufferSizeBytes(const ExecutorDeviceType device_type) const;
415 
416  bool definitelyHasNoRows() const;
417 
418  const QueryMemoryDescriptor& getQueryMemDesc() const;
419 
420  const std::vector<TargetInfo>& getTargetInfos() const;
421 
422  const std::vector<int64_t>& getTargetInitVals() const;
423 
424  int8_t* getDeviceEstimatorBuffer() const;
425 
426  int8_t* getHostEstimatorBuffer() const;
427 
428  void syncEstimatorBuffer() const;
429 
430  size_t getNDVEstimator() const;
431 
432  void setQueueTime(const int64_t queue_time);
433 
434  int64_t getQueueTime() const;
435 
436  int64_t getRenderTime() const;
437 
438  void moveToBegin() const;
439 
440  bool isTruncated() const;
441 
442  bool isExplain() const;
443 
444  bool isGeoColOnGpu(const size_t col_idx) const;
445  int getDeviceId() const;
446 
447  // Called from the executor because in the new ResultSet we assume the 'padded' field
448  // in SlotSize already contains the padding, whereas in the executor it's computed.
449  // Once the buffer initialization moves to ResultSet we can remove this method.
451 
452  void fillOneEntry(const std::vector<int64_t>& entry) {
453  CHECK(storage_);
454  if (storage_->query_mem_desc_.didOutputColumnar()) {
455  storage_->fillOneEntryColWise(entry);
456  } else {
457  storage_->fillOneEntryRowWise(entry);
458  }
459  }
460 
461  void initializeStorage() const;
462 
463  void holdChunks(const std::list<std::shared_ptr<Chunk_NS::Chunk>>& chunks) {
464  chunks_ = chunks;
465  }
466  void holdChunkIterators(const std::shared_ptr<std::list<ChunkIter>> chunk_iters) {
467  chunk_iters_.push_back(chunk_iters);
468  }
469  void holdLiterals(std::vector<int8_t>& literal_buff) {
470  literal_buffers_.push_back(std::move(literal_buff));
471  }
472 
473  std::shared_ptr<RowSetMemoryOwner> getRowSetMemOwner() const {
474  return row_set_mem_owner_;
475  }
476 
477  const std::vector<uint32_t>& getPermutationBuffer() const;
478  const bool isPermutationBufferEmpty() const { return permutation_.empty(); };
479 
480  void serialize(TSerializedRows& serialized_rows) const;
481 
482  static std::unique_ptr<ResultSet> unserialize(const TSerializedRows& serialized_rows,
483  const Executor*);
484 
485  size_t getLimit() const;
486 
490  enum class GeoReturnType {
493  WktString,
498  };
501 
502  void copyColumnIntoBuffer(const size_t column_idx,
503  int8_t* output_buffer,
504  const size_t output_buffer_size) const;
505 
507 
508  bool didOutputColumnar() const { return this->query_mem_desc_.didOutputColumnar(); }
509 
510  bool isZeroCopyColumnarConversionPossible(size_t column_idx) const;
511  const int8_t* getColumnarBuffer(size_t column_idx) const;
512 
515  }
516 
517  const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const {
518  return query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
519  }
520 
521  // returns a bitmap of all single-slot targets, as well as its count
522  std::tuple<std::vector<bool>, size_t> getSingleSlotTargetBitmap() const;
523 
524  std::tuple<std::vector<bool>, size_t> getSupportedSingleSlotTargetBitmap() const;
525 
526  std::vector<size_t> getSlotIndicesForTargetIndices() const;
527 
528  const std::vector<ColumnLazyFetchInfo>& getLazyFetchInfo() const {
529  return lazy_fetch_info_;
530  }
531 
532  void setSeparateVarlenStorageValid(const bool val) {
534  }
535 
536  std::shared_ptr<const std::vector<std::string>> getStringDictionaryPayloadCopy(
537  const int dict_id) const;
538 
539  template <typename ENTRY_TYPE, QueryDescriptionType QUERY_TYPE, bool COLUMNAR_FORMAT>
540  ENTRY_TYPE getEntryAt(const size_t row_idx,
541  const size_t target_idx,
542  const size_t slot_idx) const;
543 
544  private:
546 
547  std::vector<TargetValue> getNextRowImpl(const bool translate_strings,
548  const bool decimal_to_double) const;
549 
550  std::vector<TargetValue> getNextRowUnlocked(const bool translate_strings,
551  const bool decimal_to_double) const;
552 
553  std::vector<TargetValue> getRowAt(const size_t index,
554  const bool translate_strings,
555  const bool decimal_to_double,
556  const bool fixup_count_distinct_pointers,
557  const std::vector<bool>& targets_to_skip = {}) const;
558 
559  // NOTE: just for direct columnarization use at the moment
560  template <typename ENTRY_TYPE>
561  ENTRY_TYPE getColumnarPerfectHashEntryAt(const size_t row_idx,
562  const size_t target_idx,
563  const size_t slot_idx) const;
564 
565  template <typename ENTRY_TYPE>
566  ENTRY_TYPE getRowWisePerfectHashEntryAt(const size_t row_idx,
567  const size_t target_idx,
568  const size_t slot_idx) const;
569 
570  template <typename ENTRY_TYPE>
571  ENTRY_TYPE getRowWiseBaselineEntryAt(const size_t row_idx,
572  const size_t target_idx,
573  const size_t slot_idx) const;
574 
575  template <typename ENTRY_TYPE>
576  ENTRY_TYPE getColumnarBaselineEntryAt(const size_t row_idx,
577  const size_t target_idx,
578  const size_t slot_idx) const;
579 
580  size_t binSearchRowCount() const;
581 
582  size_t parallelRowCount() const;
583 
584  size_t advanceCursorToNextEntry() const;
585 
586  void radixSortOnGpu(const std::list<Analyzer::OrderEntry>& order_entries) const;
587 
588  void radixSortOnCpu(const std::list<Analyzer::OrderEntry>& order_entries) const;
589 
590  static bool isNull(const SQLTypeInfo& ti,
591  const InternalTargetValue& val,
592  const bool float_argument_input);
593 
595  int8_t* rowwise_target_ptr,
596  int8_t* keys_ptr,
597  const size_t entry_buff_idx,
598  const TargetInfo& target_info,
599  const size_t target_logical_idx,
600  const size_t slot_idx,
601  const bool translate_strings,
602  const bool decimal_to_double,
603  const bool fixup_count_distinct_pointers) const;
604 
605  TargetValue getTargetValueFromBufferColwise(const int8_t* col_ptr,
606  const int8_t* keys_ptr,
607  const QueryMemoryDescriptor& query_mem_desc,
608  const size_t local_entry_idx,
609  const size_t global_entry_idx,
610  const TargetInfo& target_info,
611  const size_t target_logical_idx,
612  const size_t slot_idx,
613  const bool translate_strings,
614  const bool decimal_to_double) const;
615 
616  TargetValue makeTargetValue(const int8_t* ptr,
617  const int8_t compact_sz,
618  const TargetInfo& target_info,
619  const size_t target_logical_idx,
620  const bool translate_strings,
621  const bool decimal_to_double,
622  const size_t entry_buff_idx) const;
623 
624  TargetValue makeVarlenTargetValue(const int8_t* ptr1,
625  const int8_t compact_sz1,
626  const int8_t* ptr2,
627  const int8_t compact_sz2,
628  const TargetInfo& target_info,
629  const size_t target_logical_idx,
630  const bool translate_strings,
631  const size_t entry_buff_idx) const;
632 
634  int8_t* ptr1;
635  int8_t compact_sz1;
636  int8_t* ptr2;
637  int8_t compact_sz2;
638 
641  };
642  TargetValue makeGeoTargetValue(const int8_t* geo_target_ptr,
643  const size_t slot_idx,
644  const TargetInfo& target_info,
645  const size_t target_logical_idx,
646  const size_t entry_buff_idx) const;
647 
650  const size_t fixedup_entry_idx;
651  const size_t storage_idx;
652  };
653 
655  const int8_t* buff,
656  const size_t entry_idx,
657  const size_t target_logical_idx,
658  const StorageLookupResult& storage_lookup_result) const;
659 
660  InternalTargetValue getVarlenOrderEntry(const int64_t str_ptr,
661  const size_t str_len) const;
662 
663  int64_t lazyReadInt(const int64_t ival,
664  const size_t target_logical_idx,
665  const StorageLookupResult& storage_lookup_result) const;
666 
670  std::pair<size_t, size_t> getStorageIndex(const size_t entry_idx) const;
671 
672  const std::vector<const int8_t*>& getColumnFrag(const size_t storge_idx,
673  const size_t col_logical_idx,
674  int64_t& global_idx) const;
675 
676  StorageLookupResult findStorage(const size_t entry_idx) const;
677 
678  struct TargetOffsets {
679  const int8_t* ptr1;
680  const size_t compact_sz1;
681  const int8_t* ptr2;
682  const size_t compact_sz2;
683  };
684 
686  RowWiseTargetAccessor(const ResultSet* result_set)
687  : result_set_(result_set)
689  , key_width_(result_set_->query_mem_desc_.getEffectiveKeyWidth())
693  }
694 
696  const int8_t* buff,
697  const size_t entry_idx,
698  const size_t target_logical_idx,
699  const StorageLookupResult& storage_lookup_result) const;
700 
702 
703  inline const int8_t* get_rowwise_ptr(const int8_t* buff,
704  const size_t entry_idx) const {
705  return buff + entry_idx * row_bytes_;
706  }
707 
708  std::vector<std::vector<TargetOffsets>> offsets_for_storage_;
709 
711 
712  // Row-wise iteration
713  const size_t row_bytes_;
714  const size_t key_width_;
716  };
717 
719  ColumnWiseTargetAccessor(const ResultSet* result_set) : result_set_(result_set) {
721  }
722 
724 
726  const int8_t* buff,
727  const size_t entry_idx,
728  const size_t target_logical_idx,
729  const StorageLookupResult& storage_lookup_result) const;
730 
731  std::vector<std::vector<TargetOffsets>> offsets_for_storage_;
732 
734  };
735 
736  template <typename BUFFER_ITERATOR_TYPE>
738  using BufferIteratorType = BUFFER_ITERATOR_TYPE;
739 
740  ResultSetComparator(const std::list<Analyzer::OrderEntry>& order_entries,
741  const bool use_heap,
742  const ResultSet* result_set)
743  : order_entries_(order_entries)
744  , use_heap_(use_heap)
745  , result_set_(result_set)
746  , buffer_itr_(result_set) {}
747 
748  bool operator()(const uint32_t lhs, const uint32_t rhs) const;
749 
750  // TODO(adb): make order_entries_ a pointer
751  const std::list<Analyzer::OrderEntry> order_entries_;
752  const bool use_heap_;
755  };
756 
757  std::function<bool(const uint32_t, const uint32_t)> createComparator(
758  const std::list<Analyzer::OrderEntry>& order_entries,
759  const bool use_heap) {
762  std::make_unique<ResultSetComparator<ColumnWiseTargetAccessor>>(
763  order_entries, use_heap, this);
764  return [this](const uint32_t lhs, const uint32_t rhs) -> bool {
765  return (*this->column_wise_comparator_)(lhs, rhs);
766  };
767  } else {
768  row_wise_comparator_ = std::make_unique<ResultSetComparator<RowWiseTargetAccessor>>(
769  order_entries, use_heap, this);
770  return [this](const uint32_t lhs, const uint32_t rhs) -> bool {
771  return (*this->row_wise_comparator_)(lhs, rhs);
772  };
773  }
774  }
775 
776  static void topPermutation(
777  std::vector<uint32_t>& to_sort,
778  const size_t n,
779  const std::function<bool(const uint32_t, const uint32_t)> compare);
780 
781  void sortPermutation(const std::function<bool(const uint32_t, const uint32_t)> compare);
782 
783  std::vector<uint32_t> initPermutationBuffer(const size_t start, const size_t step);
784 
785  void parallelTop(const std::list<Analyzer::OrderEntry>& order_entries,
786  const size_t top_n);
787 
788  void baselineSort(const std::list<Analyzer::OrderEntry>& order_entries,
789  const size_t top_n);
790 
791  void doBaselineSort(const ExecutorDeviceType device_type,
792  const std::list<Analyzer::OrderEntry>& order_entries,
793  const size_t top_n);
794 
795  bool canUseFastBaselineSort(const std::list<Analyzer::OrderEntry>& order_entries,
796  const size_t top_n);
797 
799 
800  int getGpuCount() const;
801 
802  void serializeProjection(TSerializedRows& serialized_rows) const;
803  void serializeVarlenAggColumn(int8_t* buf,
804  std::vector<std::string>& varlen_bufer) const;
805 
806  void serializeCountDistinctColumns(TSerializedRows&) const;
807 
808  void unserializeCountDistinctColumns(const TSerializedRows&);
809 
811 
812  using BufferSet = std::set<int64_t>;
813  void create_active_buffer_set(BufferSet& count_distinct_active_buffer_set) const;
814 
815  int64_t getDistinctBufferRefFromBufferRowwise(int8_t* rowwise_target_ptr,
816  const TargetInfo& target_info) const;
817 
818  const std::vector<TargetInfo> targets_;
820  const int device_id_;
822  mutable std::unique_ptr<ResultSetStorage> storage_;
824  mutable size_t crt_row_buff_idx_;
825  mutable size_t fetched_so_far_;
826  size_t drop_first_;
827  size_t keep_first_;
828  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner_;
829  std::vector<uint32_t> permutation_;
830  int64_t queue_time_ms_;
832  const Executor* executor_; // TODO(alex): remove
833 
834  std::list<std::shared_ptr<Chunk_NS::Chunk>> chunks_;
835  std::vector<std::shared_ptr<std::list<ChunkIter>>> chunk_iters_;
836  // TODO(miyu): refine by using one buffer and
837  // setting offset instead of ptr in group by buffer.
838  std::vector<std::vector<int8_t>> literal_buffers_;
839  const std::vector<ColumnLazyFetchInfo> lazy_fetch_info_;
840  std::vector<std::vector<std::vector<const int8_t*>>> col_buffers_;
841  std::vector<std::vector<std::vector<int64_t>>> frag_offsets_;
842  std::vector<std::vector<int64_t>> consistent_frag_sizes_;
843 
844  const std::shared_ptr<const Analyzer::Estimator> estimator_;
846  mutable int8_t* host_estimator_buffer_;
848 
849  // only used by serialization
850  using SerializedVarlenBufferStorage = std::vector<std::string>;
851 
852  std::vector<SerializedVarlenBufferStorage> serialized_varlen_buffer_;
854  std::string explanation_;
855  const bool just_explain_;
856  mutable std::atomic<ssize_t> cached_row_count_;
857  mutable std::mutex row_iteration_mutex_;
858 
859  // only used by geo
861 
862  // comparators used for sorting (note that the actual compare function is accessed using
863  // the createComparator method)
864  std::unique_ptr<ResultSetComparator<RowWiseTargetAccessor>> row_wise_comparator_;
865  std::unique_ptr<ResultSetComparator<ColumnWiseTargetAccessor>> column_wise_comparator_;
866 
867  friend class ResultSetManager;
868  friend class ResultSetRowIterator;
869  friend class ColumnarResults;
870 };
871 
874  return {};
875  }
876 
877  if (result_set_->just_explain_) {
878  return {result_set_->explanation_};
879  }
880 
881  return result_set_->getRowAt(
883 }
884 
886  if (!result_set_->storage_ && !result_set_->just_explain_) {
887  global_entry_idx_valid_ = false;
888  } else if (result_set_->just_explain_) {
890  fetched_so_far_ = 1;
891  } else {
892  result_set_->advanceCursorToNextEntry(*this);
893  }
894  return *this;
895 }
896 
898  public:
899  ResultSet* reduce(std::vector<ResultSet*>&);
900 
901  std::shared_ptr<ResultSet> getOwnResultSet();
902 
903  void rewriteVarlenAggregates(ResultSet*);
904 
905  private:
906  std::shared_ptr<ResultSet> rs_;
907 };
908 
909 class RowSortException : public std::runtime_error {
910  public:
911  RowSortException(const std::string& cause) : std::runtime_error(cause) {}
912 };
913 
914 int64_t lazy_decode(const ColumnLazyFetchInfo& col_lazy_fetch,
915  const int8_t* byte_stream,
916  const int64_t pos);
917 
918 void fill_empty_key(void* key_ptr, const size_t key_count, const size_t key_width);
919 
920 bool can_use_parallel_algorithms(const ResultSet& rows);
921 
922 bool use_parallel_algorithms(const ResultSet& rows);
923 
924 int8_t get_width_for_slot(const size_t target_slot_idx,
925  const bool float_argument_input,
926  const QueryMemoryDescriptor& query_mem_desc);
927 
928 size_t get_byteoff_of_slot(const size_t slot_idx,
929  const QueryMemoryDescriptor& query_mem_desc);
930 
931 using GroupValueInfo = std::pair<int64_t*, bool>;
932 
934  const uint32_t groups_buffer_entry_count,
935  const int64_t* key,
936  const uint32_t key_count,
937  const size_t key_width,
938  const QueryMemoryDescriptor& query_mem_desc,
939  const int64_t* that_buff_i64,
940  const size_t that_entry_idx,
941  const size_t that_entry_count,
942  const uint32_t row_size_quad);
943 
944 std::vector<int64_t> initialize_target_values_for_storage(
945  const std::vector<TargetInfo>& targets);
946 #endif // QUERYENGINE_RESULTSET_H
std::pair< int64_t *, bool > GroupValueInfo
Definition: ResultSet.h:931
void setSeparateVarlenStorageValid(const bool val)
Definition: ResultSet.h:532
const std::list< Analyzer::OrderEntry > order_entries_
Definition: ResultSet.h:751
void setGeoReturnType(const GeoReturnType val)
Definition: ResultSet.h:500
const SQLTypeInfo type
Definition: ResultSet.h:236
void serializeVarlenAggColumn(int8_t *buf, std::vector< std::string > &varlen_bufer) const
std::mutex row_iteration_mutex_
Definition: ResultSet.h:857
InternalTargetValue getColumnInternal(const int8_t *buff, const size_t entry_idx, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
void syncEstimatorBuffer() const
Definition: ResultSet.cpp:450
const int8_t * ptr1
Definition: ResultSet.h:679
const size_t compact_sz2
Definition: ResultSet.h:682
void baselineSort(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
int64_t lazy_decode(const ColumnLazyFetchInfo &col_lazy_fetch, const int8_t *byte_stream, const int64_t pos)
void holdChunks(const std::list< std::shared_ptr< Chunk_NS::Chunk >> &chunks)
Definition: ResultSet.h:463
const QueryMemoryDescriptor & getQueryMemDesc() const
Definition: ResultSet.cpp:427
std::unique_ptr< ResultSetComparator< ColumnWiseTargetAccessor > > column_wise_comparator_
Definition: ResultSet.h:865
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:635
const int32_t groups_buffer_size return groups_buffer
std::shared_ptr< RowSetMemoryOwner > getRowSetMemOwner() const
Definition: ResultSet.h:473
std::vector< int64_t > initialize_target_values_for_storage(const std::vector< TargetInfo > &targets)
Definition: ResultSet.cpp:47
bool didOutputColumnar() const
Definition: ResultSet.h:508
void moveOneEntryToBuffer(const size_t entry_index, int64_t *new_buff_i64, const size_t new_entry_count, const size_t key_count, const size_t row_qw_count, const int64_t *src_buff, const size_t key_byte_width) const
bool isEmptyEntry(const size_t entry_idx, const int8_t *buff) const
bool use_parallel_algorithms(const ResultSet &rows)
Definition: ResultSet.cpp:912
std::ptrdiff_t difference_type
Definition: ResultSet.h:249
int8_t * estimator_buffer_
Definition: ResultSet.h:845
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:207
ENTRY_TYPE getRowWisePerfectHashEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
ALWAYS_INLINE void reduceOneSlot(int8_t *this_ptr1, int8_t *this_ptr2, const int8_t *that_ptr1, const int8_t *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const ResultSetStorage &that, const size_t first_slot_idx_for_target, const std::vector< std::string > &serialized_varlen_buffer) const
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
void setEntryCount(const size_t val)
void reduceEntriesNoCollisionsColWise(int8_t *this_buff, const int8_t *that_buff, const ResultSetStorage &that, const size_t start_index, const size_t end_index, const std::vector< std::string > &serialized_varlen_buffer) const
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:211
AppendedStorage appended_storage_
Definition: ResultSet.h:823
void initializeColWise() const
void reduceOneEntryBaseline(int8_t *this_buff, const int8_t *that_buff, const size_t i, const size_t that_entry_count, const ResultSetStorage &that) const
ENTRY_TYPE getColumnarPerfectHashEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
GeoReturnType geo_return_type_
Definition: ResultSet.h:860
bool isEmptyEntryColumnar(const size_t entry_idx, const int8_t *buff) const
ExecutorDeviceType
const BufferIteratorType buffer_itr_
Definition: ResultSet.h:754
void fill_empty_key(void *key_ptr, const size_t key_count, const size_t key_width)
void moveToBegin() const
Definition: ResultSet.cpp:475
Utility functions for easy access to the result set buffers.
std::shared_ptr< ResultSet > rs_
Definition: ResultSet.h:906
std::vector< std::string > SerializedVarlenBufferStorage
Definition: ResultSet.h:850
void initializeStorage() const
QueryDescriptionType getQueryDescriptionType() const
Definition: ResultSet.h:513
ResultSetRowIterator(const ResultSet *rs, bool translate_strings, bool decimal_to_double)
Definition: ResultSet.h:284
const Executor * executor_
Definition: ResultSet.h:832
size_t get_byteoff_of_slot(const size_t slot_idx, const QueryMemoryDescriptor &query_mem_desc)
void unserializeCountDistinctColumns(const TSerializedRows &)
std::vector< TargetValue > getNextRow(const bool translate_strings, const bool decimal_to_double) const
static bool isNull(const SQLTypeInfo &ti, const InternalTargetValue &val, const bool float_argument_input)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:821
const std::vector< TargetInfo > & getTargetInfos() const
Definition: ResultSet.cpp:432
void addCountDistinctSetPointerMapping(const int64_t remote_ptr, const int64_t ptr)
Definition: ResultSet.cpp:880
ResultSetStorage(const std::vector< TargetInfo > &targets, const QueryMemoryDescriptor &query_mem_desc, int8_t *buff, const bool buff_is_provided)
Definition: ResultSet.cpp:76
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:822
bool operator==(const ResultSetRowIterator &other) const
Definition: ResultSet.h:254
void initializeRowWise() const
void initializeBaselineValueSlots(int64_t *this_entry_slots) const
ENTRY_TYPE getEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
size_t rowCount(const bool force_parallel=false) const
Definition: ResultSet.cpp:325
ResultSetRowIterator(const ResultSet *rs)
Definition: ResultSet.h:295
TargetValue makeGeoTargetValue(const int8_t *geo_target_ptr, const size_t slot_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t entry_buff_idx) const
TargetValue getTargetValueFromBufferRowwise(int8_t *rowwise_target_ptr, int8_t *keys_ptr, const size_t entry_buff_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t slot_idx, const bool translate_strings, const bool decimal_to_double, const bool fixup_count_distinct_pointers) const
size_t keep_first_
Definition: ResultSet.h:827
void keepFirstN(const size_t n)
Definition: ResultSet.cpp:90
std::vector< std::shared_ptr< std::list< ChunkIter > > > chunk_iters_
Definition: ResultSet.h:835
void reduceOneSlotBaseline(int64_t *this_buff, const size_t this_slot, const int64_t *that_buff, const size_t that_entry_count, const size_t that_slot, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const ResultSetStorage &that) const
const int64_t const uint32_t groups_buffer_entry_count
void serialize(TSerializedRows &serialized_rows) const
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:852
const size_t compact_sz1
Definition: ResultSet.h:680
int64_t lazyReadInt(const int64_t ival, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
bool operator!=(const ResultSetRowIterator &other) const
Definition: ResultSet.h:258
size_t colCount() const
Definition: ResultSet.cpp:312
OneIntegerColumnRow getOneColRow(const size_t index) const
TargetValue getTargetValueFromBufferColwise(const int8_t *col_ptr, const int8_t *keys_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t local_entry_idx, const size_t global_entry_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t slot_idx, const bool translate_strings, const bool decimal_to_double) const
int8_t get_width_for_slot(const size_t target_slot_idx, const bool float_argument_input, const QueryMemoryDescriptor &query_mem_desc)
friend class ResultSet
Definition: ResultSet.h:219
void rewriteVarlenAggregates(ResultSet *)
size_t getLimit() const
Definition: ResultSet.cpp:896
const bool just_explain_
Definition: ResultSet.h:855
ResultSetRowIterator rowIterator(size_t from_logical_index, bool translate_strings, bool decimal_to_double) const
Definition: ResultSet.h:336
bool isTruncated() const
Definition: ResultSet.cpp:480
std::vector< uint32_t > permutation_
Definition: ResultSet.h:829
std::unordered_map< int64_t, int64_t > count_distinct_sets_mapping_
Definition: ResultSet.h:217
const int local_col_id
Definition: ResultSet.h:235
const bool isPermutationBufferEmpty() const
Definition: ResultSet.h:478
void reduce(const ResultSetStorage &that, const std::vector< std::string > &serialized_varlen_buffer, const ReductionCode &reduction_code) const
int8_t * getUnderlyingBuffer() const
Definition: ResultSet.cpp:86
ResultSet(const std::vector< TargetInfo > &targets, const ExecutorDeviceType device_type, const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const Executor *executor)
Definition: ResultSet.cpp:100
size_t parallelRowCount() const
Definition: ResultSet.cpp:385
const size_t key_bytes_with_padding_
Definition: ResultSet.h:715
const ResultSet * result_set_
Definition: ResultSet.h:710
std::vector< uint32_t > initPermutationBuffer(const size_t start, const size_t step)
Definition: ResultSet.cpp:574
std::vector< TargetValue > getRowAtNoTranslations(const size_t index, const std::vector< bool > &targets_to_skip={}) const
WindowFunctionContext *WindowProjectNodeContext::s_active_window_function_ nullptr
const ResultSet * result_set_
Definition: ResultSet.h:276
void radixSortOnCpu(const std::list< Analyzer::OrderEntry > &order_entries) const
Definition: ResultSet.cpp:841
InternalTargetValue getColumnInternal(const int8_t *buff, const size_t entry_idx, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
std::unique_ptr< ResultSetComparator< RowWiseTargetAccessor > > row_wise_comparator_
Definition: ResultSet.h:864
bool definitelyHasNoRows() const
Definition: ResultSet.cpp:423
ColumnWiseTargetAccessor(const ResultSet *result_set)
Definition: ResultSet.h:719
Executor(const int db_id, const size_t block_size_x, const size_t grid_size_x, const std::string &debug_dir, const std::string &debug_file)
Definition: Execute.cpp:122
bool isZeroCopyColumnarConversionPossible(size_t column_idx) const
Definition: ResultSet.cpp:941
std::input_iterator_tag iterator_category
Definition: ResultSet.h:252
size_t global_entry_idx_
Definition: ResultSet.h:278
int8_t * getHostEstimatorBuffer() const
Definition: ResultSet.cpp:446
const bool buff_is_provided_
Definition: ResultSet.h:210
InternalTargetValue getVarlenOrderEntry(const int64_t str_ptr, const size_t str_len) const
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:818
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:828
void reduceOneEntrySlotsBaseline(int64_t *this_entry_slots, const int64_t *that_buff, const size_t that_entry_idx, const size_t that_entry_count, const ResultSetStorage &that) const
size_t drop_first_
Definition: ResultSet.h:826
const ResultSetStorage * allocateStorage() const
std::shared_ptr< const std::vector< std::string > > getStringDictionaryPayloadCopy(const int dict_id) const
Definition: ResultSet.cpp:900
CHECK(cgen_state)
void copyKeyColWise(const size_t entry_idx, int8_t *this_buff, const int8_t *that_buff) const
const int8_t * ptr2
Definition: ResultSet.h:681
std::list< std::shared_ptr< Chunk_NS::Chunk > > chunks_
Definition: ResultSet.h:834
void reduceOneCountDistinctSlot(int8_t *this_ptr1, const int8_t *that_ptr1, const size_t target_logical_idx, const ResultSetStorage &that) const
const ResultSet * result_set_
Definition: ResultSet.h:753
void moveEntriesToBuffer(int8_t *new_buff, const size_t new_entry_count) const
void setQueueTime(const int64_t queue_time)
Definition: ResultSet.cpp:463
void dropFirstN(const size_t n)
Definition: ResultSet.cpp:95
std::vector< std::vector< int8_t > > literal_buffers_
Definition: ResultSet.h:838
std::vector< std::vector< TargetOffsets > > offsets_for_storage_
Definition: ResultSet.h:731
void doBaselineSort(const ExecutorDeviceType device_type, const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
GroupValueInfo get_group_value_reduction(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const size_t key_width, const QueryMemoryDescriptor &query_mem_desc, const int64_t *that_buff_i64, const size_t that_entry_idx, const size_t that_entry_count, const uint32_t row_size_quad)
bool canUseFastBaselineSort(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
void updateEntryCount(const size_t new_entry_count)
Definition: ResultSet.h:110
size_t binSearchRowCount() const
std::vector< TargetValue > & reference
Definition: ResultSet.h:251
ResultSet * reduce(std::vector< ResultSet * > &)
std::tuple< std::vector< bool >, size_t > getSingleSlotTargetBitmap() const
Definition: ResultSet.cpp:954
ResultSetRowIterator & operator++(void)
Definition: ResultSet.h:885
std::shared_ptr< ResultSet > getOwnResultSet()
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:657
void fillOneEntryColWise(const std::vector< int64_t > &entry)
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:856
static void topPermutation(std::vector< uint32_t > &to_sort, const size_t n, const std::function< bool(const uint32_t, const uint32_t)> compare)
Definition: ResultSet.cpp:787
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
value_type operator*() const
Definition: ResultSet.h:872
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:839
RowWiseTargetAccessor(const ResultSet *result_set)
Definition: ResultSet.h:686
void copyColumnIntoBuffer(const size_t column_idx, int8_t *output_buffer, const size_t output_buffer_size) const
RowSortException(const std::string &cause)
Definition: ResultSet.h:911
size_t getEntryCount() const
Definition: ResultSet.h:96
void fixupCountDistinctPointers()
void radixSortOnGpu(const std::list< Analyzer::OrderEntry > &order_entries) const
Definition: ResultSet.cpp:807
const ResultSetStorage * getStorage() const
Definition: ResultSet.cpp:308
QueryDescriptionType getQueryDescriptionType() const
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:847
int64_t getQueueTime() const
Definition: ResultSet.cpp:467
std::vector< TargetValue > getRowAt(const size_t index) const
void fillOneEntry(const std::vector< int64_t > &entry)
Definition: ResultSet.h:452
const int64_t value
Definition: ResultSet.h:240
void updateStorageEntryCount(const size_t new_entry_count)
Definition: ResultSet.h:364
void serializeProjection(TSerializedRows &serialized_rows) const
ResultSetRowIterator operator++(int)
Definition: ResultSet.h:262
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:844
SQLTypeInfo getColType(const size_t col_idx) const
Definition: ResultSet.cpp:316
GeoReturnType getGeoReturnType() const
Definition: ResultSet.h:499
void holdChunkIterators(const std::shared_ptr< std::list< ChunkIter >> chunk_iters)
Definition: ResultSet.h:466
std::tuple< std::vector< bool >, size_t > getSupportedSingleSlotTargetBitmap() const
Definition: ResultSet.cpp:978
ExecutorDeviceType getDeviceType() const
Definition: ResultSet.cpp:234
const int8_t * getColumnarBuffer(size_t column_idx) const
Definition: ResultSet.cpp:948
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)
bool isExplain() const
Definition: ResultSet.cpp:484
int8_t * buff_
Definition: ResultSet.h:209
ResultSetComparator(const std::list< Analyzer::OrderEntry > &order_entries, const bool use_heap, const ResultSet *result_set)
Definition: ResultSet.h:740
std::vector< TargetValue > value_type
Definition: ResultSet.h:248
void sortPermutation(const std::function< bool(const uint32_t, const uint32_t)> compare)
Definition: ResultSet.cpp:802
bool isGeoColOnGpu(const size_t col_idx) const
ALWAYS_INLINE void reduceOneSlotSingleValue(int8_t *this_ptr1, const TargetInfo &target_info, const size_t target_slot_idx, const size_t init_agg_val_idx, const int8_t *that_ptr1) const
int64_t mappedPtr(const int64_t) const
Definition: ResultSet.cpp:886
const int8_t * get_rowwise_ptr(const int8_t *buff, const size_t entry_idx) const
Definition: ResultSet.h:703
size_t getNDVEstimator() const
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:840
bool isRowAtEmpty(const size_t index) const
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
Definition: ResultSet.h:517
size_t entryCount() const
const bool valid
Definition: ResultSet.h:241
static QueryMemoryDescriptor fixupQueryMemoryDescriptor(const QueryMemoryDescriptor &)
Definition: ResultSet.cpp:492
int64_t queue_time_ms_
Definition: ResultSet.h:830
TargetValue makeTargetValue(const int8_t *ptr, const int8_t compact_sz, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const bool decimal_to_double, const size_t entry_buff_idx) const
size_t getCurrentRowBufferIndex() const
Definition: ResultSet.h:268
void append(ResultSet &that)
Definition: ResultSet.cpp:278
std::string explanation_
Definition: ResultSet.h:854
const bool is_lazily_fetched
Definition: ResultSet.h:234
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:842
bool operator()(const uint32_t lhs, const uint32_t rhs) const
Definition: ResultSet.cpp:665
int8_t * host_estimator_buffer_
Definition: ResultSet.h:846
bool can_use_parallel_algorithms(const ResultSet &rows)
Definition: ResultSet.cpp:908
friend class ResultSet
Definition: ResultSet.h:295
const ExecutorDeviceType device_type_
Definition: ResultSet.h:819
std::vector< TargetValue > getNextRowImpl(const bool translate_strings, const bool decimal_to_double) const
size_t getCurrentRowBufferIndex() const
Definition: ResultSet.cpp:270
void holdLiterals(std::vector< int8_t > &literal_buff)
Definition: ResultSet.h:469
bool g_enable_watchdog false
Definition: Execute.cpp:73
void parallelTop(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
Definition: ResultSet.cpp:596
int getGpuCount() const
size_t getBufferSizeBytes(const ExecutorDeviceType device_type) const
int8_t * getDeviceEstimatorBuffer() const
Definition: ResultSet.cpp:441
size_t fetched_so_far_
Definition: ResultSet.h:825
size_t crt_row_buff_idx_
Definition: ResultSet.h:824
Estimators to be used when precise cardinality isn&#39;t useful.
QueryDescriptionType
Definition: Types.h:26
int64_t getDistinctBufferRefFromBufferRowwise(int8_t *rowwise_target_ptr, const TargetInfo &target_info) const
void fillOneEntryRowWise(const std::vector< int64_t > &entry)
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:841
bool separate_varlen_storage_valid_
Definition: ResultSet.h:853
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
void rewriteAggregateBufferOffsets(const std::vector< std::string > &serialized_varlen_buffer) const
std::vector< TargetValue > getNextRowUnlocked(const bool translate_strings, const bool decimal_to_double) const
std::vector< TargetValue > * pointer
Definition: ResultSet.h:250
const std::vector< int64_t > & getTargetInitVals() const
Definition: ResultSet.cpp:436
std::vector< size_t > getSlotIndicesForTargetIndices() const
Definition: ResultSet.cpp:997
const std::vector< uint32_t > & getPermutationBuffer() const
Definition: ResultSet.cpp:592
size_t advanceCursorToNextEntry() const
void create_active_buffer_set(BufferSet &count_distinct_active_buffer_set) const
std::set< int64_t > BufferSet
Definition: ResultSet.h:812
std::function< bool(const uint32_t, const uint32_t)> createComparator(const std::list< Analyzer::OrderEntry > &order_entries, const bool use_heap)
Definition: ResultSet.h:757
void sort(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
Definition: ResultSet.cpp:504
ResultSetRowIterator rowIterator(bool translate_strings, bool decimal_to_double) const
Definition: ResultSet.h:351
BUFFER_ITERATOR_TYPE BufferIteratorType
Definition: ResultSet.h:738
ENTRY_TYPE getColumnarBaselineEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
Data_Namespace::DataMgr * getDataManager() const
#define ALWAYS_INLINE
size_t crt_row_buff_idx_
Definition: ResultSet.h:277
InternalTargetValue getColumnInternal(const int8_t *buff, const size_t entry_idx, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
std::vector< std::vector< TargetOffsets > > offsets_for_storage_
Definition: ResultSet.h:708
static bool reduceSingleRow(const int8_t *row_ptr, const int8_t warp_count, const bool is_columnar, const bool replace_bitmap_ptr_with_bitmap_sz, std::vector< int64_t > &agg_vals, const QueryMemoryDescriptor &query_mem_desc, const std::vector< TargetInfo > &targets, const std::vector< int64_t > &agg_init_vals)
bool global_entry_idx_valid_
Definition: ResultSet.h:279
int64_t getRenderTime() const
Definition: ResultSet.cpp:471
void setCachedRowCount(const size_t row_count) const
Definition: ResultSet.cpp:362
bool isDirectColumnarConversionPossible() const
Definition: ResultSet.cpp:923
size_t get_key_bytes_rowwise(const QueryMemoryDescriptor &query_mem_desc)
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)
TargetValue makeVarlenTargetValue(const int8_t *ptr1, const int8_t compact_sz1, const int8_t *ptr2, const int8_t compact_sz2, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const size_t entry_buff_idx) const
void serializeCountDistinctColumns(TSerializedRows &) const
const ResultSetStorage * storage_ptr
Definition: ResultSet.h:649
std::vector< std::unique_ptr< ResultSetStorage >> AppendedStorage
Definition: ResultSet.h:302
const std::vector< const int8_t * > & getColumnFrag(const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:208
size_t binSearchRowCount() const
Definition: ResultSet.cpp:367
const std::vector< ColumnLazyFetchInfo > & getLazyFetchInfo() const
Definition: ResultSet.h:528
int64_t render_time_ms_
Definition: ResultSet.h:831
ENTRY_TYPE getRowWiseBaselineEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
int getDeviceId() const
Definition: ResultSet.cpp:488
static std::unique_ptr< ResultSet > unserialize(const TSerializedRows &serialized_rows, const Executor *)
const int device_id_
Definition: ResultSet.h:820