OmniSciDB  21ac014ffc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ResultSet Class Reference

#include <ResultSet.h>

+ Collaboration diagram for ResultSet:

Classes

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

Public Types

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

Public Member Functions

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

Static Public Member Functions

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

Public Attributes

friend ResultSetBuilder
 

Private Types

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

Private Member Functions

void advanceCursorToNextEntry (ResultSetRowIterator &iter) const
 
std::vector< TargetValuegetNextRowImpl (const bool translate_strings, const bool decimal_to_double) const
 
std::vector< TargetValuegetNextRowUnlocked (const bool translate_strings, const bool decimal_to_double) const
 
std::vector< TargetValuegetRowAt (const size_t index, const bool translate_strings, const bool decimal_to_double, const bool fixup_count_distinct_pointers, const std::vector< bool > &targets_to_skip={}) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getColumnarPerfectHashEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getRowWisePerfectHashEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getRowWiseBaselineEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
template<typename ENTRY_TYPE >
ENTRY_TYPE getColumnarBaselineEntryAt (const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
 
size_t binSearchRowCount () const
 
size_t parallelRowCount () const
 
size_t advanceCursorToNextEntry () const
 
void radixSortOnGpu (const std::list< Analyzer::OrderEntry > &order_entries) const
 
void radixSortOnCpu (const std::list< Analyzer::OrderEntry > &order_entries) const
 
TargetValue getTargetValueFromBufferRowwise (int8_t *rowwise_target_ptr, int8_t *keys_ptr, const size_t entry_buff_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t slot_idx, const bool translate_strings, const bool decimal_to_double, const bool fixup_count_distinct_pointers) const
 
TargetValue getTargetValueFromBufferColwise (const int8_t *col_ptr, const int8_t *keys_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t local_entry_idx, const size_t global_entry_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t slot_idx, const bool translate_strings, const bool decimal_to_double) const
 
TargetValue makeTargetValue (const int8_t *ptr, const int8_t compact_sz, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const bool decimal_to_double, const size_t entry_buff_idx) const
 
TargetValue makeVarlenTargetValue (const int8_t *ptr1, const int8_t compact_sz1, const int8_t *ptr2, const int8_t compact_sz2, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const size_t entry_buff_idx) const
 
TargetValue makeGeoTargetValue (const int8_t *geo_target_ptr, const size_t slot_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t entry_buff_idx) const
 
InternalTargetValue getVarlenOrderEntry (const int64_t str_ptr, const size_t str_len) const
 
int64_t lazyReadInt (const int64_t ival, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
 
std::pair< size_t, size_t > getStorageIndex (const size_t entry_idx) const
 
const std::vector< const
int8_t * > & 
getColumnFrag (const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
 
const VarlenOutputInfogetVarlenOutputInfo (const size_t entry_idx) const
 
StorageLookupResult findStorage (const size_t entry_idx) const
 
Comparator createComparator (const std::list< Analyzer::OrderEntry > &order_entries, const PermutationView permutation, const Executor *executor, const bool single_threaded)
 
PermutationView initPermutationBuffer (PermutationView permutation, PermutationIdx const begin, PermutationIdx const end) const
 
void parallelTop (const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n, const Executor *executor)
 
void baselineSort (const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n, const Executor *executor)
 
void doBaselineSort (const ExecutorDeviceType device_type, const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n, const Executor *executor)
 
bool canUseFastBaselineSort (const std::list< Analyzer::OrderEntry > &order_entries, const size_t top_n)
 
Data_Namespace::DataMgrgetDataManager () const
 
int getGpuCount () const
 
void serializeProjection (TSerializedRows &serialized_rows) const
 
void serializeVarlenAggColumn (int8_t *buf, std::vector< std::string > &varlen_bufer) const
 
void serializeCountDistinctColumns (TSerializedRows &) const
 
void unserializeCountDistinctColumns (const TSerializedRows &)
 
void fixupCountDistinctPointers ()
 
void create_active_buffer_set (BufferSet &count_distinct_active_buffer_set) const
 
int64_t getDistinctBufferRefFromBufferRowwise (int8_t *rowwise_target_ptr, const TargetInfo &target_info) const
 

Static Private Member Functions

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

Private Attributes

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

Friends

class ResultSetManager
 
class ResultSetRowIterator
 
class ColumnarResults
 

Detailed Description

Definition at line 157 of file ResultSet.h.

Member Typedef Documentation

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

Definition at line 623 of file ResultSet.h.

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

Definition at line 722 of file ResultSet.h.

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

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

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

Constructor & Destructor Documentation

ResultSet::ResultSet ( const std::vector< TargetInfo > &  targets,
const ExecutorDeviceType  device_type,
const QueryMemoryDescriptor query_mem_desc,
const std::shared_ptr< RowSetMemoryOwner row_set_mem_owner,
const Catalog_Namespace::Catalog catalog,
const unsigned  block_size,
const unsigned  grid_size 
)

Definition at line 60 of file ResultSet.cpp.

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

Definition at line 86 of file ResultSet.cpp.

98  : targets_(targets)
99  , device_type_(device_type)
100  , device_id_(device_id)
101  , query_mem_desc_(query_mem_desc)
102  , crt_row_buff_idx_(0)
103  , fetched_so_far_(0)
104  , drop_first_(0)
105  , keep_first_(0)
106  , row_set_mem_owner_(row_set_mem_owner)
107  , catalog_(catalog)
108  , block_size_(block_size)
109  , grid_size_(grid_size)
110  , lazy_fetch_info_(lazy_fetch_info)
111  , col_buffers_{col_buffers}
112  , frag_offsets_{frag_offsets}
113  , consistent_frag_sizes_{consistent_frag_sizes}
114  , data_mgr_(nullptr)
116  , just_explain_(false)
117  , for_validation_only_(false)
118  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:768
GeoReturnType geo_return_type_
Definition: ResultSet.h:773
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:741
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
size_t keep_first_
Definition: ResultSet.h:737
const bool just_explain_
Definition: ResultSet.h:767
unsigned block_size_
Definition: ResultSet.h:742
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:769
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:728
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:738
size_t drop_first_
Definition: ResultSet.h:736
unsigned grid_size_
Definition: ResultSet.h:743
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:751
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:759
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:752
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:754
const ExecutorDeviceType device_type_
Definition: ResultSet.h:729
size_t fetched_so_far_
Definition: ResultSet.h:735
size_t crt_row_buff_idx_
Definition: ResultSet.h:734
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:753
bool separate_varlen_storage_valid_
Definition: ResultSet.h:765
const int device_id_
Definition: ResultSet.h:730
ResultSet::ResultSet ( const std::shared_ptr< const Analyzer::Estimator ,
const ExecutorDeviceType  device_type,
const int  device_id,
Data_Namespace::DataMgr data_mgr 
)
ResultSet::ResultSet ( const std::string &  explanation)

Definition at line 148 of file ResultSet.cpp.

References CPU.

150  , device_id_(-1)
151  , fetched_so_far_(0)
153  , explanation_(explanation)
154  , just_explain_(true)
155  , for_validation_only_(false)
156  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:768
GeoReturnType geo_return_type_
Definition: ResultSet.h:773
const bool just_explain_
Definition: ResultSet.h:767
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:769
std::string explanation_
Definition: ResultSet.h:766
const ExecutorDeviceType device_type_
Definition: ResultSet.h:729
size_t fetched_so_far_
Definition: ResultSet.h:735
bool separate_varlen_storage_valid_
Definition: ResultSet.h:765
const int device_id_
Definition: ResultSet.h:730
ResultSet::ResultSet ( int64_t  queue_time_ms,
int64_t  render_time_ms,
const std::shared_ptr< RowSetMemoryOwner row_set_mem_owner 
)

Definition at line 159 of file ResultSet.cpp.

References CPU.

163  , device_id_(-1)
164  , fetched_so_far_(0)
165  , row_set_mem_owner_(row_set_mem_owner)
166  , timings_(QueryExecutionTimings{queue_time_ms, render_time_ms, 0, 0})
168  , just_explain_(true)
169  , for_validation_only_(false)
170  , cached_row_count_(-1)
bool for_validation_only_
Definition: ResultSet.h:768
GeoReturnType geo_return_type_
Definition: ResultSet.h:773
const bool just_explain_
Definition: ResultSet.h:767
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:769
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:738
QueryExecutionTimings timings_
Definition: ResultSet.h:744
const ExecutorDeviceType device_type_
Definition: ResultSet.h:729
size_t fetched_so_far_
Definition: ResultSet.h:735
bool separate_varlen_storage_valid_
Definition: ResultSet.h:765
const int device_id_
Definition: ResultSet.h:730
ResultSet::~ResultSet ( )

Definition at line 173 of file ResultSet.cpp.

References CHECK, CPU, and data_mgr_().

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

+ Here is the call graph for this function:

Member Function Documentation

void ResultSet::addCompilationQueueTime ( const int64_t  compilation_queue_time)

Definition at line 453 of file ResultSet.cpp.

453  {
454  timings_.compilation_queue_time += compilation_queue_time;
455 }
QueryExecutionTimings timings_
Definition: ResultSet.h:744
void ResultSet::advanceCursorToNextEntry ( ResultSetRowIterator iter) const
private
size_t ResultSet::advanceCursorToNextEntry ( ) const
private
const ResultSetStorage* ResultSet::allocateStorage ( ) const
const ResultSetStorage* ResultSet::allocateStorage ( int8_t *  ,
const std::vector< int64_t > &  ,
std::shared_ptr< VarlenOutputInfo = nullptr 
) const
const ResultSetStorage* ResultSet::allocateStorage ( const std::vector< int64_t > &  ) const
void ResultSet::append ( ResultSet that)

Definition at line 244 of file ResultSet.cpp.

References CHECK, and CHECK_EQ.

244  {
246  if (!that.storage_) {
247  return;
248  }
249  appended_storage_.push_back(std::move(that.storage_));
252  appended_storage_.back()->query_mem_desc_.getEntryCount());
253  chunks_.insert(chunks_.end(), that.chunks_.begin(), that.chunks_.end());
254  col_buffers_.insert(
255  col_buffers_.end(), that.col_buffers_.begin(), that.col_buffers_.end());
256  frag_offsets_.insert(
257  frag_offsets_.end(), that.frag_offsets_.begin(), that.frag_offsets_.end());
259  that.consistent_frag_sizes_.begin(),
260  that.consistent_frag_sizes_.end());
261  chunk_iters_.insert(
262  chunk_iters_.end(), that.chunk_iters_.begin(), that.chunk_iters_.end());
264  CHECK(that.separate_varlen_storage_valid_);
266  that.serialized_varlen_buffer_.begin(),
267  that.serialized_varlen_buffer_.end());
268  }
269  for (auto& buff : that.literal_buffers_) {
270  literal_buffers_.push_back(std::move(buff));
271  }
272 }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
void setEntryCount(const size_t val)
AppendedStorage appended_storage_
Definition: ResultSet.h:733
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
std::vector< std::shared_ptr< std::list< ChunkIter > > > chunk_iters_
Definition: ResultSet.h:747
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:764
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:769
std::list< std::shared_ptr< Chunk_NS::Chunk > > chunks_
Definition: ResultSet.h:746
std::vector< std::vector< int8_t > > literal_buffers_
Definition: ResultSet.h:750
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:752
std::vector< std::vector< int64_t > > consistent_frag_sizes_
Definition: ResultSet.h:754
#define CHECK(condition)
Definition: Logger.h:206
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Definition: ResultSet.h:753
bool separate_varlen_storage_valid_
Definition: ResultSet.h:765
void ResultSet::baselineSort ( const std::list< Analyzer::OrderEntry > &  order_entries,
const size_t  top_n,
const Executor executor 
)
private
size_t ResultSet::binSearchRowCount ( ) const
private

Definition at line 354 of file ResultSet.cpp.

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

354  {
355  if (!storage_) {
356  return 0;
357  }
358 
359  size_t row_count = storage_->binSearchRowCount();
360  for (auto& s : appended_storage_) {
361  row_count += s->binSearchRowCount();
362  }
363 
364  return get_truncated_row_count(row_count, getLimit(), drop_first_);
365 }
AppendedStorage appended_storage_
Definition: ResultSet.h:733
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
size_t getLimit() const
Definition: ResultSet.cpp:1019
size_t get_truncated_row_count(size_t total_row_count, size_t limit, size_t offset)
Definition: ResultSet.cpp:293
size_t drop_first_
Definition: ResultSet.h:736

+ Here is the call graph for this function:

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

Definition at line 734 of file ResultSet.cpp.

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

Referenced by makeTargetValue().

734  {
735  static_assert(sizeof(int64_t) == sizeof(quantile::TDigest*));
736  CHECK(t_digest);
737  t_digest->mergeBuffer();
738  double const quantile = t_digest->quantile();
739  return boost::math::isnan(quantile) ? NULL_DOUBLE : quantile;
740 }
#define NULL_DOUBLE
DEVICE void mergeBuffer()
Definition: quantile.h:629
DEVICE RealType quantile(IndexType *buf, RealType const q)
Definition: quantile.h:793
#define CHECK(condition)
Definition: Logger.h:206

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 278 of file ResultSet.cpp.

278  {
279  return just_explain_ ? 1 : targets_.size();
280 }
const bool just_explain_
Definition: ResultSet.h:767
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:728
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 1118 of file ResultSetIteration.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 664 of file ResultSet.h.

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

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

+ Here is the call graph for this function:

bool ResultSet::definitelyHasNoRows ( ) const

Definition at line 402 of file ResultSet.cpp.

402  {
403  return !storage_ && !estimator_ && !just_explain_;
404 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
const bool just_explain_
Definition: ResultSet.h:767
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:756
bool ResultSet::didOutputColumnar ( ) const
inline

Definition at line 397 of file ResultSet.h.

References QueryMemoryDescriptor::didOutputColumnar(), and query_mem_desc_.

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

+ Here is the call graph for this function:

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

Definition at line 55 of file ResultSet.cpp.

References CHECK_EQ.

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

Definition at line 749 of file ResultSetIteration.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 341 of file ResultSet.h.

References CHECK, and storage_.

341  {
342  CHECK(storage_);
343  if (storage_->query_mem_desc_.didOutputColumnar()) {
344  storage_->fillOneEntryColWise(entry);
345  } else {
346  storage_->fillOneEntryRowWise(entry);
347  }
348  }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
#define CHECK(condition)
Definition: Logger.h:206
ResultSet::StorageLookupResult ResultSet::findStorage ( const size_t  entry_idx) const
private

Definition at line 668 of file ResultSet.cpp.

Referenced by getVarlenOutputInfo(), and makeGeoTargetValue().

668  {
669  auto [stg_idx, fixedup_entry_idx] = getStorageIndex(entry_idx);
670  return {stg_idx ? appended_storage_[stg_idx - 1].get() : storage_.get(),
671  fixedup_entry_idx,
672  stg_idx};
673 }
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:643
AppendedStorage appended_storage_
Definition: ResultSet.h:733
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732

+ Here is the caller graph for this function:

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

Definition at line 491 of file ResultSet.cpp.

References QueryMemoryDescriptor::didOutputColumnar(), and query_mem_desc.

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t ResultSet::getBufferSizeBytes ( const ExecutorDeviceType  device_type) const

Definition at line 753 of file ResultSetIteration.cpp.

References CHECK, and storage_.

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

Definition at line 282 of file ResultSet.cpp.

References CHECK_LT, kAVG, kDOUBLE, and kTEXT.

282  {
283  if (just_explain_) {
284  return SQLTypeInfo(kTEXT, false);
285  }
286  CHECK_LT(col_idx, targets_.size());
287  return targets_[col_idx].agg_kind == kAVG ? SQLTypeInfo(kDOUBLE, false)
288  : targets_[col_idx].sql_type;
289 }
const bool just_explain_
Definition: ResultSet.h:767
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:728
#define CHECK_LT(x, y)
Definition: Logger.h:216
Definition: sqltypes.h:51
Definition: sqldefs.h:72
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getColumnarBaselineEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const
private
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getColumnarBaselineEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const

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

NOTE: Currently, only used in direct columnarization

Definition at line 1290 of file ResultSetIteration.cpp.

References CHECK_NE, and storage_.

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

Definition at line 1063 of file ResultSet.cpp.

References CHECK.

1063  {
1065  return storage_->getUnderlyingBuffer() + query_mem_desc_.getColOffInBytes(column_idx);
1066 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
bool isZeroCopyColumnarConversionPossible(size_t column_idx) const
Definition: ResultSet.cpp:1056
#define CHECK(condition)
Definition: Logger.h:206
size_t getColOffInBytes(const size_t col_idx) const
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getColumnarPerfectHashEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const
private
template<typename ENTRY_TYPE >
ENTRY_TYPE ResultSet::getColumnarPerfectHashEntryAt ( const size_t  row_idx,
const size_t  target_idx,
const size_t  slot_idx 
) const

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

NOTE: Currently, only used in direct columnarization

Definition at line 1236 of file ResultSetIteration.cpp.

References storage_.

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t ResultSet::getCurrentRowBufferIndex ( ) const

Definition at line 236 of file ResultSet.cpp.

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

Definition at line 420 of file ResultSet.cpp.

References CHECK, and GPU.

420  {
424 }
virtual int8_t * getMemoryPtr()=0
const ExecutorDeviceType device_type_
Definition: ResultSet.h:729
#define CHECK(condition)
Definition: Logger.h:206
Data_Namespace::AbstractBuffer * device_estimator_buffer_
Definition: ResultSet.h:757
int ResultSet::getDeviceId ( ) const

Definition at line 487 of file ResultSet.cpp.

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

Definition at line 195 of file ResultSet.cpp.

195  {
196  return device_type_;
197 }
const ExecutorDeviceType device_type_
Definition: ResultSet.h:729
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 1160 of file ResultSetIteration.cpp.

References GroupByBaselineHash, GroupByPerfectHash, and UNREACHABLE.

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

Definition at line 326 of file ResultSet.h.

References explanation_, and just_explain_.

326  {
327  if (just_explain_) {
328  return explanation_;
329  }
330  return {};
331  }
const bool just_explain_
Definition: ResultSet.h:767
std::string explanation_
Definition: ResultSet.h:766
GeoReturnType ResultSet::getGeoReturnType ( ) const
inline

Definition at line 388 of file ResultSet.h.

References geo_return_type_.

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

Definition at line 426 of file ResultSet.cpp.

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

Definition at line 417 of file ResultSet.h.

References lazy_fetch_info_.

417  {
418  return lazy_fetch_info_;
419  }
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:751
size_t ResultSet::getLimit ( ) const

Definition at line 1019 of file ResultSet.cpp.

1019  {
1020  return keep_first_;
1021 }
size_t keep_first_
Definition: ResultSet.h:737
size_t ResultSet::getNDVEstimator ( ) const

Definition at line 33 of file CardinalityEstimator.cpp.

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

33  {
34  CHECK(dynamic_cast<const Analyzer::NDVEstimator*>(estimator_.get()));
36  auto bits_set = bitmap_set_size(host_estimator_buffer_, estimator_->getBufferSize());
37  if (bits_set == 0) {
38  // empty result set, return 1 for a groups buffer size of 1
39  return 1;
40  }
41  const auto total_bits = estimator_->getBufferSize() * 8;
42  CHECK_LE(bits_set, total_bits);
43  const auto unset_bits = total_bits - bits_set;
44  const auto ratio = static_cast<double>(unset_bits) / total_bits;
45  if (ratio == 0.) {
46  LOG(WARNING)
47  << "Failed to get a high quality cardinality estimation, falling back to "
48  "approximate group by buffer size guess.";
49  return 0;
50  }
51  return -static_cast<double>(total_bits) * log(ratio);
52 }
#define LOG(tag)
Definition: Logger.h:200
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:756
#define CHECK_LE(x, y)
Definition: Logger.h:217
int8_t * host_estimator_buffer_
Definition: ResultSet.h:758
#define CHECK(condition)
Definition: Logger.h:206
size_t bitmap_set_size(const int8_t *bitmap, const size_t bitmap_byte_sz)
Definition: CountDistinct.h:37

+ Here is the call graph for this function:

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

Definition at line 297 of file ResultSetIteration.cpp.

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

Definition at line 319 of file ResultSetIteration.cpp.

References CHECK, and CHECK_EQ.

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

Definition at line 306 of file ResultSetIteration.cpp.

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

Definition at line 235 of file ResultSetIteration.cpp.

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

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

References QueryMemoryDescriptor::getPaddedSlotWidthBytes(), and query_mem_desc_.

406  {
407  return query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
408  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const

+ Here is the call graph for this function:

const Permutation & ResultSet::getPermutationBuffer ( ) const

Definition at line 597 of file ResultSet.cpp.

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

Definition at line 402 of file ResultSet.h.

References QueryMemoryDescriptor::getQueryDescriptionType(), and query_mem_desc_.

402  {
404  }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
QueryDescriptionType getQueryDescriptionType() const

+ Here is the call graph for this function:

const QueryMemoryDescriptor & ResultSet::getQueryMemDesc ( ) const

Definition at line 406 of file ResultSet.cpp.

References CHECK.

406  {
407  CHECK(storage_);
408  return storage_->query_mem_desc_;
409 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
#define CHECK(condition)
Definition: Logger.h:206
int64_t ResultSet::getQueueTime ( ) const

Definition at line 457 of file ResultSet.cpp.

int64_t ResultSet::getRenderTime ( ) const

Definition at line 462 of file ResultSet.cpp.

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

Definition at line 274 of file ResultSetIteration.cpp.

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

Definition at line 362 of file ResultSet.h.

References row_set_mem_owner_.

362  {
363  return row_set_mem_owner_;
364  }
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:738
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 1268 of file ResultSetIteration.cpp.

References CHECK_NE, row_ptr_rowwise(), and storage_.

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

References storage_.

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

Definition at line 1069 of file ResultSet.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 1112 of file ResultSet.cpp.

References advance_slot().

1112  {
1113  std::vector<size_t> slot_indices(targets_.size(), 0);
1114  size_t slot_index = 0;
1115  for (size_t target_idx = 0; target_idx < targets_.size(); target_idx++) {
1116  slot_indices[target_idx] = slot_index;
1117  slot_index = advance_slot(slot_index, targets_[target_idx], false);
1118  }
1119  return slot_indices;
1120 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:728
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 274 of file ResultSet.cpp.

274  {
275  return storage_.get();
276 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
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 643 of file ResultSet.cpp.

References CHECK_NE, i, and UNREACHABLE.

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

643  {
644  size_t fixedup_entry_idx = entry_idx;
645  auto entry_count = storage_->query_mem_desc_.getEntryCount();
646  const bool is_rowwise_layout = !storage_->query_mem_desc_.didOutputColumnar();
647  if (fixedup_entry_idx < entry_count) {
648  return {0, fixedup_entry_idx};
649  }
650  fixedup_entry_idx -= entry_count;
651  for (size_t i = 0; i < appended_storage_.size(); ++i) {
652  const auto& desc = appended_storage_[i]->query_mem_desc_;
653  CHECK_NE(is_rowwise_layout, desc.didOutputColumnar());
654  entry_count = desc.getEntryCount();
655  if (fixedup_entry_idx < entry_count) {
656  return {i + 1, fixedup_entry_idx};
657  }
658  fixedup_entry_idx -= entry_count;
659  }
660  UNREACHABLE() << "entry_idx = " << entry_idx << ", query_mem_desc_.getEntryCount() = "
662  return {};
663 }
AppendedStorage appended_storage_
Definition: ResultSet.h:733
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
#define UNREACHABLE()
Definition: Logger.h:250
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
#define CHECK_NE(x, y)
Definition: Logger.h:215

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

References catalog_(), and CHECK.

1024  {
1025  const auto sdp = row_set_mem_owner_->getOrAddStringDictProxy(
1026  dict_id, /*with_generation=*/false, catalog_);
1027  CHECK(sdp);
1028  return sdp->getDictionary()->copyStrings();
1029 }
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:741
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:738
#define CHECK(condition)
Definition: Logger.h:206

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

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

1094  {
1096  auto [single_slot_targets, num_single_slot_targets] = getSingleSlotTargetBitmap();
1097 
1098  for (size_t target_idx = 0; target_idx < single_slot_targets.size(); target_idx++) {
1099  const auto& target = targets_[target_idx];
1100  if (single_slot_targets[target_idx] &&
1101  (is_distinct_target(target) || target.agg_kind == kAPPROX_QUANTILE ||
1102  (target.is_agg && target.agg_kind == kSAMPLE && target.sql_type == kFLOAT))) {
1103  single_slot_targets[target_idx] = false;
1104  num_single_slot_targets--;
1105  }
1106  }
1107  CHECK_GE(num_single_slot_targets, size_t(0));
1108  return std::make_tuple(std::move(single_slot_targets), num_single_slot_targets);
1109 }
#define CHECK_GE(x, y)
Definition: Logger.h:219
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:728
std::tuple< std::vector< bool >, size_t > getSingleSlotTargetBitmap() const
Definition: ResultSet.cpp:1069
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:153
#define CHECK(condition)
Definition: Logger.h:206
bool isDirectColumnarConversionPossible() const
Definition: ResultSet.cpp:1038

+ Here is the call graph for this function:

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

Definition at line 411 of file ResultSet.cpp.

411  {
412  return targets_;
413 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:728
const std::vector< int64_t > & ResultSet::getTargetInitVals ( ) const

Definition at line 415 of file ResultSet.cpp.

References CHECK.

415  {
416  CHECK(storage_);
417  return storage_->target_init_vals_;
418 }
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
#define CHECK(condition)
Definition: Logger.h:206
TargetValue ResultSet::getTargetValueFromBufferColwise ( const int8_t *  col_ptr,
const int8_t *  keys_ptr,
const QueryMemoryDescriptor query_mem_desc,
const size_t  local_entry_idx,
const size_t  global_entry_idx,
const TargetInfo target_info,
const size_t  target_logical_idx,
const size_t  slot_idx,
const bool  translate_strings,
const bool  decimal_to_double 
) const
private

Definition at line 1882 of file ResultSetIteration.cpp.

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

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

+ Here is the call graph for this function:

TargetValue ResultSet::getTargetValueFromBufferRowwise ( int8_t *  rowwise_target_ptr,
int8_t *  keys_ptr,
const size_t  entry_buff_idx,
const TargetInfo target_info,
const size_t  target_logical_idx,
const size_t  slot_idx,
const bool  translate_strings,
const bool  decimal_to_double,
const bool  fixup_count_distinct_pointers 
) const
private

Definition at line 1955 of file ResultSetIteration.cpp.

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

1964  {
1965  if (UNLIKELY(fixup_count_distinct_pointers)) {
1966  if (is_distinct_target(target_info)) {
1967  auto count_distinct_ptr_ptr = reinterpret_cast<int64_t*>(rowwise_target_ptr);
1968  const auto remote_ptr = *count_distinct_ptr_ptr;
1969  if (remote_ptr) {
1970  const auto ptr = storage_->mappedPtr(remote_ptr);
1971  if (ptr) {
1972  *count_distinct_ptr_ptr = ptr;
1973  } else {
1974  // need to create a zero filled buffer for this remote_ptr
1975  const auto& count_distinct_desc =
1976  query_mem_desc_.count_distinct_descriptors_[target_logical_idx];
1977  const auto bitmap_byte_sz = count_distinct_desc.sub_bitmap_count == 1
1978  ? count_distinct_desc.bitmapSizeBytes()
1979  : count_distinct_desc.bitmapPaddedSizeBytes();
1980  auto count_distinct_buffer = row_set_mem_owner_->allocateCountDistinctBuffer(
1981  bitmap_byte_sz, /*thread_idx=*/0);
1982  *count_distinct_ptr_ptr = reinterpret_cast<int64_t>(count_distinct_buffer);
1983  }
1984  }
1985  }
1986  return int64_t(0);
1987  }
1988  if (target_info.sql_type.is_geometry()) {
1989  return makeGeoTargetValue(
1990  rowwise_target_ptr, slot_idx, target_info, target_logical_idx, entry_buff_idx);
1991  }
1992 
1993  auto ptr1 = rowwise_target_ptr;
1994  int8_t compact_sz1 = query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
1996  !query_mem_desc_.hasKeylessHash() && !target_info.is_agg) {
1997  // Single column perfect hash group by can utilize one slot for both the key and the
1998  // target value if both values fit in 8 bytes. Use the target value actual size for
1999  // this case. If they don't, the target value should be 8 bytes, so we can still use
2000  // the actual size rather than the compact size.
2001  compact_sz1 = query_mem_desc_.getLogicalSlotWidthBytes(slot_idx);
2002  }
2003 
2004  // logic for deciding width of column
2005  if (target_info.agg_kind == kAVG || is_real_str_or_array(target_info)) {
2006  const auto ptr2 =
2007  rowwise_target_ptr + query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
2008  int8_t compact_sz2 = 0;
2009  // Skip reading the second slot if we have a none encoded string and are using
2010  // the none encoded strings buffer attached to ResultSetStorage
2012  (target_info.sql_type.is_array() ||
2013  (target_info.sql_type.is_string() &&
2014  target_info.sql_type.get_compression() == kENCODING_NONE)))) {
2015  compact_sz2 = query_mem_desc_.getPaddedSlotWidthBytes(slot_idx + 1);
2016  }
2017  if (separate_varlen_storage_valid_ && target_info.is_agg) {
2018  compact_sz2 = 8; // TODO(adb): is there a better way to do this?
2019  }
2020  CHECK(ptr2);
2021  return target_info.agg_kind == kAVG
2022  ? make_avg_target_value(ptr1, compact_sz1, ptr2, compact_sz2, target_info)
2023  : makeVarlenTargetValue(ptr1,
2024  compact_sz1,
2025  ptr2,
2026  compact_sz2,
2027  target_info,
2028  target_logical_idx,
2029  translate_strings,
2030  entry_buff_idx);
2031  }
2033  query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
2034  return makeTargetValue(ptr1,
2035  compact_sz1,
2036  target_info,
2037  target_logical_idx,
2038  translate_strings,
2040  entry_buff_idx);
2041  }
2042  const auto key_width = query_mem_desc_.getEffectiveKeyWidth();
2043  ptr1 = keys_ptr + query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) * key_width;
2044  return makeTargetValue(ptr1,
2045  key_width,
2046  target_info,
2047  target_logical_idx,
2048  translate_strings,
2050  entry_buff_idx);
2051 }
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
int64_t getTargetGroupbyIndex(const size_t target_idx) const
SQLTypeInfo sql_type
Definition: TargetInfo.h:51
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
size_t getEffectiveKeyWidth() const
TargetValue makeGeoTargetValue(const int8_t *geo_target_ptr, const size_t slot_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t entry_buff_idx) const
TargetValue make_avg_target_value(const int8_t *ptr1, const int8_t compact_sz1, const int8_t *ptr2, const int8_t compact_sz2, const TargetInfo &target_info)
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:738
bool is_agg
Definition: TargetInfo.h:49
size_t targetGroupbyIndicesSize() const
CountDistinctDescriptors count_distinct_descriptors_
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:153
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
SQLAgg agg_kind
Definition: TargetInfo.h:50
#define UNLIKELY(x)
Definition: likely.h:25
bool is_real_str_or_array(const TargetInfo &target_info)
bool isSingleColumnGroupByWithPerfectHash() const
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
TargetValue makeTargetValue(const int8_t *ptr, const int8_t compact_sz, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const bool decimal_to_double, const size_t entry_buff_idx) const
#define CHECK(condition)
Definition: Logger.h:206
bool is_geometry() const
Definition: sqltypes.h:510
bool separate_varlen_storage_valid_
Definition: ResultSet.h:765
bool is_string() const
Definition: sqltypes.h:498
const int8_t getLogicalSlotWidthBytes(const size_t slot_idx) const
Definition: sqldefs.h:72
bool is_array() const
Definition: sqltypes.h:506
TargetValue makeVarlenTargetValue(const int8_t *ptr1, const int8_t compact_sz1, const int8_t *ptr2, const int8_t compact_sz2, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const size_t entry_buff_idx) const

+ Here is the call graph for this function:

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

Definition at line 626 of file ResultSetIteration.cpp.

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

627  {
628  char* host_str_ptr{nullptr};
629  std::vector<int8_t> cpu_buffer;
631  cpu_buffer.resize(str_len);
632  const auto executor = query_mem_desc_.getExecutor();
633  CHECK(executor);
634  auto data_mgr = executor->getDataMgr();
636  data_mgr, &cpu_buffer[0], static_cast<CUdeviceptr>(str_ptr), str_len, device_id_);
637  host_str_ptr = reinterpret_cast<char*>(&cpu_buffer[0]);
638  } else {
640  host_str_ptr = reinterpret_cast<char*>(str_ptr);
641  }
642  std::string str(host_str_ptr, str_len);
643  return InternalTargetValue(row_set_mem_owner_->addString(str));
644 }
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:738
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:729
#define CHECK(condition)
Definition: Logger.h:206
const Executor * getExecutor() const
const int device_id_
Definition: ResultSet.h:730

+ Here is the call graph for this function:

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

Definition at line 1108 of file ResultSetIteration.cpp.

References CHECK, and findStorage().

Referenced by makeGeoTargetValue().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 355 of file ResultSet.h.

References chunk_iters_.

355  {
356  chunk_iters_.push_back(chunk_iters);
357  }
std::vector< std::shared_ptr< std::list< ChunkIter > > > chunk_iters_
Definition: ResultSet.h:747
void ResultSet::holdChunks ( const std::list< std::shared_ptr< Chunk_NS::Chunk >> &  chunks)
inline

Definition at line 352 of file ResultSet.h.

References chunks_.

352  {
353  chunks_ = chunks;
354  }
std::list< std::shared_ptr< Chunk_NS::Chunk > > chunks_
Definition: ResultSet.h:746
void ResultSet::holdLiterals ( std::vector< int8_t > &  literal_buff)
inline

Definition at line 358 of file ResultSet.h.

References literal_buffers_.

358  {
359  literal_buffers_.push_back(std::move(literal_buff));
360  }
std::vector< std::vector< int8_t > > literal_buffers_
Definition: ResultSet.h:750
void ResultSet::initializeStorage ( ) const

Definition at line 1032 of file ResultSetReduction.cpp.

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

Definition at line 581 of file ResultSet.cpp.

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

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

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

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

Definition at line 1431 of file ResultSetIteration.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 2190 of file ResultSetIteration.cpp.

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

2192  {
2193  if (ti.get_notnull()) {
2194  return false;
2195  }
2196  if (val.isInt()) {
2197  return val.i1 == null_val_bit_pattern(ti, float_argument_input);
2198  }
2199  if (val.isPair()) {
2200  return !val.i2;
2201  }
2202  if (val.isStr()) {
2203  return !val.i1;
2204  }
2205  CHECK(val.isNull());
2206  return true;
2207 }
bool isPair() const
Definition: TargetValue.h:67
bool isStr() const
Definition: TargetValue.h:71
int64_t null_val_bit_pattern(const SQLTypeInfo &ti, const bool float_argument_input)
bool isNull() const
Definition: TargetValue.h:69
bool isInt() const
Definition: TargetValue.h:65
#define CHECK(condition)
Definition: Logger.h:206
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:330

+ Here is the call graph for this function:

const bool ResultSet::isPermutationBufferEmpty ( ) const
inline

Definition at line 367 of file ResultSet.h.

References permutation_.

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

Definition at line 285 of file ResultSetIteration.cpp.

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

Definition at line 471 of file ResultSet.cpp.

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

Definition at line 483 of file ResultSet.cpp.

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

Definition at line 1056 of file ResultSet.cpp.

References Projection.

1056  {
1059  appended_storage_.empty() && storage_ &&
1060  (lazy_fetch_info_.empty() || !lazy_fetch_info_[column_idx].is_lazily_fetched);
1061 }
AppendedStorage appended_storage_
Definition: ResultSet.h:733
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
const std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
Definition: ResultSet.h:751
QueryDescriptionType getQueryDescriptionType() const
void ResultSet::keepFirstN ( const size_t  n)

Definition at line 50 of file ResultSet.cpp.

References CHECK_EQ.

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

Definition at line 646 of file ResultSetIteration.cpp.

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

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

+ Here is the call graph for this function:

TargetValue ResultSet::makeGeoTargetValue ( const int8_t *  geo_target_ptr,
const size_t  slot_idx,
const TargetInfo target_info,
const size_t  target_logical_idx,
const size_t  entry_buff_idx 
) const
private

Definition at line 1462 of file ResultSetIteration.cpp.

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

Referenced by getTargetValueFromBufferColwise(), and getTargetValueFromBufferRowwise().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TargetValue ResultSet::makeTargetValue ( const int8_t *  ptr,
const int8_t  compact_sz,
const TargetInfo target_info,
const size_t  target_logical_idx,
const bool  translate_strings,
const bool  decimal_to_double,
const size_t  entry_buff_idx 
) const
private

Definition at line 1743 of file ResultSetIteration.cpp.

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

Referenced by getTargetValueFromBufferColwise(), and getTargetValueFromBufferRowwise().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TargetValue ResultSet::makeVarlenTargetValue ( const int8_t *  ptr1,
const int8_t  compact_sz1,
const int8_t *  ptr2,
const int8_t  compact_sz2,
const TargetInfo target_info,
const size_t  target_logical_idx,
const bool  translate_strings,
const size_t  entry_buff_idx 
) const
private

Definition at line 1305 of file ResultSetIteration.cpp.

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

Referenced by getTargetValueFromBufferColwise(), and getTargetValueFromBufferRowwise().

1312  {
1313  auto varlen_ptr = read_int_from_buff(ptr1, compact_sz1);
1314  if (separate_varlen_storage_valid_ && !target_info.is_agg) {
1315  if (varlen_ptr < 0) {
1316  CHECK_EQ(-1, varlen_ptr);
1317  if (target_info.sql_type.get_type() == kARRAY) {
1318  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1319  }
1320  return TargetValue(nullptr);
1321  }
1322  const auto storage_idx = getStorageIndex(entry_buff_idx);
1323  if (target_info.sql_type.is_string()) {
1324  CHECK(target_info.sql_type.get_compression() == kENCODING_NONE);
1325  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1326  const auto& varlen_buffer_for_storage =
1327  serialized_varlen_buffer_[storage_idx.first];
1328  CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer_for_storage.size());
1329  return varlen_buffer_for_storage[varlen_ptr];
1330  } else if (target_info.sql_type.get_type() == kARRAY) {
1331  CHECK_LT(storage_idx.first, serialized_varlen_buffer_.size());
1332  const auto& varlen_buffer = serialized_varlen_buffer_[storage_idx.first];
1333  CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer.size());
1334 
1335  return build_array_target_value(
1336  target_info.sql_type,
1337  reinterpret_cast<const int8_t*>(varlen_buffer[varlen_ptr].data()),
1338  varlen_buffer[varlen_ptr].size(),
1339  translate_strings,
1341  catalog_);
1342  } else {
1343  CHECK(false);
1344  }
1345  }
1346  if (!lazy_fetch_info_.empty()) {
1347  CHECK_LT(target_logical_idx, lazy_fetch_info_.size());
1348  const auto& col_lazy_fetch = lazy_fetch_info_[target_logical_idx];
1349  if (col_lazy_fetch.is_lazily_fetched) {
1350  const auto storage_idx = getStorageIndex(entry_buff_idx);
1351  CHECK_LT(storage_idx.first, col_buffers_.size());
1352  auto& frag_col_buffers =
1353  getColumnFrag(storage_idx.first, target_logical_idx, varlen_ptr);
1354  bool is_end{false};
1355  if (target_info.sql_type.is_string()) {
1356  VarlenDatum vd;
1357  ChunkIter_get_nth(reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(
1358  frag_col_buffers[col_lazy_fetch.local_col_id])),
1359  varlen_ptr,
1360  false,
1361  &vd,
1362  &is_end);
1363  CHECK(!is_end);
1364  if (vd.is_null) {
1365  return TargetValue(nullptr);
1366  }
1367  CHECK(vd.pointer);
1368  CHECK_GT(vd.length, 0u);
1369  std::string fetched_str(reinterpret_cast<char*>(vd.pointer), vd.length);
1370  return fetched_str;
1371  } else {
1372  CHECK(target_info.sql_type.is_array());
1373  ArrayDatum ad;
1374  ChunkIter_get_nth(reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(
1375  frag_col_buffers[col_lazy_fetch.local_col_id])),
1376  varlen_ptr,
1377  &ad,
1378  &is_end);
1379  CHECK(!is_end);
1380  if (ad.is_null) {
1381  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1382  }
1383  CHECK_GE(ad.length, 0u);
1384  if (ad.length > 0) {
1385  CHECK(ad.pointer);
1386  }
1387  return build_array_target_value(target_info.sql_type,
1388  ad.pointer,
1389  ad.length,
1390  translate_strings,
1392  catalog_);
1393  }
1394  }
1395  }
1396  if (!varlen_ptr) {
1397  if (target_info.sql_type.is_array()) {
1398  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
1399  }
1400  return TargetValue(nullptr);
1401  }
1402  auto length = read_int_from_buff(ptr2, compact_sz2);
1403  if (target_info.sql_type.is_array()) {
1404  const auto& elem_ti = target_info.sql_type.get_elem_type();
1405  length *= elem_ti.get_array_context_logical_size();
1406  }
1407  std::vector<int8_t> cpu_buffer;
1408  if (varlen_ptr && device_type_ == ExecutorDeviceType::GPU) {
1409  cpu_buffer.resize(length);
1410  const auto executor = query_mem_desc_.getExecutor();
1411  CHECK(executor);
1412  auto data_mgr = executor->getDataMgr();
1413  copy_from_gpu(data_mgr,
1414  &cpu_buffer[0],
1415  static_cast<CUdeviceptr>(varlen_ptr),
1416  length,
1417  device_id_);
1418  varlen_ptr = reinterpret_cast<int64_t>(&cpu_buffer[0]);
1419  }
1420  if (target_info.sql_type.is_array()) {
1421  return build_array_target_value(target_info.sql_type,
1422  reinterpret_cast<const int8_t*>(varlen_ptr),
1423  length,
1424  translate_strings,
1426  catalog_);
1427  }
1428  return std::string(reinterpret_cast<char*>(varlen_ptr), length);
1429 }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
Definition: ResultSet.cpp:643
bool is_null
Definition: sqltypes.h:147
SQLTypeInfo sql_type
Definition: TargetInfo.h:51
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:741
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
#define CHECK_GE(x, y)
Definition: Logger.h:219
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
Definition: ResultSet.h:764
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
#define CHECK_GT(x, y)
Definition: Logger.h:218
DEVICE void ChunkIter_get_nth(ChunkIter *it, int n, bool uncompress, VarlenDatum *result, bool *is_end)
Definition: ChunkIter.cpp:181
TargetValue build_array_target_value(const int8_t *buff, const size_t buff_sz, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
int8_t * pointer
Definition: sqltypes.h:146
std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:202
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
Definition: ResultSet.h:738
bool is_agg
Definition: TargetInfo.h:49
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:751
#define CHECK_LT(x, y)
Definition: Logger.h:216
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
int get_array_context_logical_size() const
Definition: sqltypes.h:565
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
Definition: ResultSet.h:752
const ExecutorDeviceType device_type_
Definition: ResultSet.h:729
#define CHECK(condition)
Definition: Logger.h:206
bool separate_varlen_storage_valid_
Definition: ResultSet.h:765
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
bool is_string() const
Definition: sqltypes.h:498
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:726
bool is_array() const
Definition: sqltypes.h:506
const std::vector< const int8_t * > & getColumnFrag(const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
const Executor * getExecutor() const
size_t length
Definition: sqltypes.h:145
const int device_id_
Definition: ResultSet.h:730

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSet::moveToBegin ( ) const

Definition at line 466 of file ResultSet.cpp.

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

Definition at line 367 of file ResultSet.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 601 of file ResultSet.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 979 of file ResultSet.cpp.

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

980  {
981  auto timer = DEBUG_TIMER(__func__);
983  std::vector<int64_t> tmp_buff(query_mem_desc_.getEntryCount());
984  std::vector<int32_t> idx_buff(query_mem_desc_.getEntryCount());
985  CHECK_EQ(size_t(1), order_entries.size());
986  auto buffer_ptr = storage_->getUnderlyingBuffer();
987  for (const auto& order_entry : order_entries) {
988  const auto target_idx = order_entry.tle_no - 1;
989  const auto sortkey_val_buff = reinterpret_cast<int64_t*>(
990  buffer_ptr + query_mem_desc_.getColOffInBytes(target_idx));
991  const auto chosen_bytes = query_mem_desc_.getPaddedSlotWidthBytes(target_idx);
992  sort_groups_cpu(sortkey_val_buff,
993  &idx_buff[0],
995  order_entry.is_desc,
996  chosen_bytes);
997  apply_permutation_cpu(reinterpret_cast<int64_t*>(buffer_ptr),
998  &idx_buff[0],
1000  &tmp_buff[0],
1001  sizeof(int64_t));
1002  for (size_t target_idx = 0; target_idx < query_mem_desc_.getSlotCount();
1003  ++target_idx) {
1004  if (static_cast<int>(target_idx) == order_entry.tle_no - 1) {
1005  continue;
1006  }
1007  const auto chosen_bytes = query_mem_desc_.getPaddedSlotWidthBytes(target_idx);
1008  const auto satellite_val_buff = reinterpret_cast<int64_t*>(
1009  buffer_ptr + query_mem_desc_.getColOffInBytes(target_idx));
1010  apply_permutation_cpu(satellite_val_buff,
1011  &idx_buff[0],
1013  &tmp_buff[0],
1014  chosen_bytes);
1015  }
1016  }
1017 }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
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:731
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
void apply_permutation_cpu(int64_t *val_buff, int32_t *idx_buff, const uint64_t entry_count, int64_t *tmp_buff, const uint32_t chosen_bytes)
Definition: InPlaceSort.cpp:46
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK(condition)
Definition: Logger.h:206
#define DEBUG_TIMER(name)
Definition: Logger.h:322
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 940 of file ResultSet.cpp.

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

941  {
942  auto timer = DEBUG_TIMER(__func__);
943  auto data_mgr = &catalog_->getDataMgr();
944  const int device_id{0};
945  CudaAllocator cuda_allocator(data_mgr, device_id);
946  CHECK_GT(block_size_, 0);
947  CHECK_GT(grid_size_, 0);
948  std::vector<int64_t*> group_by_buffers(block_size_);
949  group_by_buffers[0] = reinterpret_cast<int64_t*>(storage_->getUnderlyingBuffer());
950  auto dev_group_by_buffers =
951  create_dev_group_by_buffers(&cuda_allocator,
952  group_by_buffers,
954  block_size_,
955  grid_size_,
956  device_id,
958  /*num_input_rows=*/-1,
959  /*prepend_index_buffer=*/true,
960  /*always_init_group_by_on_host=*/true,
961  /*use_bump_allocator=*/false,
962  /*has_varlen_output=*/false,
963  /*insitu_allocator*=*/nullptr);
965  order_entries, query_mem_desc_, dev_group_by_buffers, data_mgr, device_id);
967  data_mgr,
968  group_by_buffers,
970  dev_group_by_buffers.data,
972  block_size_,
973  grid_size_,
974  device_id,
975  /*use_bump_allocator=*/false,
976  /*has_varlen_output=*/false);
977 }
size_t getBufferSizeBytes(const RelAlgExecutionUnit &ra_exe_unit, const unsigned thread_count, const ExecutorDeviceType device_type) const
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:223
const Catalog_Namespace::Catalog * catalog_
Definition: ResultSet.h:741
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
void inplace_sort_gpu(const std::list< Analyzer::OrderEntry > &order_entries, const QueryMemoryDescriptor &query_mem_desc, const GpuGroupByBuffers &group_by_buffers, Data_Namespace::DataMgr *data_mgr, const int device_id)
#define CHECK_GT(x, y)
Definition: Logger.h:218
unsigned block_size_
Definition: ResultSet.h:742
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, const bool has_varlen_output)
unsigned grid_size_
Definition: ResultSet.h:743
#define DEBUG_TIMER(name)
Definition: Logger.h:322
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, const bool has_varlen_output, Allocator *insitu_allocator)
Definition: GpuMemUtils.cpp:60

+ Here is the call graph for this function:

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

Definition at line 309 of file ResultSet.cpp.

References CHECK_GE, and Projection.

309  {
310  if (just_explain_) {
311  return 1;
312  }
313  if (!permutation_.empty()) {
314  if (drop_first_ > permutation_.size()) {
315  return 0;
316  }
317  const auto limited_row_count = keep_first_ + drop_first_;
318  return limited_row_count ? std::min(limited_row_count, permutation_.size())
319  : permutation_.size();
320  }
321  if (cached_row_count_ != -1) {
323  return cached_row_count_;
324  }
325  if (!storage_) {
326  return 0;
327  }
328  if (permutation_.empty() &&
330  return binSearchRowCount();
331  }
332  if (force_parallel || entryCount() > 20000) {
333  return parallelRowCount();
334  }
335  std::lock_guard<std::mutex> lock(row_iteration_mutex_);
336  moveToBegin();
337  size_t row_count{0};
338  while (true) {
339  auto crt_row = getNextRowUnlocked(false, false);
340  if (crt_row.empty()) {
341  break;
342  }
343  ++row_count;
344  }
345  moveToBegin();
346  return row_count;
347 }
std::mutex row_iteration_mutex_
Definition: ResultSet.h:770
Permutation permutation_
Definition: ResultSet.h:739
void moveToBegin() const
Definition: ResultSet.cpp:466
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:731
#define CHECK_GE(x, y)
Definition: Logger.h:219
std::unique_ptr< ResultSetStorage > storage_
Definition: ResultSet.h:732
size_t keep_first_
Definition: ResultSet.h:737
const bool just_explain_
Definition: ResultSet.h:767
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:769
size_t parallelRowCount() const
Definition: ResultSet.cpp:367
size_t drop_first_
Definition: ResultSet.h:736
QueryDescriptionType getQueryDescriptionType() const
size_t entryCount() const
std::vector< TargetValue > getNextRowUnlocked(const bool translate_strings, const bool decimal_to_double) const
size_t binSearchRowCount() const
Definition: ResultSet.cpp:354
ResultSetRowIterator ResultSet::rowIterator ( size_t  from_logical_index,
bool  translate_strings,
bool  decimal_to_double 
) const
inline

Definition at line 201 of file ResultSet.h.

Referenced by rowIterator().

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

+ Here is the caller graph for this function:

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

Definition at line 216 of file ResultSet.h.

References rowIterator().

217  {
218  return rowIterator(0, translate_strings, decimal_to_double);
219  }
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
ResultSetRowIterator rowIterator(size_t from_logical_index, bool translate_strings, bool decimal_to_double) const
Definition: ResultSet.h:201

+ Here is the call graph for this function:

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

Definition at line 349 of file ResultSet.cpp.

References CHECK.

349  {
350  CHECK(cached_row_count_ == -1 || cached_row_count_ == static_cast<int64_t>(row_count));
351  cached_row_count_ = row_count;
352 }
std::atomic< int64_t > cached_row_count_
Definition: ResultSet.h:769
#define CHECK(condition)
Definition: Logger.h:206
void ResultSet::setGeoReturnType ( const GeoReturnType  val)
inline

Definition at line 389 of file ResultSet.h.

References geo_return_type_.

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

Definition at line 449 of file ResultSet.cpp.

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

Definition at line 445 of file ResultSet.cpp.

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

Definition at line 421 of file ResultSet.h.

References separate_varlen_storage_valid_.

421  {
423  }
bool separate_varlen_storage_valid_
Definition: ResultSet.h:765
void ResultSet::setValidationOnlyRes ( )

Definition at line 479 of file ResultSet.cpp.

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

Definition at line 503 of file ResultSet.cpp.

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

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

+ Here is the call graph for this function:

void ResultSet::syncEstimatorBuffer ( ) const

Definition at line 430 of file ResultSet.cpp.

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

430  {
433  CHECK_EQ(size_t(0), estimator_->getBufferSize() % sizeof(int64_t));
435  static_cast<int8_t*>(checked_calloc(estimator_->getBufferSize(), 1));
437  auto device_buffer_ptr = device_estimator_buffer_->getMemoryPtr();
440  reinterpret_cast<CUdeviceptr>(device_buffer_ptr),
441  estimator_->getBufferSize(),
442  device_id_);
443 }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
virtual int8_t * getMemoryPtr()=0
void copy_from_gpu(Data_Namespace::DataMgr *data_mgr, void *dst, const CUdeviceptr src, const size_t num_bytes, const int device_id)
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:53
Data_Namespace::DataMgr * data_mgr_
Definition: ResultSet.h:759
const std::shared_ptr< const Analyzer::Estimator > estimator_
Definition: ResultSet.h:756
int8_t * host_estimator_buffer_
Definition: ResultSet.h:758
const ExecutorDeviceType device_type_
Definition: ResultSet.h:729
#define CHECK(condition)
Definition: Logger.h:206
Data_Namespace::AbstractBuffer * device_estimator_buffer_
Definition: ResultSet.h:757
const int device_id_
Definition: ResultSet.h:730

+ Here is the call graph for this function:

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

Definition at line 926 of file ResultSet.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 196 of file ResultSet.h.

References query_mem_desc_, targets_, and typeName().

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

+ Here is the call graph for this function:

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

Definition at line 232 of file ResultSet.h.

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

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

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class ColumnarResults
friend

Definition at line 777 of file ResultSet.h.

friend class ResultSetManager
friend

Definition at line 775 of file ResultSet.h.

friend class ResultSetRowIterator
friend

Definition at line 776 of file ResultSet.h.

Member Data Documentation

AppendedStorage ResultSet::appended_storage_
private

Definition at line 733 of file ResultSet.h.

Referenced by copyColumnIntoBuffer().

unsigned ResultSet::block_size_ {0}
private

Definition at line 742 of file ResultSet.h.

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

Definition at line 769 of file ResultSet.h.

const Catalog_Namespace::Catalog* ResultSet::catalog_
private

Definition at line 741 of file ResultSet.h.

Referenced by makeTargetValue(), and makeVarlenTargetValue().

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

Definition at line 747 of file ResultSet.h.

Referenced by holdChunkIterators().

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

Definition at line 746 of file ResultSet.h.

Referenced by holdChunks().

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

Definition at line 754 of file ResultSet.h.

Referenced by getColumnFrag().

size_t ResultSet::crt_row_buff_idx_
mutableprivate

Definition at line 734 of file ResultSet.h.

Data_Namespace::DataMgr* ResultSet::data_mgr_
private

Definition at line 759 of file ResultSet.h.

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

Definition at line 757 of file ResultSet.h.

const int ResultSet::device_id_
private

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

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

Definition at line 756 of file ResultSet.h.

std::string ResultSet::explanation_
private

Definition at line 766 of file ResultSet.h.

Referenced by getExplanation().

size_t ResultSet::fetched_so_far_
mutableprivate

Definition at line 735 of file ResultSet.h.

bool ResultSet::for_validation_only_
private

Definition at line 768 of file ResultSet.h.

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

Definition at line 753 of file ResultSet.h.

Referenced by getColumnFrag().

GeoReturnType ResultSet::geo_return_type_
mutableprivate

Definition at line 773 of file ResultSet.h.

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

unsigned ResultSet::grid_size_ {0}
private

Definition at line 743 of file ResultSet.h.

int8_t* ResultSet::host_estimator_buffer_ {nullptr}
mutableprivate

Definition at line 758 of file ResultSet.h.

const bool ResultSet::just_explain_
private

Definition at line 767 of file ResultSet.h.

Referenced by getExplanation().

size_t ResultSet::keep_first_
private

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

Referenced by holdLiterals().

Permutation ResultSet::permutation_
private

Definition at line 739 of file ResultSet.h.

Referenced by entryCount(), and isPermutationBufferEmpty().

friend ResultSet::ResultSetBuilder

Definition at line 159 of file ResultSet.h.

std::mutex ResultSet::row_iteration_mutex_
mutableprivate

Definition at line 770 of file ResultSet.h.

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

Definition at line 764 of file ResultSet.h.

Referenced by makeGeoTargetValue(), and makeVarlenTargetValue().

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

Definition at line 744 of file ResultSet.h.


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