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

#include <ResultSet.h>

+ Collaboration diagram for ResultSet:

Classes

struct  ColumnWiseTargetAccessor
 
struct  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 Executor *executor)
 
 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 Executor *executor)
 
 ResultSet (const std::shared_ptr< const Analyzer::Estimator >, const ExecutorDeviceType device_type, const int device_id, Data_Namespace::DataMgr *data_mgr)
 
 ResultSet (const std::string &explanation)
 
 ResultSet (int64_t queue_time_ms, int64_t render_time_ms, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 
 ~ResultSet ()
 
ResultSetRowIterator rowIterator (size_t from_logical_index, bool translate_strings, bool decimal_to_double) const
 
ResultSetRowIterator rowIterator (bool translate_strings, bool decimal_to_double) const
 
ExecutorDeviceType getDeviceType () const
 
const ResultSetStorageallocateStorage () const
 
const ResultSetStorageallocateStorage (int8_t *, const std::vector< int64_t > &) const
 
const ResultSetStorageallocateStorage (const std::vector< int64_t > &) const
 
void updateStorageEntryCount (const size_t new_entry_count)
 
std::vector< TargetValuegetNextRow (const bool translate_strings, const bool decimal_to_double) const
 
size_t getCurrentRowBufferIndex () const
 
std::vector< TargetValuegetRowAt (const size_t index) const
 
TargetValue getRowAt (const size_t row_idx, const size_t col_idx, const bool translate_strings, const bool decimal_to_double=true) const
 
OneIntegerColumnRow getOneColRow (const size_t index) const
 
std::vector< TargetValuegetRowAtNoTranslations (const size_t index, const std::vector< bool > &targets_to_skip={}) const
 
bool isRowAtEmpty (const size_t index) const
 
void sort (const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
 
void keepFirstN (const size_t n)
 
void dropFirstN (const size_t n)
 
void append (ResultSet &that)
 
const ResultSetStoragegetStorage () const
 
size_t colCount () const
 
SQLTypeInfo getColType (const size_t col_idx) const
 
size_t rowCount (const bool force_parallel=false) const
 
void setCachedRowCount (const size_t row_count) const
 
size_t entryCount () const
 
size_t getBufferSizeBytes (const ExecutorDeviceType device_type) const
 
bool definitelyHasNoRows () const
 
const QueryMemoryDescriptorgetQueryMemDesc () const
 
const std::vector< TargetInfo > & getTargetInfos () const
 
const std::vector< int64_t > & getTargetInitVals () const
 
int8_t * getDeviceEstimatorBuffer () const
 
int8_t * getHostEstimatorBuffer () const
 
void syncEstimatorBuffer () const
 
size_t getNDVEstimator () const
 
void setQueueTime (const int64_t queue_time)
 
int64_t getQueueTime () const
 
int64_t getRenderTime () const
 
void moveToBegin () const
 
bool isTruncated () const
 
bool isExplain () 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 std::vector< uint32_t > & getPermutationBuffer () const
 
const bool isPermutationBufferEmpty () const
 
void serialize (TSerializedRows &serialized_rows) const
 
size_t getLimit ()
 
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
 
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 *)
 

Private Types

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 parallelRowCount () const
 
size_t advanceCursorToNextEntry () const
 
void radixSortOnGpu (const std::list< Analyzer::OrderEntry > &order_entries) const
 
void radixSortOnCpu (const std::list< Analyzer::OrderEntry > &order_entries) const
 
TargetValue getTargetValueFromBufferRowwise (int8_t *rowwise_target_ptr, int8_t *keys_ptr, const size_t entry_buff_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t slot_idx, const bool translate_strings, const bool decimal_to_double, const bool fixup_count_distinct_pointers) const
 
TargetValue getTargetValueFromBufferColwise (const int8_t *col_ptr, const int8_t *keys_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t local_entry_idx, const size_t global_entry_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t slot_idx, const bool translate_strings, const bool decimal_to_double) const
 
TargetValue makeTargetValue (const int8_t *ptr, const int8_t compact_sz, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const bool decimal_to_double, const size_t entry_buff_idx) const
 
TargetValue makeVarlenTargetValue (const int8_t *ptr1, const int8_t compact_sz1, const int8_t *ptr2, const int8_t compact_sz2, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const size_t entry_buff_idx) const
 
TargetValue makeGeoTargetValue (const int8_t *geo_target_ptr, const size_t slot_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t entry_buff_idx) const
 
InternalTargetValue getColumnInternal (const int8_t *buff, const size_t entry_idx, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
 
InternalTargetValue getVarlenOrderEntry (const int64_t str_ptr, const size_t str_len) const
 
int64_t lazyReadInt (const int64_t ival, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
 
std::pair< size_t, size_t > getStorageIndex (const size_t entry_idx) const
 
const std::vector< const
int8_t * > & 
getColumnFrag (const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
 
StorageLookupResult findStorage (const size_t entry_idx) const
 
std::function< bool(const
uint32_t, const uint32_t)> 
createComparator (const std::list< Analyzer::OrderEntry > &order_entries, const bool use_heap)
 
void sortPermutation (const std::function< bool(const uint32_t, const uint32_t)> compare)
 
std::vector< uint32_t > initPermutationBuffer (const size_t start, const size_t step)
 
void parallelTop (const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
 
void baselineSort (const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
 
void doBaselineSort (const ExecutorDeviceType device_type, const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
 
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 void topPermutation (std::vector< uint32_t > &to_sort, const size_t n, const std::function< bool(const uint32_t, const uint32_t)> compare)
 

Private Attributes

const std::vector< TargetInfotargets_
 
const ExecutorDeviceType device_type_
 
const int device_id_
 
QueryMemoryDescriptor query_mem_desc_
 
std::unique_ptr< ResultSetStoragestorage_
 
std::vector< std::unique_ptr
< ResultSetStorage > > 
appended_storage_
 
size_t crt_row_buff_idx_
 
size_t fetched_so_far_
 
size_t drop_first_
 
size_t keep_first_
 
const std::shared_ptr
< RowSetMemoryOwner
row_set_mem_owner_
 
std::vector< uint32_t > permutation_
 
int64_t queue_time_ms_
 
int64_t render_time_ms_
 
const Executorexecutor_
 
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_
 
int8_t * estimator_buffer_
 
int8_t * host_estimator_buffer_
 
Data_Namespace::DataMgrdata_mgr_
 
std::vector
< SerializedVarlenBufferStorage
serialized_varlen_buffer_
 
bool separate_varlen_storage_valid_
 
std::string explanation_
 
const bool just_explain_
 
std::atomic< ssize_t > cached_row_count_
 
std::mutex row_iteration_mutex_
 
GeoReturnType geo_return_type_
 
std::unique_ptr
< ResultSetComparator
< RowWiseTargetAccessor > > 
row_wise_comparator_
 
std::unique_ptr
< ResultSetComparator
< ColumnWiseTargetAccessor > > 
column_wise_comparator_
 

Friends

class ResultSetManager
 
class ResultSetRowIterator
 
class ColumnarResults
 

Detailed Description

Definition at line 291 of file ResultSet.h.

Member Typedef Documentation

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

Definition at line 794 of file ResultSet.h.

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

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

477  {
480  WktString,
483  GeoTargetValueGpuPtr
485  };
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 Executor executor 
)

Definition at line 91 of file ResultSet.cpp.

96  : targets_(targets)
97  , device_type_(device_type)
98  , device_id_(-1)
99  , query_mem_desc_(query_mem_desc)
100  , crt_row_buff_idx_(0)
101  , fetched_so_far_(0)
102  , drop_first_(0)
103  , keep_first_(0)
104  , row_set_mem_owner_(row_set_mem_owner)
105  , queue_time_ms_(0)
106  , render_time_ms_(0)
107  , executor_(executor)
108  , estimator_buffer_(nullptr)
109  , host_estimator_buffer_(nullptr)
110  , data_mgr_(nullptr)
112  , just_explain_(false)
113  , cached_row_count_(-1)
int8_t * estimator_buffer_
Definition: ResultSet.h:827
GeoReturnType geo_return_type_
Definition: ResultSet.h:842
const Executor * executor_
Definition: ResultSet.h:814
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
size_t keep_first_
Definition: ResultSet.h:809
const bool just_explain_
Definition: ResultSet.h:837
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:810
size_t drop_first_
Definition: ResultSet.h:808
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:829
int64_t queue_time_ms_
Definition: ResultSet.h:812
int8_t * host_estimator_buffer_
Definition: ResultSet.h:828
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801
size_t fetched_so_far_
Definition: ResultSet.h:807
size_t crt_row_buff_idx_
Definition: ResultSet.h:806
bool separate_varlen_storage_valid_
Definition: ResultSet.h:835
int64_t render_time_ms_
Definition: ResultSet.h:813
const int device_id_
Definition: ResultSet.h:802
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 Executor executor 
)

Definition at line 116 of file ResultSet.cpp.

126  : targets_(targets)
127  , device_type_(device_type)
128  , device_id_(device_id)
129  , query_mem_desc_(query_mem_desc)
130  , crt_row_buff_idx_(0)
131  , fetched_so_far_(0)
132  , drop_first_(0)
133  , keep_first_(0)
134  , row_set_mem_owner_(row_set_mem_owner)
135  , queue_time_ms_(0)
136  , render_time_ms_(0)
137  , executor_(executor)
138  , lazy_fetch_info_(lazy_fetch_info)
139  , col_buffers_{col_buffers}
140  , frag_offsets_{frag_offsets}
141  , consistent_frag_sizes_{consistent_frag_sizes}
142  , estimator_buffer_(nullptr)
143  , host_estimator_buffer_(nullptr)
144  , data_mgr_(nullptr)
146  , just_explain_(false)
147  , cached_row_count_(-1)
int8_t * estimator_buffer_
Definition: ResultSet.h:827
GeoReturnType geo_return_type_
Definition: ResultSet.h:842
const Executor * executor_
Definition: ResultSet.h:814
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
size_t keep_first_
Definition: ResultSet.h:809
const bool just_explain_
Definition: ResultSet.h:837
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:810
size_t drop_first_
Definition: ResultSet.h:808
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:821
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:829
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:822
int64_t queue_time_ms_
Definition: ResultSet.h:812
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:824
int8_t * host_estimator_buffer_
Definition: ResultSet.h:828
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801
size_t fetched_so_far_
Definition: ResultSet.h:807
size_t crt_row_buff_idx_
Definition: ResultSet.h:806
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:823
bool separate_varlen_storage_valid_
Definition: ResultSet.h:835
int64_t render_time_ms_
Definition: ResultSet.h:813
const int device_id_
Definition: ResultSet.h:802
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 177 of file ResultSet.cpp.

References CPU.

179  , device_id_(-1)
180  , fetched_so_far_(0)
181  , queue_time_ms_(0)
182  , render_time_ms_(0)
183  , estimator_buffer_(nullptr)
184  , host_estimator_buffer_(nullptr)
186  , explanation_(explanation)
187  , just_explain_(true)
188  , cached_row_count_(-1)
int8_t * estimator_buffer_
Definition: ResultSet.h:827
GeoReturnType geo_return_type_
Definition: ResultSet.h:842
const bool just_explain_
Definition: ResultSet.h:837
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838
int64_t queue_time_ms_
Definition: ResultSet.h:812
std::string explanation_
Definition: ResultSet.h:836
int8_t * host_estimator_buffer_
Definition: ResultSet.h:828
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801
size_t fetched_so_far_
Definition: ResultSet.h:807
bool separate_varlen_storage_valid_
Definition: ResultSet.h:835
int64_t render_time_ms_
Definition: ResultSet.h:813
const int device_id_
Definition: ResultSet.h:802
ResultSet::ResultSet ( int64_t  queue_time_ms,
int64_t  render_time_ms,
const std::shared_ptr< RowSetMemoryOwner row_set_mem_owner 
)

Definition at line 191 of file ResultSet.cpp.

References CPU.

195  , device_id_(-1)
196  , fetched_so_far_(0)
197  , queue_time_ms_(queue_time_ms)
198  , render_time_ms_(render_time_ms)
199  , estimator_buffer_(nullptr)
200  , host_estimator_buffer_(nullptr)
202  , just_explain_(true)
203  , cached_row_count_(-1)
int8_t * estimator_buffer_
Definition: ResultSet.h:827
GeoReturnType geo_return_type_
Definition: ResultSet.h:842
const bool just_explain_
Definition: ResultSet.h:837
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838
int64_t queue_time_ms_
Definition: ResultSet.h:812
int8_t * host_estimator_buffer_
Definition: ResultSet.h:828
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801
size_t fetched_so_far_
Definition: ResultSet.h:807
bool separate_varlen_storage_valid_
Definition: ResultSet.h:835
int64_t render_time_ms_
Definition: ResultSet.h:813
const int device_id_
Definition: ResultSet.h:802
ResultSet::~ResultSet ( )

Definition at line 206 of file ResultSet.cpp.

References CHECK(), and CPU.

206  {
207  if (storage_) {
208  CHECK(storage_->getUnderlyingBuffer());
209  if (!storage_->buff_is_provided_) {
210  free(storage_->getUnderlyingBuffer());
211  }
212  }
213  for (auto& storage : appended_storage_) {
214  if (storage && !storage->buff_is_provided_) {
215  free(storage->getUnderlyingBuffer());
216  }
217  }
221  }
222 }
int8_t * estimator_buffer_
Definition: ResultSet.h:827
std::vector< std::unique_ptr< ResultSetStorage > > appended_storage_
Definition: ResultSet.h:805
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
CHECK(cgen_state)
int8_t * host_estimator_buffer_
Definition: ResultSet.h:828
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801

+ Here is the call graph for this function:

Member Function Documentation

void ResultSet::advanceCursorToNextEntry ( ResultSetRowIterator iter) const
private
size_t ResultSet::advanceCursorToNextEntry ( ) const
private
const ResultSetStorage* ResultSet::allocateStorage ( ) const
const ResultSetStorage* ResultSet::allocateStorage ( int8_t *  ,
const std::vector< int64_t > &   
) const
const ResultSetStorage* ResultSet::allocateStorage ( const std::vector< int64_t > &  ) const
void ResultSet::append ( ResultSet that)

Definition at line 263 of file ResultSet.cpp.

References CHECK(), and CHECK_EQ.

263  {
265  if (!that.storage_) {
266  return;
267  }
268  appended_storage_.push_back(std::move(that.storage_));
271  appended_storage_.back()->query_mem_desc_.getEntryCount());
272  chunks_.insert(chunks_.end(), that.chunks_.begin(), that.chunks_.end());
273  col_buffers_.insert(
274  col_buffers_.end(), that.col_buffers_.begin(), that.col_buffers_.end());
275  frag_offsets_.insert(
276  frag_offsets_.end(), that.frag_offsets_.begin(), that.frag_offsets_.end());
278  that.consistent_frag_sizes_.begin(),
279  that.consistent_frag_sizes_.end());
280  chunk_iters_.insert(
281  chunk_iters_.end(), that.chunk_iters_.begin(), that.chunk_iters_.end());
283  CHECK(that.separate_varlen_storage_valid_);
285  that.serialized_varlen_buffer_.begin(),
286  that.serialized_varlen_buffer_.end());
287  }
288  for (auto& buff : that.literal_buffers_) {
289  literal_buffers_.push_back(std::move(buff));
290  }
291 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
void setEntryCount(const size_t val)
std::vector< std::unique_ptr< ResultSetStorage > > appended_storage_
Definition: ResultSet.h:805
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
std::vector< std::shared_ptr< std::list< ChunkIter > > > chunk_iters_
Definition: ResultSet.h:817
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:834
CHECK(cgen_state)
std::list< std::shared_ptr< Chunk_NS::Chunk > > chunks_
Definition: ResultSet.h:816
std::vector< std::vector< int8_t > > literal_buffers_
Definition: ResultSet.h:820
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:822
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:824
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:823
bool separate_varlen_storage_valid_
Definition: ResultSet.h:835

+ Here is the call graph for this function:

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

Definition at line 297 of file ResultSet.cpp.

297  {
298  return just_explain_ ? 1 : targets_.size();
299 }
const bool just_explain_
Definition: ResultSet.h:837
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
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 1125 of file ResultSetIteration.cpp.

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

1127  {
1129  CHECK_LT(column_idx, query_mem_desc_.getSlotCount());
1130  CHECK(output_buffer_size > 0);
1131  CHECK(output_buffer);
1132  const auto column_width_size = query_mem_desc_.getPaddedSlotWidthBytes(column_idx);
1133  size_t out_buff_offset = 0;
1134 
1135  // the main storage:
1136  const size_t crt_storage_row_count = storage_->query_mem_desc_.getEntryCount();
1137  const size_t crt_buffer_size = crt_storage_row_count * column_width_size;
1138  const size_t column_offset = storage_->query_mem_desc_.getColOffInBytes(column_idx);
1139  const int8_t* storage_buffer = storage_->getUnderlyingBuffer() + column_offset;
1140  CHECK(crt_buffer_size <= output_buffer_size);
1141  std::memcpy(output_buffer, storage_buffer, crt_buffer_size);
1142 
1143  out_buff_offset += crt_buffer_size;
1144 
1145  // the appended storages:
1146  for (size_t i = 0; i < appended_storage_.size(); i++) {
1147  CHECK_LT(out_buff_offset, output_buffer_size);
1148  const size_t crt_storage_row_count =
1149  appended_storage_[i]->query_mem_desc_.getEntryCount();
1150  const size_t crt_buffer_size = crt_storage_row_count * column_width_size;
1151  const size_t column_offset =
1152  appended_storage_[i]->query_mem_desc_.getColOffInBytes(column_idx);
1153  const int8_t* storage_buffer =
1154  appended_storage_[i]->getUnderlyingBuffer() + column_offset;
1155  CHECK(out_buff_offset + crt_buffer_size <= output_buffer_size);
1156  std::memcpy(output_buffer + out_buff_offset, storage_buffer, crt_buffer_size);
1157 
1158  out_buff_offset += crt_buffer_size;
1159  }
1160 }
std::vector< std::unique_ptr< ResultSetStorage > > appended_storage_
Definition: ResultSet.h:805
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
CHECK(cgen_state)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:200
bool isDirectColumnarConversionPossible() const
Definition: ResultSet.cpp:884

+ Here is the call graph for this function:

void ResultSet::create_active_buffer_set ( BufferSet count_distinct_active_buffer_set) const
private
std::function<bool(const uint32_t, const uint32_t)> ResultSet::createComparator ( const std::list< Analyzer::OrderEntry > &  order_entries,
const bool  use_heap 
)
inlineprivate

Definition at line 739 of file ResultSet.h.

References column_wise_comparator_, QueryMemoryDescriptor::didOutputColumnar(), query_mem_desc_, and row_wise_comparator_.

741  {
744  std::make_unique<ResultSetComparator<ColumnWiseTargetAccessor>>(
745  order_entries, use_heap, this);
746  return [this](const uint32_t lhs, const uint32_t rhs) -> bool {
747  return (*this->column_wise_comparator_)(lhs, rhs);
748  };
749  } else {
750  row_wise_comparator_ = std::make_unique<ResultSetComparator<RowWiseTargetAccessor>>(
751  order_entries, use_heap, this);
752  return [this](const uint32_t lhs, const uint32_t rhs) -> bool {
753  return (*this->row_wise_comparator_)(lhs, rhs);
754  };
755  }
756  }
std::unique_ptr< ResultSetComparator< ColumnWiseTargetAccessor > > column_wise_comparator_
Definition: ResultSet.h:847
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
std::unique_ptr< ResultSetComparator< RowWiseTargetAccessor > > row_wise_comparator_
Definition: ResultSet.h:846

+ Here is the call graph for this function:

bool ResultSet::definitelyHasNoRows ( ) const

Definition at line 383 of file ResultSet.cpp.

383  {
384  return !storage_ && !estimator_ && !just_explain_;
385 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
const bool just_explain_
Definition: ResultSet.h:837
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:826
bool ResultSet::didOutputColumnar ( ) const
inline

Definition at line 495 of file ResultSet.h.

References QueryMemoryDescriptor::didOutputColumnar(), and query_mem_desc_.

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

+ 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 
)
private
void ResultSet::dropFirstN ( const size_t  n)

Definition at line 86 of file ResultSet.cpp.

References CHECK_EQ.

86  {
88  drop_first_ = n;
89 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
size_t drop_first_
Definition: ResultSet.h:808
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838
size_t ResultSet::entryCount ( ) const

Definition at line 753 of file ResultSetIteration.cpp.

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

753  {
754  return permutation_.empty() ? query_mem_desc_.getEntryCount() : permutation_.size();
755 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
std::vector< uint32_t > permutation_
Definition: ResultSet.h:811

+ Here is the call graph for this function:

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

Definition at line 439 of file ResultSet.h.

References CHECK(), and storage_.

439  {
440  CHECK(storage_);
441  if (storage_->query_mem_desc_.didOutputColumnar()) {
442  storage_->fillOneEntryColWise(entry);
443  } else {
444  storage_->fillOneEntryRowWise(entry);
445  }
446  }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
CHECK(cgen_state)

+ Here is the call graph for this function:

ResultSet::StorageLookupResult ResultSet::findStorage ( const size_t  entry_idx) const
private

Definition at line 616 of file ResultSet.cpp.

Referenced by makeGeoTargetValue().

616  {
617  size_t stg_idx;
618  size_t fixedup_entry_idx;
619  std::tie(stg_idx, fixedup_entry_idx) = getStorageIndex(entry_idx);
620  return {stg_idx ? appended_storage_[stg_idx - 1].get() : storage_.get(),
621  fixedup_entry_idx,
622  stg_idx};
623 }
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:594
std::vector< std::unique_ptr< ResultSetStorage > > appended_storage_
Definition: ResultSet.h:805
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804

+ Here is the caller graph for this function:

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

Definition at line 452 of file ResultSet.cpp.

References QueryMemoryDescriptor::didOutputColumnar(), and query_mem_desc.

Referenced by QueryExecutionContext::groupBufferToDeinterleavedResults(), QueryMemoryInitializer::initGroups(), QueryMemoryInitializer::QueryMemoryInitializer(), and Executor::reduceMultiDeviceResults().

453  {
454  auto query_mem_desc_copy = query_mem_desc;
455  query_mem_desc_copy.resetGroupColWidths(
456  std::vector<int8_t>(query_mem_desc_copy.getGroupbyColCount(), 8));
457  if (query_mem_desc.didOutputColumnar()) {
458  return query_mem_desc_copy;
459  }
460  query_mem_desc_copy.alignPaddedSlots();
461  return query_mem_desc_copy;
462 }

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

References CHECK(), and storage_.

757  {
758  CHECK(storage_);
759  return storage_->query_mem_desc_.getBufferSizeBytes(device_type);
760 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
CHECK(cgen_state)

+ Here is the call graph for this function:

SQLTypeInfo ResultSet::getColType ( const size_t  col_idx) const

Definition at line 301 of file ResultSet.cpp.

References CHECK_LT, kAVG, kDOUBLE, and kTEXT.

301  {
302  if (just_explain_) {
303  return SQLTypeInfo(kTEXT, false);
304  }
305  CHECK_LT(col_idx, targets_.size());
306  return targets_[col_idx].agg_kind == kAVG ? SQLTypeInfo(kDOUBLE, false)
307  : targets_[col_idx].sql_type;
308 }
const bool just_explain_
Definition: ResultSet.h:837
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:852
#define CHECK_LT(x, y)
Definition: Logger.h:200
Definition: sqltypes.h:55
Definition: sqldefs.h:71
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 1293 of file ResultSetIteration.cpp.

References CHECK_NE, and storage_.

1295  {
1296  CHECK_NE(storage_->query_mem_desc_.targetGroupbyIndicesSize(), size_t(0));
1297  const auto key_width = storage_->query_mem_desc_.getEffectiveKeyWidth();
1298  const auto column_offset =
1299  (storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) < 0)
1300  ? storage_->query_mem_desc_.getColOffInBytes(slot_idx)
1301  : storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) * key_width *
1302  storage_->query_mem_desc_.getEntryCount();
1303  const auto column_buffer = storage_->getUnderlyingBuffer() + column_offset;
1304  return reinterpret_cast<const ENTRY_TYPE*>(column_buffer)[row_idx];
1305 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
#define CHECK_NE(x, y)
Definition: Logger.h:199
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 1239 of file ResultSetIteration.cpp.

References storage_.

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

1098  {
1099  CHECK_LT(static_cast<size_t>(storage_idx), col_buffers_.size());
1100  if (col_buffers_[storage_idx].size() > 1) {
1101  int64_t frag_id = 0;
1102  int64_t local_idx = global_idx;
1103  if (consistent_frag_sizes_[storage_idx][col_logical_idx] != -1) {
1104  frag_id = global_idx / consistent_frag_sizes_[storage_idx][col_logical_idx];
1105  local_idx = global_idx % consistent_frag_sizes_[storage_idx][col_logical_idx];
1106  } else {
1107  std::tie(frag_id, local_idx) = get_frag_id_and_local_idx(
1108  frag_offsets_[storage_idx], col_logical_idx, global_idx);
1109  CHECK_LE(local_idx, global_idx);
1110  }
1111  CHECK_GE(frag_id, int64_t(0));
1112  CHECK_LT(static_cast<size_t>(frag_id), col_buffers_[storage_idx].size());
1113  global_idx = local_idx;
1114  return col_buffers_[storage_idx][frag_id];
1115  } else {
1116  CHECK_EQ(size_t(1), col_buffers_[storage_idx].size());
1117  return col_buffers_[storage_idx][0];
1118  }
1119 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
#define CHECK_GE(x, y)
Definition: Logger.h:203
#define CHECK_LT(x, y)
Definition: Logger.h:200
#define CHECK_LE(x, y)
Definition: Logger.h:201
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:822
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:824
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:823
std::pair< int64_t, int64_t > get_frag_id_and_local_idx(const std::vector< std::vector< T >> &frag_offsets, const size_t tab_or_col_idx, const int64_t global_idx)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 256 of file ResultSet.cpp.

256  {
257  if (crt_row_buff_idx_ == 0) {
258  throw std::runtime_error("current row buffer iteration index is undefined");
259  }
260  return crt_row_buff_idx_ - 1;
261 }
size_t crt_row_buff_idx_
Definition: ResultSet.h:806
Data_Namespace::DataMgr* ResultSet::getDataManager ( ) const
private
int8_t * ResultSet::getDeviceEstimatorBuffer ( ) const

Definition at line 401 of file ResultSet.cpp.

References CHECK(), and GPU.

401  {
403  return estimator_buffer_;
404 }
int8_t * estimator_buffer_
Definition: ResultSet.h:827
CHECK(cgen_state)
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801

+ Here is the call graph for this function:

int ResultSet::getDeviceId ( ) const

Definition at line 448 of file ResultSet.cpp.

448  {
449  return device_id_;
450 }
const int device_id_
Definition: ResultSet.h:802
ExecutorDeviceType ResultSet::getDeviceType ( ) const

Definition at line 224 of file ResultSet.cpp.

224  {
225  return device_type_;
226 }
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801
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 1163 of file ResultSetIteration.cpp.

References GroupByBaselineHash, GroupByPerfectHash, and UNREACHABLE.

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

Definition at line 486 of file ResultSet.h.

References geo_return_type_.

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

Definition at line 406 of file ResultSet.cpp.

406  {
407  return host_estimator_buffer_;
408 }
int8_t * host_estimator_buffer_
Definition: ResultSet.h:828
const std::vector<ColumnLazyFetchInfo>& ResultSet::getLazyFetchInfo ( ) const
inline

Definition at line 512 of file ResultSet.h.

References lazy_fetch_info_.

512  {
513  return lazy_fetch_info_;
514  }
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:821
size_t ResultSet::getLimit ( )

Definition at line 857 of file ResultSet.cpp.

857  {
858  return keep_first_;
859 }
size_t keep_first_
Definition: ResultSet.h:809
size_t ResultSet::getNDVEstimator ( ) const

Definition at line 22 of file CardinalityEstimator.cpp.

References bitmap_set_size(), CHECK(), and CHECK_LE.

22  {
23  CHECK(dynamic_cast<const Analyzer::NDVEstimator*>(estimator_.get()));
25  auto bits_set = bitmap_set_size(host_estimator_buffer_, estimator_->getBufferSize());
26  const auto total_bits = estimator_->getBufferSize() * 8;
27  CHECK_LE(bits_set, total_bits);
28  const auto unset_bits = total_bits - bits_set;
29  const auto ratio = static_cast<double>(unset_bits) / total_bits;
30  if (ratio == 0.) {
31  throw std::runtime_error("Failed to get a high quality cardinality estimation");
32  }
33  return -static_cast<double>(total_bits) * log(ratio);
34 }
CHECK(cgen_state)
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:826
#define CHECK_LE(x, y)
Definition: Logger.h:201
int8_t * host_estimator_buffer_
Definition: ResultSet.h:828
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 293 of file ResultSetIteration.cpp.

294  {
295  std::lock_guard<std::mutex> lock(row_iteration_mutex_);
296  if (!storage_ && !just_explain_) {
297  return {};
298  }
299  return getNextRowUnlocked(translate_strings, decimal_to_double);
300 }
std::mutex row_iteration_mutex_
Definition: ResultSet.h:839
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
const bool just_explain_
Definition: ResultSet.h:837
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 321 of file ResultSetIteration.cpp.

References CHECK(), and CHECK_EQ.

322  {
323  auto entry_buff_idx = advanceCursorToNextEntry();
325  return {};
326  }
327 
328  if (crt_row_buff_idx_ >= entryCount()) {
330  return {};
331  }
332  auto row = getRowAt(entry_buff_idx, translate_strings, decimal_to_double, false);
333  CHECK(!row.empty());
335  ++fetched_so_far_;
336 
337  return row;
338 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
size_t keep_first_
Definition: ResultSet.h:809
size_t drop_first_
Definition: ResultSet.h:808
CHECK(cgen_state)
std::vector< TargetValue > getRowAt(const size_t index) const
size_t entryCount() const
size_t fetched_so_far_
Definition: ResultSet.h:807
size_t crt_row_buff_idx_
Definition: ResultSet.h:806
size_t advanceCursorToNextEntry() const

+ Here is the call graph for this function:

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

Definition at line 302 of file ResultSetIteration.cpp.

304  {
305  if (just_explain_) {
306  if (fetched_so_far_) {
307  return {};
308  }
309  fetched_so_far_ = 1;
310  return {explanation_};
311  }
312  while (fetched_so_far_ < drop_first_) {
313  const auto row = getNextRowImpl(translate_strings, decimal_to_double);
314  if (row.empty()) {
315  return row;
316  }
317  }
318  return getNextRowImpl(translate_strings, decimal_to_double);
319 }
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
const bool just_explain_
Definition: ResultSet.h:837
size_t drop_first_
Definition: ResultSet.h:808
std::string explanation_
Definition: ResultSet.h:836
std::vector< TargetValue > getNextRowImpl(const bool translate_strings, const bool decimal_to_double) const
size_t fetched_so_far_
Definition: ResultSet.h:807
OneIntegerColumnRow ResultSet::getOneColRow ( const size_t  index) const

Definition at line 231 of file ResultSetIteration.cpp.

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

231  {
232  const auto storage_lookup_result = findStorage(global_entry_idx);
233  const auto storage = storage_lookup_result.storage_ptr;
234  const auto local_entry_idx = storage_lookup_result.fixedup_entry_idx;
235  if (storage->isEmptyEntry(local_entry_idx)) {
236  return {0, false};
237  }
238  const auto buff = storage->buff_;
239  CHECK(buff);
241  const auto keys_ptr = row_ptr_rowwise(buff, query_mem_desc_, local_entry_idx);
242  const auto key_bytes_with_padding =
244  const auto rowwise_target_ptr = keys_ptr + key_bytes_with_padding;
245  const auto tv = getTargetValueFromBufferRowwise(rowwise_target_ptr,
246  keys_ptr,
247  global_entry_idx,
248  targets_.front(),
249  0,
250  0,
251  false,
252  false,
253  false);
254  const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
255  CHECK(scalar_tv);
256  const auto ival_ptr = boost::get<int64_t>(scalar_tv);
257  CHECK(ival_ptr);
258  return {*ival_ptr, true};
259 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
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:800
CHECK(cgen_state)
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:616
T row_ptr_rowwise(T buff, const QueryMemoryDescriptor &query_mem_desc, const size_t entry_idx)
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 501 of file ResultSet.h.

References QueryMemoryDescriptor::getPaddedSlotWidthBytes(), and query_mem_desc_.

501  {
502  return query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
503  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const

+ Here is the call graph for this function:

const std::vector< uint32_t > & ResultSet::getPermutationBuffer ( ) const

Definition at line 551 of file ResultSet.cpp.

551  {
552  return permutation_;
553 }
std::vector< uint32_t > permutation_
Definition: ResultSet.h:811
QueryDescriptionType ResultSet::getQueryDescriptionType ( ) const
inline

Definition at line 497 of file ResultSet.h.

References QueryMemoryDescriptor::getQueryDescriptionType(), and query_mem_desc_.

497  {
499  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
QueryDescriptionType getQueryDescriptionType() const

+ Here is the call graph for this function:

const QueryMemoryDescriptor & ResultSet::getQueryMemDesc ( ) const

Definition at line 387 of file ResultSet.cpp.

References CHECK().

387  {
388  CHECK(storage_);
389  return storage_->query_mem_desc_;
390 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
CHECK(cgen_state)

+ Here is the call graph for this function:

int64_t ResultSet::getQueueTime ( ) const

Definition at line 427 of file ResultSet.cpp.

427  {
428  return queue_time_ms_;
429 }
int64_t queue_time_ms_
Definition: ResultSet.h:812
int64_t ResultSet::getRenderTime ( ) const

Definition at line 431 of file ResultSet.cpp.

431  {
432  return render_time_ms_;
433 }
int64_t render_time_ms_
Definition: ResultSet.h:813
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 270 of file ResultSetIteration.cpp.

272  {
273  if (logical_index >= entryCount()) {
274  return {};
275  }
276  const auto entry_idx =
277  permutation_.empty() ? logical_index : permutation_[logical_index];
278  return getRowAt(entry_idx, false, false, false, targets_to_skip);
279 }
std::vector< uint32_t > permutation_
Definition: ResultSet.h:811
std::vector< TargetValue > getRowAt(const size_t index) const
size_t entryCount() const
std::shared_ptr<RowSetMemoryOwner> ResultSet::getRowSetMemOwner ( ) const
inline

Definition at line 460 of file ResultSet.h.

References row_set_mem_owner_.

460  {
461  return row_set_mem_owner_;
462  }
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:810
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 1271 of file ResultSetIteration.cpp.

References CHECK_NE, row_ptr_rowwise(), and storage_.

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

References storage_.

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

Definition at line 903 of file ResultSet.cpp.

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

903  {
904  std::vector<bool> target_bitmap(targets_.size(), true);
905  size_t num_single_slot_targets = 0;
906  for (size_t target_idx = 0; target_idx < targets_.size(); target_idx++) {
907  const auto& sql_type = targets_[target_idx].sql_type;
908  if (targets_[target_idx].is_agg && targets_[target_idx].agg_kind == kAVG) {
909  target_bitmap[target_idx] = false;
910  } else if (sql_type.is_varlen()) {
911  target_bitmap[target_idx] = false;
912  } else {
913  num_single_slot_targets++;
914  }
915  }
916  return std::make_tuple(std::move(target_bitmap), num_single_slot_targets);
917 }
bool is_agg(const Analyzer::Expr *expr)
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
Definition: sqldefs.h:71

+ Here is the call graph for this function:

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

Definition at line 946 of file ResultSet.cpp.

References advance_slot().

946  {
947  std::vector<size_t> slot_indices(targets_.size(), 0);
948  size_t slot_index = 0;
949  for (size_t target_idx = 0; target_idx < targets_.size(); target_idx++) {
950  slot_indices[target_idx] = slot_index;
951  slot_index = advance_slot(slot_index, targets_[target_idx], false);
952  }
953  return slot_indices;
954 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
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 293 of file ResultSet.cpp.

293  {
294  return storage_.get();
295 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
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 594 of file ResultSet.cpp.

References CHECK_NE, and UNREACHABLE.

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

594  {
595  size_t fixedup_entry_idx = entry_idx;
596  auto entry_count = storage_->query_mem_desc_.getEntryCount();
597  const bool is_rowwise_layout = !storage_->query_mem_desc_.didOutputColumnar();
598  if (fixedup_entry_idx < entry_count) {
599  return {0, fixedup_entry_idx};
600  }
601  fixedup_entry_idx -= entry_count;
602  for (size_t i = 0; i < appended_storage_.size(); ++i) {
603  const auto& desc = appended_storage_[i]->query_mem_desc_;
604  CHECK_NE(is_rowwise_layout, desc.didOutputColumnar());
605  entry_count = desc.getEntryCount();
606  if (fixedup_entry_idx < entry_count) {
607  return {i + 1, fixedup_entry_idx};
608  }
609  fixedup_entry_idx -= entry_count;
610  }
611  UNREACHABLE() << "entry_idx = " << entry_idx << ", query_mem_desc_.getEntryCount() = "
613  return {};
614 }
std::vector< std::unique_ptr< ResultSetStorage > > appended_storage_
Definition: ResultSet.h:805
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
#define UNREACHABLE()
Definition: Logger.h:234
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
#define CHECK_NE(x, y)
Definition: Logger.h:199

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

References CHECK().

862  {
863  CHECK(executor_);
864  const auto sdp =
865  executor_->getStringDictionaryProxy(dict_id, row_set_mem_owner_, false);
866  return sdp->getDictionary()->copyStrings();
867 }
const Executor * executor_
Definition: ResultSet.h:814
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:810
CHECK(cgen_state)

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

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

928  {
930  auto [single_slot_targets, num_single_slot_targets] = getSingleSlotTargetBitmap();
931 
932  for (size_t target_idx = 0; target_idx < single_slot_targets.size(); target_idx++) {
933  const auto& target = targets_[target_idx];
934  if (single_slot_targets[target_idx] &&
935  (is_distinct_target(target) ||
936  (target.is_agg && target.agg_kind == kSAMPLE && target.sql_type == kFLOAT))) {
937  single_slot_targets[target_idx] = false;
938  num_single_slot_targets--;
939  }
940  }
941  CHECK_GE(num_single_slot_targets, size_t(0));
942  return std::make_tuple(std::move(single_slot_targets), num_single_slot_targets);
943 }
#define CHECK_GE(x, y)
Definition: Logger.h:203
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
CHECK(cgen_state)
std::tuple< std::vector< bool >, size_t > getSingleSlotTargetBitmap() const
Definition: ResultSet.cpp:903
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:116
bool isDirectColumnarConversionPossible() const
Definition: ResultSet.cpp:884

+ Here is the call graph for this function:

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

Definition at line 392 of file ResultSet.cpp.

392  {
393  return targets_;
394 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
const std::vector< int64_t > & ResultSet::getTargetInitVals ( ) const

Definition at line 396 of file ResultSet.cpp.

References CHECK().

396  {
397  CHECK(storage_);
398  return storage_->target_init_vals_;
399 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
CHECK(cgen_state)

+ Here is the call graph for this function:

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 1863 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, SQLTypeInfoCore< TYPE_FACET_PACK >::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().

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

References TargetInfo::agg_kind, CHECK(), checked_malloc(), QueryMemoryDescriptor::count_distinct_descriptors_, SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), QueryMemoryDescriptor::getEffectiveKeyWidth(), QueryMemoryDescriptor::getLogicalSlotWidthBytes(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getTargetGroupbyIndex(), QueryMemoryDescriptor::hasKeylessHash(), TargetInfo::is_agg, SQLTypeInfoCore< TYPE_FACET_PACK >::is_array(), is_distinct_target(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_geometry(), is_real_str_or_array(), SQLTypeInfoCore< TYPE_FACET_PACK >::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.

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

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

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

+ Here is the call graph for this function:

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

Definition at line 453 of file ResultSet.h.

References chunk_iters_.

453  {
454  chunk_iters_.push_back(chunk_iters);
455  }
std::vector< std::shared_ptr< std::list< ChunkIter > > > chunk_iters_
Definition: ResultSet.h:817
void ResultSet::holdChunks ( const std::list< std::shared_ptr< Chunk_NS::Chunk >> &  chunks)
inline

Definition at line 450 of file ResultSet.h.

References chunks_.

450  {
451  chunks_ = chunks;
452  }
std::list< std::shared_ptr< Chunk_NS::Chunk > > chunks_
Definition: ResultSet.h:816
void ResultSet::holdLiterals ( std::vector< int8_t > &  literal_buff)
inline

Definition at line 456 of file ResultSet.h.

References literal_buffers_.

456  {
457  literal_buffers_.push_back(std::move(literal_buff));
458  }
std::vector< std::vector< int8_t > > literal_buffers_
Definition: ResultSet.h:820
void ResultSet::initializeStorage ( ) const

Definition at line 986 of file ResultSetReduction.cpp.

986  {
988  storage_->initializeColWise();
989  } else {
990  storage_->initializeRowWise();
991  }
992 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
std::vector< uint32_t > ResultSet::initPermutationBuffer ( const size_t  start,
const size_t  step 
)
private

Definition at line 533 of file ResultSet.cpp.

References CHECK(), and CHECK_NE.

534  {
535  CHECK_NE(size_t(0), step);
536  std::vector<uint32_t> permutation;
537  const auto total_entries = query_mem_desc_.getEntryCount();
538  permutation.reserve(total_entries / step);
539  for (size_t i = start; i < total_entries; i += step) {
540  const auto storage_lookup_result = findStorage(i);
541  const auto lhs_storage = storage_lookup_result.storage_ptr;
542  const auto off = storage_lookup_result.fixedup_entry_idx;
543  CHECK(lhs_storage);
544  if (!lhs_storage->isEmptyEntry(off)) {
545  permutation.push_back(i);
546  }
547  }
548  return permutation;
549 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
CHECK(cgen_state)
#define CHECK_NE(x, y)
Definition: Logger.h:199
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:616

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

References g_enable_direct_columnarization, GroupByBaselineHash, GroupByPerfectHash, and Projection.

Referenced by copyColumnIntoBuffer().

+ Here is the caller graph for this function:

bool ResultSet::isExplain ( ) const

Definition at line 444 of file ResultSet.cpp.

444  {
445  return just_explain_;
446 }
const bool just_explain_
Definition: ResultSet.h:837
bool ResultSet::isGeoColOnGpu ( const size_t  col_idx) const

Definition at line 1434 of file ResultSetIteration.cpp.

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

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

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

References CHECK(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_notnull(), InternalTargetValue::i1, InternalTargetValue::i2, InternalTargetValue::isInt(), InternalTargetValue::isNull(), InternalTargetValue::isPair(), InternalTargetValue::isStr(), NULL_DOUBLE, null_val_bit_pattern(), and pair_to_double().

2132  {
2133  if (ti.get_notnull()) {
2134  return false;
2135  }
2136  if (val.isInt()) {
2137  return val.i1 == null_val_bit_pattern(ti, float_argument_input);
2138  }
2139  if (val.isPair()) {
2140  return !val.i2 ||
2141  pair_to_double({val.i1, val.i2}, ti, float_argument_input) == NULL_DOUBLE;
2142  }
2143  if (val.isStr()) {
2144  return !val.i1;
2145  }
2146  CHECK(val.isNull());
2147  return true;
2148 }
#define NULL_DOUBLE
Definition: sqltypes.h:179
bool isPair() const
Definition: TargetValue.h:67
bool isStr() const
Definition: TargetValue.h:71
double pair_to_double(const std::pair< int64_t, int64_t > &fp_pair, const SQLTypeInfo &ti, const bool float_argument_input)
int64_t null_val_bit_pattern(const SQLTypeInfo &ti, const bool float_argument_input)
CHECK(cgen_state)
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:333
bool isNull() const
Definition: TargetValue.h:69
bool isInt() const
Definition: TargetValue.h:65

+ Here is the call graph for this function:

const bool ResultSet::isPermutationBufferEmpty ( ) const
inline

Definition at line 465 of file ResultSet.h.

References permutation_.

465 { return permutation_.empty(); };
std::vector< uint32_t > permutation_
Definition: ResultSet.h:811
bool ResultSet::isRowAtEmpty ( const size_t  index) const

Definition at line 281 of file ResultSetIteration.cpp.

281  {
282  if (logical_index >= entryCount()) {
283  return true;
284  }
285  const auto entry_idx =
286  permutation_.empty() ? logical_index : permutation_[logical_index];
287  const auto storage_lookup_result = findStorage(entry_idx);
288  const auto storage = storage_lookup_result.storage_ptr;
289  const auto local_entry_idx = storage_lookup_result.fixedup_entry_idx;
290  return storage->isEmptyEntry(local_entry_idx);
291 }
std::vector< uint32_t > permutation_
Definition: ResultSet.h:811
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:616
size_t entryCount() const
bool ResultSet::isTruncated ( ) const

Definition at line 440 of file ResultSet.cpp.

440  {
441  return keep_first_ + drop_first_;
442 }
size_t keep_first_
Definition: ResultSet.h:809
size_t drop_first_
Definition: ResultSet.h:808
void ResultSet::keepFirstN ( const size_t  n)

Definition at line 81 of file ResultSet.cpp.

References CHECK_EQ.

81  {
83  keep_first_ = n;
84 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
size_t keep_first_
Definition: ResultSet.h:809
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838
int64_t ResultSet::lazyReadInt ( const int64_t  ival,
const size_t  target_logical_idx,
const StorageLookupResult storage_lookup_result 
) const
private

Definition at line 650 of file ResultSetIteration.cpp.

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

652  {
653  if (!lazy_fetch_info_.empty()) {
654  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
655  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
656  if (col_lazy_fetch.is_lazily_fetched) {
657  CHECK_LT(static_cast<size_t>(storage_lookup_result.storage_idx),
658  col_buffers_.size());
659  int64_t ival_copy = ival;
660  auto& frag_col_buffers =
661  getColumnFrag(static_cast<size_t>(storage_lookup_result.storage_idx),
662  target_logical_idx,
663  ival_copy);
664  auto& frag_col_buffer = frag_col_buffers[col_lazy_fetch.local_col_id];
665  CHECK_LT(target_logical_idx, targets_.size());
666  const TargetInfo& target_info = targets_[target_logical_idx];
667  CHECK(!target_info.is_agg);
668  if (target_info.sql_type.is_string() &&
669  target_info.sql_type.get_compression() == kENCODING_NONE) {
670  VarlenDatum vd;
671  bool is_end{false};
673  reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(frag_col_buffer)),
674  storage_lookup_result.fixedup_entry_idx,
675  false,
676  &vd,
677  &is_end);
678  CHECK(!is_end);
679  if (vd.is_null) {
680  return 0;
681  }
682  std::string fetched_str(reinterpret_cast<char*>(vd.pointer), vd.length);
683  return reinterpret_cast<int64_t>(row_set_mem_owner_->addString(fetched_str));
684  }
685  return lazy_decode(col_lazy_fetch, frag_col_buffer, ival_copy);
686  }
687  }
688  return ival;
689 }
int64_t lazy_decode(const ColumnLazyFetchInfo &col_lazy_fetch, const int8_t *byte_stream, const int64_t pos)
bool is_null
Definition: sqltypes.h:76
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:75
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:810
CHECK(cgen_state)
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:821
#define CHECK_LT(x, y)
Definition: Logger.h:200
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:822
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:74

+ 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 1465 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_, SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type_name(), getColumnFrag(), QueryMemoryDescriptor::getExecutor(), QueryMemoryDescriptor::getPaddedColWidthForRange(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), getStorageIndex(), GPU, TargetInfo::is_agg, SQLTypeInfoCore< TYPE_FACET_PACK >::is_geometry(), ColumnLazyFetchInfo::is_lazily_fetched, kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, lazy_fetch_info_, ColumnLazyFetchInfo::local_col_id, query_mem_desc_, read_int_from_buff(), separate_varlen_storage_valid_, serialized_varlen_buffer_, TargetInfo::sql_type, and UNREACHABLE.

Referenced by getTargetValueFromBufferColwise(), and getTargetValueFromBufferRowwise().

1469  {
1470  CHECK(target_info.sql_type.is_geometry());
1471 
1472  auto getNextTargetBufferRowWise = [&](const size_t slot_idx, const size_t range) {
1473  return geo_target_ptr + query_mem_desc_.getPaddedColWidthForRange(slot_idx, range);
1474  };
1475 
1476  auto getNextTargetBufferColWise = [&](const size_t slot_idx, const size_t range) {
1477  const auto storage_info = findStorage(entry_buff_idx);
1478  auto crt_geo_col_ptr = geo_target_ptr;
1479  for (size_t i = slot_idx; i < slot_idx + range; i++) {
1480  crt_geo_col_ptr = advance_to_next_columnar_target_buff(
1481  crt_geo_col_ptr, storage_info.storage_ptr->query_mem_desc_, i);
1482  }
1483  // adjusting the column pointer to represent a pointer to the geo target value
1484  return crt_geo_col_ptr +
1485  storage_info.fixedup_entry_idx *
1486  storage_info.storage_ptr->query_mem_desc_.getPaddedSlotWidthBytes(
1487  slot_idx + range);
1488  };
1489 
1490  auto getNextTargetBuffer = [&](const size_t slot_idx, const size_t range) {
1492  ? getNextTargetBufferColWise(slot_idx, range)
1493  : getNextTargetBufferRowWise(slot_idx, range);
1494  };
1495 
1496  auto getCoordsDataPtr = [&](const int8_t* geo_target_ptr) {
1497  return read_int_from_buff(getNextTargetBuffer(slot_idx, 0),
1499  };
1500 
1501  auto getCoordsLength = [&](const int8_t* geo_target_ptr) {
1502  return read_int_from_buff(getNextTargetBuffer(slot_idx, 1),
1504  };
1505 
1506  auto getRingSizesPtr = [&](const int8_t* geo_target_ptr) {
1507  return read_int_from_buff(getNextTargetBuffer(slot_idx, 2),
1509  };
1510 
1511  auto getRingSizesLength = [&](const int8_t* geo_target_ptr) {
1512  return read_int_from_buff(getNextTargetBuffer(slot_idx, 3),
1514  };
1515 
1516  auto getPolyRingsPtr = [&](const int8_t* geo_target_ptr) {
1517  return read_int_from_buff(getNextTargetBuffer(slot_idx, 4),
1519  };
1520 
1521  auto getPolyRingsLength = [&](const int8_t* geo_target_ptr) {
1522  return read_int_from_buff(getNextTargetBuffer(slot_idx, 5),
1524  };
1525 
1526  auto getFragColBuffers = [&]() -> decltype(auto) {
1527  const auto storage_idx = getStorageIndex(entry_buff_idx);
1528  CHECK_LT(storage_idx.first, col_buffers_.size());
1529  auto global_idx = getCoordsDataPtr(geo_target_ptr);
1530  return getColumnFrag(storage_idx.first, target_logical_idx, global_idx);
1531  };
1532 
1533  const bool is_gpu_fetch = device_type_ == ExecutorDeviceType::GPU;
1534 
1535  auto getDataMgr = [&]() {
1536  auto executor = query_mem_desc_.getExecutor();
1537  CHECK(executor);
1538  auto& data_mgr = executor->catalog_->getDataMgr();
1539  return &data_mgr;
1540  };
1541 
1542  auto getSeparateVarlenStorage = [&]() -> decltype(auto) {
1543  const auto storage_idx = getStorageIndex(entry_buff_idx);
1544  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1545  const auto& varlen_buffer = serialized_varlen_buffer_[storage_idx.first];
1546  return varlen_buffer;
1547  };
1548 
1549  if (separate_varlen_storage_valid_ && getCoordsDataPtr(geo_target_ptr) < 0) {
1550  CHECK_EQ(-1, getCoordsDataPtr(geo_target_ptr));
1551  return TargetValue(nullptr);
1552  }
1553 
1554  const ColumnLazyFetchInfo* col_lazy_fetch = nullptr;
1555  if (!lazy_fetch_info_.empty()) {
1556  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1557  col_lazy_fetch = &lazy_fetch_info_[target_logical_idx];
1558  }
1559 
1560  switch (target_info.sql_type.get_type()) {
1561  case kPOINT: {
1562  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1563  const auto& varlen_buffer = getSeparateVarlenStorage();
1564  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr)),
1565  varlen_buffer.size());
1566 
1567  return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1568  target_info.sql_type,
1570  nullptr,
1571  false,
1572  device_id_,
1573  reinterpret_cast<int64_t>(
1574  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1575  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()));
1576  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1577  const auto& frag_col_buffers = getFragColBuffers();
1578  return GeoTargetValueBuilder<kPOINT, GeoLazyFetchHandler>::build(
1579  target_info.sql_type,
1581  frag_col_buffers[col_lazy_fetch->local_col_id],
1582  getCoordsDataPtr(geo_target_ptr));
1583  } else {
1584  return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1585  target_info.sql_type,
1587  is_gpu_fetch ? getDataMgr() : nullptr,
1588  is_gpu_fetch,
1589  device_id_,
1590  getCoordsDataPtr(geo_target_ptr),
1591  getCoordsLength(geo_target_ptr));
1592  }
1593  break;
1594  }
1595  case kLINESTRING: {
1596  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1597  const auto& varlen_buffer = getSeparateVarlenStorage();
1598  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr)),
1599  varlen_buffer.size());
1600 
1601  return GeoTargetValueBuilder<kLINESTRING, GeoQueryOutputFetchHandler>::build(
1602  target_info.sql_type,
1604  nullptr,
1605  false,
1606  device_id_,
1607  reinterpret_cast<int64_t>(
1608  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1609  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()));
1610  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1611  const auto& frag_col_buffers = getFragColBuffers();
1612  return GeoTargetValueBuilder<kLINESTRING, GeoLazyFetchHandler>::build(
1613  target_info.sql_type,
1615  frag_col_buffers[col_lazy_fetch->local_col_id],
1616  getCoordsDataPtr(geo_target_ptr));
1617  } else {
1618  return GeoTargetValueBuilder<kLINESTRING, GeoQueryOutputFetchHandler>::build(
1619  target_info.sql_type,
1621  is_gpu_fetch ? getDataMgr() : nullptr,
1622  is_gpu_fetch,
1623  device_id_,
1624  getCoordsDataPtr(geo_target_ptr),
1625  getCoordsLength(geo_target_ptr));
1626  }
1627  break;
1628  }
1629  case kPOLYGON: {
1630  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1631  const auto& varlen_buffer = getSeparateVarlenStorage();
1632  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr) + 1),
1633  varlen_buffer.size());
1634 
1635  return GeoTargetValueBuilder<kPOLYGON, GeoQueryOutputFetchHandler>::build(
1636  target_info.sql_type,
1638  nullptr,
1639  false,
1640  device_id_,
1641  reinterpret_cast<int64_t>(
1642  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1643  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()),
1644  reinterpret_cast<int64_t>(
1645  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].data()),
1646  static_cast<int64_t>(
1647  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].size()));
1648  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1649  const auto& frag_col_buffers = getFragColBuffers();
1650 
1651  return GeoTargetValueBuilder<kPOLYGON, GeoLazyFetchHandler>::build(
1652  target_info.sql_type,
1654  frag_col_buffers[col_lazy_fetch->local_col_id],
1655  getCoordsDataPtr(geo_target_ptr),
1656  frag_col_buffers[col_lazy_fetch->local_col_id + 1],
1657  getCoordsDataPtr(geo_target_ptr));
1658  } else {
1659  return GeoTargetValueBuilder<kPOLYGON, GeoQueryOutputFetchHandler>::build(
1660  target_info.sql_type,
1662  is_gpu_fetch ? getDataMgr() : nullptr,
1663  is_gpu_fetch,
1664  device_id_,
1665  getCoordsDataPtr(geo_target_ptr),
1666  getCoordsLength(geo_target_ptr),
1667  getRingSizesPtr(geo_target_ptr),
1668  getRingSizesLength(geo_target_ptr) * 4);
1669  }
1670  break;
1671  }
1672  case kMULTIPOLYGON: {
1673  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1674  const auto& varlen_buffer = getSeparateVarlenStorage();
1675  CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr) + 2),
1676  varlen_buffer.size());
1677 
1678  return GeoTargetValueBuilder<kMULTIPOLYGON, GeoQueryOutputFetchHandler>::build(
1679  target_info.sql_type,
1681  nullptr,
1682  false,
1683  device_id_,
1684  reinterpret_cast<int64_t>(
1685  varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1686  static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()),
1687  reinterpret_cast<int64_t>(
1688  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].data()),
1689  static_cast<int64_t>(
1690  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].size()),
1691  reinterpret_cast<int64_t>(
1692  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 2].data()),
1693  static_cast<int64_t>(
1694  varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 2].size()));
1695  } else if (col_lazy_fetch && col_lazy_fetch->is_lazily_fetched) {
1696  const auto& frag_col_buffers = getFragColBuffers();
1697 
1698  return GeoTargetValueBuilder<kMULTIPOLYGON, GeoLazyFetchHandler>::build(
1699  target_info.sql_type,
1701  frag_col_buffers[col_lazy_fetch->local_col_id],
1702  getCoordsDataPtr(geo_target_ptr),
1703  frag_col_buffers[col_lazy_fetch->local_col_id + 1],
1704  getCoordsDataPtr(geo_target_ptr),
1705  frag_col_buffers[col_lazy_fetch->local_col_id + 2],
1706  getCoordsDataPtr(geo_target_ptr));
1707  } else {
1708  return GeoTargetValueBuilder<kMULTIPOLYGON, GeoQueryOutputFetchHandler>::build(
1709  target_info.sql_type,
1711  is_gpu_fetch ? getDataMgr() : nullptr,
1712  is_gpu_fetch,
1713  device_id_,
1714  getCoordsDataPtr(geo_target_ptr),
1715  getCoordsLength(geo_target_ptr),
1716  getRingSizesPtr(geo_target_ptr),
1717  getRingSizesLength(geo_target_ptr) * 4,
1718  getPolyRingsPtr(geo_target_ptr),
1719  getPolyRingsLength(geo_target_ptr) * 4);
1720  }
1721  break;
1722  }
1723  default:
1724  throw std::runtime_error("Unknown Geometry type encountered: " +
1725  target_info.sql_type.get_type_name());
1726  }
1727  UNREACHABLE();
1728  return TargetValue(nullptr);
1729 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:594
GeoReturnType geo_return_type_
Definition: ResultSet.h:842
T advance_to_next_columnar_target_buff(T target_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t target_slot_idx)
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
#define UNREACHABLE()
Definition: Logger.h:234
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:834
const int local_col_id
Definition: ResultSet.h:224
std::string get_type_name() const
Definition: sqltypes.h:429
bool is_agg
Definition: TargetInfo.h:40
CHECK(cgen_state)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
size_t getPaddedColWidthForRange(const size_t offset, const size_t range) const
StorageLookupResult findStorage(const size_t entry_idx) const
Definition: ResultSet.cpp:616
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:821
bool is_geometry() const
Definition: sqltypes.h:489
#define CHECK_LT(x, y)
Definition: Logger.h:200
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:822
const bool is_lazily_fetched
Definition: ResultSet.h:223
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801
bool separate_varlen_storage_valid_
Definition: ResultSet.h:835
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:802

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

References TargetInfo::agg_kind, CHECK(), CHECK_EQ, CHECK_GE, CHECK_LT, col_buffers_, count_distinct_set_size(), decimal_to_int_type(), executor_, exp_to_scale(), QueryMemoryDescriptor::forceFourByteFloat(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_comp_param(), get_compact_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), getColumnFrag(), QueryMemoryDescriptor::getCountDistinctDescriptor(), getStorageIndex(), inline_int_null_val(), anonymous_namespace{ResultSetIteration.cpp}::int_resize_cast(), TargetInfo::is_agg, is_distinct_target(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), QueryMemoryDescriptor::isLogicalSizedColumnsAllowed(), kAVG, kBIGINT, kENCODING_DICT, kFLOAT, kMAX, kMIN, kSUM, 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().

1738  {
1739  auto actual_compact_sz = compact_sz;
1740  if (target_info.sql_type.get_type() == kFLOAT &&
1743  actual_compact_sz = sizeof(float);
1744  } else {
1745  actual_compact_sz = sizeof(double);
1746  }
1747  if (target_info.is_agg &&
1748  (target_info.agg_kind == kAVG || target_info.agg_kind == kSUM ||
1749  target_info.agg_kind == kMIN || target_info.agg_kind == kMAX)) {
1750  // The above listed aggregates use two floats in a single 8-byte slot. Set the
1751  // padded size to 4 bytes to properly read each value.
1752  actual_compact_sz = sizeof(float);
1753  }
1754  }
1755  if (get_compact_type(target_info).is_date_in_days()) {
1756  // Dates encoded in days are converted to 8 byte values on read.
1757  actual_compact_sz = sizeof(int64_t);
1758  }
1759 
1760  // String dictionary keys are read as 32-bit values regardless of encoding
1761  if (target_info.sql_type.is_string() &&
1762  target_info.sql_type.get_compression() == kENCODING_DICT &&
1763  target_info.sql_type.get_comp_param()) {
1764  actual_compact_sz = sizeof(int32_t);
1765  }
1766 
1767  auto ival = read_int_from_buff(ptr, actual_compact_sz);
1768  const auto& chosen_type = get_compact_type(target_info);
1769  if (!lazy_fetch_info_.empty()) {
1770  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1771  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
1772  if (col_lazy_fetch.is_lazily_fetched) {
1773  CHECK_GE(ival, 0);
1774  const auto storage_idx = getStorageIndex(entry_buff_idx);
1775  CHECK_LT(storage_idx.first, col_buffers_.size());
1776  auto& frag_col_buffers = getColumnFrag(storage_idx.first, target_logical_idx, ival);
1777  ival = lazy_decode(
1778  col_lazy_fetch, frag_col_buffers[col_lazy_fetch.local_col_id], ival);
1779  if (chosen_type.is_fp()) {
1780  const auto dval = *reinterpret_cast<const double*>(may_alias_ptr(&ival));
1781  if (chosen_type.get_type() == kFLOAT) {
1782  return ScalarTargetValue(static_cast<float>(dval));
1783  } else {
1784  return ScalarTargetValue(dval);
1785  }
1786  }
1787  }
1788  }
1789  if (chosen_type.is_fp()) {
1790  switch (actual_compact_sz) {
1791  case 8: {
1792  const auto dval = *reinterpret_cast<const double*>(ptr);
1793  return chosen_type.get_type() == kFLOAT
1794  ? ScalarTargetValue(static_cast<const float>(dval))
1795  : ScalarTargetValue(dval);
1796  }
1797  case 4: {
1798  CHECK_EQ(kFLOAT, chosen_type.get_type());
1799  return *reinterpret_cast<const float*>(ptr);
1800  }
1801  default:
1802  CHECK(false);
1803  }
1804  }
1805  if (chosen_type.is_integer() | chosen_type.is_boolean() || chosen_type.is_time() ||
1806  chosen_type.is_timeinterval()) {
1807  if (is_distinct_target(target_info)) {
1809  ival, query_mem_desc_.getCountDistinctDescriptor(target_logical_idx)));
1810  }
1811  // TODO(alex): remove int_resize_cast, make read_int_from_buff return the
1812  // right type instead
1813  if (inline_int_null_val(chosen_type) ==
1814  int_resize_cast(ival, chosen_type.get_logical_size())) {
1815  return inline_int_null_val(target_info.sql_type);
1816  }
1817  return ival;
1818  }
1819  if (chosen_type.is_string() && chosen_type.get_compression() == kENCODING_DICT) {
1820  if (translate_strings) {
1821  if (static_cast<int32_t>(ival) ==
1822  NULL_INT) { // TODO(alex): this isn't nice, fix it
1823  return NullableString(nullptr);
1824  }
1825  StringDictionaryProxy* sdp{nullptr};
1826  if (!chosen_type.get_comp_param()) {
1827  sdp = row_set_mem_owner_->getLiteralStringDictProxy();
1828  } else {
1829  sdp = executor_
1830  ? executor_->getStringDictionaryProxy(
1831  chosen_type.get_comp_param(), row_set_mem_owner_, false)
1832  : row_set_mem_owner_->getStringDictProxy(chosen_type.get_comp_param());
1833  }
1834  return NullableString(sdp->getString(ival));
1835  } else {
1836  return static_cast<int64_t>(static_cast<int32_t>(ival));
1837  }
1838  }
1839  if (chosen_type.is_decimal()) {
1840  if (decimal_to_double) {
1841  if (target_info.is_agg &&
1842  (target_info.agg_kind == kAVG || target_info.agg_kind == kSUM ||
1843  target_info.agg_kind == kMIN || target_info.agg_kind == kMAX) &&
1844  ival == inline_int_null_val(SQLTypeInfo(kBIGINT, false))) {
1845  return NULL_DOUBLE;
1846  }
1847  if (ival ==
1848  inline_int_null_val(SQLTypeInfo(decimal_to_int_type(chosen_type), false))) {
1849  return NULL_DOUBLE;
1850  }
1851  return static_cast<double>(ival) / exp_to_scale(chosen_type.get_scale());
1852  }
1853  return ival;
1854  }
1855  CHECK(false);
1856  return TargetValue(int64_t(0));
1857 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
int64_t lazy_decode(const ColumnLazyFetchInfo &col_lazy_fetch, const int8_t *byte_stream, const int64_t pos)
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:594
#define NULL_DOUBLE
Definition: sqltypes.h:179
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:335
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
bool isLogicalSizedColumnsAllowed() const
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
const Executor * executor_
Definition: ResultSet.h:814
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
#define CHECK_GE(x, y)
Definition: Logger.h:203
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
Definition: sqldefs.h:71
const SQLTypeInfo get_compact_type(const TargetInfo &target)
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:810
bool is_agg
Definition: TargetInfo.h:40
CHECK(cgen_state)
int64_t count_distinct_set_size(const int64_t set_handle, const CountDistinctDescriptor &count_distinct_desc)
Definition: CountDistinct.h:75
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
Definition: sqldefs.h:71
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:116
#define NULL_INT
Definition: sqltypes.h:176
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:821
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:852
SQLAgg agg_kind
Definition: TargetInfo.h:41
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:268
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:200
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:822
boost::variant< std::string, void * > NullableString
Definition: TargetValue.h:155
bool is_string() const
Definition: sqltypes.h:477
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:71
Definition: sqldefs.h:71
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 1308 of file ResultSetIteration.cpp.

References anonymous_namespace{ResultSetIteration.cpp}::build_array_target_value(), CHECK(), CHECK_EQ, CHECK_GE, CHECK_GT, CHECK_LT, ChunkIter_get_nth(), col_buffers_, copy_from_gpu(), device_id_, device_type_, executor_, SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_elem_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), getColumnFrag(), QueryMemoryDescriptor::getExecutor(), getStorageIndex(), GPU, TargetInfo::is_agg, SQLTypeInfoCore< TYPE_FACET_PACK >::is_array(), VarlenDatum::is_null, SQLTypeInfoCore< TYPE_FACET_PACK >::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().

1315  {
1316  auto varlen_ptr = read_int_from_buff(ptr1, compact_sz1);
1317  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1318  if (varlen_ptr < 0) {
1319  CHECK_EQ(-1, varlen_ptr);
1320  if (target_info.sql_type.get_type() == kARRAY) {
1321  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1322  }
1323  return TargetValue(nullptr);
1324  }
1325  const auto storage_idx = getStorageIndex(entry_buff_idx);
1326  if (target_info.sql_type.is_string()) {
1327  CHECK(target_info.sql_type.get_compression() == kENCODING_NONE);
1328  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1329  const auto& varlen_buffer_for_storage =
1330  serialized_varlen_buffer_[storage_idx.first];
1331  CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer_for_storage.size());
1332  return varlen_buffer_for_storage[varlen_ptr];
1333  } else if (target_info.sql_type.get_type() == kARRAY) {
1334  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1335  const auto& varlen_buffer = serialized_varlen_buffer_[storage_idx.first];
1336  CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer.size());
1337 
1338  return build_array_target_value(
1339  target_info.sql_type,
1340  reinterpret_cast<const int8_t*>(varlen_buffer[varlen_ptr].data()),
1341  varlen_buffer[varlen_ptr].size(),
1342  translate_strings,
1344  executor_);
1345  } else {
1346  CHECK(false);
1347  }
1348  }
1349  if (!lazy_fetch_info_.empty()) {
1350  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1351  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
1352  if (col_lazy_fetch.is_lazily_fetched) {
1353  const auto storage_idx = getStorageIndex(entry_buff_idx);
1354  CHECK_LT(storage_idx.first, col_buffers_.size());
1355  auto& frag_col_buffers =
1356  getColumnFrag(storage_idx.first, target_logical_idx, varlen_ptr);
1357  bool is_end{false};
1358  if (target_info.sql_type.is_string()) {
1359  VarlenDatum vd;
1360  ChunkIter_get_nth(reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(
1361  frag_col_buffers[col_lazy_fetch.local_col_id])),
1362  varlen_ptr,
1363  false,
1364  &vd,
1365  &is_end);
1366  CHECK(!is_end);
1367  if (vd.is_null) {
1368  return TargetValue(nullptr);
1369  }
1370  CHECK(vd.pointer);
1371  CHECK_GT(vd.length, 0u);
1372  std::string fetched_str(reinterpret_cast<char*>(vd.pointer), vd.length);
1373  return fetched_str;
1374  } else {
1375  CHECK(target_info.sql_type.is_array());
1376  ArrayDatum ad;
1377  ChunkIter_get_nth(reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(
1378  frag_col_buffers[col_lazy_fetch.local_col_id])),
1379  varlen_ptr,
1380  &ad,
1381  &is_end);
1382  CHECK(!is_end);
1383  if (ad.is_null) {
1384  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1385  }
1386  CHECK_GE(ad.length, 0u);
1387  if (ad.length > 0) {
1388  CHECK(ad.pointer);
1389  }
1390  return build_array_target_value(target_info.sql_type,
1391  ad.pointer,
1392  ad.length,
1393  translate_strings,
1395  executor_);
1396  }
1397  }
1398  }
1399  if (!varlen_ptr) {
1400  if (target_info.sql_type.is_array()) {
1401  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1402  }
1403  return TargetValue(nullptr);
1404  }
1405  auto length = read_int_from_buff(ptr2, compact_sz2);
1406  if (target_info.sql_type.is_array()) {
1407  const auto& elem_ti = target_info.sql_type.get_elem_type();
1408  length *= elem_ti.get_array_context_logical_size();
1409  }
1410  std::vector<int8_t> cpu_buffer;
1411  if (varlen_ptr && device_type_ == ExecutorDeviceType::GPU) {
1412  cpu_buffer.resize(length);
1413  const auto executor = query_mem_desc_.getExecutor();
1414  CHECK(executor);
1415  auto& data_mgr = executor->catalog_->getDataMgr();
1416  copy_from_gpu(&data_mgr,
1417  &cpu_buffer[0],
1418  static_cast<CUdeviceptr>(varlen_ptr),
1419  length,
1420  device_id_);
1421  varlen_ptr = reinterpret_cast<int64_t>(&cpu_buffer[0]);
1422  }
1423  if (target_info.sql_type.is_array()) {
1424  return build_array_target_value(target_info.sql_type,
1425  reinterpret_cast<const int8_t*>(varlen_ptr),
1426  length,
1427  translate_strings,
1429  executor_);
1430  }
1431  return std::string(reinterpret_cast<char*>(varlen_ptr), length);
1432 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:594
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
bool is_null
Definition: sqltypes.h:76
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
const Executor * executor_
Definition: ResultSet.h:814
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
#define CHECK_GE(x, y)
Definition: Logger.h:203
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:834
#define CHECK_GT(x, y)
Definition: Logger.h:202
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:75
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:810
bool is_agg
Definition: TargetInfo.h:40
CHECK(cgen_state)
bool is_array() const
Definition: sqltypes.h:485
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
void copy_from_gpu(Data_Namespace::DataMgr *data_mgr, void *dst, const CUdeviceptr src, const size_t num_bytes, const int device_id)
boost::optional< std::vector< ScalarTargetValue >> ArrayTargetValue
Definition: TargetValue.h:157
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:821
#define CHECK_LT(x, y)
Definition: Logger.h:200
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:822
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801
bool is_string() const
Definition: sqltypes.h:477
bool separate_varlen_storage_valid_
Definition: ResultSet.h:835
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:659
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
std::conditional_t< isCudaCC(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:122
size_t length
Definition: sqltypes.h:74
const int device_id_
Definition: ResultSet.h:802

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSet::moveToBegin ( ) const

Definition at line 435 of file ResultSet.cpp.

435  {
436  crt_row_buff_idx_ = 0;
437  fetched_so_far_ = 0;
438 }
size_t fetched_so_far_
Definition: ResultSet.h:807
size_t crt_row_buff_idx_
Definition: ResultSet.h:806
size_t ResultSet::parallelRowCount ( ) const
private

Definition at line 346 of file ResultSet.cpp.

References cpu_threads().

346  {
347  size_t row_count{0};
348  const size_t worker_count = cpu_threads();
349  std::vector<std::future<size_t>> counter_threads;
350  for (size_t i = 0,
351  start_entry = 0,
352  stride = (entryCount() + worker_count - 1) / worker_count;
353  i < worker_count && start_entry < entryCount();
354  ++i, start_entry += stride) {
355  const auto end_entry = std::min(start_entry + stride, entryCount());
356  counter_threads.push_back(std::async(
357  std::launch::async,
358  [this](const size_t start, const size_t end) {
359  size_t row_count{0};
360  for (size_t i = start; i < end; ++i) {
361  if (!isRowAtEmpty(i)) {
362  ++row_count;
363  }
364  }
365  return row_count;
366  },
367  start_entry,
368  end_entry));
369  }
370  for (auto& child : counter_threads) {
371  child.wait();
372  }
373  for (auto& child : counter_threads) {
374  row_count += child.get();
375  }
376  if (keep_first_ + drop_first_) {
377  const auto limited_row_count = std::min(keep_first_ + drop_first_, row_count);
378  return limited_row_count < drop_first_ ? 0 : limited_row_count - drop_first_;
379  }
380  return row_count;
381 }
size_t keep_first_
Definition: ResultSet.h:809
size_t drop_first_
Definition: ResultSet.h:808
bool isRowAtEmpty(const size_t index) const
size_t entryCount() const
int cpu_threads()
Definition: thread_count.h:25

+ Here is the call graph for this function:

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

Definition at line 555 of file ResultSet.cpp.

References cpu_threads().

556  {
557  const size_t step = cpu_threads();
558  std::vector<std::vector<uint32_t>> strided_permutations(step);
559  std::vector<std::future<void>> init_futures;
560  for (size_t start = 0; start < step; ++start) {
561  init_futures.emplace_back(
562  std::async(std::launch::async, [this, start, step, &strided_permutations] {
563  strided_permutations[start] = initPermutationBuffer(start, step);
564  }));
565  }
566  for (auto& init_future : init_futures) {
567  init_future.wait();
568  }
569  for (auto& init_future : init_futures) {
570  init_future.get();
571  }
572  auto compare = createComparator(order_entries, true);
573  std::vector<std::future<void>> top_futures;
574  for (auto& strided_permutation : strided_permutations) {
575  top_futures.emplace_back(
576  std::async(std::launch::async, [&strided_permutation, &compare, top_n] {
577  topPermutation(strided_permutation, top_n, compare);
578  }));
579  }
580  for (auto& top_future : top_futures) {
581  top_future.wait();
582  }
583  for (auto& top_future : top_futures) {
584  top_future.get();
585  }
586  permutation_.reserve(strided_permutations.size() * top_n);
587  for (const auto& strided_permutation : strided_permutations) {
588  permutation_.insert(
589  permutation_.end(), strided_permutation.begin(), strided_permutation.end());
590  }
591  topPermutation(permutation_, top_n, compare);
592 }
std::vector< uint32_t > permutation_
Definition: ResultSet.h:811
std::vector< uint32_t > initPermutationBuffer(const size_t start, const size_t step)
Definition: ResultSet.cpp:533
static void topPermutation(std::vector< uint32_t > &to_sort, const size_t n, const std::function< bool(const uint32_t, const uint32_t)> compare)
Definition: ResultSet.cpp:748
std::function< bool(const uint32_t, const uint32_t)> createComparator(const std::list< Analyzer::OrderEntry > &order_entries, const bool use_heap)
Definition: ResultSet.h:739
int cpu_threads()
Definition: thread_count.h:25

+ Here is the call graph for this function:

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

Definition at line 802 of file ResultSet.cpp.

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

803  {
805  std::vector<int64_t> tmp_buff(query_mem_desc_.getEntryCount());
806  std::vector<int32_t> idx_buff(query_mem_desc_.getEntryCount());
807  CHECK_EQ(size_t(1), order_entries.size());
808  auto buffer_ptr = storage_->getUnderlyingBuffer();
809  for (const auto& order_entry : order_entries) {
810  const auto target_idx = order_entry.tle_no - 1;
811  const auto sortkey_val_buff = reinterpret_cast<int64_t*>(
812  buffer_ptr + query_mem_desc_.getColOffInBytes(target_idx));
813  const auto chosen_bytes = query_mem_desc_.getPaddedSlotWidthBytes(target_idx);
814  sort_groups_cpu(sortkey_val_buff,
815  &idx_buff[0],
817  order_entry.is_desc,
818  chosen_bytes);
819  apply_permutation_cpu(reinterpret_cast<int64_t*>(buffer_ptr),
820  &idx_buff[0],
822  &tmp_buff[0],
823  sizeof(int64_t));
824  for (size_t target_idx = 0; target_idx < query_mem_desc_.getSlotCount();
825  ++target_idx) {
826  if (static_cast<int>(target_idx) == order_entry.tle_no - 1) {
827  continue;
828  }
829  const auto chosen_bytes = query_mem_desc_.getPaddedSlotWidthBytes(target_idx);
830  const auto satellite_val_buff = reinterpret_cast<int64_t*>(
831  buffer_ptr + query_mem_desc_.getColOffInBytes(target_idx));
832  apply_permutation_cpu(satellite_val_buff,
833  &idx_buff[0],
835  &tmp_buff[0],
836  chosen_bytes);
837  }
838  }
839 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
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:803
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
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
CHECK(cgen_state)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
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 768 of file ResultSet.cpp.

References copy_group_by_buffers_from_gpu(), create_dev_group_by_buffers(), GPU, inplace_sort_gpu(), and KernelPerFragment.

769  {
770  auto data_mgr = &executor_->catalog_->getDataMgr();
771  const int device_id{0};
772  CudaAllocator cuda_allocator(data_mgr, device_id);
773  std::vector<int64_t*> group_by_buffers(executor_->blockSize());
774  group_by_buffers[0] = reinterpret_cast<int64_t*>(storage_->getUnderlyingBuffer());
775  auto dev_group_by_buffers =
776  create_dev_group_by_buffers(&cuda_allocator,
777  group_by_buffers,
779  executor_->blockSize(),
780  executor_->gridSize(),
781  device_id,
783  -1,
784  true,
785  true,
786  false,
787  nullptr);
789  order_entries, query_mem_desc_, dev_group_by_buffers, data_mgr, device_id);
791  data_mgr,
792  group_by_buffers,
794  dev_group_by_buffers.second,
796  executor_->blockSize(),
797  executor_->gridSize(),
798  device_id,
799  false);
800 }
size_t getBufferSizeBytes(const RelAlgExecutionUnit &ra_exe_unit, const unsigned thread_count, const ExecutorDeviceType device_type) const
GpuGroupByBuffers create_dev_group_by_buffers(DeviceAllocator *cuda_allocator, const std::vector< int64_t * > &group_by_buffers, const QueryMemoryDescriptor &query_mem_desc, const unsigned block_size_x, const unsigned grid_size_x, const int device_id, const ExecutorDispatchMode dispatch_mode, const int64_t num_input_rows, const bool prepend_index_buffer, const bool always_init_group_by_on_host, const bool use_bump_allocator, Allocator *insitu_allocator)
Definition: GpuMemUtils.cpp:61
const Executor * executor_
Definition: ResultSet.h:814
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
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)
void copy_group_by_buffers_from_gpu(Data_Namespace::DataMgr *data_mgr, const std::vector< int64_t * > &group_by_buffers, const size_t groups_buffer_size, const CUdeviceptr group_by_dev_buffers_mem, const QueryMemoryDescriptor &query_mem_desc, const unsigned block_size_x, const unsigned grid_size_x, const int device_id, const bool prepend_index_buffer)

+ Here is the call graph for this function:

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

Definition at line 310 of file ResultSet.cpp.

References CHECK_GE.

310  {
311  if (just_explain_) {
312  return 1;
313  }
314  if (!permutation_.empty()) {
315  return permutation_.size();
316  }
317  if (cached_row_count_ != -1) {
319  return cached_row_count_;
320  }
321  if (!storage_) {
322  return 0;
323  }
324  if (force_parallel || entryCount() > 20000) {
325  return parallelRowCount();
326  }
327  std::lock_guard<std::mutex> lock(row_iteration_mutex_);
328  moveToBegin();
329  size_t row_count{0};
330  while (true) {
331  auto crt_row = getNextRowUnlocked(false, false);
332  if (crt_row.empty()) {
333  break;
334  }
335  ++row_count;
336  }
337  moveToBegin();
338  return row_count;
339 }
std::mutex row_iteration_mutex_
Definition: ResultSet.h:839
void moveToBegin() const
Definition: ResultSet.cpp:435
#define CHECK_GE(x, y)
Definition: Logger.h:203
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
const bool just_explain_
Definition: ResultSet.h:837
std::vector< uint32_t > permutation_
Definition: ResultSet.h:811
size_t parallelRowCount() const
Definition: ResultSet.cpp:346
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838
size_t entryCount() const
std::vector< TargetValue > getNextRowUnlocked(const bool translate_strings, const bool decimal_to_double) const
ResultSetRowIterator ResultSet::rowIterator ( size_t  from_logical_index,
bool  translate_strings,
bool  decimal_to_double 
) const
inline

Definition at line 323 of file ResultSet.h.

Referenced by rowIterator().

325  {
326  ResultSetRowIterator rowIterator(this, translate_strings, decimal_to_double);
327 
328  // move to first logical position
329  ++rowIterator;
330 
331  for (size_t index = 0; index < from_logical_index; index++) {
332  ++rowIterator;
333  }
334 
335  return rowIterator;
336  }
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:323

+ Here is the caller graph for this function:

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

Definition at line 338 of file ResultSet.h.

References rowIterator().

339  {
340  return rowIterator(0, translate_strings, decimal_to_double);
341  }
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:323

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

References CHECK().

341  {
342  CHECK(cached_row_count_ == -1 || cached_row_count_ == static_cast<ssize_t>(row_count));
343  cached_row_count_ = row_count;
344 }
CHECK(cgen_state)
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838

+ Here is the call graph for this function:

void ResultSet::setGeoReturnType ( const GeoReturnType  val)
inline

Definition at line 487 of file ResultSet.h.

References geo_return_type_.

487 { geo_return_type_ = val; }
GeoReturnType geo_return_type_
Definition: ResultSet.h:842
void ResultSet::setQueueTime ( const int64_t  queue_time)

Definition at line 423 of file ResultSet.cpp.

423  {
424  queue_time_ms_ = queue_time;
425 }
int64_t queue_time_ms_
Definition: ResultSet.h:812
void ResultSet::setSeparateVarlenStorageValid ( const bool  val)
inline

Definition at line 516 of file ResultSet.h.

References separate_varlen_storage_valid_.

516  {
518  }
bool separate_varlen_storage_valid_
Definition: ResultSet.h:835
void ResultSet::sort ( const std::list< Analyzer::OrderEntry > &  order_entries,
const size_t  top_n 
)

Definition at line 464 of file ResultSet.cpp.

References Executor::baseline_threshold, CHECK(), CHECK_EQ, g_enable_watchdog, LOG, and logger::WARNING.

465  {
467  CHECK(!targets_.empty());
468 #ifdef HAVE_CUDA
469  if (canUseFastBaselineSort(order_entries, top_n)) {
470  baselineSort(order_entries, top_n);
471  return;
472  }
473 #endif // HAVE_CUDA
474  if (query_mem_desc_.sortOnGpu()) {
475  try {
476  radixSortOnGpu(order_entries);
477  } catch (const OutOfMemory&) {
478  LOG(WARNING) << "Out of GPU memory during sort, finish on CPU";
479  radixSortOnCpu(order_entries);
480  } catch (const std::bad_alloc&) {
481  LOG(WARNING) << "Out of GPU memory during sort, finish on CPU";
482  radixSortOnCpu(order_entries);
483  }
484  return;
485  }
486  // This check isn't strictly required, but allows the index buffer to be 32-bit.
487  if (query_mem_desc_.getEntryCount() > std::numeric_limits<uint32_t>::max()) {
488  throw RowSortException("Sorting more than 4B elements not supported");
489  }
490 
491  CHECK(permutation_.empty());
492 
493  const bool use_heap{order_entries.size() == 1 && top_n};
494  if (use_heap && entryCount() > 100000) {
495  if (g_enable_watchdog && (entryCount() > 20000000)) {
496  throw WatchdogException("Sorting the result would be too slow");
497  }
498  parallelTop(order_entries, top_n);
499  return;
500  }
501 
503  throw WatchdogException("Sorting the result would be too slow");
504  }
505 
507 
508  auto compare = createComparator(order_entries, use_heap);
509 
510  if (use_heap) {
511  topPermutation(permutation_, top_n, compare);
512  } else {
513  sortPermutation(compare);
514  }
515 }
void baselineSort(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
#define CHECK_EQ(x, y)
Definition: Logger.h:198
#define LOG(tag)
Definition: Logger.h:185
static const size_t baseline_threshold
Definition: Execute.h:1009
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
std::vector< uint32_t > permutation_
Definition: ResultSet.h:811
bool g_enable_watchdog
std::vector< uint32_t > initPermutationBuffer(const size_t start, const size_t step)
Definition: ResultSet.cpp:533
void radixSortOnCpu(const std::list< Analyzer::OrderEntry > &order_entries) const
Definition: ResultSet.cpp:802
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:800
CHECK(cgen_state)
bool canUseFastBaselineSort(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
std::atomic< ssize_t > cached_row_count_
Definition: ResultSet.h:838
static void topPermutation(std::vector< uint32_t > &to_sort, const size_t n, const std::function< bool(const uint32_t, const uint32_t)> compare)
Definition: ResultSet.cpp:748
void radixSortOnGpu(const std::list< Analyzer::OrderEntry > &order_entries) const
Definition: ResultSet.cpp:768
void sortPermutation(const std::function< bool(const uint32_t, const uint32_t)> compare)
Definition: ResultSet.cpp:763
size_t entryCount() const
void parallelTop(const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
Definition: ResultSet.cpp:555
std::function< bool(const uint32_t, const uint32_t)> createComparator(const std::list< Analyzer::OrderEntry > &order_entries, const bool use_heap)
Definition: ResultSet.h:739

+ Here is the call graph for this function:

void ResultSet::sortPermutation ( const std::function< bool(const uint32_t, const uint32_t)>  compare)
private

Definition at line 763 of file ResultSet.cpp.

764  {
765  std::sort(permutation_.begin(), permutation_.end(), compare);
766 }
std::vector< uint32_t > permutation_
Definition: ResultSet.h:811
void ResultSet::syncEstimatorBuffer ( ) const

Definition at line 410 of file ResultSet.cpp.

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

410  {
413  CHECK_EQ(size_t(0), estimator_->getBufferSize() % sizeof(int64_t));
415  static_cast<int8_t*>(checked_calloc(estimator_->getBufferSize(), 1));
418  reinterpret_cast<CUdeviceptr>(estimator_buffer_),
419  estimator_->getBufferSize(),
420  device_id_);
421 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
int8_t * estimator_buffer_
Definition: ResultSet.h:827
CHECK(cgen_state)
void copy_from_gpu(Data_Namespace::DataMgr *data_mgr, void *dst, const CUdeviceptr src, const size_t num_bytes, const int device_id)
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:48
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:829
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:826
int8_t * host_estimator_buffer_
Definition: ResultSet.h:828
const ExecutorDeviceType device_type_
Definition: ResultSet.h:801
const int device_id_
Definition: ResultSet.h:802

+ Here is the call graph for this function:

void ResultSet::topPermutation ( std::vector< uint32_t > &  to_sort,
const size_t  n,
const std::function< bool(const uint32_t, const uint32_t)>  compare 
)
staticprivate

Definition at line 748 of file ResultSet.cpp.

751  {
752  std::make_heap(to_sort.begin(), to_sort.end(), compare);
753  std::vector<uint32_t> permutation_top;
754  permutation_top.reserve(n);
755  for (size_t i = 0; i < n && !to_sort.empty(); ++i) {
756  permutation_top.push_back(to_sort.front());
757  std::pop_heap(to_sort.begin(), to_sort.end(), compare);
758  to_sort.pop_back();
759  }
760  to_sort.swap(permutation_top);
761 }
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 351 of file ResultSet.h.

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

351  {
353  query_mem_desc_.setEntryCount(new_entry_count);
354  CHECK(storage_);
355  storage_->updateEntryCount(new_entry_count);
356  }
void setEntryCount(const size_t val)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:803
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:804
CHECK(cgen_state)
QueryDescriptionType getQueryDescriptionType() const

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class ColumnarResults
friend

Definition at line 851 of file ResultSet.h.

friend class ResultSetManager
friend

Definition at line 849 of file ResultSet.h.

friend class ResultSetRowIterator
friend

Definition at line 850 of file ResultSet.h.

Member Data Documentation

std::vector<std::unique_ptr<ResultSetStorage> > ResultSet::appended_storage_
private

Definition at line 805 of file ResultSet.h.

Referenced by copyColumnIntoBuffer().

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

Definition at line 838 of file ResultSet.h.

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

Definition at line 817 of file ResultSet.h.

Referenced by holdChunkIterators().

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

Definition at line 816 of file ResultSet.h.

Referenced by holdChunks().

std::vector<std::vector<std::vector<const int8_t*> > > ResultSet::col_buffers_
private
std::unique_ptr<ResultSetComparator<ColumnWiseTargetAccessor> > ResultSet::column_wise_comparator_
private

Definition at line 847 of file ResultSet.h.

Referenced by createComparator().

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

Definition at line 824 of file ResultSet.h.

Referenced by getColumnFrag().

size_t ResultSet::crt_row_buff_idx_
mutableprivate

Definition at line 806 of file ResultSet.h.

Data_Namespace::DataMgr* ResultSet::data_mgr_
private

Definition at line 829 of file ResultSet.h.

const int ResultSet::device_id_
private

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

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

Definition at line 826 of file ResultSet.h.

int8_t* ResultSet::estimator_buffer_
private

Definition at line 827 of file ResultSet.h.

const Executor* ResultSet::executor_
private

Definition at line 814 of file ResultSet.h.

Referenced by makeTargetValue(), and makeVarlenTargetValue().

std::string ResultSet::explanation_
private

Definition at line 836 of file ResultSet.h.

size_t ResultSet::fetched_so_far_
mutableprivate

Definition at line 807 of file ResultSet.h.

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

Definition at line 823 of file ResultSet.h.

Referenced by getColumnFrag().

GeoReturnType ResultSet::geo_return_type_
mutableprivate

Definition at line 842 of file ResultSet.h.

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

int8_t* ResultSet::host_estimator_buffer_
mutableprivate

Definition at line 828 of file ResultSet.h.

const bool ResultSet::just_explain_
private

Definition at line 837 of file ResultSet.h.

size_t ResultSet::keep_first_
private

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

Referenced by holdLiterals().

std::vector<uint32_t> ResultSet::permutation_
private

Definition at line 811 of file ResultSet.h.

Referenced by entryCount(), and isPermutationBufferEmpty().

int64_t ResultSet::queue_time_ms_
private

Definition at line 812 of file ResultSet.h.

int64_t ResultSet::render_time_ms_
private

Definition at line 813 of file ResultSet.h.

std::mutex ResultSet::row_iteration_mutex_
mutableprivate

Definition at line 839 of file ResultSet.h.

const std::shared_ptr<RowSetMemoryOwner> ResultSet::row_set_mem_owner_
private
std::unique_ptr<ResultSetComparator<RowWiseTargetAccessor> > ResultSet::row_wise_comparator_
private

Definition at line 846 of file ResultSet.h.

Referenced by createComparator().

bool ResultSet::separate_varlen_storage_valid_
private
std::vector<SerializedVarlenBufferStorage> ResultSet::serialized_varlen_buffer_
private

Definition at line 834 of file ResultSet.h.

Referenced by makeGeoTargetValue(), and makeVarlenTargetValue().

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

Definition at line 800 of file ResultSet.h.

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


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