OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 ()
 
std::string toString () const
 
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 > &, std::shared_ptr< VarlenOutputInfo >=nullptr) 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
 
bool isEmpty () 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)
 

Public Attributes

friend ResultSetBuilder
 

Private Types

using ApproxQuantileBuffers = 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 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
 
const VarlenOutputInfogetVarlenOutputInfo (const size_t entry_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::ApproxQuantileBuffers = std::vector<std::vector<double>>
private

Definition at line 633 of file ResultSet.h.

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

Definition at line 732 of file ResultSet.h.

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

Definition at line 772 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 389 of file ResultSet.h.

389  {
392  WktString,
395  GeoTargetValueGpuPtr
397  };
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 57 of file ResultSet.cpp.

64  : targets_(targets)
65  , device_type_(device_type)
66  , device_id_(-1)
67  , query_mem_desc_(query_mem_desc)
69  , fetched_so_far_(0)
70  , drop_first_(0)
71  , keep_first_(0)
72  , row_set_mem_owner_(row_set_mem_owner)
73  , catalog_(catalog)
74  , block_size_(block_size)
75  , grid_size_(grid_size)
76  , data_mgr_(nullptr)
78  , just_explain_(false)
79  , for_validation_only_(false)
80  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:778
GeoReturnType geo_return_type_
Definition: ResultSet.h:783
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:751
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
size_t keep_first_
Definition: ResultSet.h:747
const bool just_explain_
Definition: ResultSet.h:777
unsigned block_size_
Definition: ResultSet.h:752
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:779
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:748
size_t drop_first_
Definition: ResultSet.h:746
unsigned grid_size_
Definition: ResultSet.h:753
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:769
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
size_t fetched_so_far_
Definition: ResultSet.h:745
size_t crt_row_buff_idx_
Definition: ResultSet.h:744
bool separate_varlen_storage_valid_
Definition: ResultSet.h:775
const int device_id_
Definition: ResultSet.h:740
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 83 of file ResultSet.cpp.

95  : targets_(targets)
96  , device_type_(device_type)
97  , device_id_(device_id)
98  , query_mem_desc_(query_mem_desc)
100  , fetched_so_far_(0)
101  , drop_first_(0)
102  , keep_first_(0)
103  , row_set_mem_owner_(row_set_mem_owner)
104  , catalog_(catalog)
105  , block_size_(block_size)
106  , grid_size_(grid_size)
107  , lazy_fetch_info_(lazy_fetch_info)
108  , col_buffers_{col_buffers}
109  , frag_offsets_{frag_offsets}
110  , consistent_frag_sizes_{consistent_frag_sizes}
111  , data_mgr_(nullptr)
113  , just_explain_(false)
114  , for_validation_only_(false)
115  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:778
GeoReturnType geo_return_type_
Definition: ResultSet.h:783
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:751
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
size_t keep_first_
Definition: ResultSet.h:747
const bool just_explain_
Definition: ResultSet.h:777
unsigned block_size_
Definition: ResultSet.h:752
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:779
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:748
size_t drop_first_
Definition: ResultSet.h:746
unsigned grid_size_
Definition: ResultSet.h:753
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:761
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:769
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:762
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:764
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
size_t fetched_so_far_
Definition: ResultSet.h:745
size_t crt_row_buff_idx_
Definition: ResultSet.h:744
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:763
bool separate_varlen_storage_valid_
Definition: ResultSet.h:775
const int device_id_
Definition: ResultSet.h:740
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 145 of file ResultSet.cpp.

References CPU.

147  , device_id_(-1)
148  , fetched_so_far_(0)
150  , explanation_(explanation)
151  , just_explain_(true)
152  , for_validation_only_(false)
153  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:778
GeoReturnType geo_return_type_
Definition: ResultSet.h:783
const bool just_explain_
Definition: ResultSet.h:777
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:779
std::string explanation_
Definition: ResultSet.h:776
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
size_t fetched_so_far_
Definition: ResultSet.h:745
bool separate_varlen_storage_valid_
Definition: ResultSet.h:775
const int device_id_
Definition: ResultSet.h:740
ResultSet::ResultSet ( int64_t  queue_time_ms,
int64_t  render_time_ms,
const std::shared_ptr< RowSetMemoryOwner row_set_mem_owner 
)

Definition at line 156 of file ResultSet.cpp.

References CPU.

160  , device_id_(-1)
161  , fetched_so_far_(0)
162  , row_set_mem_owner_(row_set_mem_owner)
163  , timings_(QueryExecutionTimings{queue_time_ms, render_time_ms, 0, 0})
165  , just_explain_(true)
166  , for_validation_only_(false)
167  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:778
GeoReturnType geo_return_type_
Definition: ResultSet.h:783
const bool just_explain_
Definition: ResultSet.h:777
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:779
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:748
QueryExecutionTimings timings_
Definition: ResultSet.h:754
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
size_t fetched_so_far_
Definition: ResultSet.h:745
bool separate_varlen_storage_valid_
Definition: ResultSet.h:775
const int device_id_
Definition: ResultSet.h:740
ResultSet::~ResultSet ( )

Definition at line 170 of file ResultSet.cpp.

References CHECK, CPU, and data_mgr_().

170  {
171  if (storage_) {
172  if (!storage_->buff_is_provided_) {
173  CHECK(storage_->getUnderlyingBuffer());
174  free(storage_->getUnderlyingBuffer());
175  }
176  }
177  for (auto& storage : appended_storage_) {
178  if (storage && !storage->buff_is_provided_) {
179  free(storage->getUnderlyingBuffer());
180  }
181  }
185  }
187  CHECK(data_mgr_);
189  }
190 }
AppendedStorage appended_storage_
Definition: ResultSet.h:743
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:769
int8_t * host_estimator_buffer_
Definition: ResultSet.h:768
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
#define CHECK(condition)
Definition: Logger.h:209
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:530
Data_Namespace::AbstractBuffer * device_estimator_buffer_
Definition: ResultSet.h:767

+ Here is the call graph for this function:

Member Function Documentation

void ResultSet::addCompilationQueueTime ( const int64_t  compilation_queue_time)

Definition at line 453 of file ResultSet.cpp.

453  {
454  timings_.compilation_queue_time += compilation_queue_time;
455 }
QueryExecutionTimings timings_
Definition: ResultSet.h:754
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 > &  ,
std::shared_ptr< VarlenOutputInfo = nullptr 
) const
const ResultSetStorage* ResultSet::allocateStorage ( const std::vector< int64_t > &  ) const
void ResultSet::append ( ResultSet that)

Definition at line 241 of file ResultSet.cpp.

References CHECK, and CHECK_EQ.

241  {
243  if (!that.storage_) {
244  return;
245  }
246  appended_storage_.push_back(std::move(that.storage_));
249  appended_storage_.back()->query_mem_desc_.getEntryCount());
250  chunks_.insert(chunks_.end(), that.chunks_.begin(), that.chunks_.end());
251  col_buffers_.insert(
252  col_buffers_.end(), that.col_buffers_.begin(), that.col_buffers_.end());
253  frag_offsets_.insert(
254  frag_offsets_.end(), that.frag_offsets_.begin(), that.frag_offsets_.end());
256  that.consistent_frag_sizes_.begin(),
257  that.consistent_frag_sizes_.end());
258  chunk_iters_.insert(
259  chunk_iters_.end(), that.chunk_iters_.begin(), that.chunk_iters_.end());
261  CHECK(that.separate_varlen_storage_valid_);
263  that.serialized_varlen_buffer_.begin(),
264  that.serialized_varlen_buffer_.end());
265  }
266  for (auto& buff : that.literal_buffers_) {
267  literal_buffers_.push_back(std::move(buff));
268  }
269 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
void setEntryCount(const size_t val)
AppendedStorage appended_storage_
Definition: ResultSet.h:743
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::vector< std::shared_ptr< std::list< ChunkIter > > > chunk_iters_
Definition: ResultSet.h:757
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:774
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:779
std::list< std::shared_ptr< Chunk_NS::Chunk > > chunks_
Definition: ResultSet.h:756
std::vector< std::vector< int8_t > > literal_buffers_
Definition: ResultSet.h:760
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:762
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:764
#define CHECK(condition)
Definition: Logger.h:209
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:763
bool separate_varlen_storage_valid_
Definition: ResultSet.h:775
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 351 of file ResultSet.cpp.

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

351  {
352  if (!storage_) {
353  return 0;
354  }
355 
356  size_t row_count = storage_->binSearchRowCount();
357  for (auto& s : appended_storage_) {
358  row_count += s->binSearchRowCount();
359  }
360 
361  return get_truncated_row_count(row_count, getLimit(), drop_first_);
362 }
AppendedStorage appended_storage_
Definition: ResultSet.h:743
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
size_t getLimit() const
Definition: ResultSet.cpp:1030
size_t get_truncated_row_count(size_t total_row_count, size_t limit, size_t offset)
Definition: ResultSet.cpp:290
size_t drop_first_
Definition: ResultSet.h:746

+ Here is the call graph for this function:

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

Definition at line 743 of file ResultSet.cpp.

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

Referenced by makeTargetValue().

743  {
744  static_assert(sizeof(int64_t) == sizeof(quantile::TDigest*));
745  CHECK(t_digest);
746  t_digest->mergeBuffer();
747  double const quantile = t_digest->quantile();
748  return boost::math::isnan(quantile) ? NULL_DOUBLE : quantile;
749 }
#define NULL_DOUBLE
DEVICE void mergeBuffer()
Definition: quantile.h:629
DEVICE RealType quantile(IndexType *buf, RealType const q)
Definition: quantile.h:793
#define CHECK(condition)
Definition: Logger.h:209

+ 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 275 of file ResultSet.cpp.

275  {
276  return just_explain_ ? 1 : targets_.size();
277 }
const bool just_explain_
Definition: ResultSet.h:777
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
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 1119 of file ResultSetIteration.cpp.

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

1121  {
1123  CHECK_LT(column_idx, query_mem_desc_.getSlotCount());
1124  CHECK(output_buffer_size > 0);
1125  CHECK(output_buffer);
1126  const auto column_width_size = query_mem_desc_.getPaddedSlotWidthBytes(column_idx);
1127  size_t out_buff_offset = 0;
1128 
1129  // the main storage:
1130  const size_t crt_storage_row_count = storage_->query_mem_desc_.getEntryCount();
1131  const size_t crt_buffer_size = crt_storage_row_count * column_width_size;
1132  const size_t column_offset = storage_->query_mem_desc_.getColOffInBytes(column_idx);
1133  const int8_t* storage_buffer = storage_->getUnderlyingBuffer() + column_offset;
1134  CHECK(crt_buffer_size <= output_buffer_size);
1135  std::memcpy(output_buffer, storage_buffer, crt_buffer_size);
1136 
1137  out_buff_offset += crt_buffer_size;
1138 
1139  // the appended storages:
1140  for (size_t i = 0; i < appended_storage_.size(); i++) {
1141  const size_t crt_storage_row_count =
1142  appended_storage_[i]->query_mem_desc_.getEntryCount();
1143  if (crt_storage_row_count == 0) {
1144  // skip an empty appended storage
1145  continue;
1146  }
1147  CHECK_LT(out_buff_offset, output_buffer_size);
1148  const size_t crt_buffer_size = crt_storage_row_count * column_width_size;
1149  const size_t column_offset =
1150  appended_storage_[i]->query_mem_desc_.getColOffInBytes(column_idx);
1151  const int8_t* storage_buffer =
1152  appended_storage_[i]->getUnderlyingBuffer() + column_offset;
1153  CHECK(out_buff_offset + crt_buffer_size <= output_buffer_size);
1154  std::memcpy(output_buffer + out_buff_offset, storage_buffer, crt_buffer_size);
1155 
1156  out_buff_offset += crt_buffer_size;
1157  }
1158 }
AppendedStorage appended_storage_
Definition: ResultSet.h:743
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:219
#define CHECK(condition)
Definition: Logger.h:209
bool isDirectColumnarConversionPossible() const
Definition: ResultSet.cpp:1049

+ 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 674 of file ResultSet.h.

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

677  {
678  auto timer = DEBUG_TIMER(__func__);
680  return [rsc = ResultSetComparator<ColumnWiseTargetAccessor>(
681  order_entries, this, permutation, executor, single_threaded)](
682  const PermutationIdx lhs, const PermutationIdx rhs) {
683  return rsc(lhs, rhs);
684  };
685  } else {
686  return [rsc = ResultSetComparator<RowWiseTargetAccessor>(
687  order_entries, this, permutation, executor, single_threaded)](
688  const PermutationIdx lhs, const PermutationIdx rhs) {
689  return rsc(lhs, rhs);
690  };
691  }
692  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
uint32_t PermutationIdx
Definition: ResultSet.h:152
#define DEBUG_TIMER(name)
Definition: Logger.h:352

+ Here is the call graph for this function:

bool ResultSet::definitelyHasNoRows ( ) const

Definition at line 404 of file ResultSet.cpp.

404  {
405  return !storage_ && !estimator_ && !just_explain_;
406 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
const bool just_explain_
Definition: ResultSet.h:777
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:766
bool ResultSet::didOutputColumnar ( ) const
inline

Definition at line 407 of file ResultSet.h.

References QueryMemoryDescriptor::didOutputColumnar(), and query_mem_desc_.

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

+ 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 52 of file ResultSet.cpp.

References CHECK_EQ, and anonymous_namespace{Utm.h}::n.

52  {
54  drop_first_ = n;
55 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:779
size_t drop_first_
Definition: ResultSet.h:746
constexpr double n
Definition: Utm.h:46
size_t ResultSet::entryCount ( ) const

Returns the count of entries we allocated for the result set to hold. Note that this is not representative of the number of rows in the result set.

More concretely: entryCount() > 0 does not imply the result set is not empty. For an empty check, use isEmpty

Definition at line 750 of file ResultSetIteration.cpp.

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

750  {
751  return permutation_.empty() ? query_mem_desc_.getEntryCount() : permutation_.size();
752 }
Permutation permutation_
Definition: ResultSet.h:749
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741

+ Here is the call graph for this function:

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

Definition at line 351 of file ResultSet.h.

References CHECK, and storage_.

351  {
352  CHECK(storage_);
353  if (storage_->query_mem_desc_.didOutputColumnar()) {
354  storage_->fillOneEntryColWise(entry);
355  } else {
356  storage_->fillOneEntryRowWise(entry);
357  }
358  }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
#define CHECK(condition)
Definition: Logger.h:209
ResultSet::StorageLookupResult ResultSet::findStorage ( const size_t  entry_idx) const
private

Definition at line 674 of file ResultSet.cpp.

Referenced by getVarlenOutputInfo(), and makeGeoTargetValue().

674  {
675  auto [stg_idx, fixedup_entry_idx] = getStorageIndex(entry_idx);
676  return {stg_idx ? appended_storage_[stg_idx - 1].get() : storage_.get(),
677  fixedup_entry_idx,
678  stg_idx};
679 }
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:649
AppendedStorage appended_storage_
Definition: ResultSet.h:743
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742

+ Here is the caller graph for this function:

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

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

492  {
493  auto query_mem_desc_copy = query_mem_desc;
494  query_mem_desc_copy.resetGroupColWidths(
495  std::vector<int8_t>(query_mem_desc_copy.getGroupbyColCount(), 8));
496  if (query_mem_desc.didOutputColumnar()) {
497  return query_mem_desc_copy;
498  }
499  query_mem_desc_copy.alignPaddedSlots();
500  return query_mem_desc_copy;
501 }

+ 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 754 of file ResultSetIteration.cpp.

References CHECK, and storage_.

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

Definition at line 279 of file ResultSet.cpp.

References CHECK_LT, kAVG, kDOUBLE, and kTEXT.

279  {
280  if (just_explain_) {
281  return SQLTypeInfo(kTEXT, false);
282  }
283  CHECK_LT(col_idx, targets_.size());
284  return targets_[col_idx].agg_kind == kAVG ? SQLTypeInfo(kDOUBLE, false)
285  : targets_[col_idx].sql_type;
286 }
const bool just_explain_
Definition: ResultSet.h:777
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
#define CHECK_LT(x, y)
Definition: Logger.h:219
Definition: sqltypes.h:52
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 1291 of file ResultSetIteration.cpp.

References CHECK_NE, and storage_.

1293  {
1294  CHECK_NE(storage_->query_mem_desc_.targetGroupbyIndicesSize(), size_t(0));
1295  const auto key_width = storage_->query_mem_desc_.getEffectiveKeyWidth();
1296  const auto column_offset =
1297  (storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) < 0)
1298  ? storage_->query_mem_desc_.getColOffInBytes(slot_idx)
1299  : storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) * key_width *
1300  storage_->query_mem_desc_.getEntryCount();
1301  const auto column_buffer = storage_->getUnderlyingBuffer() + column_offset;
1302  return reinterpret_cast<const ENTRY_TYPE*>(column_buffer)[row_idx];
1303 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
#define CHECK_NE(x, y)
Definition: Logger.h:218
const int8_t * ResultSet::getColumnarBuffer ( size_t  column_idx) const

Definition at line 1074 of file ResultSet.cpp.

References CHECK.

1074  {
1076  return storage_->getUnderlyingBuffer() + query_mem_desc_.getColOffInBytes(column_idx);
1077 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
bool isZeroCopyColumnarConversionPossible(size_t column_idx) const
Definition: ResultSet.cpp:1067
#define CHECK(condition)
Definition: Logger.h:209
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 1237 of file ResultSetIteration.cpp.

References storage_.

1239  {
1240  const size_t column_offset = storage_->query_mem_desc_.getColOffInBytes(slot_idx);
1241  const int8_t* storage_buffer = storage_->getUnderlyingBuffer() + column_offset;
1242  return reinterpret_cast<const ENTRY_TYPE*>(storage_buffer)[row_idx];
1243 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
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 1084 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().

1086  {
1087  CHECK_LT(static_cast<size_t>(storage_idx), col_buffers_.size());
1088  if (col_buffers_[storage_idx].size() > 1) {
1089  int64_t frag_id = 0;
1090  int64_t local_idx = global_idx;
1091  if (consistent_frag_sizes_[storage_idx][col_logical_idx] != -1) {
1092  frag_id = global_idx / consistent_frag_sizes_[storage_idx][col_logical_idx];
1093  local_idx = global_idx % consistent_frag_sizes_[storage_idx][col_logical_idx];
1094  } else {
1095  std::tie(frag_id, local_idx) = get_frag_id_and_local_idx(
1096  frag_offsets_[storage_idx], col_logical_idx, global_idx);
1097  CHECK_LE(local_idx, global_idx);
1098  }
1099  CHECK_GE(frag_id, int64_t(0));
1100  CHECK_LT(static_cast<size_t>(frag_id), col_buffers_[storage_idx].size());
1101  global_idx = local_idx;
1102  return col_buffers_[storage_idx][frag_id];
1103  } else {
1104  CHECK_EQ(size_t(1), col_buffers_[storage_idx].size());
1105  return col_buffers_[storage_idx][0];
1106  }
1107 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
#define CHECK_GE(x, y)
Definition: Logger.h:222
#define CHECK_LT(x, y)
Definition: Logger.h:219
#define CHECK_LE(x, y)
Definition: Logger.h:220
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:762
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:764
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:763
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:

size_t ResultSet::getCurrentRowBufferIndex ( ) const

Definition at line 233 of file ResultSet.cpp.

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

Definition at line 422 of file ResultSet.cpp.

References CHECK, and GPU.

422  {
426 }
virtual int8_t * getMemoryPtr()=0
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
#define CHECK(condition)
Definition: Logger.h:209
Data_Namespace::AbstractBuffer * device_estimator_buffer_
Definition: ResultSet.h:767
int ResultSet::getDeviceId ( ) const

Definition at line 487 of file ResultSet.cpp.

487  {
488  return device_id_;
489 }
const int device_id_
Definition: ResultSet.h:740
ExecutorDeviceType ResultSet::getDeviceType ( ) const

Definition at line 192 of file ResultSet.cpp.

192  {
193  return device_type_;
194 }
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
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 1161 of file ResultSetIteration.cpp.

References GroupByBaselineHash, GroupByPerfectHash, and UNREACHABLE.

1163  {
1164  if constexpr (QUERY_TYPE == QueryDescriptionType::GroupByPerfectHash) { // NOLINT
1165  if constexpr (COLUMNAR_FORMAT) { // NOLINT
1166  return getColumnarPerfectHashEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1167  } else {
1168  return getRowWisePerfectHashEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1169  }
1170  } else if constexpr (QUERY_TYPE == QueryDescriptionType::GroupByBaselineHash) {
1171  if constexpr (COLUMNAR_FORMAT) { // NOLINT
1172  return getColumnarBaselineEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1173  } else {
1174  return getRowWiseBaselineEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1175  }
1176  } else {
1177  UNREACHABLE() << "Invalid query type is used";
1178  return 0;
1179  }
1180 }
#define UNREACHABLE()
Definition: Logger.h:253
std::string ResultSet::getExplanation ( ) const
inline

Definition at line 336 of file ResultSet.h.

References explanation_, and just_explain_.

336  {
337  if (just_explain_) {
338  return explanation_;
339  }
340  return {};
341  }
const bool just_explain_
Definition: ResultSet.h:777
std::string explanation_
Definition: ResultSet.h:776
GeoReturnType ResultSet::getGeoReturnType ( ) const
inline

Definition at line 398 of file ResultSet.h.

References geo_return_type_.

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

Definition at line 428 of file ResultSet.cpp.

428  {
429  return host_estimator_buffer_;
430 }
int8_t * host_estimator_buffer_
Definition: ResultSet.h:768
const std::vector<ColumnLazyFetchInfo>& ResultSet::getLazyFetchInfo ( ) const
inline

Definition at line 427 of file ResultSet.h.

References lazy_fetch_info_.

427  {
428  return lazy_fetch_info_;
429  }
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:761
size_t ResultSet::getLimit ( ) const

Definition at line 1030 of file ResultSet.cpp.

1030  {
1031  return keep_first_;
1032 }
size_t keep_first_
Definition: ResultSet.h:747
size_t ResultSet::getNDVEstimator ( ) const

Definition at line 33 of file CardinalityEstimator.cpp.

References bitmap_set_size(), CHECK, CHECK_LE, LOG, and logger::WARNING.

33  {
34  CHECK(dynamic_cast<const Analyzer::NDVEstimator*>(estimator_.get()));
36  auto bits_set = bitmap_set_size(host_estimator_buffer_, estimator_->getBufferSize());
37  if (bits_set == 0) {
38  // empty result set, return 1 for a groups buffer size of 1
39  return 1;
40  }
41  const auto total_bits = estimator_->getBufferSize() * 8;
42  CHECK_LE(bits_set, total_bits);
43  const auto unset_bits = total_bits - bits_set;
44  const auto ratio = static_cast<double>(unset_bits) / total_bits;
45  if (ratio == 0.) {
46  LOG(WARNING)
47  << "Failed to get a high quality cardinality estimation, falling back to "
48  "approximate group by buffer size guess.";
49  return 0;
50  }
51  return -static_cast<double>(total_bits) * log(ratio);
52 }
#define LOG(tag)
Definition: Logger.h:203
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:766
#define CHECK_LE(x, y)
Definition: Logger.h:220
int8_t * host_estimator_buffer_
Definition: ResultSet.h:768
#define CHECK(condition)
Definition: Logger.h:209
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:780
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
const bool just_explain_
Definition: ResultSet.h:777
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:217
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
size_t keep_first_
Definition: ResultSet.h:747
size_t drop_first_
Definition: ResultSet.h:746
std::vector< TargetValue > getRowAt(const size_t index) const
size_t entryCount() const
#define CHECK(condition)
Definition: Logger.h:209
size_t fetched_so_far_
Definition: ResultSet.h:745
size_t crt_row_buff_idx_
Definition: ResultSet.h:744
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:777
std::string explanation_
Definition: ResultSet.h:776
std::vector< TargetValue > getNextRowImpl(const bool translate_strings, const bool decimal_to_double) const
size_t fetched_so_far_
Definition: ResultSet.h:745
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:741
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:738
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:674
T row_ptr_rowwise(T buff, const QueryMemoryDescriptor &query_mem_desc, const size_t entry_idx)
#define CHECK(condition)
Definition: Logger.h:209
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 416 of file ResultSet.h.

References QueryMemoryDescriptor::getPaddedSlotWidthBytes(), and query_mem_desc_.

416  {
417  return query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
418  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
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 597 of file ResultSet.cpp.

597  {
598  return permutation_;
599 }
Permutation permutation_
Definition: ResultSet.h:749
QueryDescriptionType ResultSet::getQueryDescriptionType ( ) const
inline

Definition at line 412 of file ResultSet.h.

References QueryMemoryDescriptor::getQueryDescriptionType(), and query_mem_desc_.

412  {
414  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
QueryDescriptionType getQueryDescriptionType() const

+ Here is the call graph for this function:

const QueryMemoryDescriptor & ResultSet::getQueryMemDesc ( ) const

Definition at line 408 of file ResultSet.cpp.

References CHECK.

408  {
409  CHECK(storage_);
410  return storage_->query_mem_desc_;
411 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
#define CHECK(condition)
Definition: Logger.h:209
int64_t ResultSet::getQueueTime ( ) const

Definition at line 457 of file ResultSet.cpp.

int64_t ResultSet::getRenderTime ( ) const

Definition at line 462 of file ResultSet.cpp.

462  {
463  return timings_.render_time;
464 }
QueryExecutionTimings timings_
Definition: ResultSet.h:754
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:749
std::vector< TargetValue > getRowAt(const size_t index) const
size_t entryCount() const
std::shared_ptr<RowSetMemoryOwner> ResultSet::getRowSetMemOwner ( ) const
inline

Definition at line 372 of file ResultSet.h.

References row_set_mem_owner_.

372  {
373  return row_set_mem_owner_;
374  }
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:748
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 1269 of file ResultSetIteration.cpp.

References CHECK_NE, row_ptr_rowwise(), and storage_.

1271  {
1272  CHECK_NE(storage_->query_mem_desc_.targetGroupbyIndicesSize(), size_t(0));
1273  const auto key_width = storage_->query_mem_desc_.getEffectiveKeyWidth();
1274  auto keys_ptr = row_ptr_rowwise(
1275  storage_->getUnderlyingBuffer(), storage_->query_mem_desc_, row_idx);
1276  const auto column_offset =
1277  (storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) < 0)
1278  ? storage_->query_mem_desc_.getColOffInBytes(slot_idx)
1279  : storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) * key_width;
1280  const auto storage_buffer = keys_ptr + column_offset;
1281  return *reinterpret_cast<const ENTRY_TYPE*>(storage_buffer);
1282 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
#define CHECK_NE(x, y)
Definition: Logger.h:218
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 1252 of file ResultSetIteration.cpp.

References storage_.

1254  {
1255  const size_t row_offset = storage_->query_mem_desc_.getRowSize() * row_idx;
1256  const size_t column_offset = storage_->query_mem_desc_.getColOffInBytes(slot_idx);
1257  const int8_t* storage_buffer =
1258  storage_->getUnderlyingBuffer() + row_offset + column_offset;
1259  return *reinterpret_cast<const ENTRY_TYPE*>(storage_buffer);
1260 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
std::tuple< std::vector< bool >, size_t > ResultSet::getSingleSlotTargetBitmap ( ) const

Definition at line 1080 of file ResultSet.cpp.

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

1080  {
1081  std::vector<bool> target_bitmap(targets_.size(), true);
1082  size_t num_single_slot_targets = 0;
1083  for (size_t target_idx = 0; target_idx < targets_.size(); target_idx++) {
1084  const auto& sql_type = targets_[target_idx].sql_type;
1085  if (targets_[target_idx].is_agg && targets_[target_idx].agg_kind == kAVG) {
1086  target_bitmap[target_idx] = false;
1087  } else if (sql_type.is_varlen()) {
1088  target_bitmap[target_idx] = false;
1089  } else {
1090  num_single_slot_targets++;
1091  }
1092  }
1093  return std::make_tuple(std::move(target_bitmap), num_single_slot_targets);
1094 }
bool is_agg(const Analyzer::Expr *expr)
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
Definition: sqldefs.h:72

+ Here is the call graph for this function:

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

Definition at line 1123 of file ResultSet.cpp.

References advance_slot().

1123  {
1124  std::vector<size_t> slot_indices(targets_.size(), 0);
1125  size_t slot_index = 0;
1126  for (size_t target_idx = 0; target_idx < targets_.size(); target_idx++) {
1127  slot_indices[target_idx] = slot_index;
1128  slot_index = advance_slot(slot_index, targets_[target_idx], false);
1129  }
1130  return slot_indices;
1131 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
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 271 of file ResultSet.cpp.

271  {
272  return storage_.get();
273 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
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 649 of file ResultSet.cpp.

References CHECK_NE, i, and UNREACHABLE.

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

649  {
650  size_t fixedup_entry_idx = entry_idx;
651  auto entry_count = storage_->query_mem_desc_.getEntryCount();
652  const bool is_rowwise_layout = !storage_->query_mem_desc_.didOutputColumnar();
653  if (fixedup_entry_idx < entry_count) {
654  return {0, fixedup_entry_idx};
655  }
656  fixedup_entry_idx -= entry_count;
657  for (size_t i = 0; i < appended_storage_.size(); ++i) {
658  const auto& desc = appended_storage_[i]->query_mem_desc_;
659  CHECK_NE(is_rowwise_layout, desc.didOutputColumnar());
660  entry_count = desc.getEntryCount();
661  if (fixedup_entry_idx < entry_count) {
662  return {i + 1, fixedup_entry_idx};
663  }
664  fixedup_entry_idx -= entry_count;
665  }
666  UNREACHABLE() << "entry_idx = " << entry_idx << ", query_mem_desc_.getEntryCount() = "
668  return {};
669 }
AppendedStorage appended_storage_
Definition: ResultSet.h:743
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
#define UNREACHABLE()
Definition: Logger.h:253
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
#define CHECK_NE(x, y)
Definition: Logger.h:218

+ 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 1034 of file ResultSet.cpp.

References catalog_(), and CHECK.

1035  {
1036  const auto sdp = row_set_mem_owner_->getOrAddStringDictProxy(
1037  dict_id, /*with_generation=*/false, catalog_);
1038  CHECK(sdp);
1039  return sdp->getDictionary()->copyStrings();
1040 }
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:751
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:748
#define CHECK(condition)
Definition: Logger.h:209

+ 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 1104 of file ResultSet.cpp.

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

1105  {
1107  auto [single_slot_targets, num_single_slot_targets] = getSingleSlotTargetBitmap();
1108 
1109  for (size_t target_idx = 0; target_idx < single_slot_targets.size(); target_idx++) {
1110  const auto& target = targets_[target_idx];
1111  if (single_slot_targets[target_idx] &&
1112  (is_distinct_target(target) || target.agg_kind == kAPPROX_QUANTILE ||
1113  (target.is_agg && target.agg_kind == kSAMPLE && target.sql_type == kFLOAT))) {
1114  single_slot_targets[target_idx] = false;
1115  num_single_slot_targets--;
1116  }
1117  }
1118  CHECK_GE(num_single_slot_targets, size_t(0));
1119  return std::make_tuple(std::move(single_slot_targets), num_single_slot_targets);
1120 }
#define CHECK_GE(x, y)
Definition: Logger.h:222
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
std::tuple< std::vector< bool >, size_t > getSingleSlotTargetBitmap() const
Definition: ResultSet.cpp:1080
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:153
#define CHECK(condition)
Definition: Logger.h:209
bool isDirectColumnarConversionPossible() const
Definition: ResultSet.cpp:1049

+ Here is the call graph for this function:

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

Definition at line 413 of file ResultSet.cpp.

413  {
414  return targets_;
415 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
const std::vector< int64_t > & ResultSet::getTargetInitVals ( ) const

Definition at line 417 of file ResultSet.cpp.

References CHECK.

417  {
418  CHECK(storage_);
419  return storage_->target_init_vals_;
420 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
#define CHECK(condition)
Definition: Logger.h:209
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 1882 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().

1892  {
1894  const auto col1_ptr = col_ptr;
1895  const auto compact_sz1 = query_mem_desc.getPaddedSlotWidthBytes(slot_idx);
1896  const auto next_col_ptr =
1897  advance_to_next_columnar_target_buff(col1_ptr, query_mem_desc, slot_idx);
1898  const auto col2_ptr = ((target_info.is_agg && target_info.agg_kind == kAVG) ||
1899  is_real_str_or_array(target_info))
1900  ? next_col_ptr
1901  : nullptr;
1902  const auto compact_sz2 = ((target_info.is_agg && target_info.agg_kind == kAVG) ||
1903  is_real_str_or_array(target_info))
1904  ? query_mem_desc.getPaddedSlotWidthBytes(slot_idx + 1)
1905  : 0;
1906 
1907  // TODO(Saman): add required logics for count distinct
1908  // geospatial target values:
1909  if (target_info.sql_type.is_geometry()) {
1910  return makeGeoTargetValue(
1911  col1_ptr, slot_idx, target_info, target_logical_idx, global_entry_idx);
1912  }
1913 
1914  const auto ptr1 = columnar_elem_ptr(local_entry_idx, col1_ptr, compact_sz1);
1915  if (target_info.agg_kind == kAVG || is_real_str_or_array(target_info)) {
1916  CHECK(col2_ptr);
1917  CHECK(compact_sz2);
1918  const auto ptr2 = columnar_elem_ptr(local_entry_idx, col2_ptr, compact_sz2);
1919  return target_info.agg_kind == kAVG
1920  ? make_avg_target_value(ptr1, compact_sz1, ptr2, compact_sz2, target_info)
1921  : makeVarlenTargetValue(ptr1,
1922  compact_sz1,
1923  ptr2,
1924  compact_sz2,
1925  target_info,
1926  target_logical_idx,
1927  translate_strings,
1928  global_entry_idx);
1929  }
1931  query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
1932  return makeTargetValue(ptr1,
1933  compact_sz1,
1934  target_info,
1935  target_logical_idx,
1936  translate_strings,
1938  global_entry_idx);
1939  }
1940  const auto key_width = query_mem_desc_.getEffectiveKeyWidth();
1941  const auto key_idx = query_mem_desc_.getTargetGroupbyIndex(target_logical_idx);
1942  CHECK_GE(key_idx, 0);
1943  auto key_col_ptr = keys_ptr + key_idx * query_mem_desc_.getEntryCount() * key_width;
1944  return makeTargetValue(columnar_elem_ptr(local_entry_idx, key_col_ptr, key_width),
1945  key_width,
1946  target_info,
1947  target_logical_idx,
1948  translate_strings,
1950  global_entry_idx);
1951 }
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:51
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
#define CHECK_GE(x, y)
Definition: Logger.h:222
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:49
size_t targetGroupbyIndicesSize() const
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
SQLAgg agg_kind
Definition: TargetInfo.h:50
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:209
bool is_geometry() const
Definition: sqltypes.h:521
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 1955 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.

1964  {
1965  if (UNLIKELY(fixup_count_distinct_pointers)) {
1966  if (is_distinct_target(target_info)) {
1967  auto count_distinct_ptr_ptr = reinterpret_cast<int64_t*>(rowwise_target_ptr);
1968  const auto remote_ptr = *count_distinct_ptr_ptr;
1969  if (remote_ptr) {
1970  const auto ptr = storage_->mappedPtr(remote_ptr);
1971  if (ptr) {
1972  *count_distinct_ptr_ptr = ptr;
1973  } else {
1974  // need to create a zero filled buffer for this remote_ptr
1975  const auto& count_distinct_desc =
1976  query_mem_desc_.count_distinct_descriptors_[target_logical_idx];
1977  const auto bitmap_byte_sz = count_distinct_desc.sub_bitmap_count == 1
1978  ? count_distinct_desc.bitmapSizeBytes()
1979  : count_distinct_desc.bitmapPaddedSizeBytes();
1980  auto count_distinct_buffer = row_set_mem_owner_->allocateCountDistinctBuffer(
1981  bitmap_byte_sz, /*thread_idx=*/0);
1982  *count_distinct_ptr_ptr = reinterpret_cast<int64_t>(count_distinct_buffer);
1983  }
1984  }
1985  }
1986  return int64_t(0);
1987  }
1988  if (target_info.sql_type.is_geometry()) {
1989  return makeGeoTargetValue(
1990  rowwise_target_ptr, slot_idx, target_info, target_logical_idx, entry_buff_idx);
1991  }
1992 
1993  auto ptr1 = rowwise_target_ptr;
1994  int8_t compact_sz1 = query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
1996  !query_mem_desc_.hasKeylessHash() && !target_info.is_agg) {
1997  // Single column perfect hash group by can utilize one slot for both the key and the
1998  // target value if both values fit in 8 bytes. Use the target value actual size for
1999  // this case. If they don't, the target value should be 8 bytes, so we can still use
2000  // the actual size rather than the compact size.
2001  compact_sz1 = query_mem_desc_.getLogicalSlotWidthBytes(slot_idx);
2002  }
2003 
2004  // logic for deciding width of column
2005  if (target_info.agg_kind == kAVG || is_real_str_or_array(target_info)) {
2006  const auto ptr2 =
2007  rowwise_target_ptr + query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
2008  int8_t compact_sz2 = 0;
2009  // Skip reading the second slot if we have a none encoded string and are using
2010  // the none encoded strings buffer attached to ResultSetStorage
2012  (target_info.sql_type.is_array() ||
2013  (target_info.sql_type.is_string() &&
2014  target_info.sql_type.get_compression() == kENCODING_NONE)))) {
2015  compact_sz2 = query_mem_desc_.getPaddedSlotWidthBytes(slot_idx + 1);
2016  }
2017  if (separate_varlen_storage_valid_ && target_info.is_agg) {
2018  compact_sz2 = 8; // TODO(adb): is there a better way to do this?
2019  }
2020  CHECK(ptr2);
2021  return target_info.agg_kind == kAVG
2022  ? make_avg_target_value(ptr1, compact_sz1, ptr2, compact_sz2, target_info)
2023  : makeVarlenTargetValue(ptr1,
2024  compact_sz1,
2025  ptr2,
2026  compact_sz2,
2027  target_info,
2028  target_logical_idx,
2029  translate_strings,
2030  entry_buff_idx);
2031  }
2033  query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
2034  return makeTargetValue(ptr1,
2035  compact_sz1,
2036  target_info,
2037  target_logical_idx,
2038  translate_strings,
2040  entry_buff_idx);
2041  }
2042  const auto key_width = query_mem_desc_.getEffectiveKeyWidth();
2043  ptr1 = keys_ptr + query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) * key_width;
2044  return makeTargetValue(ptr1,
2045  key_width,
2046  target_info,
2047  target_logical_idx,
2048  translate_strings,
2050  entry_buff_idx);
2051 }
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:51
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
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:748
bool is_agg
Definition: TargetInfo.h:49
size_t targetGroupbyIndicesSize() const
CountDistinctDescriptors count_distinct_descriptors_
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:153
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
SQLAgg agg_kind
Definition: TargetInfo.h:50
#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:337
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:209
bool is_geometry() const
Definition: sqltypes.h:521
bool separate_varlen_storage_valid_
Definition: ResultSet.h:775
bool is_string() const
Definition: sqltypes.h:509
const int8_t getLogicalSlotWidthBytes(const size_t slot_idx) const
Definition: sqldefs.h:72
bool is_array() const
Definition: sqltypes.h:517
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, 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->getDataMgr();
635  auto allocator = data_mgr->createGpuAllocator(device_id_);
636  allocator->copyFromDevice(
637  &cpu_buffer[0], reinterpret_cast<int8_t*>(str_ptr), str_len);
638  host_str_ptr = reinterpret_cast<char*>(&cpu_buffer[0]);
639  } else {
641  host_str_ptr = reinterpret_cast<char*>(str_ptr);
642  }
643  std::string str(host_str_ptr, str_len);
644  return InternalTargetValue(row_set_mem_owner_->addString(str));
645 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:748
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
#define CHECK(condition)
Definition: Logger.h:209
const Executor * getExecutor() const
const int device_id_
Definition: ResultSet.h:740

+ Here is the call graph for this function:

const VarlenOutputInfo * ResultSet::getVarlenOutputInfo ( const size_t  entry_idx) const
private

Definition at line 1109 of file ResultSetIteration.cpp.

References CHECK, and findStorage().

Referenced by makeGeoTargetValue().

1109  {
1110  auto storage_lookup_result = findStorage(entry_idx);
1111  CHECK(storage_lookup_result.storage_ptr);
1112  return storage_lookup_result.storage_ptr->getVarlenOutputInfo();
1113 }
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:674
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 365 of file ResultSet.h.

References chunk_iters_.

365  {
366  chunk_iters_.push_back(chunk_iters);
367  }
std::vector< std::shared_ptr< std::list< ChunkIter > > > chunk_iters_
Definition: ResultSet.h:757
void ResultSet::holdChunks ( const std::list< std::shared_ptr< Chunk_NS::Chunk >> &  chunks)
inline

Definition at line 362 of file ResultSet.h.

References chunks_.

362  {
363  chunks_ = chunks;
364  }
std::list< std::shared_ptr< Chunk_NS::Chunk > > chunks_
Definition: ResultSet.h:756
void ResultSet::holdLiterals ( std::vector< int8_t > &  literal_buff)
inline

Definition at line 368 of file ResultSet.h.

References literal_buffers_.

368  {
369  literal_buffers_.push_back(std::move(literal_buff));
370  }
std::vector< std::vector< int8_t > > literal_buffers_
Definition: ResultSet.h:760
void ResultSet::initializeStorage ( ) const

Definition at line 1044 of file ResultSetReduction.cpp.

1044  {
1046  storage_->initializeColWise();
1047  } else {
1048  storage_->initializeRowWise();
1049  }
1050 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
PermutationView ResultSet::initPermutationBuffer ( PermutationView  permutation,
PermutationIdx const  begin,
PermutationIdx const  end 
) const
private

Definition at line 581 of file ResultSet.cpp.

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

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

+ 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 1049 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::isEmpty ( ) const

Definition at line 384 of file ResultSet.cpp.

384  {
385  if (entryCount() == 0) {
386  return true;
387  }
388  if (!storage_) {
389  return true;
390  }
391 
392  std::lock_guard<std::mutex> lock(row_iteration_mutex_);
393  moveToBegin();
394  while (true) {
395  auto crt_row = getNextRowUnlocked(false, false);
396  if (!crt_row.empty()) {
397  return false;
398  }
399  }
400  moveToBegin();
401  return true;
402 }
std::mutex row_iteration_mutex_
Definition: ResultSet.h:780
void moveToBegin() const
Definition: ResultSet.cpp:466
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
size_t entryCount() const
std::vector< TargetValue > getNextRowUnlocked(const bool translate_strings, const bool decimal_to_double) const
bool ResultSet::isExplain ( ) const

Definition at line 475 of file ResultSet.cpp.

475  {
476  return just_explain_;
477 }
const bool just_explain_
Definition: ResultSet.h:777
bool ResultSet::isGeoColOnGpu ( const size_t  col_idx) const

Definition at line 1431 of file ResultSetIteration.cpp.

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

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

+ 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 2190 of file ResultSetIteration.cpp.

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

2192  {
2193  if (ti.get_notnull()) {
2194  return false;
2195  }
2196  if (val.isInt()) {
2197  return val.i1 == null_val_bit_pattern(ti, float_argument_input);
2198  }
2199  if (val.isPair()) {
2200  return !val.i2;
2201  }
2202  if (val.isStr()) {
2203  return !val.i1;
2204  }
2205  CHECK(val.isNull());
2206  return true;
2207 }
bool isPair() const
Definition: TargetValue.h:67
bool isStr() const
Definition: TargetValue.h:71
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:209
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336

+ Here is the call graph for this function:

const bool ResultSet::isPermutationBufferEmpty ( ) const
inline

Definition at line 377 of file ResultSet.h.

References permutation_.

377 { return permutation_.empty(); };
Permutation permutation_
Definition: ResultSet.h:749
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:749
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:674
size_t entryCount() const
bool ResultSet::isTruncated ( ) const

Definition at line 471 of file ResultSet.cpp.

471  {
472  return keep_first_ + drop_first_;
473 }
size_t keep_first_
Definition: ResultSet.h:747
size_t drop_first_
Definition: ResultSet.h:746
bool ResultSet::isValidationOnlyRes ( ) const

Definition at line 483 of file ResultSet.cpp.

483  {
484  return for_validation_only_;
485 }
bool for_validation_only_
Definition: ResultSet.h:778
bool ResultSet::isZeroCopyColumnarConversionPossible ( size_t  column_idx) const

Definition at line 1067 of file ResultSet.cpp.

References Projection.

1067  {
1070  appended_storage_.empty() && storage_ &&
1071  (lazy_fetch_info_.empty() || !lazy_fetch_info_[column_idx].is_lazily_fetched);
1072 }
AppendedStorage appended_storage_
Definition: ResultSet.h:743
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:761
QueryDescriptionType getQueryDescriptionType() const
void ResultSet::keepFirstN ( const size_t  n)

Definition at line 47 of file ResultSet.cpp.

References CHECK_EQ, and anonymous_namespace{Utm.h}::n.

47  {
49  keep_first_ = n;
50 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
size_t keep_first_
Definition: ResultSet.h:747
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:779
constexpr double n
Definition: Utm.h:46
int64_t ResultSet::lazyReadInt ( const int64_t  ival,
const size_t  target_logical_idx,
const StorageLookupResult storage_lookup_result 
) const
private

Definition at line 647 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_.

649  {
650  if (!lazy_fetch_info_.empty()) {
651  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
652  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
653  if (col_lazy_fetch.is_lazily_fetched) {
654  CHECK_LT(static_cast<size_t>(storage_lookup_result.storage_idx),
655  col_buffers_.size());
656  int64_t ival_copy = ival;
657  auto& frag_col_buffers =
658  getColumnFrag(static_cast<size_t>(storage_lookup_result.storage_idx),
659  target_logical_idx,
660  ival_copy);
661  auto& frag_col_buffer = frag_col_buffers[col_lazy_fetch.local_col_id];
662  CHECK_LT(target_logical_idx, targets_.size());
663  const TargetInfo& target_info = targets_[target_logical_idx];
664  CHECK(!target_info.is_agg);
665  if (target_info.sql_type.is_string() &&
666  target_info.sql_type.get_compression() == kENCODING_NONE) {
667  VarlenDatum vd;
668  bool is_end{false};
670  reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(frag_col_buffer)),
671  storage_lookup_result.fixedup_entry_idx,
672  false,
673  &vd,
674  &is_end);
675  CHECK(!is_end);
676  if (vd.is_null) {
677  return 0;
678  }
679  std::string fetched_str(reinterpret_cast<char*>(vd.pointer), vd.length);
680  return reinterpret_cast<int64_t>(row_set_mem_owner_->addString(fetched_str));
681  }
682  return result_set::lazy_decode(col_lazy_fetch, frag_col_buffer, ival_copy);
683  }
684  }
685  return ival;
686 }
bool is_null
Definition: sqltypes.h:153
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:152
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:748
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:761
#define CHECK_LT(x, y)
Definition: Logger.h:219
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:762
#define CHECK(condition)
Definition: Logger.h:209
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:151

+ 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 1462 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_compression(), SQLTypeInfo::get_type(), SQLTypeInfo::get_type_name(), getColumnFrag(), QueryMemoryDescriptor::getExecutor(), QueryMemoryDescriptor::getPaddedColWidthForRange(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), getStorageIndex(), getVarlenOutputInfo(), GPU, i, TargetInfo::is_agg, SQLTypeInfo::is_geometry(), ColumnLazyFetchInfo::is_lazily_fetched, kENCODING_GEOINT, 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_, QueryMemoryDescriptor::slotIsVarlenOutput(), TargetInfo::sql_type, and UNREACHABLE.

Referenced by getTargetValueFromBufferColwise(), and getTargetValueFromBufferRowwise().

1466  {
1467  CHECK(target_info.sql_type.is_geometry());
1468 
1469  auto getNextTargetBufferRowWise = [&](const size_t slot_idx, const size_t range) {
1470  return geo_target_ptr + query_mem_desc_.getPaddedColWidthForRange(slot_idx, range);
1471  };
1472 
1473  auto getNextTargetBufferColWise = [&](const size_t slot_idx, const size_t range) {
1474  const auto storage_info = findStorage(entry_buff_idx);
1475  auto crt_geo_col_ptr = geo_target_ptr;
1476  for (size_t i = slot_idx; i < slot_idx + range; i++) {
1477  crt_geo_col_ptr = advance_to_next_columnar_target_buff(
1478  crt_geo_col_ptr, storage_info.storage_ptr->query_mem_desc_, i);
1479  }
1480  // adjusting the column pointer to represent a pointer to the geo target value
1481  return crt_geo_col_ptr +
1482  storage_info.fixedup_entry_idx *
1483  storage_info.storage_ptr->query_mem_desc_.getPaddedSlotWidthBytes(
1484  slot_idx + range);
1485  };
1486 
1487  auto getNextTargetBuffer = [&](const size_t slot_idx, const size_t range) {
1489  ? getNextTargetBufferColWise(slot_idx, range)
1490  : getNextTargetBufferRowWise(slot_idx, range);
1491  };
1492 
1493  auto getCoordsDataPtr = [&](const int8_t* geo_target_ptr) {
1494  return read_int_from_buff(getNextTargetBuffer(slot_idx, 0),
1496  };
1497 
1498  auto getCoordsLength = [&](const int8_t* geo_target_ptr) {
1499  return read_int_from_buff(getNextTargetBuffer(slot_idx, 1),
1501  };
1502 
1503  auto getRingSizesPtr = [&](const int8_t* geo_target_ptr) {
1504  return read_int_from_buff(getNextTargetBuffer(slot_idx, 2),
1506  };
1507 
1508  auto getRingSizesLength = [&](const int8_t* geo_target_ptr) {
1509  return read_int_from_buff(getNextTargetBuffer(slot_idx, 3),
1511  };
1512 
1513  auto getPolyRingsPtr = [&](const int8_t* geo_target_ptr) {
1514  return read_int_from_buff(getNextTargetBuffer(slot_idx, 4),
1516  };
1517 
1518  auto getPolyRingsLength = [&](const int8_t* geo_target_ptr) {
1519  return read_int_from_buff(getNextTargetBuffer(slot_idx, 5),
1521  };
1522 
1523  auto getFragColBuffers = [&]() -> decltype(auto) {
1524  const auto storage_idx = getStorageIndex(entry_buff_idx);
1525  CHECK_LT(storage_idx.first, col_buffers_.size());
1526  auto global_idx = getCoordsDataPtr(geo_target_ptr);
1527  return getColumnFrag(storage_idx.first, target_logical_idx, global_idx);
1528  };
1529 
1530  const bool is_gpu_fetch = device_type_ == ExecutorDeviceType::GPU;
1531 
1532  auto getDataMgr = [&]() {
1533  auto executor = query_mem_desc_.getExecutor();
1534  CHECK(executor);
1535  return executor->getDataMgr();
1536  };
1537 
1538  auto getSeparateVarlenStorage = [&]() -> decltype(auto) {
1539  const auto storage_idx = getStorageIndex(entry_buff_idx);
1540  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1541  const auto& varlen_buffer = serialized_varlen_buffer_[storage_idx.first];
1542  return varlen_buffer;
1543  };
1544 
1545  if (separate_varlen_storage_valid_ && getCoordsDataPtr(geo_target_ptr) < 0) {
1546  CHECK_EQ(-1, getCoordsDataPtr(geo_target_ptr));
1547  return TargetValue(nullptr);
1548  }
1549 
1550  const ColumnLazyFetchInfo* col_lazy_fetch = nullptr;
1551  if (!lazy_fetch_info_.empty()) {
1552  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1553  col_lazy_fetch = &lazy_fetch_info_[target_logical_idx];
1554  }
1555 
1556  switch (target_info.sql_type.get_type()) {
1557  case kPOINT: {
1558  if (query_mem_desc_.slotIsVarlenOutput(slot_idx)) {
1559  auto varlen_output_info = getVarlenOutputInfo(entry_buff_idx);
1560  CHECK(varlen_output_info);
1561  auto geo_data_ptr = read_int_from_buff(
1562  geo_target_ptr, query_mem_desc_.getPaddedSlotWidthBytes(slot_idx));
1563  auto cpu_data_ptr =
1564  reinterpret_cast<int64_t>(varlen_output_info->computeCpuOffset(geo_data_ptr));
1565  return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1566  target_info.sql_type,
1568  /*data_mgr=*/nullptr,
1569  /*is_gpu_fetch=*/false,
1570  device_id_,
1571  cpu_data_ptr,
1572  target_info.sql_type.get_compression() == kENCODING_GEOINT ? 8 : 16);
1573  } else if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1574  const auto& varlen_buffer = getSeparateVarlenStorage();
1575  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr)),
1576  varlen_buffer.size());
1577 
1578  return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1579  target_info.sql_type,
1581  nullptr,
1582  false,
1583  device_id_,
1584  reinterpret_cast<int64_t>(
1585  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1586  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()));
1587  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1588  const auto& frag_col_buffers = getFragColBuffers();
1589  return GeoTargetValueBuilder<kPOINT, GeoLazyFetchHandler>::build(
1590  target_info.sql_type,
1592  frag_col_buffers[col_lazy_fetch->local_col_id],
1593  getCoordsDataPtr(geo_target_ptr));
1594  } else {
1595  return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1596  target_info.sql_type,
1598  is_gpu_fetch ? getDataMgr() : nullptr,
1599  is_gpu_fetch,
1600  device_id_,
1601  getCoordsDataPtr(geo_target_ptr),
1602  getCoordsLength(geo_target_ptr));
1603  }
1604  break;
1605  }
1606  case kLINESTRING: {
1607  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1608  const auto& varlen_buffer = getSeparateVarlenStorage();
1609  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr)),
1610  varlen_buffer.size());
1611 
1612  return GeoTargetValueBuilder<kLINESTRING, GeoQueryOutputFetchHandler>::build(
1613  target_info.sql_type,
1615  nullptr,
1616  false,
1617  device_id_,
1618  reinterpret_cast<int64_t>(
1619  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1620  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()));
1621  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1622  const auto& frag_col_buffers = getFragColBuffers();
1623  return GeoTargetValueBuilder<kLINESTRING, GeoLazyFetchHandler>::build(
1624  target_info.sql_type,
1626  frag_col_buffers[col_lazy_fetch->local_col_id],
1627  getCoordsDataPtr(geo_target_ptr));
1628  } else {
1629  return GeoTargetValueBuilder<kLINESTRING, GeoQueryOutputFetchHandler>::build(
1630  target_info.sql_type,
1632  is_gpu_fetch ? getDataMgr() : nullptr,
1633  is_gpu_fetch,
1634  device_id_,
1635  getCoordsDataPtr(geo_target_ptr),
1636  getCoordsLength(geo_target_ptr));
1637  }
1638  break;
1639  }
1640  case kPOLYGON: {
1641  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1642  const auto& varlen_buffer = getSeparateVarlenStorage();
1643  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr) + 1),
1644  varlen_buffer.size());
1645 
1646  return GeoTargetValueBuilder<kPOLYGON, GeoQueryOutputFetchHandler>::build(
1647  target_info.sql_type,
1649  nullptr,
1650  false,
1651  device_id_,
1652  reinterpret_cast<int64_t>(
1653  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1654  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()),
1655  reinterpret_cast<int64_t>(
1656  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].data()),
1657  static_cast<int64_t>(
1658  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].size()));
1659  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1660  const auto& frag_col_buffers = getFragColBuffers();
1661 
1662  return GeoTargetValueBuilder<kPOLYGON, GeoLazyFetchHandler>::build(
1663  target_info.sql_type,
1665  frag_col_buffers[col_lazy_fetch->local_col_id],
1666  getCoordsDataPtr(geo_target_ptr),
1667  frag_col_buffers[col_lazy_fetch->local_col_id + 1],
1668  getCoordsDataPtr(geo_target_ptr));
1669  } else {
1670  return GeoTargetValueBuilder<kPOLYGON, GeoQueryOutputFetchHandler>::build(
1671  target_info.sql_type,
1673  is_gpu_fetch ? getDataMgr() : nullptr,
1674  is_gpu_fetch,
1675  device_id_,
1676  getCoordsDataPtr(geo_target_ptr),
1677  getCoordsLength(geo_target_ptr),
1678  getRingSizesPtr(geo_target_ptr),
1679  getRingSizesLength(geo_target_ptr) * 4);
1680  }
1681  break;
1682  }
1683  case kMULTIPOLYGON: {
1684  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1685  const auto& varlen_buffer = getSeparateVarlenStorage();
1686  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr) + 2),
1687  varlen_buffer.size());
1688 
1689  return GeoTargetValueBuilder<kMULTIPOLYGON, GeoQueryOutputFetchHandler>::build(
1690  target_info.sql_type,
1692  nullptr,
1693  false,
1694  device_id_,
1695  reinterpret_cast<int64_t>(
1696  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1697  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()),
1698  reinterpret_cast<int64_t>(
1699  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].data()),
1700  static_cast<int64_t>(
1701  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].size()),
1702  reinterpret_cast<int64_t>(
1703  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 2].data()),
1704  static_cast<int64_t>(
1705  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 2].size()));
1706  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1707  const auto& frag_col_buffers = getFragColBuffers();
1708 
1709  return GeoTargetValueBuilder<kMULTIPOLYGON, GeoLazyFetchHandler>::build(
1710  target_info.sql_type,
1712  frag_col_buffers[col_lazy_fetch->local_col_id],
1713  getCoordsDataPtr(geo_target_ptr),
1714  frag_col_buffers[col_lazy_fetch->local_col_id + 1],
1715  getCoordsDataPtr(geo_target_ptr),
1716  frag_col_buffers[col_lazy_fetch->local_col_id + 2],
1717  getCoordsDataPtr(geo_target_ptr));
1718  } else {
1719  return GeoTargetValueBuilder<kMULTIPOLYGON, GeoQueryOutputFetchHandler>::build(
1720  target_info.sql_type,
1722  is_gpu_fetch ? getDataMgr() : nullptr,
1723  is_gpu_fetch,
1724  device_id_,
1725  getCoordsDataPtr(geo_target_ptr),
1726  getCoordsLength(geo_target_ptr),
1727  getRingSizesPtr(geo_target_ptr),
1728  getRingSizesLength(geo_target_ptr) * 4,
1729  getPolyRingsPtr(geo_target_ptr),
1730  getPolyRingsLength(geo_target_ptr) * 4);
1731  }
1732  break;
1733  }
1734  default:
1735  throw std::runtime_error("Unknown Geometry type encountered: " +
1736  target_info.sql_type.get_type_name());
1737  }
1738  UNREACHABLE();
1739  return TargetValue(nullptr);
1740 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
bool slotIsVarlenOutput(const size_t slot_idx) const
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:649
GeoReturnType geo_return_type_
Definition: ResultSet.h:783
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:51
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
#define UNREACHABLE()
Definition: Logger.h:253
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:774
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
bool is_agg
Definition: TargetInfo.h:49
size_t getPaddedColWidthForRange(const size_t offset, const size_t range) const
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:674
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:761
const VarlenOutputInfo * getVarlenOutputInfo(const size_t entry_idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:219
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:762
std::string get_type_name() const
Definition: sqltypes.h:432
const bool is_lazily_fetched
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
#define CHECK(condition)
Definition: Logger.h:209
bool is_geometry() const
Definition: sqltypes.h:521
bool separate_varlen_storage_valid_
Definition: ResultSet.h:775
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:740

+ 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 1743 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_QUANTILE, 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().

1749  {
1750  auto actual_compact_sz = compact_sz;
1751  const auto& type_info = target_info.sql_type;
1752  if (type_info.get_type() == kFLOAT && !query_mem_desc_.forceFourByteFloat()) {
1754  actual_compact_sz = sizeof(float);
1755  } else {
1756  actual_compact_sz = sizeof(double);
1757  }
1758  if (target_info.is_agg &&
1759  (target_info.agg_kind == kAVG || target_info.agg_kind == kSUM ||
1760  target_info.agg_kind == kMIN || target_info.agg_kind == kMAX ||
1761  target_info.agg_kind == kSINGLE_VALUE)) {
1762  // The above listed aggregates use two floats in a single 8-byte slot. Set the
1763  // padded size to 4 bytes to properly read each value.
1764  actual_compact_sz = sizeof(float);
1765  }
1766  }
1767  if (get_compact_type(target_info).is_date_in_days()) {
1768  // Dates encoded in days are converted to 8 byte values on read.
1769  actual_compact_sz = sizeof(int64_t);
1770  }
1771 
1772  // String dictionary keys are read as 32-bit values regardless of encoding
1773  if (type_info.is_string() && type_info.get_compression() == kENCODING_DICT &&
1774  type_info.get_comp_param()) {
1775  actual_compact_sz = sizeof(int32_t);
1776  }
1777 
1778  auto ival = read_int_from_buff(ptr, actual_compact_sz);
1779  const auto& chosen_type = get_compact_type(target_info);
1780  if (!lazy_fetch_info_.empty()) {
1781  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1782  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
1783  if (col_lazy_fetch.is_lazily_fetched) {
1784  CHECK_GE(ival, 0);
1785  const auto storage_idx = getStorageIndex(entry_buff_idx);
1786  CHECK_LT(storage_idx.first, col_buffers_.size());
1787  auto& frag_col_buffers = getColumnFrag(storage_idx.first, target_logical_idx, ival);
1788  CHECK_LT(size_t(col_lazy_fetch.local_col_id), frag_col_buffers.size());
1789  ival = result_set::lazy_decode(
1790  col_lazy_fetch, frag_col_buffers[col_lazy_fetch.local_col_id], ival);
1791  if (chosen_type.is_fp()) {
1792  const auto dval = *reinterpret_cast<const double*>(may_alias_ptr(&ival));
1793  if (chosen_type.get_type() == kFLOAT) {
1794  return ScalarTargetValue(static_cast<float>(dval));
1795  } else {
1796  return ScalarTargetValue(dval);
1797  }
1798  }
1799  }
1800  }
1801  if (chosen_type.is_fp()) {
1802  if (target_info.agg_kind == kAPPROX_QUANTILE) {
1803  return *reinterpret_cast<double const*>(ptr) == NULL_DOUBLE
1804  ? NULL_DOUBLE // sql_validate / just_validate
1805  : calculateQuantile(*reinterpret_cast<quantile::TDigest* const*>(ptr));
1806  }
1807  switch (actual_compact_sz) {
1808  case 8: {
1809  const auto dval = *reinterpret_cast<const double*>(ptr);
1810  return chosen_type.get_type() == kFLOAT
1811  ? ScalarTargetValue(static_cast<const float>(dval))
1812  : ScalarTargetValue(dval);
1813  }
1814  case 4: {
1815  CHECK_EQ(kFLOAT, chosen_type.get_type());
1816  return *reinterpret_cast<const float*>(ptr);
1817  }
1818  default:
1819  CHECK(false);
1820  }
1821  }
1822  if (chosen_type.is_integer() | chosen_type.is_boolean() || chosen_type.is_time() ||
1823  chosen_type.is_timeinterval()) {
1824  if (is_distinct_target(target_info)) {
1826  ival, query_mem_desc_.getCountDistinctDescriptor(target_logical_idx)));
1827  }
1828  // TODO(alex): remove int_resize_cast, make read_int_from_buff return the
1829  // right type instead
1830  if (inline_int_null_val(chosen_type) ==
1831  int_resize_cast(ival, chosen_type.get_logical_size())) {
1832  return inline_int_null_val(type_info);
1833  }
1834  return ival;
1835  }
1836  if (chosen_type.is_string() && chosen_type.get_compression() == kENCODING_DICT) {
1837  if (translate_strings) {
1838  if (static_cast<int32_t>(ival) ==
1839  NULL_INT) { // TODO(alex): this isn't nice, fix it
1840  return NullableString(nullptr);
1841  }
1842  StringDictionaryProxy* sdp{nullptr};
1843  if (!chosen_type.get_comp_param()) {
1844  sdp = row_set_mem_owner_->getLiteralStringDictProxy();
1845  } else {
1846  sdp = catalog_
1847  ? row_set_mem_owner_->getOrAddStringDictProxy(
1848  chosen_type.get_comp_param(), /*with_generation=*/false, catalog_)
1849  : row_set_mem_owner_->getStringDictProxy(
1850  chosen_type.get_comp_param()); // unit tests bypass the catalog
1851  }
1852  return NullableString(sdp->getString(ival));
1853  } else {
1854  return static_cast<int64_t>(static_cast<int32_t>(ival));
1855  }
1856  }
1857  if (chosen_type.is_decimal()) {
1858  if (decimal_to_double) {
1859  if (target_info.is_agg &&
1860  (target_info.agg_kind == kAVG || target_info.agg_kind == kSUM ||
1861  target_info.agg_kind == kMIN || target_info.agg_kind == kMAX) &&
1862  ival == inline_int_null_val(SQLTypeInfo(kBIGINT, false))) {
1863  return NULL_DOUBLE;
1864  }
1865  if (!chosen_type.get_notnull() &&
1866  ival ==
1867  inline_int_null_val(SQLTypeInfo(decimal_to_int_type(chosen_type), false))) {
1868  return NULL_DOUBLE;
1869  }
1870  return static_cast<double>(ival) / exp_to_scale(chosen_type.get_scale());
1871  }
1872  return ival;
1873  }
1874  CHECK(false);
1875  return TargetValue(int64_t(0));
1876 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:649
#define NULL_DOUBLE
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
bool isLogicalSizedColumnsAllowed() const
#define const
SQLTypeInfo sql_type
Definition: TargetInfo.h:51
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:751
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
#define CHECK_GE(x, y)
Definition: Logger.h:222
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:748
bool is_agg
Definition: TargetInfo.h:49
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:153
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:761
static double calculateQuantile(quantile::TDigest *const t_digest)
Definition: ResultSet.cpp:743
SQLAgg agg_kind
Definition: TargetInfo.h:50
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:455
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:219
bool is_date_in_days() const
Definition: sqltypes.h:858
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:762
boost::variant< std::string, void * > NullableString
Definition: TargetValue.h:155
#define CHECK(condition)
Definition: Logger.h:209
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 1306 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_, 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().

1313  {
1314  auto varlen_ptr = read_int_from_buff(ptr1, compact_sz1);
1315  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1316  if (varlen_ptr < 0) {
1317  CHECK_EQ(-1, varlen_ptr);
1318  if (target_info.sql_type.get_type() == kARRAY) {
1319  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1320  }
1321  return TargetValue(nullptr);
1322  }
1323  const auto storage_idx = getStorageIndex(entry_buff_idx);
1324  if (target_info.sql_type.is_string()) {
1325  CHECK(target_info.sql_type.get_compression() == kENCODING_NONE);
1326  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1327  const auto& varlen_buffer_for_storage =
1328  serialized_varlen_buffer_[storage_idx.first];
1329  CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer_for_storage.size());
1330  return varlen_buffer_for_storage[varlen_ptr];
1331  } else if (target_info.sql_type.get_type() == kARRAY) {
1332  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1333  const auto& varlen_buffer = serialized_varlen_buffer_[storage_idx.first];
1334  CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer.size());
1335 
1336  return build_array_target_value(
1337  target_info.sql_type,
1338  reinterpret_cast<const int8_t*>(varlen_buffer[varlen_ptr].data()),
1339  varlen_buffer[varlen_ptr].size(),
1340  translate_strings,
1342  catalog_);
1343  } else {
1344  CHECK(false);
1345  }
1346  }
1347  if (!lazy_fetch_info_.empty()) {
1348  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1349  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
1350  if (col_lazy_fetch.is_lazily_fetched) {
1351  const auto storage_idx = getStorageIndex(entry_buff_idx);
1352  CHECK_LT(storage_idx.first, col_buffers_.size());
1353  auto& frag_col_buffers =
1354  getColumnFrag(storage_idx.first, target_logical_idx, varlen_ptr);
1355  bool is_end{false};
1356  if (target_info.sql_type.is_string()) {
1357  VarlenDatum vd;
1358  ChunkIter_get_nth(reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(
1359  frag_col_buffers[col_lazy_fetch.local_col_id])),
1360  varlen_ptr,
1361  false,
1362  &vd,
1363  &is_end);
1364  CHECK(!is_end);
1365  if (vd.is_null) {
1366  return TargetValue(nullptr);
1367  }
1368  CHECK(vd.pointer);
1369  CHECK_GT(vd.length, 0u);
1370  std::string fetched_str(reinterpret_cast<char*>(vd.pointer), vd.length);
1371  return fetched_str;
1372  } else {
1373  CHECK(target_info.sql_type.is_array());
1374  ArrayDatum ad;
1375  ChunkIter_get_nth(reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(
1376  frag_col_buffers[col_lazy_fetch.local_col_id])),
1377  varlen_ptr,
1378  &ad,
1379  &is_end);
1380  CHECK(!is_end);
1381  if (ad.is_null) {
1382  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1383  }
1384  CHECK_GE(ad.length, 0u);
1385  if (ad.length > 0) {
1386  CHECK(ad.pointer);
1387  }
1388  return build_array_target_value(target_info.sql_type,
1389  ad.pointer,
1390  ad.length,
1391  translate_strings,
1393  catalog_);
1394  }
1395  }
1396  }
1397  if (!varlen_ptr) {
1398  if (target_info.sql_type.is_array()) {
1399  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1400  }
1401  return TargetValue(nullptr);
1402  }
1403  auto length = read_int_from_buff(ptr2, compact_sz2);
1404  if (target_info.sql_type.is_array()) {
1405  const auto& elem_ti = target_info.sql_type.get_elem_type();
1406  length *= elem_ti.get_array_context_logical_size();
1407  }
1408  std::vector<int8_t> cpu_buffer;
1409  if (varlen_ptr && device_type_ == ExecutorDeviceType::GPU) {
1410  cpu_buffer.resize(length);
1411  const auto executor = query_mem_desc_.getExecutor();
1412  CHECK(executor);
1413  auto data_mgr = executor->getDataMgr();
1414  auto allocator = data_mgr->createGpuAllocator(device_id_);
1415 
1416  allocator->copyFromDevice(
1417  &cpu_buffer[0], reinterpret_cast<int8_t*>(varlen_ptr), length);
1418  varlen_ptr = reinterpret_cast<int64_t>(&cpu_buffer[0]);
1419  }
1420  if (target_info.sql_type.is_array()) {
1421  return build_array_target_value(target_info.sql_type,
1422  reinterpret_cast<const int8_t*>(varlen_ptr),
1423  length,
1424  translate_strings,
1426  catalog_);
1427  }
1428  return std::string(reinterpret_cast<char*>(varlen_ptr), length);
1429 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:649
bool is_null
Definition: sqltypes.h:153
SQLTypeInfo sql_type
Definition: TargetInfo.h:51
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:751
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
#define CHECK_GE(x, y)
Definition: Logger.h:222
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:774
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
#define CHECK_GT(x, y)
Definition: Logger.h:221
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:152
std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:208
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:748
bool is_agg
Definition: TargetInfo.h:49
boost::optional< std::vector< ScalarTargetValue >> ArrayTargetValue
Definition: TargetValue.h:157
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:761
#define CHECK_LT(x, y)
Definition: Logger.h:219
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
int get_array_context_logical_size() const
Definition: sqltypes.h:576
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:762
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
#define CHECK(condition)
Definition: Logger.h:209
bool separate_varlen_storage_valid_
Definition: ResultSet.h:775
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
bool is_string() const
Definition: sqltypes.h:509
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:850
bool is_array() const
Definition: sqltypes.h:517
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:151
const int device_id_
Definition: ResultSet.h:740

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSet::moveToBegin ( ) const

Definition at line 466 of file ResultSet.cpp.

466  {
467  crt_row_buff_idx_ = 0;
468  fetched_so_far_ = 0;
469 }
size_t fetched_so_far_
Definition: ResultSet.h:745
size_t crt_row_buff_idx_
Definition: ResultSet.h:744
size_t ResultSet::parallelRowCount ( ) const
private

Definition at line 364 of file ResultSet.cpp.

References anonymous_namespace{ResultSet.cpp}::get_truncated_row_count(), i, threading_serial::parallel_reduce(), logger::query_id(), and logger::set_thread_local_query_id().

364  {
365  using namespace threading;
366  auto execute_parallel_row_count = [this, query_id = logger::query_id()](
367  const blocked_range<size_t>& r,
368  size_t row_count) {
369  auto qid_scope_guard = logger::set_thread_local_query_id(query_id);
370  for (size_t i = r.begin(); i < r.end(); ++i) {
371  if (!isRowAtEmpty(i)) {
372  ++row_count;
373  }
374  }
375  return row_count;
376  };
377  const auto row_count = parallel_reduce(blocked_range<size_t>(0, entryCount()),
378  size_t(0),
379  execute_parallel_row_count,
380  std::plus<int>());
381  return get_truncated_row_count(row_count, getLimit(), drop_first_);
382 }
QidScopeGuard set_thread_local_query_id(QueryId const query_id)
Definition: Logger.cpp:468
size_t getLimit() const
Definition: ResultSet.cpp:1030
size_t get_truncated_row_count(size_t total_row_count, size_t limit, size_t offset)
Definition: ResultSet.cpp:290
size_t drop_first_
Definition: ResultSet.h:746
Value parallel_reduce(const blocked_range< Int > &range, const Value &identity, const RealBody &real_body, const Reduction &reduction, const Partitioner &p=Partitioner())
Parallel iteration with reduction.
bool isRowAtEmpty(const size_t index) const
size_t entryCount() const
QueryId query_id()
Definition: Logger.cpp:454

+ 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 601 of file ResultSet.cpp.

References gpu_enabled::copy(), cpu_threads(), DEBUG_TIMER, i, logger::query_id(), threading_std::task_group::run(), logger::set_thread_local_query_id(), and threading_std::task_group::wait().

603  {
604  auto timer = DEBUG_TIMER(__func__);
605  const size_t nthreads = cpu_threads();
606 
607  // Split permutation_ into nthreads subranges and top-sort in-place.
609  std::vector<PermutationView> permutation_views(nthreads);
610  threading::task_group top_sort_threads;
611  for (auto interval : makeIntervals<PermutationIdx>(0, permutation_.size(), nthreads)) {
612  top_sort_threads.run([this,
613  &order_entries,
614  &permutation_views,
615  top_n,
616  executor,
618  interval] {
619  auto qid_scope_guard = logger::set_thread_local_query_id(query_id);
620  PermutationView pv(permutation_.data() + interval.begin, 0, interval.size());
621  pv = initPermutationBuffer(pv, interval.begin, interval.end);
622  const auto compare = createComparator(order_entries, pv, executor, true);
623  permutation_views[interval.index] = topPermutation(pv, top_n, compare);
624  });
625  }
626  top_sort_threads.wait();
627 
628  // In case you are considering implementing a parallel reduction, note that the
629  // ResultSetComparator constructor is O(N) in order to materialize some of the aggregate
630  // columns as necessary to perform a comparison. This cost is why reduction is chosen to
631  // be serial instead; only one more Comparator is needed below.
632 
633  // Left-copy disjoint top-sorted subranges into one contiguous range.
634  // ++++....+++.....+++++... -> ++++++++++++............
635  auto end = permutation_.begin() + permutation_views.front().size();
636  for (size_t i = 1; i < nthreads; ++i) {
637  std::copy(permutation_views[i].begin(), permutation_views[i].end(), end);
638  end += permutation_views[i].size();
639  }
640 
641  // Top sort final range.
642  PermutationView pv(permutation_.data(), end - permutation_.begin());
643  const auto compare = createComparator(order_entries, pv, executor, false);
644  pv = topPermutation(pv, top_n, compare);
645  permutation_.resize(pv.size());
646  permutation_.shrink_to_fit();
647 }
QidScopeGuard set_thread_local_query_id(QueryId const query_id)
Definition: Logger.cpp:468
Permutation permutation_
Definition: ResultSet.h:749
PermutationView initPermutationBuffer(PermutationView permutation, PermutationIdx const begin, PermutationIdx const end) const
Definition: ResultSet.cpp:581
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
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:674
static PermutationView topPermutation(PermutationView, const size_t n, const Comparator &)
Definition: ResultSet.cpp:937
QueryId query_id()
Definition: Logger.cpp:454
#define DEBUG_TIMER(name)
Definition: Logger.h:352
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 990 of file ResultSet.cpp.

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

991  {
992  auto timer = DEBUG_TIMER(__func__);
994  std::vector<int64_t> tmp_buff(query_mem_desc_.getEntryCount());
995  std::vector<int32_t> idx_buff(query_mem_desc_.getEntryCount());
996  CHECK_EQ(size_t(1), order_entries.size());
997  auto buffer_ptr = storage_->getUnderlyingBuffer();
998  for (const auto& order_entry : order_entries) {
999  const auto target_idx = order_entry.tle_no - 1;
1000  const auto sortkey_val_buff = reinterpret_cast<int64_t*>(
1001  buffer_ptr + query_mem_desc_.getColOffInBytes(target_idx));
1002  const auto chosen_bytes = query_mem_desc_.getPaddedSlotWidthBytes(target_idx);
1003  sort_groups_cpu(sortkey_val_buff,
1004  &idx_buff[0],
1006  order_entry.is_desc,
1007  chosen_bytes);
1008  apply_permutation_cpu(reinterpret_cast<int64_t*>(buffer_ptr),
1009  &idx_buff[0],
1011  &tmp_buff[0],
1012  sizeof(int64_t));
1013  for (size_t target_idx = 0; target_idx < query_mem_desc_.getSlotCount();
1014  ++target_idx) {
1015  if (static_cast<int>(target_idx) == order_entry.tle_no - 1) {
1016  continue;
1017  }
1018  const auto chosen_bytes = query_mem_desc_.getPaddedSlotWidthBytes(target_idx);
1019  const auto satellite_val_buff = reinterpret_cast<int64_t*>(
1020  buffer_ptr + query_mem_desc_.getColOffInBytes(target_idx));
1021  apply_permutation_cpu(satellite_val_buff,
1022  &idx_buff[0],
1024  &tmp_buff[0],
1025  chosen_bytes);
1026  }
1027  }
1028 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
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:741
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
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:209
#define DEBUG_TIMER(name)
Definition: Logger.h:352
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 951 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.

952  {
953  auto timer = DEBUG_TIMER(__func__);
954  auto data_mgr = &catalog_->getDataMgr();
955  const int device_id{0};
956  auto allocator = data_mgr->createGpuAllocator(device_id);
957  CHECK_GT(block_size_, 0);
958  CHECK_GT(grid_size_, 0);
959  std::vector<int64_t*> group_by_buffers(block_size_);
960  group_by_buffers[0] = reinterpret_cast<int64_t*>(storage_->getUnderlyingBuffer());
961  auto dev_group_by_buffers =
962  create_dev_group_by_buffers(allocator.get(),
963  group_by_buffers,
965  block_size_,
966  grid_size_,
967  device_id,
969  /*num_input_rows=*/-1,
970  /*prepend_index_buffer=*/true,
971  /*always_init_group_by_on_host=*/true,
972  /*use_bump_allocator=*/false,
973  /*has_varlen_output=*/false,
974  /*insitu_allocator*=*/nullptr);
976  order_entries, query_mem_desc_, dev_group_by_buffers, data_mgr, device_id);
978  *allocator,
979  group_by_buffers,
980  query_mem_desc_.getBufferSizeBytes(ExecutorDeviceType::GPU),
981  dev_group_by_buffers.data,
983  block_size_,
984  grid_size_,
985  device_id,
986  /*use_bump_allocator=*/false,
987  /*has_varlen_output=*/false);
988 }
GpuGroupByBuffers create_dev_group_by_buffers(DeviceAllocator *device_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, const bool has_varlen_output, Allocator *insitu_allocator)
Definition: GpuMemUtils.cpp:60
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:222
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:751
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
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:221
unsigned block_size_
Definition: ResultSet.h:752
std::unique_ptr< DeviceAllocator > createGpuAllocator(int device_id)
Definition: DataMgr.cpp:522
unsigned grid_size_
Definition: ResultSet.h:753
#define DEBUG_TIMER(name)
Definition: Logger.h:352
void copy_group_by_buffers_from_gpu(DeviceAllocator &device_allocator, const std::vector< int64_t * > &group_by_buffers, const size_t groups_buffer_size, const int8_t *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, const bool has_varlen_output)

+ Here is the call graph for this function:

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

Definition at line 306 of file ResultSet.cpp.

References CHECK_GE, and Projection.

306  {
307  if (just_explain_) {
308  return 1;
309  }
310  if (!permutation_.empty()) {
311  if (drop_first_ > permutation_.size()) {
312  return 0;
313  }
314  const auto limited_row_count = keep_first_ + drop_first_;
315  return limited_row_count ? std::min(limited_row_count, permutation_.size())
316  : permutation_.size();
317  }
318  if (cached_row_count_ != -1) {
320  return cached_row_count_;
321  }
322  if (!storage_) {
323  return 0;
324  }
325  if (permutation_.empty() &&
327  return binSearchRowCount();
328  }
329  if (force_parallel || entryCount() > 20000) {
330  return parallelRowCount();
331  }
332  std::lock_guard<std::mutex> lock(row_iteration_mutex_);
333  moveToBegin();
334  size_t row_count{0};
335  while (true) {
336  auto crt_row = getNextRowUnlocked(false, false);
337  if (crt_row.empty()) {
338  break;
339  }
340  ++row_count;
341  }
342  moveToBegin();
343  return row_count;
344 }
std::mutex row_iteration_mutex_
Definition: ResultSet.h:780
Permutation permutation_
Definition: ResultSet.h:749
void moveToBegin() const
Definition: ResultSet.cpp:466
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
#define CHECK_GE(x, y)
Definition: Logger.h:222
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
size_t keep_first_
Definition: ResultSet.h:747
const bool just_explain_
Definition: ResultSet.h:777
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:779
size_t parallelRowCount() const
Definition: ResultSet.cpp:364
size_t drop_first_
Definition: ResultSet.h:746
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:351
ResultSetRowIterator ResultSet::rowIterator ( size_t  from_logical_index,
bool  translate_strings,
bool  decimal_to_double 
) const
inline

Definition at line 201 of file ResultSet.h.

Referenced by rowIterator().

203  {
204  ResultSetRowIterator rowIterator(this, translate_strings, decimal_to_double);
205 
206  // move to first logical position
207  ++rowIterator;
208 
209  for (size_t index = 0; index < from_logical_index; index++) {
210  ++rowIterator;
211  }
212 
213  return rowIterator;
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:201

+ Here is the caller graph for this function:

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

Definition at line 216 of file ResultSet.h.

References rowIterator().

217  {
218  return rowIterator(0, translate_strings, decimal_to_double);
219  }
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:201

+ 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 346 of file ResultSet.cpp.

References CHECK.

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

Definition at line 399 of file ResultSet.h.

References geo_return_type_.

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

Definition at line 449 of file ResultSet.cpp.

449  {
450  timings_.kernel_queue_time = kernel_queue_time;
451 }
QueryExecutionTimings timings_
Definition: ResultSet.h:754
void ResultSet::setQueueTime ( const int64_t  queue_time)

Definition at line 445 of file ResultSet.cpp.

445  {
446  timings_.executor_queue_time = queue_time;
447 }
QueryExecutionTimings timings_
Definition: ResultSet.h:754
void ResultSet::setSeparateVarlenStorageValid ( const bool  val)
inline

Definition at line 431 of file ResultSet.h.

References separate_varlen_storage_valid_.

431  {
433  }
bool separate_varlen_storage_valid_
Definition: ResultSet.h:775
void ResultSet::setValidationOnlyRes ( )

Definition at line 479 of file ResultSet.cpp.

479  {
480  for_validation_only_ = true;
481 }
bool for_validation_only_
Definition: ResultSet.h:778
void ResultSet::sort ( const std::list< Analyzer::OrderEntry > &  order_entries,
size_t  top_n,
const Executor executor 
)

Definition at line 503 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.

505  {
506  auto timer = DEBUG_TIMER(__func__);
507 
508  if (!storage_) {
509  return;
510  }
512  CHECK(!targets_.empty());
513 #ifdef HAVE_CUDA
514  if (canUseFastBaselineSort(order_entries, top_n)) {
515  baselineSort(order_entries, top_n, executor);
516  return;
517  }
518 #endif // HAVE_CUDA
519  if (query_mem_desc_.sortOnGpu()) {
520  try {
521  radixSortOnGpu(order_entries);
522  } catch (const OutOfMemory&) {
523  LOG(WARNING) << "Out of GPU memory during sort, finish on CPU";
524  radixSortOnCpu(order_entries);
525  } catch (const std::bad_alloc&) {
526  LOG(WARNING) << "Out of GPU memory during sort, finish on CPU";
527  radixSortOnCpu(order_entries);
528  }
529  return;
530  }
531  // This check isn't strictly required, but allows the index buffer to be 32-bit.
532  if (query_mem_desc_.getEntryCount() > std::numeric_limits<uint32_t>::max()) {
533  throw RowSortException("Sorting more than 4B elements not supported");
534  }
535 
536  CHECK(permutation_.empty());
537 
538  if (top_n && g_parallel_top_min < entryCount()) {
540  throw WatchdogException("Sorting the result would be too slow");
541  }
542  parallelTop(order_entries, top_n, executor);
543  } else {
545  throw WatchdogException("Sorting the result would be too slow");
546  }
548  // PermutationView is used to share common API with parallelTop().
549  PermutationView pv(permutation_.data(), 0, permutation_.size());
550  pv = initPermutationBuffer(pv, 0, permutation_.size());
551  if (top_n == 0) {
552  top_n = pv.size(); // top_n == 0 implies a full sort
553  }
554  pv = topPermutation(pv, top_n, createComparator(order_entries, pv, executor, false));
555  if (pv.size() < permutation_.size()) {
556  permutation_.resize(pv.size());
557  permutation_.shrink_to_fit();
558  }
559  }
560 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
size_t g_parallel_top_max
Definition: ResultSet.cpp:45
Permutation permutation_
Definition: ResultSet.h:749
bool g_enable_watchdog
PermutationView initPermutationBuffer(PermutationView permutation, PermutationIdx const begin, PermutationIdx const end) const
Definition: ResultSet.cpp:581
#define LOG(tag)
Definition: Logger.h:203
static const size_t baseline_threshold
Definition: Execute.h:1091
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
void parallelTop(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n, const Executor *executor)
Definition: ResultSet.cpp:601
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:779
void radixSortOnCpu(const std::list< Analyzer::OrderEntry > &order_entries) const
Definition: ResultSet.cpp:990
size_t g_parallel_top_min
Definition: ResultSet.cpp:44
DEVICE size_type size() const
Definition: VectorView.h:84
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
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:674
void radixSortOnGpu(const std::list< Analyzer::OrderEntry > &order_entries) const
Definition: ResultSet.cpp:951
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:937
#define CHECK(condition)
Definition: Logger.h:209
#define DEBUG_TIMER(name)
Definition: Logger.h:352

+ Here is the call graph for this function:

void ResultSet::syncEstimatorBuffer ( ) const

Definition at line 432 of file ResultSet.cpp.

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

432  {
435  CHECK_EQ(size_t(0), estimator_->getBufferSize() % sizeof(int64_t));
437  static_cast<int8_t*>(checked_calloc(estimator_->getBufferSize(), 1));
439  auto device_buffer_ptr = device_estimator_buffer_->getMemoryPtr();
440  auto allocator = data_mgr_->createGpuAllocator(device_id_);
441  allocator->copyFromDevice(
442  host_estimator_buffer_, device_buffer_ptr, estimator_->getBufferSize());
443 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
virtual int8_t * getMemoryPtr()=0
std::unique_ptr< DeviceAllocator > createGpuAllocator(int device_id)
Definition: DataMgr.cpp:522
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:53
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:769
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:766
int8_t * host_estimator_buffer_
Definition: ResultSet.h:768
const ExecutorDeviceType device_type_
Definition: ResultSet.h:739
#define CHECK(condition)
Definition: Logger.h:209
Data_Namespace::AbstractBuffer * device_estimator_buffer_
Definition: ResultSet.h:767
const int device_id_
Definition: ResultSet.h:740

+ Here is the call graph for this function:

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

Definition at line 937 of file ResultSet.cpp.

References VectorView< T >::begin(), DEBUG_TIMER, VectorView< T >::end(), anonymous_namespace{Utm.h}::n, VectorView< T >::resize(), VectorView< T >::size(), and gpu_enabled::sort().

939  {
940  auto timer = DEBUG_TIMER(__func__);
941  if (n < permutation.size()) {
942  std::partial_sort(
943  permutation.begin(), permutation.begin() + n, permutation.end(), compare);
944  permutation.resize(n);
945  } else {
946  std::sort(permutation.begin(), permutation.end(), compare);
947  }
948  return permutation;
949 }
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:352
constexpr double n
Definition: Utm.h:46
DEVICE T * end() const
Definition: VectorView.h:68

+ Here is the call graph for this function:

std::string ResultSet::toString ( ) const
inline

Definition at line 196 of file ResultSet.h.

References query_mem_desc_, targets_, and typeName().

196  {
197  return typeName(this) + "(targets=" + ::toString(targets_) +
198  ", query_mem_desc=" + ::toString(query_mem_desc_) + ")";
199  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:738
std::string toString() const
Definition: ResultSet.h:196
std::string typeName(const T *v)
Definition: toString.h:88

+ 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 232 of file ResultSet.h.

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

232  {
234  query_mem_desc_.setEntryCount(new_entry_count);
235  CHECK(storage_);
236  storage_->updateEntryCount(new_entry_count);
237  }
void setEntryCount(const size_t val)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:741
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:742
QueryDescriptionType getQueryDescriptionType() const
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class ColumnarResults
friend

Definition at line 787 of file ResultSet.h.

friend class ResultSetManager
friend

Definition at line 785 of file ResultSet.h.

friend class ResultSetRowIterator
friend

Definition at line 786 of file ResultSet.h.

Member Data Documentation

AppendedStorage ResultSet::appended_storage_
private

Definition at line 743 of file ResultSet.h.

Referenced by copyColumnIntoBuffer().

unsigned ResultSet::block_size_ {0}
private

Definition at line 752 of file ResultSet.h.

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

Definition at line 779 of file ResultSet.h.

const Catalog_Namespace::Catalog* ResultSet::catalog_
private

Definition at line 751 of file ResultSet.h.

Referenced by makeTargetValue(), and makeVarlenTargetValue().

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

Definition at line 757 of file ResultSet.h.

Referenced by holdChunkIterators().

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

Definition at line 756 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 764 of file ResultSet.h.

Referenced by getColumnFrag().

size_t ResultSet::crt_row_buff_idx_
mutableprivate

Definition at line 744 of file ResultSet.h.

Data_Namespace::DataMgr* ResultSet::data_mgr_
private

Definition at line 769 of file ResultSet.h.

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

Definition at line 767 of file ResultSet.h.

const int ResultSet::device_id_
private

Definition at line 740 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 746 of file ResultSet.h.

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

Definition at line 766 of file ResultSet.h.

std::string ResultSet::explanation_
private

Definition at line 776 of file ResultSet.h.

Referenced by getExplanation().

size_t ResultSet::fetched_so_far_
mutableprivate

Definition at line 745 of file ResultSet.h.

bool ResultSet::for_validation_only_
private

Definition at line 778 of file ResultSet.h.

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

Definition at line 763 of file ResultSet.h.

Referenced by getColumnFrag().

GeoReturnType ResultSet::geo_return_type_
mutableprivate

Definition at line 783 of file ResultSet.h.

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

unsigned ResultSet::grid_size_ {0}
private

Definition at line 753 of file ResultSet.h.

int8_t* ResultSet::host_estimator_buffer_ {nullptr}
mutableprivate

Definition at line 768 of file ResultSet.h.

const bool ResultSet::just_explain_
private

Definition at line 777 of file ResultSet.h.

Referenced by getExplanation().

size_t ResultSet::keep_first_
private

Definition at line 747 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 760 of file ResultSet.h.

Referenced by holdLiterals().

Permutation ResultSet::permutation_
private

Definition at line 749 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 780 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 774 of file ResultSet.h.

Referenced by makeGeoTargetValue(), and makeVarlenTargetValue().

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

Definition at line 754 of file ResultSet.h.


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