OmniSciDB  85c2d10cdc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResultSet Class Reference

#include <ResultSet.h>

+ Collaboration diagram for ResultSet:

Classes

struct  ColumnWiseTargetAccessor
 
struct  QueryExecutionTimings
 
struct  ResultSetComparator
 
struct  RowWiseTargetAccessor
 
struct  StorageLookupResult
 
struct  TargetOffsets
 
struct  VarlenTargetPtrPair
 

Public Types

enum  GeoReturnType { GeoReturnType::GeoTargetValue, GeoReturnType::WktString, GeoReturnType::GeoTargetValuePtr, GeoReturnType::GeoTargetValueGpuPtr }
 

Public Member Functions

 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 Catalog_Namespace::Catalog *catalog, const unsigned block_size, const unsigned grid_size)
 
 ResultSet (const std::vector< TargetInfo > &targets, const std::vector< ColumnLazyFetchInfo > &lazy_fetch_info, const std::vector< std::vector< const int8_t * >> &col_buffers, const std::vector< std::vector< int64_t >> &frag_offsets, const std::vector< int64_t > &consistent_frag_sizes, const ExecutorDeviceType device_type, const int device_id, const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const Catalog_Namespace::Catalog *catalog, const unsigned block_size, const unsigned grid_size)
 
 ResultSet (const std::shared_ptr< const Analyzer::Estimator >, const ExecutorDeviceType device_type, const int device_id, Data_Namespace::DataMgr *data_mgr)
 
 ResultSet (const std::string &explanation)
 
 ResultSet (int64_t queue_time_ms, int64_t render_time_ms, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 
 ~ResultSet ()
 
ResultSetRowIterator rowIterator (size_t from_logical_index, bool translate_strings, bool decimal_to_double) const
 
ResultSetRowIterator rowIterator (bool translate_strings, bool decimal_to_double) const
 
ExecutorDeviceType getDeviceType () const
 
const ResultSetStorageallocateStorage () const
 
const ResultSetStorageallocateStorage (int8_t *, const std::vector< int64_t > &) const
 
const ResultSetStorageallocateStorage (const std::vector< int64_t > &) const
 
void updateStorageEntryCount (const size_t new_entry_count)
 
std::vector< TargetValuegetNextRow (const bool translate_strings, const bool decimal_to_double) const
 
size_t getCurrentRowBufferIndex () const
 
std::vector< TargetValuegetRowAt (const size_t index) const
 
TargetValue getRowAt (const size_t row_idx, const size_t col_idx, const bool translate_strings, const bool decimal_to_double=true) const
 
OneIntegerColumnRow getOneColRow (const size_t index) const
 
std::vector< TargetValuegetRowAtNoTranslations (const size_t index, const std::vector< bool > &targets_to_skip={}) const
 
bool isRowAtEmpty (const size_t index) const
 
void sort (const std::list< Analyzer::OrderEntry > &order_entries, size_t top_n, const Executor *executor)
 
void keepFirstN (const size_t n)
 
void dropFirstN (const size_t n)
 
void append (ResultSet &that)
 
const ResultSetStoragegetStorage () const
 
size_t colCount () const
 
SQLTypeInfo getColType (const size_t col_idx) const
 
size_t rowCount (const bool force_parallel=false) const
 
void setCachedRowCount (const size_t row_count) const
 
size_t entryCount () const
 
size_t getBufferSizeBytes (const ExecutorDeviceType device_type) const
 
bool definitelyHasNoRows () const
 
const QueryMemoryDescriptorgetQueryMemDesc () const
 
const std::vector< TargetInfo > & getTargetInfos () const
 
const std::vector< int64_t > & getTargetInitVals () const
 
int8_t * getDeviceEstimatorBuffer () const
 
int8_t * getHostEstimatorBuffer () const
 
void syncEstimatorBuffer () const
 
size_t getNDVEstimator () const
 
void setQueueTime (const int64_t queue_time)
 
void setKernelQueueTime (const int64_t kernel_queue_time)
 
void addCompilationQueueTime (const int64_t compilation_queue_time)
 
int64_t getQueueTime () const
 
int64_t getRenderTime () const
 
void moveToBegin () const
 
bool isTruncated () const
 
bool isExplain () const
 
void setValidationOnlyRes ()
 
bool isValidationOnlyRes () const
 
std::string getExplanation () const
 
bool isGeoColOnGpu (const size_t col_idx) const
 
int getDeviceId () const
 
void fillOneEntry (const std::vector< int64_t > &entry)
 
void initializeStorage () const
 
void holdChunks (const std::list< std::shared_ptr< Chunk_NS::Chunk >> &chunks)
 
void holdChunkIterators (const std::shared_ptr< std::list< ChunkIter >> chunk_iters)
 
void holdLiterals (std::vector< int8_t > &literal_buff)
 
std::shared_ptr
< RowSetMemoryOwner
getRowSetMemOwner () const
 
const PermutationgetPermutationBuffer () const
 
const bool isPermutationBufferEmpty () const
 
void serialize (TSerializedRows &serialized_rows) const
 
size_t getLimit () const
 
GeoReturnType getGeoReturnType () const
 
void setGeoReturnType (const GeoReturnType val)
 
void copyColumnIntoBuffer (const size_t column_idx, int8_t *output_buffer, const size_t output_buffer_size) const
 
bool isDirectColumnarConversionPossible () const
 
bool didOutputColumnar () const
 
bool isZeroCopyColumnarConversionPossible (size_t column_idx) const
 
const int8_t * getColumnarBuffer (size_t column_idx) const
 
QueryDescriptionType getQueryDescriptionType () const
 
const int8_t getPaddedSlotWidthBytes (const size_t slot_idx) const
 
std::tuple< std::vector< bool >
, size_t > 
getSingleSlotTargetBitmap () const
 
std::tuple< std::vector< bool >
, size_t > 
getSupportedSingleSlotTargetBitmap () const
 
std::vector< size_t > getSlotIndicesForTargetIndices () const
 
const std::vector
< ColumnLazyFetchInfo > & 
getLazyFetchInfo () const
 
void setSeparateVarlenStorageValid (const bool val)
 
std::shared_ptr< const
std::vector< std::string > > 
getStringDictionaryPayloadCopy (const int dict_id) const
 
template<typename ENTRY_TYPE , QueryDescriptionType QUERY_TYPE, bool COLUMNAR_FORMAT>
ENTRY_TYPE getEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE , QueryDescriptionType QUERY_TYPE, bool COLUMNAR_FORMAT>
ENTRY_TYPE getEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getColumnarPerfectHashEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getRowWisePerfectHashEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getRowWiseBaselineEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getColumnarBaselineEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 

Static Public Member Functions

static QueryMemoryDescriptor fixupQueryMemoryDescriptor (const QueryMemoryDescriptor &)
 
static std::unique_ptr< ResultSetunserialize (const TSerializedRows &serialized_rows, const Executor *)
 
static double calculateQuantile (quantile::TDigest *const t_digest, double const q)
 

Public Attributes

friend ResultSetBuilder
 

Private Types

using ApproxMedianBuffers = std::vector< std::vector< double >>
 
using BufferSet = std::set< int64_t >
 
using SerializedVarlenBufferStorage = std::vector< std::string >
 

Private Member Functions

void advanceCursorToNextEntry (ResultSetRowIterator &iter) const
 
std::vector< TargetValuegetNextRowImpl (const bool translate_strings, const bool decimal_to_double) const
 
std::vector< TargetValuegetNextRowUnlocked (const bool translate_strings, const bool decimal_to_double) const
 
std::vector< TargetValuegetRowAt (const size_t index, const bool translate_strings, const bool decimal_to_double, const bool fixup_count_distinct_pointers, const std::vector< bool > &targets_to_skip={}) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getColumnarPerfectHashEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getRowWisePerfectHashEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getRowWiseBaselineEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getColumnarBaselineEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
size_t binSearchRowCount () const
 
size_t parallelRowCount () const
 
size_t advanceCursorToNextEntry () const
 
void radixSortOnGpu (const std::list< Analyzer::OrderEntry > &order_entries) const
 
void radixSortOnCpu (const std::list< Analyzer::OrderEntry > &order_entries) 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
 
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
 
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
 
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
 
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
 
InternalTargetValue getColumnInternal (const int8_t *buff, const size_t entry_idx, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
 
InternalTargetValue getVarlenOrderEntry (const int64_t str_ptr, const size_t str_len) const
 
int64_t lazyReadInt (const int64_t ival, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
 
std::pair< size_t, size_t > getStorageIndex (const size_t entry_idx) const
 
const std::vector< const
int8_t * > & 
getColumnFrag (const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
 
StorageLookupResult findStorage (const size_t entry_idx) const
 
Comparator createComparator (const std::list< Analyzer::OrderEntry > &order_entries, const PermutationView permutation, const Executor *executor, const bool single_threaded)
 
PermutationView initPermutationBuffer (PermutationView permutation, PermutationIdx const begin, PermutationIdx const end) const
 
void parallelTop (const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n, const Executor *executor)
 
void baselineSort (const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n, const Executor *executor)
 
void doBaselineSort (const ExecutorDeviceType device_type, const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n, const Executor *executor)
 
bool canUseFastBaselineSort (const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
 
Data_Namespace::DataMgrgetDataManager () const
 
int getGpuCount () const
 
void serializeProjection (TSerializedRows &serialized_rows) const
 
void serializeVarlenAggColumn (int8_t *buf, std::vector< std::string > &varlen_bufer) const
 
void serializeCountDistinctColumns (TSerializedRows &) const
 
void unserializeCountDistinctColumns (const TSerializedRows &)
 
void fixupCountDistinctPointers ()
 
void create_active_buffer_set (BufferSet &count_distinct_active_buffer_set) const
 
int64_t getDistinctBufferRefFromBufferRowwise (int8_t *rowwise_target_ptr, const TargetInfo &target_info) const
 

Static Private Member Functions

static bool isNull (const SQLTypeInfo &ti, const InternalTargetValue &val, const bool float_argument_input)
 
static PermutationView topPermutation (PermutationView, const size_t n, const Comparator &)
 

Private Attributes

const std::vector< TargetInfotargets_
 
const ExecutorDeviceType device_type_
 
const int device_id_
 
QueryMemoryDescriptor query_mem_desc_
 
std::unique_ptr< ResultSetStoragestorage_
 
AppendedStorage appended_storage_
 
size_t crt_row_buff_idx_
 
size_t fetched_so_far_
 
size_t drop_first_
 
size_t keep_first_
 
std::shared_ptr
< RowSetMemoryOwner
row_set_mem_owner_
 
Permutation permutation_
 
const Catalog_Namespace::Catalogcatalog_
 
unsigned block_size_ {0}
 
unsigned grid_size_ {0}
 
QueryExecutionTimings timings_
 
std::list< std::shared_ptr
< Chunk_NS::Chunk > > 
chunks_
 
std::vector< std::shared_ptr
< std::list< ChunkIter > > > 
chunk_iters_
 
std::vector< std::vector
< int8_t > > 
literal_buffers_
 
const std::vector
< ColumnLazyFetchInfo
lazy_fetch_info_
 
std::vector< std::vector
< std::vector< const int8_t * > > > 
col_buffers_
 
std::vector< std::vector
< std::vector< int64_t > > > 
frag_offsets_
 
std::vector< std::vector
< int64_t > > 
consistent_frag_sizes_
 
const std::shared_ptr< const
Analyzer::Estimator
estimator_
 
Data_Namespace::AbstractBufferdevice_estimator_buffer_ {nullptr}
 
int8_t * host_estimator_buffer_ {nullptr}
 
Data_Namespace::DataMgrdata_mgr_
 
std::vector
< SerializedVarlenBufferStorage
serialized_varlen_buffer_
 
bool separate_varlen_storage_valid_
 
std::string explanation_
 
const bool just_explain_
 
bool for_validation_only_
 
std::atomic< int64_t > cached_row_count_
 
std::mutex row_iteration_mutex_
 
GeoReturnType geo_return_type_
 

Friends

class ResultSetManager
 
class ResultSetRowIterator
 
class ColumnarResults
 

Detailed Description

Definition at line 157 of file ResultSet.h.

Member Typedef Documentation

using ResultSet::ApproxMedianBuffers = std::vector<std::vector<double>>
private

Definition at line 619 of file ResultSet.h.

using ResultSet::BufferSet = std::set<int64_t>
private

Definition at line 718 of file ResultSet.h.

using ResultSet::SerializedVarlenBufferStorage = std::vector<std::string>
private

Definition at line 758 of file ResultSet.h.

Member Enumeration Documentation

Geo return type options when accessing geo columns from a result set.

Enumerator
GeoTargetValue 

Copies the geo data into a struct of vectors - coords are uncompressed

WktString 

Returns the geo data as a WKT string

GeoTargetValuePtr 

Returns only the pointers of the underlying buffers for the geo data.

GeoTargetValueGpuPtr 

If geo data is currently on a device, keep the data on the device and return the device ptrs

Definition at line 371 of file ResultSet.h.

371  {
374  WktString,
377  GeoTargetValueGpuPtr
379  };
boost::optional< boost::variant< GeoPointTargetValue, GeoLineStringTargetValue, GeoPolyTargetValue, GeoMultiPolyTargetValue >> GeoTargetValue
Definition: TargetValue.h:161
boost::variant< GeoPointTargetValuePtr, GeoLineStringTargetValuePtr, GeoPolyTargetValuePtr, GeoMultiPolyTargetValuePtr > GeoTargetValuePtr
Definition: TargetValue.h:165

Constructor & Destructor Documentation

ResultSet::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 Catalog_Namespace::Catalog catalog,
const unsigned  block_size,
const unsigned  grid_size 
)

Definition at line 60 of file ResultSet.cpp.

67  : targets_(targets)
68  , device_type_(device_type)
69  , device_id_(-1)
70  , query_mem_desc_(query_mem_desc)
72  , fetched_so_far_(0)
73  , drop_first_(0)
74  , keep_first_(0)
75  , row_set_mem_owner_(row_set_mem_owner)
76  , catalog_(catalog)
77  , block_size_(block_size)
78  , grid_size_(grid_size)
79  , data_mgr_(nullptr)
81  , just_explain_(false)
82  , for_validation_only_(false)
83  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:764
GeoReturnType geo_return_type_
Definition: ResultSet.h:769
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:737
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
size_t keep_first_
Definition: ResultSet.h:733
const bool just_explain_
Definition: ResultSet.h:763
unsigned block_size_
Definition: ResultSet.h:738
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
size_t drop_first_
Definition: ResultSet.h:732
unsigned grid_size_
Definition: ResultSet.h:739
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:755
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
size_t fetched_so_far_
Definition: ResultSet.h:731
size_t crt_row_buff_idx_
Definition: ResultSet.h:730
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
const int device_id_
Definition: ResultSet.h:726
ResultSet::ResultSet ( const std::vector< TargetInfo > &  targets,
const std::vector< ColumnLazyFetchInfo > &  lazy_fetch_info,
const std::vector< std::vector< const int8_t * >> &  col_buffers,
const std::vector< std::vector< int64_t >> &  frag_offsets,
const std::vector< int64_t > &  consistent_frag_sizes,
const ExecutorDeviceType  device_type,
const int  device_id,
const QueryMemoryDescriptor query_mem_desc,
const std::shared_ptr< RowSetMemoryOwner row_set_mem_owner,
const Catalog_Namespace::Catalog catalog,
const unsigned  block_size,
const unsigned  grid_size 
)

Definition at line 86 of file ResultSet.cpp.

98  : targets_(targets)
99  , device_type_(device_type)
100  , device_id_(device_id)
101  , query_mem_desc_(query_mem_desc)
102  , crt_row_buff_idx_(0)
103  , fetched_so_far_(0)
104  , drop_first_(0)
105  , keep_first_(0)
106  , row_set_mem_owner_(row_set_mem_owner)
107  , catalog_(catalog)
108  , block_size_(block_size)
109  , grid_size_(grid_size)
110  , lazy_fetch_info_(lazy_fetch_info)
111  , col_buffers_{col_buffers}
112  , frag_offsets_{frag_offsets}
113  , consistent_frag_sizes_{consistent_frag_sizes}
114  , data_mgr_(nullptr)
116  , just_explain_(false)
117  , for_validation_only_(false)
118  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:764
GeoReturnType geo_return_type_
Definition: ResultSet.h:769
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:737
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
size_t keep_first_
Definition: ResultSet.h:733
const bool just_explain_
Definition: ResultSet.h:763
unsigned block_size_
Definition: ResultSet.h:738
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
size_t drop_first_
Definition: ResultSet.h:732
unsigned grid_size_
Definition: ResultSet.h:739
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:747
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:755
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:748
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:750
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
size_t fetched_so_far_
Definition: ResultSet.h:731
size_t crt_row_buff_idx_
Definition: ResultSet.h:730
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:749
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
const int device_id_
Definition: ResultSet.h:726
ResultSet::ResultSet ( const std::shared_ptr< const Analyzer::Estimator ,
const ExecutorDeviceType  device_type,
const int  device_id,
Data_Namespace::DataMgr data_mgr 
)
ResultSet::ResultSet ( const std::string &  explanation)

Definition at line 148 of file ResultSet.cpp.

References CPU.

150  , device_id_(-1)
151  , fetched_so_far_(0)
153  , explanation_(explanation)
154  , just_explain_(true)
155  , for_validation_only_(false)
156  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:764
GeoReturnType geo_return_type_
Definition: ResultSet.h:769
const bool just_explain_
Definition: ResultSet.h:763
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
std::string explanation_
Definition: ResultSet.h:762
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
size_t fetched_so_far_
Definition: ResultSet.h:731
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
const int device_id_
Definition: ResultSet.h:726
ResultSet::ResultSet ( int64_t  queue_time_ms,
int64_t  render_time_ms,
const std::shared_ptr< RowSetMemoryOwner row_set_mem_owner 
)

Definition at line 159 of file ResultSet.cpp.

References CPU.

163  , device_id_(-1)
164  , fetched_so_far_(0)
165  , row_set_mem_owner_(row_set_mem_owner)
166  , timings_(QueryExecutionTimings{queue_time_ms, render_time_ms, 0, 0})
168  , just_explain_(true)
169  , for_validation_only_(false)
170  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:764
GeoReturnType geo_return_type_
Definition: ResultSet.h:769
const bool just_explain_
Definition: ResultSet.h:763
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
QueryExecutionTimings timings_
Definition: ResultSet.h:740
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
size_t fetched_so_far_
Definition: ResultSet.h:731
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
const int device_id_
Definition: ResultSet.h:726
ResultSet::~ResultSet ( )

Definition at line 173 of file ResultSet.cpp.

References CHECK, and CPU.

173  {
174  if (storage_) {
175  if (!storage_->buff_is_provided_) {
176  CHECK(storage_->getUnderlyingBuffer());
177  free(storage_->getUnderlyingBuffer());
178  }
179  }
180  for (auto& storage : appended_storage_) {
181  if (storage && !storage->buff_is_provided_) {
182  free(storage->getUnderlyingBuffer());
183  }
184  }
188  }
190  CHECK(data_mgr_);
192  }
193 }
AppendedStorage appended_storage_
Definition: ResultSet.h:729
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:755
int8_t * host_estimator_buffer_
Definition: ResultSet.h:754
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
#define CHECK(condition)
Definition: Logger.h:197
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:469
Data_Namespace::AbstractBuffer * device_estimator_buffer_
Definition: ResultSet.h:753

Member Function Documentation

void ResultSet::addCompilationQueueTime ( const int64_t  compilation_queue_time)

Definition at line 448 of file ResultSet.cpp.

448  {
449  timings_.compilation_queue_time += compilation_queue_time;
450 }
QueryExecutionTimings timings_
Definition: ResultSet.h:740
void ResultSet::advanceCursorToNextEntry ( ResultSetRowIterator iter) const
private
size_t ResultSet::advanceCursorToNextEntry ( ) const
private
const ResultSetStorage* ResultSet::allocateStorage ( ) const
const ResultSetStorage* ResultSet::allocateStorage ( int8_t *  ,
const std::vector< int64_t > &   
) const
const ResultSetStorage* ResultSet::allocateStorage ( const std::vector< int64_t > &  ) const
void ResultSet::append ( ResultSet that)

Definition at line 239 of file ResultSet.cpp.

References CHECK, and CHECK_EQ.

239  {
241  if (!that.storage_) {
242  return;
243  }
244  appended_storage_.push_back(std::move(that.storage_));
247  appended_storage_.back()->query_mem_desc_.getEntryCount());
248  chunks_.insert(chunks_.end(), that.chunks_.begin(), that.chunks_.end());
249  col_buffers_.insert(
250  col_buffers_.end(), that.col_buffers_.begin(), that.col_buffers_.end());
251  frag_offsets_.insert(
252  frag_offsets_.end(), that.frag_offsets_.begin(), that.frag_offsets_.end());
254  that.consistent_frag_sizes_.begin(),
255  that.consistent_frag_sizes_.end());
256  chunk_iters_.insert(
257  chunk_iters_.end(), that.chunk_iters_.begin(), that.chunk_iters_.end());
259  CHECK(that.separate_varlen_storage_valid_);
261  that.serialized_varlen_buffer_.begin(),
262  that.serialized_varlen_buffer_.end());
263  }
264  for (auto& buff : that.literal_buffers_) {
265  literal_buffers_.push_back(std::move(buff));
266  }
267 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
void setEntryCount(const size_t val)
AppendedStorage appended_storage_
Definition: ResultSet.h:729
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::vector< std::shared_ptr< std::list< ChunkIter > > > chunk_iters_
Definition: ResultSet.h:743
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:760
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
std::list< std::shared_ptr< Chunk_NS::Chunk > > chunks_
Definition: ResultSet.h:742
std::vector< std::vector< int8_t > > literal_buffers_
Definition: ResultSet.h:746
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:748
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:750
#define CHECK(condition)
Definition: Logger.h:197
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:749
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
void ResultSet::baselineSort ( const std::list< Analyzer::OrderEntry > &  order_entries,
const size_t  top_n,
const Executor executor 
)
private
size_t ResultSet::binSearchRowCount ( ) const
private

Definition at line 349 of file ResultSet.cpp.

References anonymous_namespace{ResultSet.cpp}::get_truncated_row_count().

349  {
350  if (!storage_) {
351  return 0;
352  }
353 
354  size_t row_count = storage_->binSearchRowCount();
355  for (auto& s : appended_storage_) {
356  row_count += s->binSearchRowCount();
357  }
358 
359  return get_truncated_row_count(row_count, getLimit(), drop_first_);
360 }
AppendedStorage appended_storage_
Definition: ResultSet.h:729
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
size_t getLimit() const
Definition: ResultSet.cpp:1013
size_t get_truncated_row_count(size_t total_row_count, size_t limit, size_t offset)
Definition: ResultSet.cpp:288
size_t drop_first_
Definition: ResultSet.h:732

+ Here is the call graph for this function:

double ResultSet::calculateQuantile ( quantile::TDigest *const  t_digest,
double const  q 
)
static

Definition at line 729 of file ResultSet.cpp.

References CHECK, quantile::detail::TDigest< RealType, IndexType >::mergeBuffer(), NULL_DOUBLE, and quantile::detail::TDigest< RealType, IndexType >::quantile().

Referenced by makeTargetValue().

729  {
730  static_assert(sizeof(int64_t) == sizeof(quantile::TDigest*));
731  CHECK(t_digest) << "t_digest=" << (void*)t_digest << ", q=" << q;
732  t_digest->mergeBuffer();
733  double const median = t_digest->quantile(q);
734  return boost::math::isnan(median) ? NULL_DOUBLE : median;
735 }
#define NULL_DOUBLE
DEVICE RealType quantile(RealType const q)
Definition: quantile.h:246
DEVICE void mergeBuffer()
Definition: quantile.h:604
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ResultSet::canUseFastBaselineSort ( const std::list< Analyzer::OrderEntry > &  order_entries,
const size_t  top_n 
)
private
size_t ResultSet::colCount ( ) const

Definition at line 273 of file ResultSet.cpp.

273  {
274  return just_explain_ ? 1 : targets_.size();
275 }
const bool just_explain_
Definition: ResultSet.h:763
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
void ResultSet::copyColumnIntoBuffer ( const size_t  column_idx,
int8_t *  output_buffer,
const size_t  output_buffer_size 
) const

For each specified column, this function goes through all available storages and copy its content into a contiguous output_buffer

Definition at line 1110 of file ResultSetIteration.cpp.

References appended_storage_, CHECK, CHECK_LT, QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getSlotCount(), i, isDirectColumnarConversionPossible(), query_mem_desc_, and storage_.

1112  {
1114  CHECK_LT(column_idx, query_mem_desc_.getSlotCount());
1115  CHECK(output_buffer_size > 0);
1116  CHECK(output_buffer);
1117  const auto column_width_size = query_mem_desc_.getPaddedSlotWidthBytes(column_idx);
1118  size_t out_buff_offset = 0;
1119 
1120  // the main storage:
1121  const size_t crt_storage_row_count = storage_->query_mem_desc_.getEntryCount();
1122  const size_t crt_buffer_size = crt_storage_row_count * column_width_size;
1123  const size_t column_offset = storage_->query_mem_desc_.getColOffInBytes(column_idx);
1124  const int8_t* storage_buffer = storage_->getUnderlyingBuffer() + column_offset;
1125  CHECK(crt_buffer_size <= output_buffer_size);
1126  std::memcpy(output_buffer, storage_buffer, crt_buffer_size);
1127 
1128  out_buff_offset += crt_buffer_size;
1129 
1130  // the appended storages:
1131  for (size_t i = 0; i < appended_storage_.size(); i++) {
1132  const size_t crt_storage_row_count =
1133  appended_storage_[i]->query_mem_desc_.getEntryCount();
1134  if (crt_storage_row_count == 0) {
1135  // skip an empty appended storage
1136  continue;
1137  }
1138  CHECK_LT(out_buff_offset, output_buffer_size);
1139  const size_t crt_buffer_size = crt_storage_row_count * column_width_size;
1140  const size_t column_offset =
1141  appended_storage_[i]->query_mem_desc_.getColOffInBytes(column_idx);
1142  const int8_t* storage_buffer =
1143  appended_storage_[i]->getUnderlyingBuffer() + column_offset;
1144  CHECK(out_buff_offset + crt_buffer_size <= output_buffer_size);
1145  std::memcpy(output_buffer + out_buff_offset, storage_buffer, crt_buffer_size);
1146 
1147  out_buff_offset += crt_buffer_size;
1148  }
1149 }
AppendedStorage appended_storage_
Definition: ResultSet.h:729
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:207
#define CHECK(condition)
Definition: Logger.h:197
bool isDirectColumnarConversionPossible() const
Definition: ResultSet.cpp:1032

+ Here is the call graph for this function:

void ResultSet::create_active_buffer_set ( BufferSet count_distinct_active_buffer_set) const
private
Comparator ResultSet::createComparator ( const std::list< Analyzer::OrderEntry > &  order_entries,
const PermutationView  permutation,
const Executor executor,
const bool  single_threaded 
)
inlineprivate

Definition at line 660 of file ResultSet.h.

References DEBUG_TIMER, QueryMemoryDescriptor::didOutputColumnar(), and query_mem_desc_.

663  {
664  auto timer = DEBUG_TIMER(__func__);
666  return [rsc = ResultSetComparator<ColumnWiseTargetAccessor>(
667  order_entries, this, permutation, executor, single_threaded)](
668  const PermutationIdx lhs, const PermutationIdx rhs) {
669  return rsc(lhs, rhs);
670  };
671  } else {
672  return [rsc = ResultSetComparator<RowWiseTargetAccessor>(
673  order_entries, this, permutation, executor, single_threaded)](
674  const PermutationIdx lhs, const PermutationIdx rhs) {
675  return rsc(lhs, rhs);
676  };
677  }
678  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
uint32_t PermutationIdx
Definition: ResultSet.h:152
#define DEBUG_TIMER(name)
Definition: Logger.h:313

+ Here is the call graph for this function:

bool ResultSet::definitelyHasNoRows ( ) const

Definition at line 397 of file ResultSet.cpp.

397  {
398  return !storage_ && !estimator_ && !just_explain_;
399 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
const bool just_explain_
Definition: ResultSet.h:763
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:752
bool ResultSet::didOutputColumnar ( ) const
inline

Definition at line 389 of file ResultSet.h.

References QueryMemoryDescriptor::didOutputColumnar(), and query_mem_desc_.

389 { return this->query_mem_desc_.didOutputColumnar(); }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727

+ Here is the call graph for this function:

void ResultSet::doBaselineSort ( const ExecutorDeviceType  device_type,
const std::list< Analyzer::OrderEntry > &  order_entries,
const size_t  top_n,
const Executor executor 
)
private
void ResultSet::dropFirstN ( const size_t  n)

Definition at line 55 of file ResultSet.cpp.

References CHECK_EQ.

55  {
57  drop_first_ = n;
58 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
size_t drop_first_
Definition: ResultSet.h:732
size_t ResultSet::entryCount ( ) const

Definition at line 752 of file ResultSetIteration.cpp.

References QueryMemoryDescriptor::getEntryCount(), permutation_, and query_mem_desc_.

752  {
753  return permutation_.empty() ? query_mem_desc_.getEntryCount() : permutation_.size();
754 }
Permutation permutation_
Definition: ResultSet.h:735
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727

+ Here is the call graph for this function:

void ResultSet::fillOneEntry ( const std::vector< int64_t > &  entry)
inline

Definition at line 333 of file ResultSet.h.

References CHECK, and storage_.

333  {
334  CHECK(storage_);
335  if (storage_->query_mem_desc_.didOutputColumnar()) {
336  storage_->fillOneEntryColWise(entry);
337  } else {
338  storage_->fillOneEntryRowWise(entry);
339  }
340  }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
#define CHECK(condition)
Definition: Logger.h:197
ResultSet::StorageLookupResult ResultSet::findStorage ( const size_t  entry_idx) const
private

Definition at line 663 of file ResultSet.cpp.

Referenced by makeGeoTargetValue().

663  {
664  auto [stg_idx, fixedup_entry_idx] = getStorageIndex(entry_idx);
665  return {stg_idx ? appended_storage_[stg_idx - 1].get() : storage_.get(),
666  fixedup_entry_idx,
667  stg_idx};
668 }
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:638
AppendedStorage appended_storage_
Definition: ResultSet.h:729
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728

+ Here is the caller graph for this function:

void ResultSet::fixupCountDistinctPointers ( )
private
QueryMemoryDescriptor ResultSet::fixupQueryMemoryDescriptor ( const QueryMemoryDescriptor query_mem_desc)
static

Definition at line 486 of file ResultSet.cpp.

References QueryMemoryDescriptor::didOutputColumnar(), and query_mem_desc.

Referenced by GpuSharedMemCodeBuilder::codegenInitialization(), GpuSharedMemCodeBuilder::codegenReduction(), Executor::executeTableFunction(), QueryExecutionContext::groupBufferToDeinterleavedResults(), QueryMemoryInitializer::initRowGroups(), QueryMemoryInitializer::QueryMemoryInitializer(), and Executor::reduceMultiDeviceResults().

487  {
488  auto query_mem_desc_copy = query_mem_desc;
489  query_mem_desc_copy.resetGroupColWidths(
490  std::vector<int8_t>(query_mem_desc_copy.getGroupbyColCount(), 8));
491  if (query_mem_desc.didOutputColumnar()) {
492  return query_mem_desc_copy;
493  }
494  query_mem_desc_copy.alignPaddedSlots();
495  return query_mem_desc_copy;
496 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t ResultSet::getBufferSizeBytes ( const ExecutorDeviceType  device_type) const

Definition at line 756 of file ResultSetIteration.cpp.

References CHECK, and storage_.

756  {
757  CHECK(storage_);
758  return storage_->query_mem_desc_.getBufferSizeBytes(device_type);
759 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
#define CHECK(condition)
Definition: Logger.h:197
SQLTypeInfo ResultSet::getColType ( const size_t  col_idx) const

Definition at line 277 of file ResultSet.cpp.

References CHECK_LT, kAVG, kDOUBLE, and kTEXT.

277  {
278  if (just_explain_) {
279  return SQLTypeInfo(kTEXT, false);
280  }
281  CHECK_LT(col_idx, targets_.size());
282  return targets_[col_idx].agg_kind == kAVG ? SQLTypeInfo(kDOUBLE, false)
283  : targets_[col_idx].sql_type;
284 }
const bool just_explain_
Definition: ResultSet.h:763
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
#define CHECK_LT(x, y)
Definition: Logger.h:207
Definition: sqltypes.h:51
Definition: sqldefs.h:72
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getColumnarBaselineEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const
private
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getColumnarBaselineEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const

Directly accesses the result set's storage buffer for a particular data type (row-wise output, baseline hash group by)

NOTE: Currently, only used in direct columnarization

Definition at line 1282 of file ResultSetIteration.cpp.

References CHECK_NE, and storage_.

1284  {
1285  CHECK_NE(storage_->query_mem_desc_.targetGroupbyIndicesSize(), size_t(0));
1286  const auto key_width = storage_->query_mem_desc_.getEffectiveKeyWidth();
1287  const auto column_offset =
1288  (storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) < 0)
1289  ? storage_->query_mem_desc_.getColOffInBytes(slot_idx)
1290  : storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) * key_width *
1291  storage_->query_mem_desc_.getEntryCount();
1292  const auto column_buffer = storage_->getUnderlyingBuffer() + column_offset;
1293  return reinterpret_cast<const ENTRY_TYPE*>(column_buffer)[row_idx];
1294 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
#define CHECK_NE(x, y)
Definition: Logger.h:206
const int8_t * ResultSet::getColumnarBuffer ( size_t  column_idx) const

Definition at line 1057 of file ResultSet.cpp.

References CHECK.

1057  {
1059  return storage_->getUnderlyingBuffer() + query_mem_desc_.getColOffInBytes(column_idx);
1060 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
bool isZeroCopyColumnarConversionPossible(size_t column_idx) const
Definition: ResultSet.cpp:1050
#define CHECK(condition)
Definition: Logger.h:197
size_t getColOffInBytes(const size_t col_idx) const
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getColumnarPerfectHashEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const
private
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getColumnarPerfectHashEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const

Directly accesses the result set's storage buffer for a particular data type (columnar output, perfect hash group by)

NOTE: Currently, only used in direct columnarization

Definition at line 1228 of file ResultSetIteration.cpp.

References storage_.

1230  {
1231  const size_t column_offset = storage_->query_mem_desc_.getColOffInBytes(slot_idx);
1232  const int8_t* storage_buffer = storage_->getUnderlyingBuffer() + column_offset;
1233  return reinterpret_cast<const ENTRY_TYPE*>(storage_buffer)[row_idx];
1234 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
const std::vector< const int8_t * > & ResultSet::getColumnFrag ( const size_t  storge_idx,
const size_t  col_logical_idx,
int64_t &  global_idx 
) const
private

Definition at line 1081 of file ResultSetIteration.cpp.

References CHECK_EQ, CHECK_GE, CHECK_LE, CHECK_LT, col_buffers_, consistent_frag_sizes_, frag_offsets_, and anonymous_namespace{ResultSetIteration.cpp}::get_frag_id_and_local_idx().

Referenced by lazyReadInt(), makeGeoTargetValue(), makeTargetValue(), and makeVarlenTargetValue().

1083  {
1084  CHECK_LT(static_cast<size_t>(storage_idx), col_buffers_.size());
1085  if (col_buffers_[storage_idx].size() > 1) {
1086  int64_t frag_id = 0;
1087  int64_t local_idx = global_idx;
1088  if (consistent_frag_sizes_[storage_idx][col_logical_idx] != -1) {
1089  frag_id = global_idx / consistent_frag_sizes_[storage_idx][col_logical_idx];
1090  local_idx = global_idx % consistent_frag_sizes_[storage_idx][col_logical_idx];
1091  } else {
1092  std::tie(frag_id, local_idx) = get_frag_id_and_local_idx(
1093  frag_offsets_[storage_idx], col_logical_idx, global_idx);
1094  CHECK_LE(local_idx, global_idx);
1095  }
1096  CHECK_GE(frag_id, int64_t(0));
1097  CHECK_LT(static_cast<size_t>(frag_id), col_buffers_[storage_idx].size());
1098  global_idx = local_idx;
1099  return col_buffers_[storage_idx][frag_id];
1100  } else {
1101  CHECK_EQ(size_t(1), col_buffers_[storage_idx].size());
1102  return col_buffers_[storage_idx][0];
1103  }
1104 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define CHECK_GE(x, y)
Definition: Logger.h:210
#define CHECK_LT(x, y)
Definition: Logger.h:207
#define CHECK_LE(x, y)
Definition: Logger.h:208
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:748
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:750
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:749
std::pair< int64_t, int64_t > get_frag_id_and_local_idx(const std::vector< std::vector< T >> &frag_offsets, const size_t tab_or_col_idx, const int64_t global_idx)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

InternalTargetValue ResultSet::getColumnInternal ( const int8_t *  buff,
const size_t  entry_idx,
const size_t  target_logical_idx,
const StorageLookupResult storage_lookup_result 
) const
private
size_t ResultSet::getCurrentRowBufferIndex ( ) const

Definition at line 231 of file ResultSet.cpp.

231  {
232  if (crt_row_buff_idx_ == 0) {
233  throw std::runtime_error("current row buffer iteration index is undefined");
234  }
235  return crt_row_buff_idx_ - 1;
236 }
size_t crt_row_buff_idx_
Definition: ResultSet.h:730
Data_Namespace::DataMgr* ResultSet::getDataManager ( ) const
private
int8_t * ResultSet::getDeviceEstimatorBuffer ( ) const

Definition at line 415 of file ResultSet.cpp.

References CHECK, and GPU.

415  {
419 }
virtual int8_t * getMemoryPtr()=0
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
#define CHECK(condition)
Definition: Logger.h:197
Data_Namespace::AbstractBuffer * device_estimator_buffer_
Definition: ResultSet.h:753
int ResultSet::getDeviceId ( ) const

Definition at line 482 of file ResultSet.cpp.

482  {
483  return device_id_;
484 }
const int device_id_
Definition: ResultSet.h:726
ExecutorDeviceType ResultSet::getDeviceType ( ) const

Definition at line 195 of file ResultSet.cpp.

195  {
196  return device_type_;
197 }
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
int64_t ResultSet::getDistinctBufferRefFromBufferRowwise ( int8_t *  rowwise_target_ptr,
const TargetInfo target_info 
) const
private
template<typename ENTRY_TYPE , QueryDescriptionType QUERY_TYPE, bool COLUMNAR_FORMAT>
ENTRY_TYPE ResultSet::getEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const
template<typename ENTRY_TYPE , QueryDescriptionType QUERY_TYPE, bool COLUMNAR_FORMAT>
ENTRY_TYPE ResultSet::getEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const

Definition at line 1152 of file ResultSetIteration.cpp.

References GroupByBaselineHash, GroupByPerfectHash, and UNREACHABLE.

1154  {
1155  if constexpr (QUERY_TYPE == QueryDescriptionType::GroupByPerfectHash) { // NOLINT
1156  if constexpr (COLUMNAR_FORMAT) { // NOLINT
1157  return getColumnarPerfectHashEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1158  } else {
1159  return getRowWisePerfectHashEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1160  }
1161  } else if constexpr (QUERY_TYPE == QueryDescriptionType::GroupByBaselineHash) {
1162  if constexpr (COLUMNAR_FORMAT) { // NOLINT
1163  return getColumnarBaselineEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1164  } else {
1165  return getRowWiseBaselineEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1166  }
1167  } else {
1168  UNREACHABLE() << "Invalid query type is used";
1169  return 0;
1170  }
1171 }
#define UNREACHABLE()
Definition: Logger.h:241
std::string ResultSet::getExplanation ( ) const
inline

Definition at line 318 of file ResultSet.h.

References explanation_, and just_explain_.

318  {
319  if (just_explain_) {
320  return explanation_;
321  }
322  return {};
323  }
const bool just_explain_
Definition: ResultSet.h:763
std::string explanation_
Definition: ResultSet.h:762
GeoReturnType ResultSet::getGeoReturnType ( ) const
inline

Definition at line 380 of file ResultSet.h.

References geo_return_type_.

380 { return geo_return_type_; }
GeoReturnType geo_return_type_
Definition: ResultSet.h:769
int ResultSet::getGpuCount ( ) const
private
int8_t * ResultSet::getHostEstimatorBuffer ( ) const

Definition at line 421 of file ResultSet.cpp.

421  {
422  return host_estimator_buffer_;
423 }
int8_t * host_estimator_buffer_
Definition: ResultSet.h:754
const std::vector<ColumnLazyFetchInfo>& ResultSet::getLazyFetchInfo ( ) const
inline

Definition at line 409 of file ResultSet.h.

References lazy_fetch_info_.

409  {
410  return lazy_fetch_info_;
411  }
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:747
size_t ResultSet::getLimit ( ) const

Definition at line 1013 of file ResultSet.cpp.

1013  {
1014  return keep_first_;
1015 }
size_t keep_first_
Definition: ResultSet.h:733
size_t ResultSet::getNDVEstimator ( ) const

Definition at line 33 of file CardinalityEstimator.cpp.

References bitmap_set_size(), CHECK, and CHECK_LE.

33  {
34  CHECK(dynamic_cast<const Analyzer::NDVEstimator*>(estimator_.get()));
36  auto bits_set = bitmap_set_size(host_estimator_buffer_, estimator_->getBufferSize());
37  const auto total_bits = estimator_->getBufferSize() * 8;
38  CHECK_LE(bits_set, total_bits);
39  const auto unset_bits = total_bits - bits_set;
40  const auto ratio = static_cast<double>(unset_bits) / total_bits;
41  if (ratio == 0.) {
42  throw std::runtime_error("Failed to get a high quality cardinality estimation");
43  }
44  return -static_cast<double>(total_bits) * log(ratio);
45 }
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:752
#define CHECK_LE(x, y)
Definition: Logger.h:208
int8_t * host_estimator_buffer_
Definition: ResultSet.h:754
#define CHECK(condition)
Definition: Logger.h:197
size_t bitmap_set_size(const int8_t *bitmap, const size_t bitmap_byte_sz)
Definition: CountDistinct.h:37

+ Here is the call graph for this function:

std::vector< TargetValue > ResultSet::getNextRow ( const bool  translate_strings,
const bool  decimal_to_double 
) const

Definition at line 297 of file ResultSetIteration.cpp.

298  {
299  std::lock_guard<std::mutex> lock(row_iteration_mutex_);
300  if (!storage_ && !just_explain_) {
301  return {};
302  }
303  return getNextRowUnlocked(translate_strings, decimal_to_double);
304 }
std::mutex row_iteration_mutex_
Definition: ResultSet.h:766
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
const bool just_explain_
Definition: ResultSet.h:763
std::vector< TargetValue > getNextRowUnlocked(const bool translate_strings, const bool decimal_to_double) const
std::vector< TargetValue > ResultSet::getNextRowImpl ( const bool  translate_strings,
const bool  decimal_to_double 
) const
private

Definition at line 319 of file ResultSetIteration.cpp.

References CHECK, and CHECK_EQ.

320  {
321  size_t entry_buff_idx = 0;
322  do {
324  return {};
325  }
326 
327  entry_buff_idx = advanceCursorToNextEntry();
328 
329  if (crt_row_buff_idx_ >= entryCount()) {
331  return {};
332  }
334  ++fetched_so_far_;
335 
336  } while (drop_first_ && fetched_so_far_ <= drop_first_);
337 
338  auto row = getRowAt(entry_buff_idx, translate_strings, decimal_to_double, false);
339  CHECK(!row.empty());
340 
341  return row;
342 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
size_t keep_first_
Definition: ResultSet.h:733
size_t drop_first_
Definition: ResultSet.h:732
std::vector< TargetValue > getRowAt(const size_t index) const
size_t entryCount() const
#define CHECK(condition)
Definition: Logger.h:197
size_t fetched_so_far_
Definition: ResultSet.h:731
size_t crt_row_buff_idx_
Definition: ResultSet.h:730
size_t advanceCursorToNextEntry() const
std::vector< TargetValue > ResultSet::getNextRowUnlocked ( const bool  translate_strings,
const bool  decimal_to_double 
) const
private

Definition at line 306 of file ResultSetIteration.cpp.

308  {
309  if (just_explain_) {
310  if (fetched_so_far_) {
311  return {};
312  }
313  fetched_so_far_ = 1;
314  return {explanation_};
315  }
316  return getNextRowImpl(translate_strings, decimal_to_double);
317 }
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
const bool just_explain_
Definition: ResultSet.h:763
std::string explanation_
Definition: ResultSet.h:762
std::vector< TargetValue > getNextRowImpl(const bool translate_strings, const bool decimal_to_double) const
size_t fetched_so_far_
Definition: ResultSet.h:731
OneIntegerColumnRow ResultSet::getOneColRow ( const size_t  index) const

Definition at line 235 of file ResultSetIteration.cpp.

References align_to_int64(), CHECK, get_key_bytes_rowwise(), and row_ptr_rowwise().

235  {
236  const auto storage_lookup_result = findStorage(global_entry_idx);
237  const auto storage = storage_lookup_result.storage_ptr;
238  const auto local_entry_idx = storage_lookup_result.fixedup_entry_idx;
239  if (storage->isEmptyEntry(local_entry_idx)) {
240  return {0, false};
241  }
242  const auto buff = storage->buff_;
243  CHECK(buff);
245  const auto keys_ptr = row_ptr_rowwise(buff, query_mem_desc_, local_entry_idx);
246  const auto key_bytes_with_padding =
248  const auto rowwise_target_ptr = keys_ptr + key_bytes_with_padding;
249  const auto tv = getTargetValueFromBufferRowwise(rowwise_target_ptr,
250  keys_ptr,
251  global_entry_idx,
252  targets_.front(),
253  0,
254  0,
255  false,
256  false,
257  false);
258  const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
259  CHECK(scalar_tv);
260  const auto ival_ptr = boost::get<int64_t>(scalar_tv);
261  CHECK(ival_ptr);
262  return {*ival_ptr, true};
263 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
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
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:663
T row_ptr_rowwise(T buff, const QueryMemoryDescriptor &query_mem_desc, const size_t entry_idx)
#define CHECK(condition)
Definition: Logger.h:197
size_t get_key_bytes_rowwise(const QueryMemoryDescriptor &query_mem_desc)
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)

+ Here is the call graph for this function:

const int8_t ResultSet::getPaddedSlotWidthBytes ( const size_t  slot_idx) const
inline

Definition at line 398 of file ResultSet.h.

References QueryMemoryDescriptor::getPaddedSlotWidthBytes(), and query_mem_desc_.

398  {
399  return query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
400  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const

+ Here is the call graph for this function:

const Permutation & ResultSet::getPermutationBuffer ( ) const

Definition at line 592 of file ResultSet.cpp.

592  {
593  return permutation_;
594 }
Permutation permutation_
Definition: ResultSet.h:735
QueryDescriptionType ResultSet::getQueryDescriptionType ( ) const
inline

Definition at line 394 of file ResultSet.h.

References QueryMemoryDescriptor::getQueryDescriptionType(), and query_mem_desc_.

394  {
396  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
QueryDescriptionType getQueryDescriptionType() const

+ Here is the call graph for this function:

const QueryMemoryDescriptor & ResultSet::getQueryMemDesc ( ) const

Definition at line 401 of file ResultSet.cpp.

References CHECK.

401  {
402  CHECK(storage_);
403  return storage_->query_mem_desc_;
404 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
#define CHECK(condition)
Definition: Logger.h:197
int64_t ResultSet::getQueueTime ( ) const

Definition at line 452 of file ResultSet.cpp.

int64_t ResultSet::getRenderTime ( ) const

Definition at line 457 of file ResultSet.cpp.

457  {
458  return timings_.render_time;
459 }
QueryExecutionTimings timings_
Definition: ResultSet.h:740
std::vector<TargetValue> ResultSet::getRowAt ( const size_t  index) const
TargetValue ResultSet::getRowAt ( const size_t  row_idx,
const size_t  col_idx,
const bool  translate_strings,
const bool  decimal_to_double = true 
) const
std::vector<TargetValue> ResultSet::getRowAt ( const size_t  index,
const bool  translate_strings,
const bool  decimal_to_double,
const bool  fixup_count_distinct_pointers,
const std::vector< bool > &  targets_to_skip = {} 
) const
private
std::vector< TargetValue > ResultSet::getRowAtNoTranslations ( const size_t  index,
const std::vector< bool > &  targets_to_skip = {} 
) const

Definition at line 274 of file ResultSetIteration.cpp.

276  {
277  if (logical_index >= entryCount()) {
278  return {};
279  }
280  const auto entry_idx =
281  permutation_.empty() ? logical_index : permutation_[logical_index];
282  return getRowAt(entry_idx, false, false, false, targets_to_skip);
283 }
Permutation permutation_
Definition: ResultSet.h:735
std::vector< TargetValue > getRowAt(const size_t index) const
size_t entryCount() const
std::shared_ptr<RowSetMemoryOwner> ResultSet::getRowSetMemOwner ( ) const
inline

Definition at line 354 of file ResultSet.h.

References row_set_mem_owner_.

354  {
355  return row_set_mem_owner_;
356  }
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getRowWiseBaselineEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const
private
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getRowWiseBaselineEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const

Directly accesses the result set's storage buffer for a particular data type (columnar output, baseline hash group by)

NOTE: Currently, only used in direct columnarization

Definition at line 1260 of file ResultSetIteration.cpp.

References CHECK_NE, row_ptr_rowwise(), and storage_.

1262  {
1263  CHECK_NE(storage_->query_mem_desc_.targetGroupbyIndicesSize(), size_t(0));
1264  const auto key_width = storage_->query_mem_desc_.getEffectiveKeyWidth();
1265  auto keys_ptr = row_ptr_rowwise(
1266  storage_->getUnderlyingBuffer(), storage_->query_mem_desc_, row_idx);
1267  const auto column_offset =
1268  (storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) < 0)
1269  ? storage_->query_mem_desc_.getColOffInBytes(slot_idx)
1270  : storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) * key_width;
1271  const auto storage_buffer = keys_ptr + column_offset;
1272  return *reinterpret_cast<const ENTRY_TYPE*>(storage_buffer);
1273 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
#define CHECK_NE(x, y)
Definition: Logger.h:206
T row_ptr_rowwise(T buff, const QueryMemoryDescriptor &query_mem_desc, const size_t entry_idx)

+ Here is the call graph for this function:

template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getRowWisePerfectHashEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const
private
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getRowWisePerfectHashEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const

Directly accesses the result set's storage buffer for a particular data type (row-wise output, perfect hash group by)

NOTE: Currently, only used in direct columnarization

Definition at line 1243 of file ResultSetIteration.cpp.

References storage_.

1245  {
1246  const size_t row_offset = storage_->query_mem_desc_.getRowSize() * row_idx;
1247  const size_t column_offset = storage_->query_mem_desc_.getColOffInBytes(slot_idx);
1248  const int8_t* storage_buffer =
1249  storage_->getUnderlyingBuffer() + row_offset + column_offset;
1250  return *reinterpret_cast<const ENTRY_TYPE*>(storage_buffer);
1251 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
std::tuple< std::vector< bool >, size_t > ResultSet::getSingleSlotTargetBitmap ( ) const

Definition at line 1063 of file ResultSet.cpp.

References anonymous_namespace{RelAlgExecutor.cpp}::is_agg(), and kAVG.

1063  {
1064  std::vector<bool> target_bitmap(targets_.size(), true);
1065  size_t num_single_slot_targets = 0;
1066  for (size_t target_idx = 0; target_idx < targets_.size(); target_idx++) {
1067  const auto& sql_type = targets_[target_idx].sql_type;
1068  if (targets_[target_idx].is_agg && targets_[target_idx].agg_kind == kAVG) {
1069  target_bitmap[target_idx] = false;
1070  } else if (sql_type.is_varlen()) {
1071  target_bitmap[target_idx] = false;
1072  } else {
1073  num_single_slot_targets++;
1074  }
1075  }
1076  return std::make_tuple(std::move(target_bitmap), num_single_slot_targets);
1077 }
bool is_agg(const Analyzer::Expr *expr)
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
Definition: sqldefs.h:72

+ Here is the call graph for this function:

std::vector< size_t > ResultSet::getSlotIndicesForTargetIndices ( ) const

Definition at line 1106 of file ResultSet.cpp.

References advance_slot().

1106  {
1107  std::vector<size_t> slot_indices(targets_.size(), 0);
1108  size_t slot_index = 0;
1109  for (size_t target_idx = 0; target_idx < targets_.size(); target_idx++) {
1110  slot_indices[target_idx] = slot_index;
1111  slot_index = advance_slot(slot_index, targets_[target_idx], false);
1112  }
1113  return slot_indices;
1114 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
size_t advance_slot(const size_t j, const TargetInfo &target_info, const bool separate_varlen_storage)

+ Here is the call graph for this function:

const ResultSetStorage * ResultSet::getStorage ( ) const

Definition at line 269 of file ResultSet.cpp.

269  {
270  return storage_.get();
271 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
std::pair< size_t, size_t > ResultSet::getStorageIndex ( const size_t  entry_idx) const
private

Returns (storageIdx, entryIdx) pair, where: storageIdx : 0 is storage_, storageIdx-1 is index into appended_storage_. entryIdx : local index into the storage object.

Definition at line 638 of file ResultSet.cpp.

References CHECK_NE, i, and UNREACHABLE.

Referenced by makeGeoTargetValue(), makeTargetValue(), and makeVarlenTargetValue().

638  {
639  size_t fixedup_entry_idx = entry_idx;
640  auto entry_count = storage_->query_mem_desc_.getEntryCount();
641  const bool is_rowwise_layout = !storage_->query_mem_desc_.didOutputColumnar();
642  if (fixedup_entry_idx < entry_count) {
643  return {0, fixedup_entry_idx};
644  }
645  fixedup_entry_idx -= entry_count;
646  for (size_t i = 0; i < appended_storage_.size(); ++i) {
647  const auto& desc = appended_storage_[i]->query_mem_desc_;
648  CHECK_NE(is_rowwise_layout, desc.didOutputColumnar());
649  entry_count = desc.getEntryCount();
650  if (fixedup_entry_idx < entry_count) {
651  return {i + 1, fixedup_entry_idx};
652  }
653  fixedup_entry_idx -= entry_count;
654  }
655  UNREACHABLE() << "entry_idx = " << entry_idx << ", query_mem_desc_.getEntryCount() = "
657  return {};
658 }
AppendedStorage appended_storage_
Definition: ResultSet.h:729
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
#define UNREACHABLE()
Definition: Logger.h:241
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
#define CHECK_NE(x, y)
Definition: Logger.h:206

+ Here is the caller graph for this function:

std::shared_ptr< const std::vector< std::string > > ResultSet::getStringDictionaryPayloadCopy ( const int  dict_id) const

Definition at line 1017 of file ResultSet.cpp.

References catalog_(), and CHECK.

1018  {
1019  const auto sdp = row_set_mem_owner_->getOrAddStringDictProxy(
1020  dict_id, /*with_generation=*/false, catalog_);
1021  CHECK(sdp);
1022  return sdp->getDictionary()->copyStrings();
1023 }
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:737
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

std::tuple< std::vector< bool >, size_t > ResultSet::getSupportedSingleSlotTargetBitmap ( ) const

This function returns a bitmap and population count of it, where it denotes all supported single-column targets suitable for direct columnarization.

The final goal is to remove the need for such selection, but at the moment for any target that doesn't qualify for direct columnarization, we use the traditional result set's iteration to handle it (e.g., count distinct, approximate count distinct)

Definition at line 1087 of file ResultSet.cpp.

References CHECK, CHECK_GE, is_distinct_target(), kAPPROX_MEDIAN, kFLOAT, and kSAMPLE.

1088  {
1090  auto [single_slot_targets, num_single_slot_targets] = getSingleSlotTargetBitmap();
1091 
1092  for (size_t target_idx = 0; target_idx < single_slot_targets.size(); target_idx++) {
1093  const auto& target = targets_[target_idx];
1094  if (single_slot_targets[target_idx] &&
1095  (is_distinct_target(target) || target.agg_kind == kAPPROX_MEDIAN ||
1096  (target.is_agg && target.agg_kind == kSAMPLE && target.sql_type == kFLOAT))) {
1097  single_slot_targets[target_idx] = false;
1098  num_single_slot_targets--;
1099  }
1100  }
1101  CHECK_GE(num_single_slot_targets, size_t(0));
1102  return std::make_tuple(std::move(single_slot_targets), num_single_slot_targets);
1103 }
#define CHECK_GE(x, y)
Definition: Logger.h:210
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
std::tuple< std::vector< bool >, size_t > getSingleSlotTargetBitmap() const
Definition: ResultSet.cpp:1063
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:130
#define CHECK(condition)
Definition: Logger.h:197
bool isDirectColumnarConversionPossible() const
Definition: ResultSet.cpp:1032

+ Here is the call graph for this function:

const std::vector< TargetInfo > & ResultSet::getTargetInfos ( ) const

Definition at line 406 of file ResultSet.cpp.

406  {
407  return targets_;
408 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
const std::vector< int64_t > & ResultSet::getTargetInitVals ( ) const

Definition at line 410 of file ResultSet.cpp.

References CHECK.

410  {
411  CHECK(storage_);
412  return storage_->target_init_vals_;
413 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
#define CHECK(condition)
Definition: Logger.h:197
TargetValue ResultSet::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
private

Definition at line 1860 of file ResultSetIteration.cpp.

References advance_to_next_columnar_target_buff(), TargetInfo::agg_kind, CHECK, CHECK_GE, anonymous_namespace{ResultSetIteration.cpp}::columnar_elem_ptr(), QueryMemoryDescriptor::didOutputColumnar(), QueryMemoryDescriptor::getEffectiveKeyWidth(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getTargetGroupbyIndex(), TargetInfo::is_agg, SQLTypeInfo::is_geometry(), is_real_str_or_array(), kAVG, anonymous_namespace{ResultSetIteration.cpp}::make_avg_target_value(), makeGeoTargetValue(), makeTargetValue(), makeVarlenTargetValue(), query_mem_desc_, TargetInfo::sql_type, and QueryMemoryDescriptor::targetGroupbyIndicesSize().

1870  {
1872  const auto col1_ptr = col_ptr;
1873  const auto compact_sz1 = query_mem_desc.getPaddedSlotWidthBytes(slot_idx);
1874  const auto next_col_ptr =
1875  advance_to_next_columnar_target_buff(col1_ptr, query_mem_desc, slot_idx);
1876  const auto col2_ptr = ((target_info.is_agg && target_info.agg_kind == kAVG) ||
1877  is_real_str_or_array(target_info))
1878  ? next_col_ptr
1879  : nullptr;
1880  const auto compact_sz2 = ((target_info.is_agg && target_info.agg_kind == kAVG) ||
1881  is_real_str_or_array(target_info))
1882  ? query_mem_desc.getPaddedSlotWidthBytes(slot_idx + 1)
1883  : 0;
1884 
1885  // TODO(Saman): add required logics for count distinct
1886  // geospatial target values:
1887  if (target_info.sql_type.is_geometry()) {
1888  return makeGeoTargetValue(
1889  col1_ptr, slot_idx, target_info, target_logical_idx, global_entry_idx);
1890  }
1891 
1892  const auto ptr1 = columnar_elem_ptr(local_entry_idx, col1_ptr, compact_sz1);
1893  if (target_info.agg_kind == kAVG || is_real_str_or_array(target_info)) {
1894  CHECK(col2_ptr);
1895  CHECK(compact_sz2);
1896  const auto ptr2 = columnar_elem_ptr(local_entry_idx, col2_ptr, compact_sz2);
1897  return target_info.agg_kind == kAVG
1898  ? make_avg_target_value(ptr1, compact_sz1, ptr2, compact_sz2, target_info)
1899  : makeVarlenTargetValue(ptr1,
1900  compact_sz1,
1901  ptr2,
1902  compact_sz2,
1903  target_info,
1904  target_logical_idx,
1905  translate_strings,
1906  global_entry_idx);
1907  }
1909  query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
1910  return makeTargetValue(ptr1,
1911  compact_sz1,
1912  target_info,
1913  target_logical_idx,
1914  translate_strings,
1916  global_entry_idx);
1917  }
1918  const auto key_width = query_mem_desc_.getEffectiveKeyWidth();
1919  const auto key_idx = query_mem_desc_.getTargetGroupbyIndex(target_logical_idx);
1920  CHECK_GE(key_idx, 0);
1921  auto key_col_ptr = keys_ptr + key_idx * query_mem_desc_.getEntryCount() * key_width;
1922  return makeTargetValue(columnar_elem_ptr(local_entry_idx, key_col_ptr, key_width),
1923  key_width,
1924  target_info,
1925  target_logical_idx,
1926  translate_strings,
1928  global_entry_idx);
1929 }
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
int64_t getTargetGroupbyIndex(const size_t target_idx) const
T advance_to_next_columnar_target_buff(T target_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t target_slot_idx)
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
#define CHECK_GE(x, y)
Definition: Logger.h:210
size_t getEffectiveKeyWidth() const
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 make_avg_target_value(const int8_t *ptr1, const int8_t compact_sz1, const int8_t *ptr2, const int8_t compact_sz2, const TargetInfo &target_info)
bool is_agg
Definition: TargetInfo.h:40
size_t targetGroupbyIndicesSize() const
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
SQLAgg agg_kind
Definition: TargetInfo.h:41
bool is_real_str_or_array(const TargetInfo &target_info)
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
#define CHECK(condition)
Definition: Logger.h:197
bool is_geometry() const
Definition: sqltypes.h:500
Definition: sqldefs.h:72
const int8_t * columnar_elem_ptr(const size_t entry_idx, const int8_t *col1_ptr, const int8_t compact_sz1)
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

+ Here is the call graph for this function:

TargetValue ResultSet::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
private

Definition at line 1933 of file ResultSetIteration.cpp.

References TargetInfo::agg_kind, CHECK, QueryMemoryDescriptor::count_distinct_descriptors_, SQLTypeInfo::get_compression(), QueryMemoryDescriptor::getEffectiveKeyWidth(), QueryMemoryDescriptor::getLogicalSlotWidthBytes(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getTargetGroupbyIndex(), QueryMemoryDescriptor::hasKeylessHash(), TargetInfo::is_agg, SQLTypeInfo::is_array(), is_distinct_target(), SQLTypeInfo::is_geometry(), is_real_str_or_array(), SQLTypeInfo::is_string(), QueryMemoryDescriptor::isSingleColumnGroupByWithPerfectHash(), kAVG, kENCODING_NONE, anonymous_namespace{ResultSetIteration.cpp}::make_avg_target_value(), makeGeoTargetValue(), makeTargetValue(), makeVarlenTargetValue(), query_mem_desc_, row_set_mem_owner_, separate_varlen_storage_valid_, TargetInfo::sql_type, storage_, QueryMemoryDescriptor::targetGroupbyIndicesSize(), and UNLIKELY.

1942  {
1943  if (UNLIKELY(fixup_count_distinct_pointers)) {
1944  if (is_distinct_target(target_info)) {
1945  auto count_distinct_ptr_ptr = reinterpret_cast<int64_t*>(rowwise_target_ptr);
1946  const auto remote_ptr = *count_distinct_ptr_ptr;
1947  if (remote_ptr) {
1948  const auto ptr = storage_->mappedPtr(remote_ptr);
1949  if (ptr) {
1950  *count_distinct_ptr_ptr = ptr;
1951  } else {
1952  // need to create a zero filled buffer for this remote_ptr
1953  const auto& count_distinct_desc =
1954  query_mem_desc_.count_distinct_descriptors_[target_logical_idx];
1955  const auto bitmap_byte_sz = count_distinct_desc.sub_bitmap_count == 1
1956  ? count_distinct_desc.bitmapSizeBytes()
1957  : count_distinct_desc.bitmapPaddedSizeBytes();
1958  auto count_distinct_buffer = row_set_mem_owner_->allocateCountDistinctBuffer(
1959  bitmap_byte_sz, /*thread_idx=*/0);
1960  *count_distinct_ptr_ptr = reinterpret_cast<int64_t>(count_distinct_buffer);
1961  }
1962  }
1963  }
1964  return int64_t(0);
1965  }
1966  if (target_info.sql_type.is_geometry()) {
1967  return makeGeoTargetValue(
1968  rowwise_target_ptr, slot_idx, target_info, target_logical_idx, entry_buff_idx);
1969  }
1970 
1971  auto ptr1 = rowwise_target_ptr;
1972  int8_t compact_sz1 = query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
1974  !query_mem_desc_.hasKeylessHash() && !target_info.is_agg) {
1975  // Single column perfect hash group by can utilize one slot for both the key and the
1976  // target value if both values fit in 8 bytes. Use the target value actual size for
1977  // this case. If they don't, the target value should be 8 bytes, so we can still use
1978  // the actual size rather than the compact size.
1979  compact_sz1 = query_mem_desc_.getLogicalSlotWidthBytes(slot_idx);
1980  }
1981 
1982  // logic for deciding width of column
1983  if (target_info.agg_kind == kAVG || is_real_str_or_array(target_info)) {
1984  const auto ptr2 =
1985  rowwise_target_ptr + query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
1986  int8_t compact_sz2 = 0;
1987  // Skip reading the second slot if we have a none encoded string and are using
1988  // the none encoded strings buffer attached to ResultSetStorage
1990  (target_info.sql_type.is_array() ||
1991  (target_info.sql_type.is_string() &&
1992  target_info.sql_type.get_compression() == kENCODING_NONE)))) {
1993  compact_sz2 = query_mem_desc_.getPaddedSlotWidthBytes(slot_idx + 1);
1994  }
1995  if (separate_varlen_storage_valid_ && target_info.is_agg) {
1996  compact_sz2 = 8; // TODO(adb): is there a better way to do this?
1997  }
1998  CHECK(ptr2);
1999  return target_info.agg_kind == kAVG
2000  ? make_avg_target_value(ptr1, compact_sz1, ptr2, compact_sz2, target_info)
2001  : makeVarlenTargetValue(ptr1,
2002  compact_sz1,
2003  ptr2,
2004  compact_sz2,
2005  target_info,
2006  target_logical_idx,
2007  translate_strings,
2008  entry_buff_idx);
2009  }
2011  query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
2012  return makeTargetValue(ptr1,
2013  compact_sz1,
2014  target_info,
2015  target_logical_idx,
2016  translate_strings,
2018  entry_buff_idx);
2019  }
2020  const auto key_width = query_mem_desc_.getEffectiveKeyWidth();
2021  ptr1 = keys_ptr + query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) * key_width;
2022  return makeTargetValue(ptr1,
2023  key_width,
2024  target_info,
2025  target_logical_idx,
2026  translate_strings,
2028  entry_buff_idx);
2029 }
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
int64_t getTargetGroupbyIndex(const size_t target_idx) const
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
size_t getEffectiveKeyWidth() const
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 make_avg_target_value(const int8_t *ptr1, const int8_t compact_sz1, const int8_t *ptr2, const int8_t compact_sz2, const TargetInfo &target_info)
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
bool is_agg
Definition: TargetInfo.h:40
size_t targetGroupbyIndicesSize() const
CountDistinctDescriptors count_distinct_descriptors_
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:130
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
SQLAgg agg_kind
Definition: TargetInfo.h:41
#define UNLIKELY(x)
Definition: likely.h:25
bool is_real_str_or_array(const TargetInfo &target_info)
bool isSingleColumnGroupByWithPerfectHash() const
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
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
#define CHECK(condition)
Definition: Logger.h:197
bool is_geometry() const
Definition: sqltypes.h:500
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
bool is_string() const
Definition: sqltypes.h:488
const int8_t getLogicalSlotWidthBytes(const size_t slot_idx) const
Definition: sqldefs.h:72
bool is_array() const
Definition: sqltypes.h:496
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

+ Here is the call graph for this function:

InternalTargetValue ResultSet::getVarlenOrderEntry ( const int64_t  str_ptr,
const size_t  str_len 
) const
private

Definition at line 626 of file ResultSetIteration.cpp.

References CHECK, copy_from_gpu(), CPU, device_id_, device_type_, QueryMemoryDescriptor::getExecutor(), GPU, query_mem_desc_, and row_set_mem_owner_.

627  {
628  char* host_str_ptr{nullptr};
629  std::vector<int8_t> cpu_buffer;
631  cpu_buffer.resize(str_len);
632  const auto executor = query_mem_desc_.getExecutor();
633  CHECK(executor);
634  auto& data_mgr = executor->catalog_->getDataMgr();
635  copy_from_gpu(&data_mgr,
636  &cpu_buffer[0],
637  static_cast<CUdeviceptr>(str_ptr),
638  str_len,
639  device_id_);
640  host_str_ptr = reinterpret_cast<char*>(&cpu_buffer[0]);
641  } else {
643  host_str_ptr = reinterpret_cast<char*>(str_ptr);
644  }
645  std::string str(host_str_ptr, str_len);
646  return InternalTargetValue(row_set_mem_owner_->addString(str));
647 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
void copy_from_gpu(Data_Namespace::DataMgr *data_mgr, void *dst, const CUdeviceptr src, const size_t num_bytes, const int device_id)
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
#define CHECK(condition)
Definition: Logger.h:197
const Executor * getExecutor() const
const int device_id_
Definition: ResultSet.h:726

+ Here is the call graph for this function:

void ResultSet::holdChunkIterators ( const std::shared_ptr< std::list< ChunkIter >>  chunk_iters)
inline

Definition at line 347 of file ResultSet.h.

References chunk_iters_.

347  {
348  chunk_iters_.push_back(chunk_iters);
349  }
std::vector< std::shared_ptr< std::list< ChunkIter > > > chunk_iters_
Definition: ResultSet.h:743
void ResultSet::holdChunks ( const std::list< std::shared_ptr< Chunk_NS::Chunk >> &  chunks)
inline

Definition at line 344 of file ResultSet.h.

References chunks_.

344  {
345  chunks_ = chunks;
346  }
std::list< std::shared_ptr< Chunk_NS::Chunk > > chunks_
Definition: ResultSet.h:742
void ResultSet::holdLiterals ( std::vector< int8_t > &  literal_buff)
inline

Definition at line 350 of file ResultSet.h.

References literal_buffers_.

350  {
351  literal_buffers_.push_back(std::move(literal_buff));
352  }
std::vector< std::vector< int8_t > > literal_buffers_
Definition: ResultSet.h:746
void ResultSet::initializeStorage ( ) const

Definition at line 1032 of file ResultSetReduction.cpp.

1032  {
1034  storage_->initializeColWise();
1035  } else {
1036  storage_->initializeRowWise();
1037  }
1038 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
PermutationView ResultSet::initPermutationBuffer ( PermutationView  permutation,
PermutationIdx const  begin,
PermutationIdx const  end 
) const
private

Definition at line 576 of file ResultSet.cpp.

References CHECK, DEBUG_TIMER, i, and VectorView< T >::push_back().

578  {
579  auto timer = DEBUG_TIMER(__func__);
580  for (PermutationIdx i = begin; i < end; ++i) {
581  const auto storage_lookup_result = findStorage(i);
582  const auto lhs_storage = storage_lookup_result.storage_ptr;
583  const auto off = storage_lookup_result.fixedup_entry_idx;
584  CHECK(lhs_storage);
585  if (!lhs_storage->isEmptyEntry(off)) {
586  permutation.push_back(i);
587  }
588  }
589  return permutation;
590 }
DEVICE void push_back(T const &value)
Definition: VectorView.h:74
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:663
uint32_t PermutationIdx
Definition: ResultSet.h:152
#define CHECK(condition)
Definition: Logger.h:197
#define DEBUG_TIMER(name)
Definition: Logger.h:313

+ Here is the call graph for this function:

bool ResultSet::isDirectColumnarConversionPossible ( ) const

Determines if it is possible to directly form a ColumnarResults class from this result set, bypassing the default columnarization.

NOTE: If there exists a permutation vector (i.e., in some ORDER BY queries), it becomes equivalent to the row-wise columnarization.

Definition at line 1032 of file ResultSet.cpp.

References g_enable_direct_columnarization, GroupByBaselineHash, GroupByPerfectHash, and Projection.

Referenced by copyColumnIntoBuffer().

+ Here is the caller graph for this function:

bool ResultSet::isExplain ( ) const

Definition at line 470 of file ResultSet.cpp.

470  {
471  return just_explain_;
472 }
const bool just_explain_
Definition: ResultSet.h:763
bool ResultSet::isGeoColOnGpu ( const size_t  col_idx) const

Definition at line 1423 of file ResultSetIteration.cpp.

References CHECK_LT, device_type_, GPU, IS_GEO, lazy_fetch_info_, separate_varlen_storage_valid_, targets_, and to_string().

1423  {
1424  // This should match the logic in makeGeoTargetValue which ultimately calls
1425  // fetch_data_from_gpu when the geo column is on the device.
1426  // TODO(croot): somehow find a way to refactor this and makeGeoTargetValue to use a
1427  // utility function that handles this logic in one place
1428  CHECK_LT(col_idx, targets_.size());
1429  if (!IS_GEO(targets_[col_idx].sql_type.get_type())) {
1430  throw std::runtime_error("Column target at index " + std::to_string(col_idx) +
1431  " is not a geo column. It is of type " +
1432  targets_[col_idx].sql_type.get_type_name() + ".");
1433  }
1434 
1435  const auto& target_info = targets_[col_idx];
1436  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1437  return false;
1438  }
1439 
1440  if (!lazy_fetch_info_.empty()) {
1441  CHECK_LT(col_idx, lazy_fetch_info_.size());
1442  if (lazy_fetch_info_[col_idx].is_lazily_fetched) {
1443  return false;
1444  }
1445  }
1446 
1448 }
std::string to_string(char const *&&v)
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:747
#define CHECK_LT(x, y)
Definition: Logger.h:207
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
#define IS_GEO(T)
Definition: sqltypes.h:245

+ Here is the call graph for this function:

bool ResultSet::isNull ( const SQLTypeInfo ti,
const InternalTargetValue val,
const bool  float_argument_input 
)
staticprivate

Definition at line 2168 of file ResultSetIteration.cpp.

References CHECK, SQLTypeInfo::get_notnull(), InternalTargetValue::i1, InternalTargetValue::i2, InternalTargetValue::isInt(), InternalTargetValue::isNull(), InternalTargetValue::isPair(), InternalTargetValue::isStr(), NULL_DOUBLE, null_val_bit_pattern(), and pair_to_double().

2170  {
2171  if (ti.get_notnull()) {
2172  return false;
2173  }
2174  if (val.isInt()) {
2175  return val.i1 == null_val_bit_pattern(ti, float_argument_input);
2176  }
2177  if (val.isPair()) {
2178  return !val.i2 ||
2179  pair_to_double({val.i1, val.i2}, ti, float_argument_input) == NULL_DOUBLE;
2180  }
2181  if (val.isStr()) {
2182  return !val.i1;
2183  }
2184  CHECK(val.isNull());
2185  return true;
2186 }
#define NULL_DOUBLE
bool isPair() const
Definition: TargetValue.h:67
bool isStr() const
Definition: TargetValue.h:71
double pair_to_double(const std::pair< int64_t, int64_t > &fp_pair, const SQLTypeInfo &ti, const bool float_argument_input)
int64_t null_val_bit_pattern(const SQLTypeInfo &ti, const bool float_argument_input)
bool isNull() const
Definition: TargetValue.h:69
bool isInt() const
Definition: TargetValue.h:65
#define CHECK(condition)
Definition: Logger.h:197
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:321

+ Here is the call graph for this function:

const bool ResultSet::isPermutationBufferEmpty ( ) const
inline

Definition at line 359 of file ResultSet.h.

References permutation_.

359 { return permutation_.empty(); };
Permutation permutation_
Definition: ResultSet.h:735
bool ResultSet::isRowAtEmpty ( const size_t  index) const

Definition at line 285 of file ResultSetIteration.cpp.

285  {
286  if (logical_index >= entryCount()) {
287  return true;
288  }
289  const auto entry_idx =
290  permutation_.empty() ? logical_index : permutation_[logical_index];
291  const auto storage_lookup_result = findStorage(entry_idx);
292  const auto storage = storage_lookup_result.storage_ptr;
293  const auto local_entry_idx = storage_lookup_result.fixedup_entry_idx;
294  return storage->isEmptyEntry(local_entry_idx);
295 }
Permutation permutation_
Definition: ResultSet.h:735
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:663
size_t entryCount() const
bool ResultSet::isTruncated ( ) const

Definition at line 466 of file ResultSet.cpp.

466  {
467  return keep_first_ + drop_first_;
468 }
size_t keep_first_
Definition: ResultSet.h:733
size_t drop_first_
Definition: ResultSet.h:732
bool ResultSet::isValidationOnlyRes ( ) const

Definition at line 478 of file ResultSet.cpp.

478  {
479  return for_validation_only_;
480 }
bool for_validation_only_
Definition: ResultSet.h:764
bool ResultSet::isZeroCopyColumnarConversionPossible ( size_t  column_idx) const

Definition at line 1050 of file ResultSet.cpp.

References Projection.

1050  {
1053  appended_storage_.empty() && storage_ &&
1054  (lazy_fetch_info_.empty() || !lazy_fetch_info_[column_idx].is_lazily_fetched);
1055 }
AppendedStorage appended_storage_
Definition: ResultSet.h:729
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:747
QueryDescriptionType getQueryDescriptionType() const
void ResultSet::keepFirstN ( const size_t  n)

Definition at line 50 of file ResultSet.cpp.

References CHECK_EQ.

50  {
52  keep_first_ = n;
53 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
size_t keep_first_
Definition: ResultSet.h:733
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
int64_t ResultSet::lazyReadInt ( const int64_t  ival,
const size_t  target_logical_idx,
const StorageLookupResult storage_lookup_result 
) const
private

Definition at line 649 of file ResultSetIteration.cpp.

References CHECK, CHECK_LT, ChunkIter_get_nth(), col_buffers_, ResultSet::StorageLookupResult::fixedup_entry_idx, getColumnFrag(), VarlenDatum::is_null, kENCODING_NONE, result_set::lazy_decode(), lazy_fetch_info_, VarlenDatum::length, VarlenDatum::pointer, row_set_mem_owner_, ResultSet::StorageLookupResult::storage_idx, and targets_.

651  {
652  if (!lazy_fetch_info_.empty()) {
653  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
654  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
655  if (col_lazy_fetch.is_lazily_fetched) {
656  CHECK_LT(static_cast<size_t>(storage_lookup_result.storage_idx),
657  col_buffers_.size());
658  int64_t ival_copy = ival;
659  auto& frag_col_buffers =
660  getColumnFrag(static_cast<size_t>(storage_lookup_result.storage_idx),
661  target_logical_idx,
662  ival_copy);
663  auto& frag_col_buffer = frag_col_buffers[col_lazy_fetch.local_col_id];
664  CHECK_LT(target_logical_idx, targets_.size());
665  const TargetInfo& target_info = targets_[target_logical_idx];
666  CHECK(!target_info.is_agg);
667  if (target_info.sql_type.is_string() &&
668  target_info.sql_type.get_compression() == kENCODING_NONE) {
669  VarlenDatum vd;
670  bool is_end{false};
672  reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(frag_col_buffer)),
673  storage_lookup_result.fixedup_entry_idx,
674  false,
675  &vd,
676  &is_end);
677  CHECK(!is_end);
678  if (vd.is_null) {
679  return 0;
680  }
681  std::string fetched_str(reinterpret_cast<char*>(vd.pointer), vd.length);
682  return reinterpret_cast<int64_t>(row_set_mem_owner_->addString(fetched_str));
683  }
684  return result_set::lazy_decode(col_lazy_fetch, frag_col_buffer, ival_copy);
685  }
686  }
687  return ival;
688 }
bool is_null
Definition: sqltypes.h:147
DEVICE void ChunkIter_get_nth(ChunkIter *it, int n, bool uncompress, VarlenDatum *result, bool *is_end)
Definition: ChunkIter.cpp:181
int8_t * pointer
Definition: sqltypes.h:146
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
int64_t lazy_decode(const ColumnLazyFetchInfo &col_lazy_fetch, const int8_t *byte_stream, const int64_t pos)
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:747
#define CHECK_LT(x, y)
Definition: Logger.h:207
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:748
#define CHECK(condition)
Definition: Logger.h:197
const std::vector< const int8_t * > & getColumnFrag(const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
size_t length
Definition: sqltypes.h:145

+ Here is the call graph for this function:

TargetValue ResultSet::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
private

Definition at line 1454 of file ResultSetIteration.cpp.

References advance_to_next_columnar_target_buff(), CHECK, CHECK_EQ, CHECK_LT, col_buffers_, device_id_, device_type_, QueryMemoryDescriptor::didOutputColumnar(), findStorage(), geo_return_type_, SQLTypeInfo::get_type(), SQLTypeInfo::get_type_name(), getColumnFrag(), QueryMemoryDescriptor::getExecutor(), QueryMemoryDescriptor::getPaddedColWidthForRange(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), getStorageIndex(), GPU, i, TargetInfo::is_agg, SQLTypeInfo::is_geometry(), ColumnLazyFetchInfo::is_lazily_fetched, kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, lazy_fetch_info_, ColumnLazyFetchInfo::local_col_id, query_mem_desc_, read_int_from_buff(), separate_varlen_storage_valid_, serialized_varlen_buffer_, TargetInfo::sql_type, and UNREACHABLE.

Referenced by getTargetValueFromBufferColwise(), and getTargetValueFromBufferRowwise().

1458  {
1459  CHECK(target_info.sql_type.is_geometry());
1460 
1461  auto getNextTargetBufferRowWise = [&](const size_t slot_idx, const size_t range) {
1462  return geo_target_ptr + query_mem_desc_.getPaddedColWidthForRange(slot_idx, range);
1463  };
1464 
1465  auto getNextTargetBufferColWise = [&](const size_t slot_idx, const size_t range) {
1466  const auto storage_info = findStorage(entry_buff_idx);
1467  auto crt_geo_col_ptr = geo_target_ptr;
1468  for (size_t i = slot_idx; i < slot_idx + range; i++) {
1469  crt_geo_col_ptr = advance_to_next_columnar_target_buff(
1470  crt_geo_col_ptr, storage_info.storage_ptr->query_mem_desc_, i);
1471  }
1472  // adjusting the column pointer to represent a pointer to the geo target value
1473  return crt_geo_col_ptr +
1474  storage_info.fixedup_entry_idx *
1475  storage_info.storage_ptr->query_mem_desc_.getPaddedSlotWidthBytes(
1476  slot_idx + range);
1477  };
1478 
1479  auto getNextTargetBuffer = [&](const size_t slot_idx, const size_t range) {
1481  ? getNextTargetBufferColWise(slot_idx, range)
1482  : getNextTargetBufferRowWise(slot_idx, range);
1483  };
1484 
1485  auto getCoordsDataPtr = [&](const int8_t* geo_target_ptr) {
1486  return read_int_from_buff(getNextTargetBuffer(slot_idx, 0),
1488  };
1489 
1490  auto getCoordsLength = [&](const int8_t* geo_target_ptr) {
1491  return read_int_from_buff(getNextTargetBuffer(slot_idx, 1),
1493  };
1494 
1495  auto getRingSizesPtr = [&](const int8_t* geo_target_ptr) {
1496  return read_int_from_buff(getNextTargetBuffer(slot_idx, 2),
1498  };
1499 
1500  auto getRingSizesLength = [&](const int8_t* geo_target_ptr) {
1501  return read_int_from_buff(getNextTargetBuffer(slot_idx, 3),
1503  };
1504 
1505  auto getPolyRingsPtr = [&](const int8_t* geo_target_ptr) {
1506  return read_int_from_buff(getNextTargetBuffer(slot_idx, 4),
1508  };
1509 
1510  auto getPolyRingsLength = [&](const int8_t* geo_target_ptr) {
1511  return read_int_from_buff(getNextTargetBuffer(slot_idx, 5),
1513  };
1514 
1515  auto getFragColBuffers = [&]() -> decltype(auto) {
1516  const auto storage_idx = getStorageIndex(entry_buff_idx);
1517  CHECK_LT(storage_idx.first, col_buffers_.size());
1518  auto global_idx = getCoordsDataPtr(geo_target_ptr);
1519  return getColumnFrag(storage_idx.first, target_logical_idx, global_idx);
1520  };
1521 
1522  const bool is_gpu_fetch = device_type_ == ExecutorDeviceType::GPU;
1523 
1524  auto getDataMgr = [&]() {
1525  auto executor = query_mem_desc_.getExecutor();
1526  CHECK(executor);
1527  auto& data_mgr = executor->catalog_->getDataMgr();
1528  return &data_mgr;
1529  };
1530 
1531  auto getSeparateVarlenStorage = [&]() -> decltype(auto) {
1532  const auto storage_idx = getStorageIndex(entry_buff_idx);
1533  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1534  const auto& varlen_buffer = serialized_varlen_buffer_[storage_idx.first];
1535  return varlen_buffer;
1536  };
1537 
1538  if (separate_varlen_storage_valid_ && getCoordsDataPtr(geo_target_ptr) < 0) {
1539  CHECK_EQ(-1, getCoordsDataPtr(geo_target_ptr));
1540  return TargetValue(nullptr);
1541  }
1542 
1543  const ColumnLazyFetchInfo* col_lazy_fetch = nullptr;
1544  if (!lazy_fetch_info_.empty()) {
1545  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1546  col_lazy_fetch = &lazy_fetch_info_[target_logical_idx];
1547  }
1548 
1549  switch (target_info.sql_type.get_type()) {
1550  case kPOINT: {
1551  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1552  const auto& varlen_buffer = getSeparateVarlenStorage();
1553  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr)),
1554  varlen_buffer.size());
1555 
1556  return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1557  target_info.sql_type,
1559  nullptr,
1560  false,
1561  device_id_,
1562  reinterpret_cast<int64_t>(
1563  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1564  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()));
1565  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1566  const auto& frag_col_buffers = getFragColBuffers();
1567  return GeoTargetValueBuilder<kPOINT, GeoLazyFetchHandler>::build(
1568  target_info.sql_type,
1570  frag_col_buffers[col_lazy_fetch->local_col_id],
1571  getCoordsDataPtr(geo_target_ptr));
1572  } else {
1573  return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1574  target_info.sql_type,
1576  is_gpu_fetch ? getDataMgr() : nullptr,
1577  is_gpu_fetch,
1578  device_id_,
1579  getCoordsDataPtr(geo_target_ptr),
1580  getCoordsLength(geo_target_ptr));
1581  }
1582  break;
1583  }
1584  case kLINESTRING: {
1585  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1586  const auto& varlen_buffer = getSeparateVarlenStorage();
1587  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr)),
1588  varlen_buffer.size());
1589 
1590  return GeoTargetValueBuilder<kLINESTRING, GeoQueryOutputFetchHandler>::build(
1591  target_info.sql_type,
1593  nullptr,
1594  false,
1595  device_id_,
1596  reinterpret_cast<int64_t>(
1597  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1598  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()));
1599  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1600  const auto& frag_col_buffers = getFragColBuffers();
1601  return GeoTargetValueBuilder<kLINESTRING, GeoLazyFetchHandler>::build(
1602  target_info.sql_type,
1604  frag_col_buffers[col_lazy_fetch->local_col_id],
1605  getCoordsDataPtr(geo_target_ptr));
1606  } else {
1607  return GeoTargetValueBuilder<kLINESTRING, GeoQueryOutputFetchHandler>::build(
1608  target_info.sql_type,
1610  is_gpu_fetch ? getDataMgr() : nullptr,
1611  is_gpu_fetch,
1612  device_id_,
1613  getCoordsDataPtr(geo_target_ptr),
1614  getCoordsLength(geo_target_ptr));
1615  }
1616  break;
1617  }
1618  case kPOLYGON: {
1619  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1620  const auto& varlen_buffer = getSeparateVarlenStorage();
1621  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr) + 1),
1622  varlen_buffer.size());
1623 
1624  return GeoTargetValueBuilder<kPOLYGON, GeoQueryOutputFetchHandler>::build(
1625  target_info.sql_type,
1627  nullptr,
1628  false,
1629  device_id_,
1630  reinterpret_cast<int64_t>(
1631  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1632  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()),
1633  reinterpret_cast<int64_t>(
1634  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].data()),
1635  static_cast<int64_t>(
1636  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].size()));
1637  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1638  const auto& frag_col_buffers = getFragColBuffers();
1639 
1640  return GeoTargetValueBuilder<kPOLYGON, GeoLazyFetchHandler>::build(
1641  target_info.sql_type,
1643  frag_col_buffers[col_lazy_fetch->local_col_id],
1644  getCoordsDataPtr(geo_target_ptr),
1645  frag_col_buffers[col_lazy_fetch->local_col_id + 1],
1646  getCoordsDataPtr(geo_target_ptr));
1647  } else {
1648  return GeoTargetValueBuilder<kPOLYGON, GeoQueryOutputFetchHandler>::build(
1649  target_info.sql_type,
1651  is_gpu_fetch ? getDataMgr() : nullptr,
1652  is_gpu_fetch,
1653  device_id_,
1654  getCoordsDataPtr(geo_target_ptr),
1655  getCoordsLength(geo_target_ptr),
1656  getRingSizesPtr(geo_target_ptr),
1657  getRingSizesLength(geo_target_ptr) * 4);
1658  }
1659  break;
1660  }
1661  case kMULTIPOLYGON: {
1662  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1663  const auto& varlen_buffer = getSeparateVarlenStorage();
1664  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr) + 2),
1665  varlen_buffer.size());
1666 
1667  return GeoTargetValueBuilder<kMULTIPOLYGON, GeoQueryOutputFetchHandler>::build(
1668  target_info.sql_type,
1670  nullptr,
1671  false,
1672  device_id_,
1673  reinterpret_cast<int64_t>(
1674  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1675  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()),
1676  reinterpret_cast<int64_t>(
1677  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].data()),
1678  static_cast<int64_t>(
1679  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].size()),
1680  reinterpret_cast<int64_t>(
1681  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 2].data()),
1682  static_cast<int64_t>(
1683  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 2].size()));
1684  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1685  const auto& frag_col_buffers = getFragColBuffers();
1686 
1687  return GeoTargetValueBuilder<kMULTIPOLYGON, GeoLazyFetchHandler>::build(
1688  target_info.sql_type,
1690  frag_col_buffers[col_lazy_fetch->local_col_id],
1691  getCoordsDataPtr(geo_target_ptr),
1692  frag_col_buffers[col_lazy_fetch->local_col_id + 1],
1693  getCoordsDataPtr(geo_target_ptr),
1694  frag_col_buffers[col_lazy_fetch->local_col_id + 2],
1695  getCoordsDataPtr(geo_target_ptr));
1696  } else {
1697  return GeoTargetValueBuilder<kMULTIPOLYGON, GeoQueryOutputFetchHandler>::build(
1698  target_info.sql_type,
1700  is_gpu_fetch ? getDataMgr() : nullptr,
1701  is_gpu_fetch,
1702  device_id_,
1703  getCoordsDataPtr(geo_target_ptr),
1704  getCoordsLength(geo_target_ptr),
1705  getRingSizesPtr(geo_target_ptr),
1706  getRingSizesLength(geo_target_ptr) * 4,
1707  getPolyRingsPtr(geo_target_ptr),
1708  getPolyRingsLength(geo_target_ptr) * 4);
1709  }
1710  break;
1711  }
1712  default:
1713  throw std::runtime_error("Unknown Geometry type encountered: " +
1714  target_info.sql_type.get_type_name());
1715  }
1716  UNREACHABLE();
1717  return TargetValue(nullptr);
1718 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:638
GeoReturnType geo_return_type_
Definition: ResultSet.h:769
T advance_to_next_columnar_target_buff(T target_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t target_slot_idx)
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
#define UNREACHABLE()
Definition: Logger.h:241
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:760
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
bool is_agg
Definition: TargetInfo.h:40
size_t getPaddedColWidthForRange(const size_t offset, const size_t range) const
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:663
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:747
#define CHECK_LT(x, y)
Definition: Logger.h:207
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:748
std::string get_type_name() const
Definition: sqltypes.h:417
const bool is_lazily_fetched
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
#define CHECK(condition)
Definition: Logger.h:197
bool is_geometry() const
Definition: sqltypes.h:500
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
const std::vector< const int8_t * > & getColumnFrag(const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
const Executor * getExecutor() const
const int device_id_
Definition: ResultSet.h:726

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TargetValue ResultSet::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
private

Definition at line 1721 of file ResultSetIteration.cpp.

References TargetInfo::agg_kind, calculateQuantile(), catalog_, CHECK, CHECK_EQ, CHECK_GE, CHECK_LT, col_buffers_, const, count_distinct_set_size(), decimal_to_int_type(), exp_to_scale(), QueryMemoryDescriptor::forceFourByteFloat(), get_compact_type(), getColumnFrag(), QueryMemoryDescriptor::getCountDistinctDescriptor(), getStorageIndex(), inline_int_null_val(), anonymous_namespace{ResultSetIteration.cpp}::int_resize_cast(), TargetInfo::is_agg, SQLTypeInfo::is_date_in_days(), is_distinct_target(), QueryMemoryDescriptor::isLogicalSizedColumnsAllowed(), kAPPROX_MEDIAN, kAVG, kBIGINT, kENCODING_DICT, kFLOAT, kMAX, kMIN, kSINGLE_VALUE, kSUM, result_set::lazy_decode(), lazy_fetch_info_, NULL_DOUBLE, NULL_INT, query_mem_desc_, read_int_from_buff(), row_set_mem_owner_, and TargetInfo::sql_type.

Referenced by getTargetValueFromBufferColwise(), and getTargetValueFromBufferRowwise().

1727  {
1728  auto actual_compact_sz = compact_sz;
1729  const auto& type_info = target_info.sql_type;
1730  if (type_info.get_type() == kFLOAT && !query_mem_desc_.forceFourByteFloat()) {
1732  actual_compact_sz = sizeof(float);
1733  } else {
1734  actual_compact_sz = sizeof(double);
1735  }
1736  if (target_info.is_agg &&
1737  (target_info.agg_kind == kAVG || target_info.agg_kind == kSUM ||
1738  target_info.agg_kind == kMIN || target_info.agg_kind == kMAX ||
1739  target_info.agg_kind == kSINGLE_VALUE)) {
1740  // The above listed aggregates use two floats in a single 8-byte slot. Set the
1741  // padded size to 4 bytes to properly read each value.
1742  actual_compact_sz = sizeof(float);
1743  }
1744  }
1745  if (get_compact_type(target_info).is_date_in_days()) {
1746  // Dates encoded in days are converted to 8 byte values on read.
1747  actual_compact_sz = sizeof(int64_t);
1748  }
1749 
1750  // String dictionary keys are read as 32-bit values regardless of encoding
1751  if (type_info.is_string() && type_info.get_compression() == kENCODING_DICT &&
1752  type_info.get_comp_param()) {
1753  actual_compact_sz = sizeof(int32_t);
1754  }
1755 
1756  auto ival = read_int_from_buff(ptr, actual_compact_sz);
1757  const auto& chosen_type = get_compact_type(target_info);
1758  if (!lazy_fetch_info_.empty()) {
1759  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1760  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
1761  if (col_lazy_fetch.is_lazily_fetched) {
1762  CHECK_GE(ival, 0);
1763  const auto storage_idx = getStorageIndex(entry_buff_idx);
1764  CHECK_LT(storage_idx.first, col_buffers_.size());
1765  auto& frag_col_buffers = getColumnFrag(storage_idx.first, target_logical_idx, ival);
1766  CHECK_LT(size_t(col_lazy_fetch.local_col_id), frag_col_buffers.size());
1767  ival = result_set::lazy_decode(
1768  col_lazy_fetch, frag_col_buffers[col_lazy_fetch.local_col_id], ival);
1769  if (chosen_type.is_fp()) {
1770  const auto dval = *reinterpret_cast<const double*>(may_alias_ptr(&ival));
1771  if (chosen_type.get_type() == kFLOAT) {
1772  return ScalarTargetValue(static_cast<float>(dval));
1773  } else {
1774  return ScalarTargetValue(dval);
1775  }
1776  }
1777  }
1778  }
1779  if (chosen_type.is_fp()) {
1780  if (target_info.agg_kind == kAPPROX_MEDIAN) {
1781  return *reinterpret_cast<double const*>(ptr) == NULL_DOUBLE
1782  ? NULL_DOUBLE // sql_validate / just_validate
1783  : calculateQuantile(*reinterpret_cast<quantile::TDigest* const*>(ptr),
1784  0.5);
1785  }
1786  switch (actual_compact_sz) {
1787  case 8: {
1788  const auto dval = *reinterpret_cast<const double*>(ptr);
1789  return chosen_type.get_type() == kFLOAT
1790  ? ScalarTargetValue(static_cast<const float>(dval))
1791  : ScalarTargetValue(dval);
1792  }
1793  case 4: {
1794  CHECK_EQ(kFLOAT, chosen_type.get_type());
1795  return *reinterpret_cast<const float*>(ptr);
1796  }
1797  default:
1798  CHECK(false);
1799  }
1800  }
1801  if (chosen_type.is_integer() | chosen_type.is_boolean() || chosen_type.is_time() ||
1802  chosen_type.is_timeinterval()) {
1803  if (is_distinct_target(target_info)) {
1805  ival, query_mem_desc_.getCountDistinctDescriptor(target_logical_idx)));
1806  }
1807  // TODO(alex): remove int_resize_cast, make read_int_from_buff return the
1808  // right type instead
1809  if (inline_int_null_val(chosen_type) ==
1810  int_resize_cast(ival, chosen_type.get_logical_size())) {
1811  return inline_int_null_val(type_info);
1812  }
1813  return ival;
1814  }
1815  if (chosen_type.is_string() && chosen_type.get_compression() == kENCODING_DICT) {
1816  if (translate_strings) {
1817  if (static_cast<int32_t>(ival) ==
1818  NULL_INT) { // TODO(alex): this isn't nice, fix it
1819  return NullableString(nullptr);
1820  }
1821  StringDictionaryProxy* sdp{nullptr};
1822  if (!chosen_type.get_comp_param()) {
1823  sdp = row_set_mem_owner_->getLiteralStringDictProxy();
1824  } else {
1825  sdp = catalog_
1826  ? row_set_mem_owner_->getOrAddStringDictProxy(
1827  chosen_type.get_comp_param(), /*with_generation=*/false, catalog_)
1828  : row_set_mem_owner_->getStringDictProxy(
1829  chosen_type.get_comp_param()); // unit tests bypass the catalog
1830  }
1831  return NullableString(sdp->getString(ival));
1832  } else {
1833  return static_cast<int64_t>(static_cast<int32_t>(ival));
1834  }
1835  }
1836  if (chosen_type.is_decimal()) {
1837  if (decimal_to_double) {
1838  if (target_info.is_agg &&
1839  (target_info.agg_kind == kAVG || target_info.agg_kind == kSUM ||
1840  target_info.agg_kind == kMIN || target_info.agg_kind == kMAX) &&
1841  ival == inline_int_null_val(SQLTypeInfo(kBIGINT, false))) {
1842  return NULL_DOUBLE;
1843  }
1844  if (ival ==
1845  inline_int_null_val(SQLTypeInfo(decimal_to_int_type(chosen_type), false))) {
1846  return NULL_DOUBLE;
1847  }
1848  return static_cast<double>(ival) / exp_to_scale(chosen_type.get_scale());
1849  }
1850  return ival;
1851  }
1852  CHECK(false);
1853  return TargetValue(int64_t(0));
1854 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:638
#define NULL_DOUBLE
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
bool isLogicalSizedColumnsAllowed() const
#define const
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:737
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
#define CHECK_GE(x, y)
Definition: Logger.h:210
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
#define NULL_INT
Definition: sqldefs.h:73
const SQLTypeInfo get_compact_type(const TargetInfo &target)
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
bool is_agg
Definition: TargetInfo.h:40
int64_t count_distinct_set_size(const int64_t set_handle, const CountDistinctDescriptor &count_distinct_desc)
Definition: CountDistinct.h:75
int64_t lazy_decode(const ColumnLazyFetchInfo &col_lazy_fetch, const int8_t *byte_stream, const int64_t pos)
Definition: sqldefs.h:75
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:130
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:747
SQLAgg agg_kind
Definition: TargetInfo.h:41
static double calculateQuantile(quantile::TDigest *const t_digest, double const q)
Definition: ResultSet.cpp:729
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:419
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:207
bool is_date_in_days() const
Definition: sqltypes.h:720
int64_t int_resize_cast(const int64_t ival, const size_t sz)
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:748
boost::variant< std::string, void * > NullableString
Definition: TargetValue.h:155
#define CHECK(condition)
Definition: Logger.h:197
uint64_t exp_to_scale(const unsigned exp)
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
Definition: sqldefs.h:74
Definition: sqldefs.h:72
const std::vector< const int8_t * > & getColumnFrag(const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
boost::variant< int64_t, double, float, NullableString > ScalarTargetValue
Definition: TargetValue.h:156

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TargetValue ResultSet::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
private

Definition at line 1297 of file ResultSetIteration.cpp.

References anonymous_namespace{ResultSetIteration.cpp}::build_array_target_value(), catalog_, CHECK, CHECK_EQ, CHECK_GE, CHECK_GT, CHECK_LT, ChunkIter_get_nth(), col_buffers_, copy_from_gpu(), device_id_, device_type_, SQLTypeInfo::get_array_context_logical_size(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_elem_type(), SQLTypeInfo::get_type(), getColumnFrag(), QueryMemoryDescriptor::getExecutor(), getStorageIndex(), GPU, TargetInfo::is_agg, SQLTypeInfo::is_array(), VarlenDatum::is_null, SQLTypeInfo::is_string(), kARRAY, kENCODING_NONE, lazy_fetch_info_, VarlenDatum::length, run_benchmark_import::optional, VarlenDatum::pointer, query_mem_desc_, read_int_from_buff(), row_set_mem_owner_, separate_varlen_storage_valid_, serialized_varlen_buffer_, and TargetInfo::sql_type.

Referenced by getTargetValueFromBufferColwise(), and getTargetValueFromBufferRowwise().

1304  {
1305  auto varlen_ptr = read_int_from_buff(ptr1, compact_sz1);
1306  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1307  if (varlen_ptr < 0) {
1308  CHECK_EQ(-1, varlen_ptr);
1309  if (target_info.sql_type.get_type() == kARRAY) {
1310  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1311  }
1312  return TargetValue(nullptr);
1313  }
1314  const auto storage_idx = getStorageIndex(entry_buff_idx);
1315  if (target_info.sql_type.is_string()) {
1316  CHECK(target_info.sql_type.get_compression() == kENCODING_NONE);
1317  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1318  const auto& varlen_buffer_for_storage =
1319  serialized_varlen_buffer_[storage_idx.first];
1320  CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer_for_storage.size());
1321  return varlen_buffer_for_storage[varlen_ptr];
1322  } else if (target_info.sql_type.get_type() == kARRAY) {
1323  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1324  const auto& varlen_buffer = serialized_varlen_buffer_[storage_idx.first];
1325  CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer.size());
1326 
1327  return build_array_target_value(
1328  target_info.sql_type,
1329  reinterpret_cast<const int8_t*>(varlen_buffer[varlen_ptr].data()),
1330  varlen_buffer[varlen_ptr].size(),
1331  translate_strings,
1333  catalog_);
1334  } else {
1335  CHECK(false);
1336  }
1337  }
1338  if (!lazy_fetch_info_.empty()) {
1339  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1340  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
1341  if (col_lazy_fetch.is_lazily_fetched) {
1342  const auto storage_idx = getStorageIndex(entry_buff_idx);
1343  CHECK_LT(storage_idx.first, col_buffers_.size());
1344  auto& frag_col_buffers =
1345  getColumnFrag(storage_idx.first, target_logical_idx, varlen_ptr);
1346  bool is_end{false};
1347  if (target_info.sql_type.is_string()) {
1348  VarlenDatum vd;
1349  ChunkIter_get_nth(reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(
1350  frag_col_buffers[col_lazy_fetch.local_col_id])),
1351  varlen_ptr,
1352  false,
1353  &vd,
1354  &is_end);
1355  CHECK(!is_end);
1356  if (vd.is_null) {
1357  return TargetValue(nullptr);
1358  }
1359  CHECK(vd.pointer);
1360  CHECK_GT(vd.length, 0u);
1361  std::string fetched_str(reinterpret_cast<char*>(vd.pointer), vd.length);
1362  return fetched_str;
1363  } else {
1364  CHECK(target_info.sql_type.is_array());
1365  ArrayDatum ad;
1366  ChunkIter_get_nth(reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(
1367  frag_col_buffers[col_lazy_fetch.local_col_id])),
1368  varlen_ptr,
1369  &ad,
1370  &is_end);
1371  CHECK(!is_end);
1372  if (ad.is_null) {
1373  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1374  }
1375  CHECK_GE(ad.length, 0u);
1376  if (ad.length > 0) {
1377  CHECK(ad.pointer);
1378  }
1379  return build_array_target_value(target_info.sql_type,
1380  ad.pointer,
1381  ad.length,
1382  translate_strings,
1384  catalog_);
1385  }
1386  }
1387  }
1388  if (!varlen_ptr) {
1389  if (target_info.sql_type.is_array()) {
1390  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1391  }
1392  return TargetValue(nullptr);
1393  }
1394  auto length = read_int_from_buff(ptr2, compact_sz2);
1395  if (target_info.sql_type.is_array()) {
1396  const auto& elem_ti = target_info.sql_type.get_elem_type();
1397  length *= elem_ti.get_array_context_logical_size();
1398  }
1399  std::vector<int8_t> cpu_buffer;
1400  if (varlen_ptr && device_type_ == ExecutorDeviceType::GPU) {
1401  cpu_buffer.resize(length);
1402  const auto executor = query_mem_desc_.getExecutor();
1403  CHECK(executor);
1404  auto& data_mgr = executor->catalog_->getDataMgr();
1405  copy_from_gpu(&data_mgr,
1406  &cpu_buffer[0],
1407  static_cast<CUdeviceptr>(varlen_ptr),
1408  length,
1409  device_id_);
1410  varlen_ptr = reinterpret_cast<int64_t>(&cpu_buffer[0]);
1411  }
1412  if (target_info.sql_type.is_array()) {
1413  return build_array_target_value(target_info.sql_type,
1414  reinterpret_cast<const int8_t*>(varlen_ptr),
1415  length,
1416  translate_strings,
1418  catalog_);
1419  }
1420  return std::string(reinterpret_cast<char*>(varlen_ptr), length);
1421 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:638
bool is_null
Definition: sqltypes.h:147
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:737
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
#define CHECK_GE(x, y)
Definition: Logger.h:210
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:760
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
#define CHECK_GT(x, y)
Definition: Logger.h:209
DEVICE void ChunkIter_get_nth(ChunkIter *it, int n, bool uncompress, VarlenDatum *result, bool *is_end)
Definition: ChunkIter.cpp:181
TargetValue build_array_target_value(const int8_t *buff, const size_t buff_sz, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
int8_t * pointer
Definition: sqltypes.h:146
std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:202
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:734
bool is_agg
Definition: TargetInfo.h:40
void copy_from_gpu(Data_Namespace::DataMgr *data_mgr, void *dst, const CUdeviceptr src, const size_t num_bytes, const int device_id)
boost::optional< std::vector< ScalarTargetValue >> ArrayTargetValue
Definition: TargetValue.h:157
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:747
#define CHECK_LT(x, y)
Definition: Logger.h:207
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
int get_array_context_logical_size() const
Definition: sqltypes.h:551
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:748
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
#define CHECK(condition)
Definition: Logger.h:197
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
bool is_string() const
Definition: sqltypes.h:488
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:712
bool is_array() const
Definition: sqltypes.h:496
const std::vector< const int8_t * > & getColumnFrag(const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
const Executor * getExecutor() const
size_t length
Definition: sqltypes.h:145
const int device_id_
Definition: ResultSet.h:726

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSet::moveToBegin ( ) const

Definition at line 461 of file ResultSet.cpp.

461  {
462  crt_row_buff_idx_ = 0;
463  fetched_so_far_ = 0;
464 }
size_t fetched_so_far_
Definition: ResultSet.h:731
size_t crt_row_buff_idx_
Definition: ResultSet.h:730
size_t ResultSet::parallelRowCount ( ) const
private

Definition at line 362 of file ResultSet.cpp.

References gpu_enabled::accumulate(), cpu_threads(), g_use_tbb_pool, anonymous_namespace{ResultSet.cpp}::get_truncated_row_count(), and i.

362  {
363  auto execute_parallel_row_count = [this](auto counter_threads) -> size_t {
364  const size_t worker_count = cpu_threads();
365  for (size_t i = 0,
366  start_entry = 0,
367  stride = (entryCount() + worker_count - 1) / worker_count;
368  i < worker_count && start_entry < entryCount();
369  ++i, start_entry += stride) {
370  const auto end_entry = std::min(start_entry + stride, entryCount());
371  counter_threads.spawn(
372  [this](const size_t start, const size_t end) {
373  size_t row_count{0};
374  for (size_t i = start; i < end; ++i) {
375  if (!isRowAtEmpty(i)) {
376  ++row_count;
377  }
378  }
379  return row_count;
380  },
381  start_entry,
382  end_entry);
383  }
384  const auto row_counts = counter_threads.join();
385  const size_t row_count = std::accumulate(row_counts.begin(), row_counts.end(), 0);
386  return row_count;
387  };
388  // will fall back to futures threadpool if TBB is not enabled
389  const auto row_count =
391  ? execute_parallel_row_count(threadpool::ThreadPool<size_t>())
392  : execute_parallel_row_count(threadpool::FuturesThreadPool<size_t>());
393 
394  return get_truncated_row_count(row_count, getLimit(), drop_first_);
395 }
size_t getLimit() const
Definition: ResultSet.cpp:1013
size_t get_truncated_row_count(size_t total_row_count, size_t limit, size_t offset)
Definition: ResultSet.cpp:288
size_t drop_first_
Definition: ResultSet.h:732
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
bool isRowAtEmpty(const size_t index) const
size_t entryCount() const
int cpu_threads()
Definition: thread_count.h:24
bool g_use_tbb_pool
Definition: Execute.cpp:78

+ Here is the call graph for this function:

void ResultSet::parallelTop ( const std::list< Analyzer::OrderEntry > &  order_entries,
const size_t  top_n,
const Executor executor 
)
private

Definition at line 596 of file ResultSet.cpp.

References gpu_enabled::copy(), cpu_threads(), DEBUG_TIMER, i, threadpool::FuturesThreadPool< T, ENABLE >::join(), and threadpool::FuturesThreadPoolBase< T >::spawn().

598  {
599  auto timer = DEBUG_TIMER(__func__);
600  const size_t nthreads = cpu_threads();
601 
602  // Split permutation_ into nthreads subranges and top-sort in-place.
604  std::vector<PermutationView> permutation_views(nthreads);
605  const auto top_sort_interval = [&, top_n, executor](const auto interval) {
606  PermutationView pv(permutation_.data() + interval.begin, 0, interval.size());
607  pv = initPermutationBuffer(pv, interval.begin, interval.end);
608  const auto compare = createComparator(order_entries, pv, executor, true);
609  permutation_views[interval.index] = topPermutation(pv, top_n, compare);
610  };
611  threadpool::FuturesThreadPool<void> top_sort_threads;
612  for (auto interval : makeIntervals<PermutationIdx>(0, permutation_.size(), nthreads)) {
613  top_sort_threads.spawn(top_sort_interval, interval);
614  }
615  top_sort_threads.join();
616 
617  // In case you are considering implementing a parallel reduction, note that the
618  // ResultSetComparator constructor is O(N) in order to materialize some of the aggregate
619  // columns as necessary to perform a comparison. This cost is why reduction is chosen to
620  // be serial instead; only one more Comparator is needed below.
621 
622  // Left-copy disjoint top-sorted subranges into one contiguous range.
623  // ++++....+++.....+++++... -> ++++++++++++............
624  auto end = permutation_.begin() + permutation_views.front().size();
625  for (size_t i = 1; i < nthreads; ++i) {
626  std::copy(permutation_views[i].begin(), permutation_views[i].end(), end);
627  end += permutation_views[i].size();
628  }
629 
630  // Top sort final range.
631  PermutationView pv(permutation_.data(), end - permutation_.begin());
632  const auto compare = createComparator(order_entries, pv, executor, false);
633  pv = topPermutation(pv, top_n, compare);
634  permutation_.resize(pv.size());
635  permutation_.shrink_to_fit();
636 }
Permutation permutation_
Definition: ResultSet.h:735
PermutationView initPermutationBuffer(PermutationView permutation, PermutationIdx const begin, PermutationIdx const end) const
Definition: ResultSet.cpp:576
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
DEVICE auto copy(ARGS &&...args)
Definition: gpu_enabled.h:51
Comparator createComparator(const std::list< Analyzer::OrderEntry > &order_entries, const PermutationView permutation, const Executor *executor, const bool single_threaded)
Definition: ResultSet.h:660
void spawn(Function &&f, Args &&...args)
Definition: threadpool.h:33
static PermutationView topPermutation(PermutationView, const size_t n, const Comparator &)
Definition: ResultSet.cpp:922
#define DEBUG_TIMER(name)
Definition: Logger.h:313
int cpu_threads()
Definition: thread_count.h:24

+ Here is the call graph for this function:

void ResultSet::radixSortOnCpu ( const std::list< Analyzer::OrderEntry > &  order_entries) const
private

Definition at line 973 of file ResultSet.cpp.

References apply_permutation_cpu(), CHECK, CHECK_EQ, DEBUG_TIMER, and sort_groups_cpu().

974  {
975  auto timer = DEBUG_TIMER(__func__);
977  std::vector<int64_t> tmp_buff(query_mem_desc_.getEntryCount());
978  std::vector<int32_t> idx_buff(query_mem_desc_.getEntryCount());
979  CHECK_EQ(size_t(1), order_entries.size());
980  auto buffer_ptr = storage_->getUnderlyingBuffer();
981  for (const auto& order_entry : order_entries) {
982  const auto target_idx = order_entry.tle_no - 1;
983  const auto sortkey_val_buff = reinterpret_cast<int64_t*>(
984  buffer_ptr + query_mem_desc_.getColOffInBytes(target_idx));
985  const auto chosen_bytes = query_mem_desc_.getPaddedSlotWidthBytes(target_idx);
986  sort_groups_cpu(sortkey_val_buff,
987  &idx_buff[0],
989  order_entry.is_desc,
990  chosen_bytes);
991  apply_permutation_cpu(reinterpret_cast<int64_t*>(buffer_ptr),
992  &idx_buff[0],
994  &tmp_buff[0],
995  sizeof(int64_t));
996  for (size_t target_idx = 0; target_idx < query_mem_desc_.getSlotCount();
997  ++target_idx) {
998  if (static_cast<int>(target_idx) == order_entry.tle_no - 1) {
999  continue;
1000  }
1001  const auto chosen_bytes = query_mem_desc_.getPaddedSlotWidthBytes(target_idx);
1002  const auto satellite_val_buff = reinterpret_cast<int64_t*>(
1003  buffer_ptr + query_mem_desc_.getColOffInBytes(target_idx));
1004  apply_permutation_cpu(satellite_val_buff,
1005  &idx_buff[0],
1007  &tmp_buff[0],
1008  chosen_bytes);
1009  }
1010  }
1011 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
void sort_groups_cpu(int64_t *val_buff, int32_t *idx_buff, const uint64_t entry_count, const bool desc, const uint32_t chosen_bytes)
Definition: InPlaceSort.cpp:27
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
void apply_permutation_cpu(int64_t *val_buff, int32_t *idx_buff, const uint64_t entry_count, int64_t *tmp_buff, const uint32_t chosen_bytes)
Definition: InPlaceSort.cpp:46
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK(condition)
Definition: Logger.h:197
#define DEBUG_TIMER(name)
Definition: Logger.h:313
size_t getColOffInBytes(const size_t col_idx) const

+ Here is the call graph for this function:

void ResultSet::radixSortOnGpu ( const std::list< Analyzer::OrderEntry > &  order_entries) const
private

Definition at line 936 of file ResultSet.cpp.

References catalog_(), CHECK_GT, copy_group_by_buffers_from_gpu(), create_dev_group_by_buffers(), DEBUG_TIMER, GPU, inplace_sort_gpu(), and KernelPerFragment.

937  {
938  auto timer = DEBUG_TIMER(__func__);
939  auto data_mgr = &catalog_->getDataMgr();
940  const int device_id{0};
941  CudaAllocator cuda_allocator(data_mgr, device_id);
942  CHECK_GT(block_size_, 0);
943  CHECK_GT(grid_size_, 0);
944  std::vector<int64_t*> group_by_buffers(block_size_);
945  group_by_buffers[0] = reinterpret_cast<int64_t*>(storage_->getUnderlyingBuffer());
946  auto dev_group_by_buffers =
947  create_dev_group_by_buffers(&cuda_allocator,
948  group_by_buffers,
950  block_size_,
951  grid_size_,
952  device_id,
954  -1,
955  true,
956  true,
957  false,
958  nullptr);
960  order_entries, query_mem_desc_, dev_group_by_buffers, data_mgr, device_id);
962  data_mgr,
963  group_by_buffers,
965  dev_group_by_buffers.second,
967  block_size_,
968  grid_size_,
969  device_id,
970  false);
971 }
size_t getBufferSizeBytes(const RelAlgExecutionUnit &ra_exe_unit, const unsigned thread_count, const ExecutorDeviceType device_type) const
GpuGroupByBuffers create_dev_group_by_buffers(DeviceAllocator *cuda_allocator, const std::vector< int64_t * > &group_by_buffers, const QueryMemoryDescriptor &query_mem_desc, const unsigned block_size_x, const unsigned grid_size_x, const int device_id, const ExecutorDispatchMode dispatch_mode, const int64_t num_input_rows, const bool prepend_index_buffer, const bool always_init_group_by_on_host, const bool use_bump_allocator, Allocator *insitu_allocator)
Definition: GpuMemUtils.cpp:60
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:222
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:737
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
void inplace_sort_gpu(const std::list< Analyzer::OrderEntry > &order_entries, const QueryMemoryDescriptor &query_mem_desc, const GpuGroupByBuffers &group_by_buffers, Data_Namespace::DataMgr *data_mgr, const int device_id)
#define CHECK_GT(x, y)
Definition: Logger.h:209
unsigned block_size_
Definition: ResultSet.h:738
unsigned grid_size_
Definition: ResultSet.h:739
void copy_group_by_buffers_from_gpu(Data_Namespace::DataMgr *data_mgr, const std::vector< int64_t * > &group_by_buffers, const size_t groups_buffer_size, const CUdeviceptr group_by_dev_buffers_mem, const QueryMemoryDescriptor &query_mem_desc, const unsigned block_size_x, const unsigned grid_size_x, const int device_id, const bool prepend_index_buffer)
#define DEBUG_TIMER(name)
Definition: Logger.h:313

+ Here is the call graph for this function:

size_t ResultSet::rowCount ( const bool  force_parallel = false) const

Definition at line 304 of file ResultSet.cpp.

References CHECK_GE, and Projection.

304  {
305  if (just_explain_) {
306  return 1;
307  }
308  if (!permutation_.empty()) {
309  if (drop_first_ > permutation_.size()) {
310  return 0;
311  }
312  const auto limited_row_count = keep_first_ + drop_first_;
313  return limited_row_count ? std::min(limited_row_count, permutation_.size())
314  : permutation_.size();
315  }
316  if (cached_row_count_ != -1) {
318  return cached_row_count_;
319  }
320  if (!storage_) {
321  return 0;
322  }
323  if (permutation_.empty() &&
325  return binSearchRowCount();
326  }
327  if (force_parallel || entryCount() > 20000) {
328  return parallelRowCount();
329  }
330  std::lock_guard<std::mutex> lock(row_iteration_mutex_);
331  moveToBegin();
332  size_t row_count{0};
333  while (true) {
334  auto crt_row = getNextRowUnlocked(false, false);
335  if (crt_row.empty()) {
336  break;
337  }
338  ++row_count;
339  }
340  moveToBegin();
341  return row_count;
342 }
std::mutex row_iteration_mutex_
Definition: ResultSet.h:766
Permutation permutation_
Definition: ResultSet.h:735
void moveToBegin() const
Definition: ResultSet.cpp:461
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
#define CHECK_GE(x, y)
Definition: Logger.h:210
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
size_t keep_first_
Definition: ResultSet.h:733
const bool just_explain_
Definition: ResultSet.h:763
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
size_t parallelRowCount() const
Definition: ResultSet.cpp:362
size_t drop_first_
Definition: ResultSet.h:732
QueryDescriptionType getQueryDescriptionType() const
size_t entryCount() const
std::vector< TargetValue > getNextRowUnlocked(const bool translate_strings, const bool decimal_to_double) const
size_t binSearchRowCount() const
Definition: ResultSet.cpp:349
ResultSetRowIterator ResultSet::rowIterator ( size_t  from_logical_index,
bool  translate_strings,
bool  decimal_to_double 
) const
inline

Definition at line 196 of file ResultSet.h.

Referenced by rowIterator().

198  {
199  ResultSetRowIterator rowIterator(this, translate_strings, decimal_to_double);
200 
201  // move to first logical position
202  ++rowIterator;
203 
204  for (size_t index = 0; index < from_logical_index; index++) {
205  ++rowIterator;
206  }
207 
208  return rowIterator;
209  }
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
ResultSetRowIterator rowIterator(size_t from_logical_index, bool translate_strings, bool decimal_to_double) const
Definition: ResultSet.h:196

+ Here is the caller graph for this function:

ResultSetRowIterator ResultSet::rowIterator ( bool  translate_strings,
bool  decimal_to_double 
) const
inline

Definition at line 211 of file ResultSet.h.

References rowIterator().

212  {
213  return rowIterator(0, translate_strings, decimal_to_double);
214  }
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
ResultSetRowIterator rowIterator(size_t from_logical_index, bool translate_strings, bool decimal_to_double) const
Definition: ResultSet.h:196

+ Here is the call graph for this function:

void ResultSet::serialize ( TSerializedRows &  serialized_rows) const
void ResultSet::serializeCountDistinctColumns ( TSerializedRows &  ) const
private
void ResultSet::serializeProjection ( TSerializedRows &  serialized_rows) const
private
void ResultSet::serializeVarlenAggColumn ( int8_t *  buf,
std::vector< std::string > &  varlen_bufer 
) const
private
void ResultSet::setCachedRowCount ( const size_t  row_count) const

Definition at line 344 of file ResultSet.cpp.

References CHECK.

344  {
345  CHECK(cached_row_count_ == -1 || cached_row_count_ == static_cast<int64_t>(row_count));
346  cached_row_count_ = row_count;
347 }
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
#define CHECK(condition)
Definition: Logger.h:197
void ResultSet::setGeoReturnType ( const GeoReturnType  val)
inline

Definition at line 381 of file ResultSet.h.

References geo_return_type_.

381 { geo_return_type_ = val; }
GeoReturnType geo_return_type_
Definition: ResultSet.h:769
void ResultSet::setKernelQueueTime ( const int64_t  kernel_queue_time)

Definition at line 444 of file ResultSet.cpp.

444  {
445  timings_.kernel_queue_time = kernel_queue_time;
446 }
QueryExecutionTimings timings_
Definition: ResultSet.h:740
void ResultSet::setQueueTime ( const int64_t  queue_time)

Definition at line 440 of file ResultSet.cpp.

440  {
441  timings_.executor_queue_time = queue_time;
442 }
QueryExecutionTimings timings_
Definition: ResultSet.h:740
void ResultSet::setSeparateVarlenStorageValid ( const bool  val)
inline

Definition at line 413 of file ResultSet.h.

References separate_varlen_storage_valid_.

413  {
415  }
bool separate_varlen_storage_valid_
Definition: ResultSet.h:761
void ResultSet::setValidationOnlyRes ( )

Definition at line 474 of file ResultSet.cpp.

474  {
475  for_validation_only_ = true;
476 }
bool for_validation_only_
Definition: ResultSet.h:764
void ResultSet::sort ( const std::list< Analyzer::OrderEntry > &  order_entries,
size_t  top_n,
const Executor executor 
)

Definition at line 498 of file ResultSet.cpp.

References Executor::baseline_threshold, CHECK, CHECK_EQ, DEBUG_TIMER, g_enable_watchdog, g_parallel_top_max, g_parallel_top_min, LOG, VectorView< T >::size(), and logger::WARNING.

500  {
501  auto timer = DEBUG_TIMER(__func__);
502 
503  if (!storage_) {
504  return;
505  }
507  CHECK(!targets_.empty());
508 #ifdef HAVE_CUDA
509  if (canUseFastBaselineSort(order_entries, top_n)) {
510  baselineSort(order_entries, top_n, executor);
511  return;
512  }
513 #endif // HAVE_CUDA
514  if (query_mem_desc_.sortOnGpu()) {
515  try {
516  radixSortOnGpu(order_entries);
517  } catch (const OutOfMemory&) {
518  LOG(WARNING) << "Out of GPU memory during sort, finish on CPU";
519  radixSortOnCpu(order_entries);
520  } catch (const std::bad_alloc&) {
521  LOG(WARNING) << "Out of GPU memory during sort, finish on CPU";
522  radixSortOnCpu(order_entries);
523  }
524  return;
525  }
526  // This check isn't strictly required, but allows the index buffer to be 32-bit.
527  if (query_mem_desc_.getEntryCount() > std::numeric_limits<uint32_t>::max()) {
528  throw RowSortException("Sorting more than 4B elements not supported");
529  }
530 
531  CHECK(permutation_.empty());
532 
533  if (top_n && g_parallel_top_min < entryCount()) {
535  throw WatchdogException("Sorting the result would be too slow");
536  }
537  parallelTop(order_entries, top_n, executor);
538  } else {
540  throw WatchdogException("Sorting the result would be too slow");
541  }
543  // PermutationView is used to share common API with parallelTop().
544  PermutationView pv(permutation_.data(), 0, permutation_.size());
545  pv = initPermutationBuffer(pv, 0, permutation_.size());
546  if (top_n == 0) {
547  top_n = pv.size(); // top_n == 0 implies a full sort
548  }
549  pv = topPermutation(pv, top_n, createComparator(order_entries, pv, executor, false));
550  if (pv.size() < permutation_.size()) {
551  permutation_.resize(pv.size());
552  permutation_.shrink_to_fit();
553  }
554  }
555 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
size_t g_parallel_top_max
Definition: ResultSet.cpp:48
Permutation permutation_
Definition: ResultSet.h:735
bool g_enable_watchdog
PermutationView initPermutationBuffer(PermutationView permutation, PermutationIdx const begin, PermutationIdx const end) const
Definition: ResultSet.cpp:576
#define LOG(tag)
Definition: Logger.h:188
static const size_t baseline_threshold
Definition: Execute.h:1043
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
void parallelTop(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n, const Executor *executor)
Definition: ResultSet.cpp:596
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:765
void radixSortOnCpu(const std::list< Analyzer::OrderEntry > &order_entries) const
Definition: ResultSet.cpp:973
size_t g_parallel_top_min
Definition: ResultSet.cpp:47
DEVICE size_type size() const
Definition: VectorView.h:84
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:724
bool canUseFastBaselineSort(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
Comparator createComparator(const std::list< Analyzer::OrderEntry > &order_entries, const PermutationView permutation, const Executor *executor, const bool single_threaded)
Definition: ResultSet.h:660
void radixSortOnGpu(const std::list< Analyzer::OrderEntry > &order_entries) const
Definition: ResultSet.cpp:936
size_t entryCount() const
void baselineSort(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n, const Executor *executor)
static PermutationView topPermutation(PermutationView, const size_t n, const Comparator &)
Definition: ResultSet.cpp:922
#define CHECK(condition)
Definition: Logger.h:197
#define DEBUG_TIMER(name)
Definition: Logger.h:313

+ Here is the call graph for this function:

void ResultSet::syncEstimatorBuffer ( ) const

Definition at line 425 of file ResultSet.cpp.

References CHECK, CHECK_EQ, checked_calloc(), copy_from_gpu(), and GPU.

425  {
428  CHECK_EQ(size_t(0), estimator_->getBufferSize() % sizeof(int64_t));
430  static_cast<int8_t*>(checked_calloc(estimator_->getBufferSize(), 1));
432  auto device_buffer_ptr = device_estimator_buffer_->getMemoryPtr();
435  reinterpret_cast<CUdeviceptr>(device_buffer_ptr),
436  estimator_->getBufferSize(),
437  device_id_);
438 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
virtual int8_t * getMemoryPtr()=0
void copy_from_gpu(Data_Namespace::DataMgr *data_mgr, void *dst, const CUdeviceptr src, const size_t num_bytes, const int device_id)
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:53
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:755
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:752
int8_t * host_estimator_buffer_
Definition: ResultSet.h:754
const ExecutorDeviceType device_type_
Definition: ResultSet.h:725
#define CHECK(condition)
Definition: Logger.h:197
Data_Namespace::AbstractBuffer * device_estimator_buffer_
Definition: ResultSet.h:753
const int device_id_
Definition: ResultSet.h:726

+ Here is the call graph for this function:

PermutationView ResultSet::topPermutation ( PermutationView  permutation,
const size_t  n,
const Comparator compare 
)
staticprivate

Definition at line 922 of file ResultSet.cpp.

References VectorView< T >::begin(), DEBUG_TIMER, VectorView< T >::end(), VectorView< T >::resize(), VectorView< T >::size(), and gpu_enabled::sort().

924  {
925  auto timer = DEBUG_TIMER(__func__);
926  if (n < permutation.size()) {
927  std::partial_sort(
928  permutation.begin(), permutation.begin() + n, permutation.end(), compare);
929  permutation.resize(n);
930  } else {
931  std::sort(permutation.begin(), permutation.end(), compare);
932  }
933  return permutation;
934 }
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
DEVICE void resize(size_type const size)
Definition: VectorView.h:75
DEVICE size_type size() const
Definition: VectorView.h:84
DEVICE T * begin() const
Definition: VectorView.h:60
#define DEBUG_TIMER(name)
Definition: Logger.h:313
DEVICE T * end() const
Definition: VectorView.h:68

+ Here is the call graph for this function:

static std::unique_ptr<ResultSet> ResultSet::unserialize ( const TSerializedRows &  serialized_rows,
const Executor  
)
static
void ResultSet::unserializeCountDistinctColumns ( const TSerializedRows &  )
private
void ResultSet::updateStorageEntryCount ( const size_t  new_entry_count)
inline

Definition at line 224 of file ResultSet.h.

References CHECK, QueryMemoryDescriptor::getQueryDescriptionType(), Projection, query_mem_desc_, QueryMemoryDescriptor::setEntryCount(), and storage_.

224  {
226  query_mem_desc_.setEntryCount(new_entry_count);
227  CHECK(storage_);
228  storage_->updateEntryCount(new_entry_count);
229  }
void setEntryCount(const size_t val)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:727
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:728
QueryDescriptionType getQueryDescriptionType() const
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class ColumnarResults
friend

Definition at line 773 of file ResultSet.h.

friend class ResultSetManager
friend

Definition at line 771 of file ResultSet.h.

friend class ResultSetRowIterator
friend

Definition at line 772 of file ResultSet.h.

Member Data Documentation

AppendedStorage ResultSet::appended_storage_
private

Definition at line 729 of file ResultSet.h.

Referenced by copyColumnIntoBuffer().

unsigned ResultSet::block_size_ {0}
private

Definition at line 738 of file ResultSet.h.

std::atomic<int64_t> ResultSet::cached_row_count_
mutableprivate

Definition at line 765 of file ResultSet.h.

const Catalog_Namespace::Catalog* ResultSet::catalog_
private

Definition at line 737 of file ResultSet.h.

Referenced by makeTargetValue(), and makeVarlenTargetValue().

std::vector<std::shared_ptr<std::list<ChunkIter> > > ResultSet::chunk_iters_
private

Definition at line 743 of file ResultSet.h.

Referenced by holdChunkIterators().

std::list<std::shared_ptr<Chunk_NS::Chunk> > ResultSet::chunks_
private

Definition at line 742 of file ResultSet.h.

Referenced by holdChunks().

std::vector<std::vector<std::vector<const int8_t*> > > ResultSet::col_buffers_
private
std::vector<std::vector<int64_t> > ResultSet::consistent_frag_sizes_
private

Definition at line 750 of file ResultSet.h.

Referenced by getColumnFrag().

size_t ResultSet::crt_row_buff_idx_
mutableprivate

Definition at line 730 of file ResultSet.h.

Data_Namespace::DataMgr* ResultSet::data_mgr_
private

Definition at line 755 of file ResultSet.h.

Data_Namespace::AbstractBuffer* ResultSet::device_estimator_buffer_ {nullptr}
private

Definition at line 753 of file ResultSet.h.

const int ResultSet::device_id_
private

Definition at line 726 of file ResultSet.h.

Referenced by getVarlenOrderEntry(), makeGeoTargetValue(), and makeVarlenTargetValue().

const ExecutorDeviceType ResultSet::device_type_
private
size_t ResultSet::drop_first_
private

Definition at line 732 of file ResultSet.h.

const std::shared_ptr<const Analyzer::Estimator> ResultSet::estimator_
private

Definition at line 752 of file ResultSet.h.

std::string ResultSet::explanation_
private

Definition at line 762 of file ResultSet.h.

Referenced by getExplanation().

size_t ResultSet::fetched_so_far_
mutableprivate

Definition at line 731 of file ResultSet.h.

bool ResultSet::for_validation_only_
private

Definition at line 764 of file ResultSet.h.

std::vector<std::vector<std::vector<int64_t> > > ResultSet::frag_offsets_
private

Definition at line 749 of file ResultSet.h.

Referenced by getColumnFrag().

GeoReturnType ResultSet::geo_return_type_
mutableprivate

Definition at line 769 of file ResultSet.h.

Referenced by getGeoReturnType(), makeGeoTargetValue(), and setGeoReturnType().

unsigned ResultSet::grid_size_ {0}
private

Definition at line 739 of file ResultSet.h.

int8_t* ResultSet::host_estimator_buffer_ {nullptr}
mutableprivate

Definition at line 754 of file ResultSet.h.

const bool ResultSet::just_explain_
private

Definition at line 763 of file ResultSet.h.

Referenced by getExplanation().

size_t ResultSet::keep_first_
private

Definition at line 733 of file ResultSet.h.

const std::vector<ColumnLazyFetchInfo> ResultSet::lazy_fetch_info_
private
std::vector<std::vector<int8_t> > ResultSet::literal_buffers_
private

Definition at line 746 of file ResultSet.h.

Referenced by holdLiterals().

Permutation ResultSet::permutation_
private

Definition at line 735 of file ResultSet.h.

Referenced by entryCount(), and isPermutationBufferEmpty().

friend ResultSet::ResultSetBuilder

Definition at line 159 of file ResultSet.h.

std::mutex ResultSet::row_iteration_mutex_
mutableprivate

Definition at line 766 of file ResultSet.h.

std::shared_ptr<RowSetMemoryOwner> ResultSet::row_set_mem_owner_
private
bool ResultSet::separate_varlen_storage_valid_
private
std::vector<SerializedVarlenBufferStorage> ResultSet::serialized_varlen_buffer_
private

Definition at line 760 of file ResultSet.h.

Referenced by makeGeoTargetValue(), and makeVarlenTargetValue().

const std::vector<TargetInfo> ResultSet::targets_
private

Definition at line 724 of file ResultSet.h.

Referenced by ResultSetStorage::isEmptyEntryColumnar(), isGeoColOnGpu(), and lazyReadInt().

QueryExecutionTimings ResultSet::timings_
private

Definition at line 740 of file ResultSet.h.


The documentation for this class was generated from the following files: