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

#include <ResultSet.h>

+ Collaboration diagram for ResultSetStorage:

Public Member Functions

 ResultSetStorage (const std::vector< TargetInfo > &targets, const QueryMemoryDescriptor &query_mem_desc, int8_t *buff, const bool buff_is_provided)
 
void reduce (const ResultSetStorage &that, const std::vector< std::string > &serialized_varlen_buffer, const ReductionCode &reduction_code) const
 
void rewriteAggregateBufferOffsets (const std::vector< std::string > &serialized_varlen_buffer) const
 
int8_t * getUnderlyingBuffer () const
 
template<class KeyType >
void moveEntriesToBuffer (int8_t *new_buff, const size_t new_entry_count) const
 
template<class KeyType >
void moveOneEntryToBuffer (const size_t entry_index, int64_t *new_buff_i64, const size_t new_entry_count, const size_t key_count, const size_t row_qw_count, const int64_t *src_buff, const size_t key_byte_width) const
 
void updateEntryCount (const size_t new_entry_count)
 

Static Public Member Functions

static bool reduceSingleRow (const int8_t *row_ptr, const int8_t warp_count, const bool is_columnar, const bool replace_bitmap_ptr_with_bitmap_sz, std::vector< int64_t > &agg_vals, const QueryMemoryDescriptor &query_mem_desc, const std::vector< TargetInfo > &targets, const std::vector< int64_t > &agg_init_vals)
 

Private Member Functions

void reduceEntriesNoCollisionsColWise (int8_t *this_buff, const int8_t *that_buff, const ResultSetStorage &that, const size_t start_index, const size_t end_index, const std::vector< std::string > &serialized_varlen_buffer) const
 
void copyKeyColWise (const size_t entry_idx, int8_t *this_buff, const int8_t *that_buff) const
 
bool isEmptyEntry (const size_t entry_idx, const int8_t *buff) const
 
bool isEmptyEntry (const size_t entry_idx) const
 
bool isEmptyEntryColumnar (const size_t entry_idx, const int8_t *buff) const
 
void reduceOneEntryBaseline (int8_t *this_buff, const int8_t *that_buff, const size_t i, const size_t that_entry_count, const ResultSetStorage &that) const
 
void reduceOneEntrySlotsBaseline (int64_t *this_entry_slots, const int64_t *that_buff, const size_t that_entry_idx, const size_t that_entry_count, const ResultSetStorage &that) const
 
void initializeBaselineValueSlots (int64_t *this_entry_slots) const
 
void reduceOneSlotBaseline (int64_t *this_buff, const size_t this_slot, const int64_t *that_buff, const size_t that_entry_count, const size_t that_slot, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const ResultSetStorage &that) const
 
ALWAYS_INLINE void reduceOneSlot (int8_t *this_ptr1, int8_t *this_ptr2, const int8_t *that_ptr1, const int8_t *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const ResultSetStorage &that, const size_t first_slot_idx_for_target, const std::vector< std::string > &serialized_varlen_buffer) const
 
void reduceOneCountDistinctSlot (int8_t *this_ptr1, const int8_t *that_ptr1, const size_t target_logical_idx, const ResultSetStorage &that) const
 
void fillOneEntryRowWise (const std::vector< int64_t > &entry)
 
void fillOneEntryColWise (const std::vector< int64_t > &entry)
 
void initializeRowWise () const
 
void initializeColWise () const
 
void addCountDistinctSetPointerMapping (const int64_t remote_ptr, const int64_t ptr)
 
int64_t mappedPtr (const int64_t) const
 

Private Attributes

const std::vector< TargetInfotargets_
 
QueryMemoryDescriptor query_mem_desc_
 
int8_t * buff_
 
const bool buff_is_provided_
 
std::vector< int64_t > target_init_vals_
 
std::unordered_map< int64_t,
int64_t > 
count_distinct_sets_mapping_
 

Friends

class ResultSet
 
class ResultSetManager
 

Detailed Description

Definition at line 80 of file ResultSet.h.

Constructor & Destructor Documentation

ResultSetStorage::ResultSetStorage ( const std::vector< TargetInfo > &  targets,
const QueryMemoryDescriptor query_mem_desc,
int8_t *  buff,
const bool  buff_is_provided 
)

Definition at line 44 of file ResultSet.cpp.

References kAPPROX_COUNT_DISTINCT, kAVG, kCOUNT, kSAMPLE, null_val_bit_pattern(), takes_float_argument(), target_init_vals_, and targets_.

48  : targets_(targets)
49  , query_mem_desc_(query_mem_desc)
50  , buff_(buff)
51  , buff_is_provided_(buff_is_provided) {
52  for (const auto& target_info : targets_) {
53  if (target_info.agg_kind == kCOUNT ||
54  target_info.agg_kind == kAPPROX_COUNT_DISTINCT) {
55  target_init_vals_.push_back(0);
56  continue;
57  }
58  if (!target_info.sql_type.get_notnull()) {
59  int64_t init_val =
60  null_val_bit_pattern(target_info.sql_type, takes_float_argument(target_info));
61  target_init_vals_.push_back(target_info.is_agg ? init_val : 0);
62  } else {
63  target_init_vals_.push_back(target_info.is_agg ? 0xdeadbeef : 0);
64  }
65  if (target_info.agg_kind == kAVG) {
66  target_init_vals_.push_back(0);
67  } else if (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_geometry()) {
68  for (int i = 1; i < 2 * target_info.sql_type.get_physical_coord_cols(); i++) {
69  target_init_vals_.push_back(0);
70  }
71  } else if (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()) {
72  target_init_vals_.push_back(0);
73  }
74  }
75 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:196
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:200
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:120
int64_t null_val_bit_pattern(const SQLTypeInfo &ti, const bool float_argument_input)
const bool buff_is_provided_
Definition: ResultSet.h:199
int8_t * buff_
Definition: ResultSet.h:198
Definition: sqldefs.h:71
Definition: sqldefs.h:71
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

Member Function Documentation

void ResultSetStorage::addCountDistinctSetPointerMapping ( const int64_t  remote_ptr,
const int64_t  ptr 
)
private

Definition at line 841 of file ResultSet.cpp.

References CHECK(), and count_distinct_sets_mapping_.

842  {
843  const auto it_ok = count_distinct_sets_mapping_.emplace(remote_ptr, ptr);
844  CHECK(it_ok.second);
845 }
std::unordered_map< int64_t, int64_t > count_distinct_sets_mapping_
Definition: ResultSet.h:206
CHECK(cgen_state)

+ Here is the call graph for this function:

void ResultSetStorage::copyKeyColWise ( const size_t  entry_idx,
int8_t *  this_buff,
const int8_t *  that_buff 
) const
private

Definition at line 471 of file ResultSetReduction.cpp.

References CHECK(), QueryMemoryDescriptor::didOutputColumnar(), QueryMemoryDescriptor::getGroupbyColCount(), QueryMemoryDescriptor::getPrependedGroupColOffInBytes(), QueryMemoryDescriptor::groupColWidth(), and query_mem_desc_.

Referenced by reduceEntriesNoCollisionsColWise().

473  {
475  for (size_t group_idx = 0; group_idx < query_mem_desc_.getGroupbyColCount();
476  group_idx++) {
477  // if the column corresponds to a group key
478  const auto column_offset_bytes =
480  auto lhs_key_ptr = this_buff + column_offset_bytes;
481  auto rhs_key_ptr = that_buff + column_offset_bytes;
482  switch (query_mem_desc_.groupColWidth(group_idx)) {
483  case 8:
484  *(reinterpret_cast<int64_t*>(lhs_key_ptr) + entry_idx) =
485  *(reinterpret_cast<const int64_t*>(rhs_key_ptr) + entry_idx);
486  break;
487  case 4:
488  *(reinterpret_cast<int32_t*>(lhs_key_ptr) + entry_idx) =
489  *(reinterpret_cast<const int32_t*>(rhs_key_ptr) + entry_idx);
490  break;
491  case 2:
492  *(reinterpret_cast<int16_t*>(lhs_key_ptr) + entry_idx) =
493  *(reinterpret_cast<const int16_t*>(rhs_key_ptr) + entry_idx);
494  break;
495  case 1:
496  *(reinterpret_cast<int8_t*>(lhs_key_ptr) + entry_idx) =
497  *(reinterpret_cast<const int8_t*>(rhs_key_ptr) + entry_idx);
498  break;
499  default:
500  CHECK(false);
501  break;
502  }
503  }
504 }
int8_t groupColWidth(const size_t key_idx) const
CHECK(cgen_state)
size_t getGroupbyColCount() const
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197
size_t getPrependedGroupColOffInBytes(const size_t group_idx) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetStorage::fillOneEntryColWise ( const std::vector< int64_t > &  entry)
private

Definition at line 1138 of file ResultSetReduction.cpp.

References buff_, CHECK(), CHECK_EQ, QueryMemoryDescriptor::didOutputColumnar(), QueryMemoryDescriptor::getBufferColSlotCount(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getGroupbyColCount(), key_offset_colwise(), query_mem_desc_, slot_offset_colwise(), and target_init_vals_.

1138  {
1140  CHECK_EQ(size_t(1), query_mem_desc_.getEntryCount());
1141  const auto slot_count = query_mem_desc_.getBufferColSlotCount();
1142  const auto key_count = query_mem_desc_.getGroupbyColCount();
1143  CHECK_EQ(slot_count + key_count, entry.size());
1144  auto this_buff = reinterpret_cast<int64_t*>(buff_);
1145 
1146  for (size_t i = 0; i < key_count; i++) {
1147  const auto key_offset = key_offset_colwise(0, i, 1);
1148  this_buff[key_offset] = entry[i];
1149  }
1150 
1151  for (size_t i = 0; i < target_init_vals_.size(); i++) {
1152  const auto slot_offset = slot_offset_colwise(0, i, key_count, 1);
1153  this_buff[slot_offset] = entry[key_count + i];
1154  }
1155 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:200
size_t slot_offset_colwise(const size_t entry_idx, const size_t slot_idx, const size_t key_count, const size_t entry_count)
CHECK(cgen_state)
size_t getGroupbyColCount() const
size_t key_offset_colwise(const size_t entry_idx, const size_t key_idx, const size_t entry_count)
int8_t * buff_
Definition: ResultSet.h:198
size_t getBufferColSlotCount() const
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

void ResultSetStorage::fillOneEntryRowWise ( const std::vector< int64_t > &  entry)
private

Definition at line 1085 of file ResultSetReduction.cpp.

References buff_, CHECK(), CHECK_EQ, QueryMemoryDescriptor::didOutputColumnar(), QueryMemoryDescriptor::getBufferColSlotCount(), QueryMemoryDescriptor::getEffectiveKeyWidth(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getGroupbyColCount(), key_offset_rowwise(), query_mem_desc_, slot_offset_rowwise(), and target_init_vals_.

1085  {
1086  const auto slot_count = query_mem_desc_.getBufferColSlotCount();
1087  const auto key_count = query_mem_desc_.getGroupbyColCount();
1088  CHECK_EQ(slot_count + key_count, entry.size());
1089  auto this_buff = reinterpret_cast<int64_t*>(buff_);
1091  CHECK_EQ(size_t(1), query_mem_desc_.getEntryCount());
1092  const auto key_off = key_offset_rowwise(0, key_count, slot_count);
1093  CHECK_EQ(query_mem_desc_.getEffectiveKeyWidth(), sizeof(int64_t));
1094  for (size_t i = 0; i < key_count; ++i) {
1095  this_buff[key_off + i] = entry[i];
1096  }
1097  const auto first_slot_off = slot_offset_rowwise(0, 0, key_count, slot_count);
1098  for (size_t i = 0; i < target_init_vals_.size(); ++i) {
1099  this_buff[first_slot_off + i] = entry[key_count + i];
1100  }
1101 }
size_t slot_offset_rowwise(const size_t entry_idx, const size_t slot_idx, const size_t key_count, const size_t slot_count)
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:200
size_t getEffectiveKeyWidth() const
CHECK(cgen_state)
size_t getGroupbyColCount() const
int8_t * buff_
Definition: ResultSet.h:198
size_t key_offset_rowwise(const size_t entry_idx, const size_t key_count, const size_t slot_count)
size_t getBufferColSlotCount() const
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

int8_t * ResultSetStorage::getUnderlyingBuffer ( ) const

Definition at line 77 of file ResultSet.cpp.

References buff_.

Referenced by anonymous_namespace{Execute.cpp}::permute_storage_columnar(), and anonymous_namespace{Execute.cpp}::permute_storage_row_wise().

77  {
78  return buff_;
79 }
int8_t * buff_
Definition: ResultSet.h:198

+ Here is the caller graph for this function:

void ResultSetStorage::initializeBaselineValueSlots ( int64_t *  this_entry_slots) const
private

Definition at line 1177 of file ResultSetReduction.cpp.

References CHECK(), QueryMemoryDescriptor::didOutputColumnar(), QueryMemoryDescriptor::getEntryCount(), query_mem_desc_, and target_init_vals_.

1177  {
1178  CHECK(entry_slots);
1180  size_t slot_off = 0;
1181  for (size_t j = 0; j < target_init_vals_.size(); ++j) {
1182  entry_slots[slot_off] = target_init_vals_[j];
1183  slot_off += query_mem_desc_.getEntryCount();
1184  }
1185  } else {
1186  for (size_t j = 0; j < target_init_vals_.size(); ++j) {
1187  entry_slots[j] = target_init_vals_[j];
1188  }
1189  }
1190 }
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:200
CHECK(cgen_state)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

void ResultSetStorage::initializeColWise ( ) const
private

Definition at line 1157 of file ResultSetReduction.cpp.

References buff_, CHECK(), EMPTY_KEY_64, QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getGroupbyColCount(), QueryMemoryDescriptor::hasKeylessHash(), key_offset_colwise(), query_mem_desc_, slot_offset_colwise(), and target_init_vals_.

1157  {
1158  const auto key_count = query_mem_desc_.getGroupbyColCount();
1159  auto this_buff = reinterpret_cast<int64_t*>(buff_);
1161  for (size_t key_idx = 0; key_idx < key_count; ++key_idx) {
1162  const auto first_key_off =
1164  for (size_t i = 0; i < query_mem_desc_.getEntryCount(); ++i) {
1165  this_buff[first_key_off + i] = EMPTY_KEY_64;
1166  }
1167  }
1168  for (size_t target_idx = 0; target_idx < target_init_vals_.size(); ++target_idx) {
1169  const auto first_val_off =
1170  slot_offset_colwise(0, target_idx, key_count, query_mem_desc_.getEntryCount());
1171  for (size_t i = 0; i < query_mem_desc_.getEntryCount(); ++i) {
1172  this_buff[first_val_off + i] = target_init_vals_[target_idx];
1173  }
1174  }
1175 }
#define EMPTY_KEY_64
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:200
size_t slot_offset_colwise(const size_t entry_idx, const size_t slot_idx, const size_t key_count, const size_t entry_count)
CHECK(cgen_state)
size_t getGroupbyColCount() const
size_t key_offset_colwise(const size_t entry_idx, const size_t key_idx, const size_t entry_count)
int8_t * buff_
Definition: ResultSet.h:198
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

void ResultSetStorage::initializeRowWise ( ) const
private

Definition at line 1103 of file ResultSetReduction.cpp.

References align_to_int64(), buff_, CHECK(), CHECK_EQ, anonymous_namespace{ResultSetReduction.cpp}::fill_empty_key_32(), anonymous_namespace{ResultSetReduction.cpp}::fill_empty_key_64(), get_key_bytes_rowwise(), get_row_bytes(), QueryMemoryDescriptor::getEffectiveKeyWidth(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getGroupbyColCount(), QueryMemoryDescriptor::hasKeylessHash(), query_mem_desc_, and target_init_vals_.

1103  {
1104  const auto key_count = query_mem_desc_.getGroupbyColCount();
1105  const auto row_size = get_row_bytes(query_mem_desc_);
1106  CHECK_EQ(row_size % 8, 0u);
1107  const auto key_bytes_with_padding =
1111  case 4: {
1112  for (size_t i = 0; i < query_mem_desc_.getEntryCount(); ++i) {
1113  auto row_ptr = buff_ + i * row_size;
1114  fill_empty_key_32(reinterpret_cast<int32_t*>(row_ptr), key_count);
1115  auto slot_ptr = reinterpret_cast<int64_t*>(row_ptr + key_bytes_with_padding);
1116  for (size_t j = 0; j < target_init_vals_.size(); ++j) {
1117  slot_ptr[j] = target_init_vals_[j];
1118  }
1119  }
1120  break;
1121  }
1122  case 8: {
1123  for (size_t i = 0; i < query_mem_desc_.getEntryCount(); ++i) {
1124  auto row_ptr = buff_ + i * row_size;
1125  fill_empty_key_64(reinterpret_cast<int64_t*>(row_ptr), key_count);
1126  auto slot_ptr = reinterpret_cast<int64_t*>(row_ptr + key_bytes_with_padding);
1127  for (size_t j = 0; j < target_init_vals_.size(); ++j) {
1128  slot_ptr[j] = target_init_vals_[j];
1129  }
1130  }
1131  break;
1132  }
1133  default:
1134  CHECK(false);
1135  }
1136 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:200
size_t getEffectiveKeyWidth() const
ALWAYS_INLINE void fill_empty_key_32(int32_t *key_ptr_i32, const size_t key_count)
CHECK(cgen_state)
size_t getGroupbyColCount() const
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)
int8_t * buff_
Definition: ResultSet.h:198
ALWAYS_INLINE void fill_empty_key_64(int64_t *key_ptr_i64, const size_t key_count)
size_t get_key_bytes_rowwise(const QueryMemoryDescriptor &query_mem_desc)
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

bool ResultSetStorage::isEmptyEntry ( const size_t  entry_idx,
const int8_t *  buff 
) const
private

Definition at line 2038 of file ResultSetIteration.cpp.

References CHECK(), CHECK_GE, CHECK_LT, QueryMemoryDescriptor::didOutputColumnar(), EMPTY_KEY_32, EMPTY_KEY_64, get_byteoff_of_slot(), QueryMemoryDescriptor::getEffectiveKeyWidth(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getQueryDescriptionType(), QueryMemoryDescriptor::getTargetIdxForKey(), GroupByPerfectHash, QueryMemoryDescriptor::hasKeylessHash(), NonGroupedAggregate, ResultSet::query_mem_desc_, read_int_from_buff(), and row_ptr_rowwise().

Referenced by reduceOneEntryBaseline(), and rewriteAggregateBufferOffsets().

2038  {
2041  return false;
2042  }
2044  return isEmptyEntryColumnar(entry_idx, buff);
2045  }
2050  CHECK_LT(static_cast<size_t>(query_mem_desc_.getTargetIdxForKey()),
2051  target_init_vals_.size());
2052  const auto rowwise_target_ptr = row_ptr_rowwise(buff, query_mem_desc_, entry_idx);
2053  const auto target_slot_off =
2055  return read_int_from_buff(rowwise_target_ptr + target_slot_off,
2059  } else {
2060  const auto keys_ptr = row_ptr_rowwise(buff, query_mem_desc_, entry_idx);
2062  case 4:
2065  return *reinterpret_cast<const int32_t*>(keys_ptr) == EMPTY_KEY_32;
2066  case 8:
2067  return *reinterpret_cast<const int64_t*>(keys_ptr) == EMPTY_KEY_64;
2068  default:
2069  CHECK(false);
2070  return true;
2071  }
2072  }
2073 }
#define EMPTY_KEY_64
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:200
bool isEmptyEntryColumnar(const size_t entry_idx, const int8_t *buff) const
size_t get_byteoff_of_slot(const size_t slot_idx, const QueryMemoryDescriptor &query_mem_desc)
#define CHECK_GE(x, y)
Definition: Logger.h:203
size_t getEffectiveKeyWidth() const
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
CHECK(cgen_state)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
T row_ptr_rowwise(T buff, const QueryMemoryDescriptor &query_mem_desc, const size_t entry_idx)
QueryDescriptionType getQueryDescriptionType() const
#define CHECK_LT(x, y)
Definition: Logger.h:200
#define EMPTY_KEY_32
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197
int32_t getTargetIdxForKey() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ResultSetStorage::isEmptyEntry ( const size_t  entry_idx) const
private

Definition at line 2126 of file ResultSetIteration.cpp.

2126  {
2127  return isEmptyEntry(entry_idx, buff_);
2128 }
bool isEmptyEntry(const size_t entry_idx, const int8_t *buff) const
int8_t * buff_
Definition: ResultSet.h:198
bool ResultSetStorage::isEmptyEntryColumnar ( const size_t  entry_idx,
const int8_t *  buff 
) const
private

Definition at line 2079 of file ResultSetIteration.cpp.

References anonymous_namespace{ResultSetIteration.cpp}::advance_col_buff_to_slot(), CHECK(), CHECK_GE, CHECK_LT, QueryMemoryDescriptor::didOutputColumnar(), EMPTY_KEY_16, EMPTY_KEY_32, EMPTY_KEY_64, EMPTY_KEY_8, QueryMemoryDescriptor::getGroupbyColCount(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getPrependedGroupColOffInBytes(), QueryMemoryDescriptor::getQueryDescriptionType(), QueryMemoryDescriptor::getTargetIdxForKey(), GroupByPerfectHash, QueryMemoryDescriptor::groupColWidth(), QueryMemoryDescriptor::hasKeylessHash(), NonGroupedAggregate, Projection, ResultSet::query_mem_desc_, read_int_from_buff(), and ResultSet::targets_.

Referenced by reduceEntriesNoCollisionsColWise().

2080  {
2084  return false;
2085  }
2090  CHECK_LT(static_cast<size_t>(query_mem_desc_.getTargetIdxForKey()),
2091  target_init_vals_.size());
2092  const auto col_buff = advance_col_buff_to_slot(
2094  const auto entry_buff =
2095  col_buff + entry_idx * query_mem_desc_.getPaddedSlotWidthBytes(
2097  return read_int_from_buff(entry_buff,
2101  } else {
2102  // it's enough to find the first group key which is empty
2104  return reinterpret_cast<const int64_t*>(buff)[entry_idx] == EMPTY_KEY_64;
2105  } else {
2107  const auto target_buff = buff + query_mem_desc_.getPrependedGroupColOffInBytes(0);
2108  switch (query_mem_desc_.groupColWidth(0)) {
2109  case 8:
2110  return reinterpret_cast<const int64_t*>(target_buff)[entry_idx] == EMPTY_KEY_64;
2111  case 4:
2112  return reinterpret_cast<const int32_t*>(target_buff)[entry_idx] == EMPTY_KEY_32;
2113  case 2:
2114  return reinterpret_cast<const int16_t*>(target_buff)[entry_idx] == EMPTY_KEY_16;
2115  case 1:
2116  return reinterpret_cast<const int8_t*>(target_buff)[entry_idx] == EMPTY_KEY_8;
2117  default:
2118  CHECK(false);
2119  }
2120  }
2121  return false;
2122  }
2123  return false;
2124 }
#define EMPTY_KEY_64
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:196
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:200
#define CHECK_GE(x, y)
Definition: Logger.h:203
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
const int8_t * advance_col_buff_to_slot(const int8_t *buff, const QueryMemoryDescriptor &query_mem_desc, const std::vector< TargetInfo > &targets, const size_t slot_idx, const bool separate_varlen_storage)
int8_t groupColWidth(const size_t key_idx) const
CHECK(cgen_state)
size_t getGroupbyColCount() const
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define EMPTY_KEY_8
QueryDescriptionType getQueryDescriptionType() const
#define CHECK_LT(x, y)
Definition: Logger.h:200
#define EMPTY_KEY_16
#define EMPTY_KEY_32
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197
int32_t getTargetIdxForKey() const
size_t getPrependedGroupColOffInBytes(const size_t group_idx) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int64_t ResultSetStorage::mappedPtr ( const int64_t  remote_ptr) const
private

Definition at line 847 of file ResultSet.cpp.

References count_distinct_sets_mapping_.

847  {
848  const auto it = count_distinct_sets_mapping_.find(remote_ptr);
849  // Due to the removal of completely zero bitmaps in a distributed transfer there will be
850  // remote ptr that do not not exists. Return 0 if no pointer found
851  if (it == count_distinct_sets_mapping_.end()) {
852  return int64_t(0);
853  }
854  return it->second;
855 }
std::unordered_map< int64_t, int64_t > count_distinct_sets_mapping_
Definition: ResultSet.h:206
template<class KeyType >
void ResultSetStorage::moveEntriesToBuffer ( int8_t *  new_buff,
const size_t  new_entry_count 
) const

Definition at line 883 of file ResultSetReduction.cpp.

References buff_, CHECK(), CHECK_GT, cpu_threads(), anonymous_namespace{ResultSetReduction.cpp}::get_row_qw_count(), QueryMemoryDescriptor::getEffectiveKeyWidth(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getGroupbyColCount(), QueryMemoryDescriptor::getQueryDescriptionType(), GroupByBaselineHash, QueryMemoryDescriptor::hasKeylessHash(), query_mem_desc_, and anonymous_namespace{ResultSetReduction.cpp}::use_multithreaded_reduction().

884  {
886  CHECK_GT(new_entry_count, query_mem_desc_.getEntryCount());
887  auto new_buff_i64 = reinterpret_cast<int64_t*>(new_buff);
888  const auto key_count = query_mem_desc_.getGroupbyColCount();
891  const auto src_buff = reinterpret_cast<const int64_t*>(buff_);
892  const auto row_qw_count = get_row_qw_count(query_mem_desc_);
893  const auto key_byte_width = query_mem_desc_.getEffectiveKeyWidth();
894 
896  const size_t thread_count = cpu_threads();
897  std::vector<std::future<void>> move_threads;
898 
899  for (size_t thread_idx = 0; thread_idx < thread_count; ++thread_idx) {
900  const auto thread_entry_count =
901  (query_mem_desc_.getEntryCount() + thread_count - 1) / thread_count;
902  const auto start_index = thread_idx * thread_entry_count;
903  const auto end_index =
904  std::min(start_index + thread_entry_count, query_mem_desc_.getEntryCount());
905  move_threads.emplace_back(std::async(
906  std::launch::async,
907  [this,
908  src_buff,
909  new_buff_i64,
910  new_entry_count,
911  start_index,
912  end_index,
913  key_count,
914  row_qw_count,
915  key_byte_width] {
916  for (size_t entry_idx = start_index; entry_idx < end_index; ++entry_idx) {
917  moveOneEntryToBuffer<KeyType>(entry_idx,
918  new_buff_i64,
919  new_entry_count,
920  key_count,
921  row_qw_count,
922  src_buff,
923  key_byte_width);
924  }
925  }));
926  }
927  for (auto& move_thread : move_threads) {
928  move_thread.wait();
929  }
930  for (auto& move_thread : move_threads) {
931  move_thread.get();
932  }
933  } else {
934  for (size_t entry_idx = 0; entry_idx < query_mem_desc_.getEntryCount(); ++entry_idx) {
935  moveOneEntryToBuffer<KeyType>(entry_idx,
936  new_buff_i64,
937  new_entry_count,
938  key_count,
939  row_qw_count,
940  src_buff,
941  key_byte_width);
942  }
943  }
944 }
size_t getEffectiveKeyWidth() const
#define CHECK_GT(x, y)
Definition: Logger.h:202
CHECK(cgen_state)
size_t getGroupbyColCount() const
QueryDescriptionType getQueryDescriptionType() const
int8_t * buff_
Definition: ResultSet.h:198
bool use_multithreaded_reduction(const size_t entry_count)
size_t get_row_qw_count(const QueryMemoryDescriptor &query_mem_desc)
int cpu_threads()
Definition: thread_count.h:25
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

template<class KeyType >
void ResultSetStorage::moveOneEntryToBuffer ( const size_t  entry_index,
int64_t *  new_buff_i64,
const size_t  new_entry_count,
const size_t  key_count,
const size_t  row_qw_count,
const int64_t *  src_buff,
const size_t  key_byte_width 
) const

Definition at line 947 of file ResultSetReduction.cpp.

References CHECK(), QueryMemoryDescriptor::didOutputColumnar(), anonymous_namespace{ResultSetReduction.cpp}::fill_slots(), get_group_value(), get_group_value_columnar(), QueryMemoryDescriptor::getEntryCount(), key_offset_colwise(), anonymous_namespace{ResultSetReduction.cpp}::make_key(), and query_mem_desc_.

953  {
954  const auto key_off =
957  : row_qw_count * entry_index;
958  const auto key_ptr = reinterpret_cast<const KeyType*>(&src_buff[key_off]);
959  if (*key_ptr == get_empty_key<KeyType>()) {
960  return;
961  }
962  int64_t* new_entries_ptr{nullptr};
964  const auto key =
965  make_key(&src_buff[key_off], query_mem_desc_.getEntryCount(), key_count);
966  new_entries_ptr =
967  get_group_value_columnar(new_buff_i64, new_entry_count, &key[0], key_count);
968  } else {
969  new_entries_ptr = get_group_value(new_buff_i64,
970  new_entry_count,
971  &src_buff[key_off],
972  key_count,
973  key_byte_width,
974  row_qw_count,
975  nullptr);
976  }
977  CHECK(new_entries_ptr);
978  fill_slots(new_entries_ptr,
979  new_entry_count,
980  src_buff,
981  entry_index,
984 }
NEVER_INLINE DEVICE int64_t * get_group_value_columnar(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_qw_count)
void fill_slots(int64_t *dst_entry, const size_t dst_entry_count, const int64_t *src_buff, const size_t src_entry_idx, const size_t src_entry_count, const QueryMemoryDescriptor &query_mem_desc)
std::vector< int64_t > make_key(const int64_t *buff, const size_t entry_count, const size_t key_count)
CHECK(cgen_state)
NEVER_INLINE DEVICE int64_t * get_group_value(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad, const int64_t *init_vals)
size_t key_offset_colwise(const size_t entry_idx, const size_t key_idx, const size_t entry_count)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

void ResultSetStorage::reduce ( const ResultSetStorage that,
const std::vector< std::string > &  serialized_varlen_buffer,
const ReductionCode reduction_code 
) const

Definition at line 194 of file ResultSetReduction.cpp.

References buff_, CHECK(), CHECK_EQ, CHECK_GE, CHECK_GT, cpu_threads(), QueryMemoryDescriptor::didOutputColumnar(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getQueryDescriptionType(), GroupByBaselineHash, GroupByPerfectHash, ReductionCode::ir_reduce_loop, NonGroupedAggregate, query_mem_desc_, reduceOneEntryBaseline(), anonymous_namespace{ResultSetReduction.cpp}::run_reduction_code(), and anonymous_namespace{ResultSetReduction.cpp}::use_multithreaded_reduction().

196  {
197  auto entry_count = query_mem_desc_.getEntryCount();
198  CHECK_GT(entry_count, size_t(0));
206  }
207  const auto that_entry_count = that.query_mem_desc_.getEntryCount();
210  CHECK_GE(entry_count, that_entry_count);
211  break;
212  default:
213  CHECK_EQ(entry_count, that_entry_count);
214  }
215  auto this_buff = buff_;
216  CHECK(this_buff);
217  auto that_buff = that.buff_;
218  CHECK(that_buff);
221  if (!serialized_varlen_buffer.empty()) {
222  throw std::runtime_error(
223  "Projection of variable length targets with baseline hash group by is not yet "
224  "supported in Distributed mode");
225  }
226  if (use_multithreaded_reduction(that_entry_count)) {
227  const size_t thread_count = cpu_threads();
228  std::vector<std::future<void>> reduction_threads;
229  for (size_t thread_idx = 0; thread_idx < thread_count; ++thread_idx) {
230  const auto thread_entry_count =
231  (that_entry_count + thread_count - 1) / thread_count;
232  const auto start_index = thread_idx * thread_entry_count;
233  const auto end_index =
234  std::min(start_index + thread_entry_count, that_entry_count);
235  reduction_threads.emplace_back(std::async(
236  std::launch::async,
237  [this,
238  this_buff,
239  that_buff,
240  start_index,
241  end_index,
242  that_entry_count,
243  &reduction_code,
244  &that] {
245  if (reduction_code.ir_reduce_loop) {
246  run_reduction_code(reduction_code,
247  this_buff,
248  that_buff,
249  start_index,
250  end_index,
251  that_entry_count,
253  &that.query_mem_desc_,
254  nullptr);
255  } else {
256  for (size_t entry_idx = start_index; entry_idx < end_index; ++entry_idx) {
258  this_buff, that_buff, entry_idx, that_entry_count, that);
259  }
260  }
261  }));
262  }
263  for (auto& reduction_thread : reduction_threads) {
264  reduction_thread.wait();
265  }
266  for (auto& reduction_thread : reduction_threads) {
267  reduction_thread.get();
268  }
269  } else {
270  if (reduction_code.ir_reduce_loop) {
271  run_reduction_code(reduction_code,
272  this_buff,
273  that_buff,
274  0,
275  that_entry_count,
276  that_entry_count,
278  &that.query_mem_desc_,
279  nullptr);
280  } else {
281  for (size_t i = 0; i < that_entry_count; ++i) {
282  reduceOneEntryBaseline(this_buff, that_buff, i, that_entry_count, that);
283  }
284  }
285  }
286  return;
287  }
288  if (use_multithreaded_reduction(entry_count)) {
289  const size_t thread_count = cpu_threads();
290  std::vector<std::future<void>> reduction_threads;
291  for (size_t thread_idx = 0; thread_idx < thread_count; ++thread_idx) {
292  const auto thread_entry_count = (entry_count + thread_count - 1) / thread_count;
293  const auto start_index = thread_idx * thread_entry_count;
294  const auto end_index = std::min(start_index + thread_entry_count, entry_count);
296  reduction_threads.emplace_back(std::async(std::launch::async,
297  [this,
298  this_buff,
299  that_buff,
300  start_index,
301  end_index,
302  &that,
303  &serialized_varlen_buffer] {
305  this_buff,
306  that_buff,
307  that,
308  start_index,
309  end_index,
310  serialized_varlen_buffer);
311  }));
312  } else {
313  reduction_threads.emplace_back(std::async(std::launch::async,
314  [this,
315  this_buff,
316  that_buff,
317  start_index,
318  end_index,
319  that_entry_count,
320  &reduction_code,
321  &that,
322  &serialized_varlen_buffer] {
323  CHECK(reduction_code.ir_reduce_loop);
325  reduction_code,
326  this_buff,
327  that_buff,
328  start_index,
329  end_index,
330  that_entry_count,
332  &that.query_mem_desc_,
333  &serialized_varlen_buffer);
334  }));
335  }
336  }
337  for (auto& reduction_thread : reduction_threads) {
338  reduction_thread.wait();
339  }
340  for (auto& reduction_thread : reduction_threads) {
341  reduction_thread.get();
342  }
343  } else {
346  that_buff,
347  that,
348  0,
350  serialized_varlen_buffer);
351  } else {
352  CHECK(reduction_code.ir_reduce_loop);
353  run_reduction_code(reduction_code,
354  this_buff,
355  that_buff,
356  0,
357  entry_count,
358  that_entry_count,
360  &that.query_mem_desc_,
361  &serialized_varlen_buffer);
362  }
363  }
364 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
void run_reduction_code(const ReductionCode &reduction_code, int8_t *this_buff, const int8_t *that_buff, const int32_t start_entry_index, const int32_t end_entry_index, const int32_t that_entry_count, const void *this_qmd, const void *that_qmd, const void *serialized_varlen_buffer)
void reduceEntriesNoCollisionsColWise(int8_t *this_buff, const int8_t *that_buff, const ResultSetStorage &that, const size_t start_index, const size_t end_index, const std::vector< std::string > &serialized_varlen_buffer) const
void reduceOneEntryBaseline(int8_t *this_buff, const int8_t *that_buff, const size_t i, const size_t that_entry_count, const ResultSetStorage &that) const
std::unique_ptr< Function > ir_reduce_loop
#define CHECK_GE(x, y)
Definition: Logger.h:203
#define CHECK_GT(x, y)
Definition: Logger.h:202
CHECK(cgen_state)
QueryDescriptionType getQueryDescriptionType() const
int8_t * buff_
Definition: ResultSet.h:198
bool use_multithreaded_reduction(const size_t entry_count)
int cpu_threads()
Definition: thread_count.h:25
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

void ResultSetStorage::reduceEntriesNoCollisionsColWise ( int8_t *  this_buff,
const int8_t *  that_buff,
const ResultSetStorage that,
const size_t  start_index,
const size_t  end_index,
const std::vector< std::string > &  serialized_varlen_buffer 
) const
private

Definition at line 380 of file ResultSetReduction.cpp.

References advance_to_next_columnar_target_buff(), CHECK(), anonymous_namespace{ResultSetReduction.cpp}::check_watchdog(), copyKeyColWise(), get_cols_ptr(), QueryMemoryDescriptor::getColSlotContext(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::hasKeylessHash(), isEmptyEntryColumnar(), kAVG, kSAMPLE, LIKELY, query_mem_desc_, reduceOneSlot(), targets_, and UNLIKELY.

386  {
387  // TODO(adb / saman): Support column wise output when serializing distributed agg
388  // functions
389  CHECK(serialized_varlen_buffer.empty());
390 
391  const auto& col_slot_context = query_mem_desc_.getColSlotContext();
392 
393  auto this_crt_col_ptr = get_cols_ptr(this_buff, query_mem_desc_);
394  auto that_crt_col_ptr = get_cols_ptr(that_buff, query_mem_desc_);
395  for (size_t target_idx = 0; target_idx < targets_.size(); ++target_idx) {
396  const auto& agg_info = targets_[target_idx];
397  const auto& slots_for_col = col_slot_context.getSlotsForCol(target_idx);
398 
399  bool two_slot_target{false};
400  if (agg_info.is_agg &&
401  (agg_info.agg_kind == kAVG ||
402  (agg_info.agg_kind == kSAMPLE && agg_info.sql_type.is_varlen()))) {
403  // Note that this assumes if one of the slot pairs in a given target is an array,
404  // all slot pairs are arrays. Currently this is true for all geo targets, but we
405  // should better codify and store this information in the future
406  two_slot_target = true;
407  }
408 
409  for (size_t target_slot_idx = slots_for_col.front();
410  target_slot_idx < slots_for_col.back() + 1;
411  target_slot_idx += 2) {
412  const auto this_next_col_ptr = advance_to_next_columnar_target_buff(
413  this_crt_col_ptr, query_mem_desc_, target_slot_idx);
414  const auto that_next_col_ptr = advance_to_next_columnar_target_buff(
415  that_crt_col_ptr, query_mem_desc_, target_slot_idx);
416 
417  for (size_t entry_idx = start_index; entry_idx < end_index; ++entry_idx) {
418  check_watchdog(entry_idx);
419  if (isEmptyEntryColumnar(entry_idx, that_buff)) {
420  continue;
421  }
423  // copy the key from right hand side
424  copyKeyColWise(entry_idx, this_buff, that_buff);
425  }
426  auto this_ptr1 =
427  this_crt_col_ptr +
428  entry_idx * query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx);
429  auto that_ptr1 =
430  that_crt_col_ptr +
431  entry_idx * query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx);
432  int8_t* this_ptr2{nullptr};
433  const int8_t* that_ptr2{nullptr};
434  if (UNLIKELY(two_slot_target)) {
435  this_ptr2 =
436  this_next_col_ptr +
437  entry_idx * query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx + 1);
438  that_ptr2 =
439  that_next_col_ptr +
440  entry_idx * query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx + 1);
441  }
442  reduceOneSlot(this_ptr1,
443  this_ptr2,
444  that_ptr1,
445  that_ptr2,
446  agg_info,
447  target_idx,
448  target_slot_idx,
449  target_slot_idx,
450  that,
451  slots_for_col.front(),
452  serialized_varlen_buffer);
453  }
454 
455  this_crt_col_ptr = this_next_col_ptr;
456  that_crt_col_ptr = that_next_col_ptr;
457  if (UNLIKELY(two_slot_target)) {
458  this_crt_col_ptr = advance_to_next_columnar_target_buff(
459  this_crt_col_ptr, query_mem_desc_, target_slot_idx + 1);
460  that_crt_col_ptr = advance_to_next_columnar_target_buff(
461  that_crt_col_ptr, query_mem_desc_, target_slot_idx + 1);
462  }
463  }
464  }
465 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:196
ALWAYS_INLINE void reduceOneSlot(int8_t *this_ptr1, int8_t *this_ptr2, const int8_t *that_ptr1, const int8_t *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const ResultSetStorage &that, const size_t first_slot_idx_for_target, const std::vector< std::string > &serialized_varlen_buffer) const
bool isEmptyEntryColumnar(const size_t entry_idx, const int8_t *buff) const
T advance_to_next_columnar_target_buff(T target_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t target_slot_idx)
CHECK(cgen_state)
void copyKeyColWise(const size_t entry_idx, int8_t *this_buff, const int8_t *that_buff) const
ALWAYS_INLINE void check_watchdog(const size_t sample_seed)
#define LIKELY(x)
Definition: likely.h:19
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define UNLIKELY(x)
Definition: likely.h:20
const ColSlotContext & getColSlotContext() const
T get_cols_ptr(T buff, const QueryMemoryDescriptor &query_mem_desc)
Definition: sqldefs.h:71
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

void ResultSetStorage::reduceOneCountDistinctSlot ( int8_t *  this_ptr1,
const int8_t *  that_ptr1,
const size_t  target_logical_idx,
const ResultSetStorage that 
) const
private

Definition at line 1485 of file ResultSetReduction.cpp.

References CHECK(), CHECK_LT, count_distinct_set_union(), QueryMemoryDescriptor::getCountDistinctDescriptor(), QueryMemoryDescriptor::getCountDistinctDescriptorsSize(), Invalid, and query_mem_desc_.

Referenced by reduceOneSlot().

1488  {
1490  const auto& old_count_distinct_desc =
1491  query_mem_desc_.getCountDistinctDescriptor(target_logical_idx);
1492  CHECK(old_count_distinct_desc.impl_type_ != CountDistinctImplType::Invalid);
1493  const auto& new_count_distinct_desc =
1494  that.query_mem_desc_.getCountDistinctDescriptor(target_logical_idx);
1495  CHECK(old_count_distinct_desc.impl_type_ == new_count_distinct_desc.impl_type_);
1496  CHECK(this_ptr1 && that_ptr1);
1497  auto old_set_ptr = reinterpret_cast<const int64_t*>(this_ptr1);
1498  auto new_set_ptr = reinterpret_cast<const int64_t*>(that_ptr1);
1500  *new_set_ptr, *old_set_ptr, new_count_distinct_desc, old_count_distinct_desc);
1501 }
void count_distinct_set_union(const int64_t new_set_handle, const int64_t old_set_handle, const CountDistinctDescriptor &new_count_distinct_desc, const CountDistinctDescriptor &old_count_distinct_desc)
CHECK(cgen_state)
size_t getCountDistinctDescriptorsSize() const
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:200
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetStorage::reduceOneEntryBaseline ( int8_t *  this_buff,
const int8_t *  that_buff,
const size_t  i,
const size_t  that_entry_count,
const ResultSetStorage that 
) const
private

Definition at line 772 of file ResultSetReduction.cpp.

References CHECK(), anonymous_namespace{ResultSetReduction.cpp}::check_watchdog(), QueryMemoryDescriptor::didOutputColumnar(), anonymous_namespace{ResultSetReduction.cpp}::fill_slots(), anonymous_namespace{ResultSetReduction.cpp}::get_group_value_columnar_reduction(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getGroupbyColCount(), QueryMemoryDescriptor::getQueryDescriptionType(), GroupByBaselineHash, QueryMemoryDescriptor::hasKeylessHash(), isEmptyEntry(), key_offset_colwise(), anonymous_namespace{ResultSetReduction.cpp}::make_key(), query_mem_desc_, and reduceOneEntrySlotsBaseline().

Referenced by reduce().

776  {
777  check_watchdog(that_entry_idx);
778  const auto key_count = query_mem_desc_.getGroupbyColCount();
783  const auto key_off =
785  if (isEmptyEntry(that_entry_idx, that_buff)) {
786  return;
787  }
788  int64_t* this_entry_slots{nullptr};
789  auto this_buff_i64 = reinterpret_cast<int64_t*>(this_buff);
790  auto that_buff_i64 = reinterpret_cast<const int64_t*>(that_buff);
791  bool empty_entry = false;
792  const auto key = make_key(&that_buff_i64[key_off], that_entry_count, key_count);
793  std::tie(this_entry_slots, empty_entry) = get_group_value_columnar_reduction(
794  this_buff_i64, query_mem_desc_.getEntryCount(), &key[0], key_count);
795  CHECK(this_entry_slots);
796  if (empty_entry) {
797  fill_slots(this_entry_slots,
799  that_buff_i64,
800  that_entry_idx,
801  that_entry_count,
803  return;
804  }
806  this_entry_slots, that_buff_i64, that_entry_idx, that_entry_count, that);
807 }
bool isEmptyEntry(const size_t entry_idx, const int8_t *buff) const
void fill_slots(int64_t *dst_entry, const size_t dst_entry_count, const int64_t *src_buff, const size_t src_entry_idx, const size_t src_entry_count, const QueryMemoryDescriptor &query_mem_desc)
GroupValueInfo get_group_value_columnar_reduction(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_qw_count)
std::vector< int64_t > make_key(const int64_t *buff, const size_t entry_count, const size_t key_count)
void reduceOneEntrySlotsBaseline(int64_t *this_entry_slots, const int64_t *that_buff, const size_t that_entry_idx, const size_t that_entry_count, const ResultSetStorage &that) const
CHECK(cgen_state)
size_t getGroupbyColCount() const
ALWAYS_INLINE void check_watchdog(const size_t sample_seed)
QueryDescriptionType getQueryDescriptionType() const
size_t key_offset_colwise(const size_t entry_idx, const size_t key_idx, const size_t entry_count)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetStorage::reduceOneEntrySlotsBaseline ( int64_t *  this_entry_slots,
const int64_t *  that_buff,
const size_t  that_entry_idx,
const size_t  that_entry_count,
const ResultSetStorage that 
) const
private

Definition at line 809 of file ResultSetReduction.cpp.

References advance_slot(), CHECK(), QueryMemoryDescriptor::didOutputColumnar(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getGroupbyColCount(), QueryMemoryDescriptor::getTargetGroupbyIndex(), query_mem_desc_, reduceOneSlotBaseline(), slot_offset_colwise(), QueryMemoryDescriptor::targetGroupbyIndicesSize(), and targets_.

Referenced by reduceOneEntryBaseline().

813  {
815  const auto key_count = query_mem_desc_.getGroupbyColCount();
816  size_t j = 0;
817  size_t init_agg_val_idx = 0;
818  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
819  ++target_logical_idx) {
820  const auto& target_info = targets_[target_logical_idx];
821  const auto that_slot_off = slot_offset_colwise(
822  that_entry_idx, init_agg_val_idx, key_count, that_entry_count);
823  const auto this_slot_off = init_agg_val_idx * query_mem_desc_.getEntryCount();
824  reduceOneSlotBaseline(this_entry_slots,
825  this_slot_off,
826  that_buff,
827  that_entry_count,
828  that_slot_off,
829  target_info,
830  target_logical_idx,
831  j,
832  init_agg_val_idx,
833  that);
835  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
836  } else {
837  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
838  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
839  }
840  }
841  j = advance_slot(j, target_info, false);
842  }
843 }
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:196
size_t slot_offset_colwise(const size_t entry_idx, const size_t slot_idx, const size_t key_count, const size_t entry_count)
void reduceOneSlotBaseline(int64_t *this_buff, const size_t this_slot, const int64_t *that_buff, const size_t that_entry_count, const size_t that_slot, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const ResultSetStorage &that) const
size_t advance_slot(const size_t j, const TargetInfo &target_info, const bool separate_varlen_storage)
CHECK(cgen_state)
size_t getGroupbyColCount() const
size_t targetGroupbyIndicesSize() const
ssize_t getTargetGroupbyIndex(const size_t target_idx) const
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetStorage::reduceOneSlot ( int8_t *  this_ptr1,
int8_t *  this_ptr2,
const int8_t *  that_ptr1,
const int8_t *  that_ptr2,
const TargetInfo target_info,
const size_t  target_logical_idx,
const size_t  target_slot_idx,
const size_t  init_agg_val_idx,
const ResultSetStorage that,
const size_t  first_slot_idx_for_target,
const std::vector< std::string > &  serialized_varlen_buffer 
) const
private

Definition at line 1349 of file ResultSetReduction.cpp.

References TargetInfo::agg_kind, AGGREGATE_ONE_COUNT, AGGREGATE_ONE_NULLABLE_VALUE, AGGREGATE_ONE_NULLABLE_VALUE_SMALL, CHECK(), CHECK_EQ, CHECK_LT, logger::FATAL, SQLTypeInfoCore< TYPE_FACET_PACK >::get_elem_type(), get_width_for_slot(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getTargetGroupbyIndex(), TargetInfo::is_agg, is_distinct_target(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_geometry(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_varlen(), QueryMemoryDescriptor::isLogicalSizedColumnsAllowed(), kAPPROX_COUNT_DISTINCT, kAVG, kCOUNT, kMAX, kMIN, kSAMPLE, kSUM, LOG, query_mem_desc_, reduceOneCountDistinctSlot(), TargetInfo::sql_type, takes_float_argument(), target_init_vals_, and QueryMemoryDescriptor::targetGroupbyIndicesSize().

Referenced by reduceEntriesNoCollisionsColWise(), and reduceOneSlotBaseline().

1360  {
1362  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) >= 0) {
1363  return;
1364  }
1365  }
1366  CHECK_LT(init_agg_val_idx, target_init_vals_.size());
1367  const bool float_argument_input = takes_float_argument(target_info);
1368  const auto chosen_bytes =
1369  get_width_for_slot(target_slot_idx, float_argument_input, query_mem_desc_);
1370  auto init_val = target_init_vals_[init_agg_val_idx];
1371  if (target_info.is_agg && target_info.agg_kind != kSAMPLE) {
1372  switch (target_info.agg_kind) {
1373  case kCOUNT:
1374  case kAPPROX_COUNT_DISTINCT: {
1375  if (is_distinct_target(target_info)) {
1376  CHECK_EQ(static_cast<size_t>(chosen_bytes), sizeof(int64_t));
1377  reduceOneCountDistinctSlot(this_ptr1, that_ptr1, target_logical_idx, that);
1378  break;
1379  }
1380  CHECK_EQ(int64_t(0), init_val);
1381  AGGREGATE_ONE_COUNT(this_ptr1, that_ptr1, chosen_bytes);
1382  break;
1383  }
1384  case kAVG: {
1385  // Ignore float argument compaction for count component for fear of its overflow
1386  AGGREGATE_ONE_COUNT(this_ptr2,
1387  that_ptr2,
1388  query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx));
1389  }
1390  // fall thru
1391  case kSUM: {
1393  sum, this_ptr1, that_ptr1, init_val, chosen_bytes, target_info);
1394  break;
1395  }
1396  case kMIN: {
1397  if (static_cast<size_t>(chosen_bytes) <= sizeof(int16_t)) {
1399  min, this_ptr1, that_ptr1, init_val, chosen_bytes, target_info);
1400  } else {
1402  min, this_ptr1, that_ptr1, init_val, chosen_bytes, target_info);
1403  }
1404  break;
1405  }
1406  case kMAX: {
1407  if (static_cast<size_t>(chosen_bytes) <= sizeof(int16_t)) {
1409  max, this_ptr1, that_ptr1, init_val, chosen_bytes, target_info);
1410  } else {
1412  max, this_ptr1, that_ptr1, init_val, chosen_bytes, target_info);
1413  }
1414  break;
1415  }
1416  default:
1417  CHECK(false);
1418  }
1419  } else {
1420  switch (chosen_bytes) {
1421  case 1: {
1423  const auto rhs_proj_col = *reinterpret_cast<const int8_t*>(that_ptr1);
1424  if (rhs_proj_col != init_val) {
1425  *reinterpret_cast<int8_t*>(this_ptr1) = rhs_proj_col;
1426  }
1427  break;
1428  }
1429  case 2: {
1431  const auto rhs_proj_col = *reinterpret_cast<const int16_t*>(that_ptr1);
1432  if (rhs_proj_col != init_val) {
1433  *reinterpret_cast<int16_t*>(this_ptr1) = rhs_proj_col;
1434  }
1435  break;
1436  }
1437  case 4: {
1438  CHECK(target_info.agg_kind != kSAMPLE ||
1440  const auto rhs_proj_col = *reinterpret_cast<const int32_t*>(that_ptr1);
1441  if (rhs_proj_col != init_val) {
1442  *reinterpret_cast<int32_t*>(this_ptr1) = rhs_proj_col;
1443  }
1444  break;
1445  }
1446  case 8: {
1447  auto rhs_proj_col = *reinterpret_cast<const int64_t*>(that_ptr1);
1448  if ((target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()) &&
1449  !serialized_varlen_buffer.empty()) {
1450  size_t length_to_elems{0};
1451  if (target_info.sql_type.is_geometry()) {
1452  // TODO: Assumes hard-coded sizes for geometry targets
1453  length_to_elems = target_slot_idx == first_slot_idx_for_target ? 1 : 4;
1454  } else {
1455  const auto& elem_ti = target_info.sql_type.get_elem_type();
1456  length_to_elems = target_info.sql_type.is_string() ? 1 : elem_ti.get_size();
1457  }
1458 
1459  CHECK_LT(static_cast<size_t>(rhs_proj_col), serialized_varlen_buffer.size());
1460  const auto& varlen_bytes_str = serialized_varlen_buffer[rhs_proj_col];
1461  const auto str_ptr = reinterpret_cast<const int8_t*>(varlen_bytes_str.c_str());
1462  *reinterpret_cast<int64_t*>(this_ptr1) =
1463  reinterpret_cast<const int64_t>(str_ptr);
1464  *reinterpret_cast<int64_t*>(this_ptr2) =
1465  static_cast<int64_t>(varlen_bytes_str.size() / length_to_elems);
1466  } else {
1467  if (rhs_proj_col != init_val) {
1468  *reinterpret_cast<int64_t*>(this_ptr1) = rhs_proj_col;
1469  }
1470  if ((target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen())) {
1471  CHECK(this_ptr2 && that_ptr2);
1472  *reinterpret_cast<int64_t*>(this_ptr2) =
1473  *reinterpret_cast<const int64_t*>(that_ptr2);
1474  }
1475  }
1476 
1477  break;
1478  }
1479  default:
1480  LOG(FATAL) << "Invalid slot width: " << chosen_bytes;
1481  }
1482  }
1483 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::vector< int64_t > target_init_vals_
Definition: ResultSet.h:200
bool isLogicalSizedColumnsAllowed() const
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
#define LOG(tag)
Definition: Logger.h:185
bool is_varlen() const
Definition: sqltypes.h:491
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:120
int8_t get_width_for_slot(const size_t target_slot_idx, const bool float_argument_input, const QueryMemoryDescriptor &query_mem_desc)
Definition: sqldefs.h:71
bool is_agg
Definition: TargetInfo.h:40
CHECK(cgen_state)
void reduceOneCountDistinctSlot(int8_t *this_ptr1, const int8_t *that_ptr1, const size_t target_logical_idx, const ResultSetStorage &that) const
size_t targetGroupbyIndicesSize() const
Definition: sqldefs.h:71
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:116
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
SQLAgg agg_kind
Definition: TargetInfo.h:41
bool is_geometry() const
Definition: sqltypes.h:489
ssize_t getTargetGroupbyIndex(const size_t target_idx) const
#define AGGREGATE_ONE_NULLABLE_VALUE(agg_kind__, val_ptr__, other_ptr__, init_val__, chosen_bytes__, agg_info__)
#define CHECK_LT(x, y)
Definition: Logger.h:200
#define AGGREGATE_ONE_COUNT(val_ptr__, other_ptr__, chosen_bytes__)
Definition: sqldefs.h:71
bool is_string() const
Definition: sqltypes.h:477
#define AGGREGATE_ONE_NULLABLE_VALUE_SMALL(agg_kind__, val_ptr__, other_ptr__, init_val__, chosen_bytes__, agg_info__)
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:659
Definition: sqldefs.h:71
Definition: sqldefs.h:71
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetStorage::reduceOneSlotBaseline ( int64_t *  this_buff,
const size_t  this_slot,
const int64_t *  that_buff,
const size_t  that_entry_count,
const size_t  that_slot,
const TargetInfo target_info,
const size_t  target_logical_idx,
const size_t  target_slot_idx,
const size_t  init_agg_val_idx,
const ResultSetStorage that 
) const
private

Definition at line 845 of file ResultSetReduction.cpp.

References TargetInfo::agg_kind, CHECK(), QueryMemoryDescriptor::didOutputColumnar(), QueryMemoryDescriptor::getEntryCount(), TargetInfo::is_agg, SQLTypeInfoCore< TYPE_FACET_PACK >::is_varlen(), kAVG, kSAMPLE, query_mem_desc_, reduceOneSlot(), and TargetInfo::sql_type.

Referenced by reduceOneEntrySlotsBaseline().

854  {
856  int8_t* this_ptr2{nullptr};
857  const int8_t* that_ptr2{nullptr};
858  if (target_info.is_agg &&
859  (target_info.agg_kind == kAVG ||
860  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
861  const auto this_count_off = query_mem_desc_.getEntryCount();
862  const auto that_count_off = that_entry_count;
863  this_ptr2 = reinterpret_cast<int8_t*>(&this_buff[this_slot + this_count_off]);
864  that_ptr2 = reinterpret_cast<const int8_t*>(&that_buff[that_slot + that_count_off]);
865  }
866  reduceOneSlot(reinterpret_cast<int8_t*>(&this_buff[this_slot]),
867  this_ptr2,
868  reinterpret_cast<const int8_t*>(&that_buff[that_slot]),
869  that_ptr2,
870  target_info,
871  target_logical_idx,
872  target_slot_idx,
873  init_agg_val_idx,
874  that,
875  target_slot_idx, // dummy, for now
876  {});
877 }
ALWAYS_INLINE void reduceOneSlot(int8_t *this_ptr1, int8_t *this_ptr2, const int8_t *that_ptr1, const int8_t *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const ResultSetStorage &that, const size_t first_slot_idx_for_target, const std::vector< std::string > &serialized_varlen_buffer) const
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
bool is_varlen() const
Definition: sqltypes.h:491
bool is_agg
Definition: TargetInfo.h:40
CHECK(cgen_state)
SQLAgg agg_kind
Definition: TargetInfo.h:41
Definition: sqldefs.h:71
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ResultSetStorage::reduceSingleRow ( const int8_t *  row_ptr,
const int8_t  warp_count,
const bool  is_columnar,
const bool  replace_bitmap_ptr_with_bitmap_sz,
std::vector< int64_t > &  agg_vals,
const QueryMemoryDescriptor query_mem_desc,
const std::vector< TargetInfo > &  targets,
const std::vector< int64_t > &  agg_init_vals 
)
static

Definition at line 1503 of file ResultSetReduction.cpp.

References agg_col_count, AGGREGATE_ONE_COUNT, AGGREGATE_ONE_NULLABLE_COUNT, AGGREGATE_ONE_NULLABLE_VALUE, AGGREGATE_ONE_NULLABLE_VALUE_SMALL, CHECK(), CHECK_EQ, CHECK_GE, count_distinct_set_size(), QueryMemoryDescriptor::didOutputColumnar(), logger::ERROR, get_compact_type(), anonymous_namespace{ResultSetReduction.cpp}::get_component(), QueryMemoryDescriptor::getColOnlyOffInBytes(), QueryMemoryDescriptor::getCountDistinctDescriptor(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getRowSize(), QueryMemoryDescriptor::getSlotCount(), QueryMemoryDescriptor::getTargetIdxForKey(), QueryMemoryDescriptor::hasKeylessHash(), is_distinct_target(), kAPPROX_COUNT_DISTINCT, kAVG, kCOUNT, kMAX, kMIN, kSAMPLE, kSUM, LOG, and takes_float_argument().

Referenced by QueryExecutionContext::groupBufferToDeinterleavedResults().

1510  {
1511  const size_t agg_col_count{agg_vals.size()};
1512  const auto row_size = query_mem_desc.getRowSize();
1513  CHECK_EQ(agg_col_count, query_mem_desc.getSlotCount());
1514  CHECK_GE(agg_col_count, targets.size());
1515  CHECK_EQ(is_columnar, query_mem_desc.didOutputColumnar());
1516  CHECK(query_mem_desc.hasKeylessHash());
1517  std::vector<int64_t> partial_agg_vals(agg_col_count, 0);
1518  bool discard_row = true;
1519  for (int8_t warp_idx = 0; warp_idx < warp_count; ++warp_idx) {
1520  bool discard_partial_result = true;
1521  for (size_t target_idx = 0, agg_col_idx = 0;
1522  target_idx < targets.size() && agg_col_idx < agg_col_count;
1523  ++target_idx, ++agg_col_idx) {
1524  const auto& agg_info = targets[target_idx];
1525  const bool float_argument_input = takes_float_argument(agg_info);
1526  const auto chosen_bytes = float_argument_input
1527  ? sizeof(float)
1528  : query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx);
1529  auto partial_bin_val = get_component(
1530  row_ptr + query_mem_desc.getColOnlyOffInBytes(agg_col_idx), chosen_bytes);
1531  partial_agg_vals[agg_col_idx] = partial_bin_val;
1532  if (is_distinct_target(agg_info)) {
1533  CHECK_EQ(int8_t(1), warp_count);
1534  CHECK(agg_info.is_agg && (agg_info.agg_kind == kCOUNT ||
1535  agg_info.agg_kind == kAPPROX_COUNT_DISTINCT));
1536  partial_bin_val = count_distinct_set_size(
1537  partial_bin_val, query_mem_desc.getCountDistinctDescriptor(target_idx));
1538  if (replace_bitmap_ptr_with_bitmap_sz) {
1539  partial_agg_vals[agg_col_idx] = partial_bin_val;
1540  }
1541  }
1542  if (kAVG == agg_info.agg_kind) {
1543  CHECK(agg_info.is_agg && !agg_info.is_distinct);
1544  ++agg_col_idx;
1545  partial_bin_val = partial_agg_vals[agg_col_idx] =
1546  get_component(row_ptr + query_mem_desc.getColOnlyOffInBytes(agg_col_idx),
1547  query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx));
1548  }
1549  if (agg_col_idx == static_cast<size_t>(query_mem_desc.getTargetIdxForKey()) &&
1550  partial_bin_val != agg_init_vals[query_mem_desc.getTargetIdxForKey()]) {
1551  CHECK(agg_info.is_agg);
1552  discard_partial_result = false;
1553  }
1554  }
1555  row_ptr += row_size;
1556  if (discard_partial_result) {
1557  continue;
1558  }
1559  discard_row = false;
1560  for (size_t target_idx = 0, agg_col_idx = 0;
1561  target_idx < targets.size() && agg_col_idx < agg_col_count;
1562  ++target_idx, ++agg_col_idx) {
1563  auto partial_bin_val = partial_agg_vals[agg_col_idx];
1564  const auto& agg_info = targets[target_idx];
1565  const bool float_argument_input = takes_float_argument(agg_info);
1566  const auto chosen_bytes = float_argument_input
1567  ? sizeof(float)
1568  : query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx);
1569  const auto& chosen_type = get_compact_type(agg_info);
1570  if (agg_info.is_agg && agg_info.agg_kind != kSAMPLE) {
1571  try {
1572  switch (agg_info.agg_kind) {
1573  case kCOUNT:
1576  reinterpret_cast<int8_t*>(&agg_vals[agg_col_idx]),
1577  reinterpret_cast<int8_t*>(&partial_agg_vals[agg_col_idx]),
1578  agg_init_vals[agg_col_idx],
1579  chosen_bytes,
1580  agg_info);
1581  break;
1582  case kAVG:
1583  // Ignore float argument compaction for count component for fear of its
1584  // overflow
1586  reinterpret_cast<int8_t*>(&agg_vals[agg_col_idx + 1]),
1587  reinterpret_cast<int8_t*>(&partial_agg_vals[agg_col_idx + 1]),
1588  query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx));
1589  // fall thru
1590  case kSUM:
1592  sum,
1593  reinterpret_cast<int8_t*>(&agg_vals[agg_col_idx]),
1594  reinterpret_cast<int8_t*>(&partial_agg_vals[agg_col_idx]),
1595  agg_init_vals[agg_col_idx],
1596  chosen_bytes,
1597  agg_info);
1598  break;
1599  case kMIN:
1600  if (static_cast<size_t>(chosen_bytes) <= sizeof(int16_t)) {
1602  min,
1603  reinterpret_cast<int8_t*>(&agg_vals[agg_col_idx]),
1604  reinterpret_cast<int8_t*>(&partial_agg_vals[agg_col_idx]),
1605  agg_init_vals[agg_col_idx],
1606  chosen_bytes,
1607  agg_info);
1608  } else {
1610  min,
1611  reinterpret_cast<int8_t*>(&agg_vals[agg_col_idx]),
1612  reinterpret_cast<int8_t*>(&partial_agg_vals[agg_col_idx]),
1613  agg_init_vals[agg_col_idx],
1614  chosen_bytes,
1615  agg_info);
1616  }
1617  break;
1618  case kMAX:
1619  if (static_cast<size_t>(chosen_bytes) <= sizeof(int16_t)) {
1621  max,
1622  reinterpret_cast<int8_t*>(&agg_vals[agg_col_idx]),
1623  reinterpret_cast<int8_t*>(&partial_agg_vals[agg_col_idx]),
1624  agg_init_vals[agg_col_idx],
1625  chosen_bytes,
1626  agg_info);
1627  } else {
1629  max,
1630  reinterpret_cast<int8_t*>(&agg_vals[agg_col_idx]),
1631  reinterpret_cast<int8_t*>(&partial_agg_vals[agg_col_idx]),
1632  agg_init_vals[agg_col_idx],
1633  chosen_bytes,
1634  agg_info);
1635  }
1636  break;
1637  default:
1638  CHECK(false);
1639  break;
1640  }
1641  } catch (std::runtime_error& e) {
1642  // TODO(miyu): handle the case where chosen_bytes < 8
1643  LOG(ERROR) << e.what();
1644  }
1645  if (chosen_type.is_integer() || chosen_type.is_decimal()) {
1646  switch (chosen_bytes) {
1647  case 8:
1648  break;
1649  case 4: {
1650  int32_t ret = *reinterpret_cast<const int32_t*>(&agg_vals[agg_col_idx]);
1651  if (!(agg_info.agg_kind == kCOUNT && ret != agg_init_vals[agg_col_idx])) {
1652  agg_vals[agg_col_idx] = static_cast<int64_t>(ret);
1653  }
1654  break;
1655  }
1656  default:
1657  CHECK(false);
1658  }
1659  }
1660  if (kAVG == agg_info.agg_kind) {
1661  ++agg_col_idx;
1662  }
1663  } else {
1664  if (agg_info.agg_kind == kSAMPLE) {
1665  CHECK(!agg_info.sql_type.is_varlen())
1666  << "Interleaved bins reduction not supported for variable length "
1667  "arguments "
1668  "to SAMPLE";
1669  }
1670  if (agg_vals[agg_col_idx]) {
1671  if (agg_info.agg_kind == kSAMPLE) {
1672  continue;
1673  }
1674  CHECK_EQ(agg_vals[agg_col_idx], partial_bin_val);
1675  } else {
1676  agg_vals[agg_col_idx] = partial_bin_val;
1677  }
1678  }
1679  }
1680  }
1681  return discard_row;
1682 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
const int64_t const uint32_t const uint32_t const uint32_t agg_col_count
int64_t get_component(const int8_t *group_by_buffer, const size_t comp_sz, const size_t index=0)
#define LOG(tag)
Definition: Logger.h:185
#define CHECK_GE(x, y)
Definition: Logger.h:203
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:120
size_t getColOnlyOffInBytes(const size_t col_idx) const
Definition: sqldefs.h:71
const SQLTypeInfo get_compact_type(const TargetInfo &target)
CHECK(cgen_state)
int64_t count_distinct_set_size(const int64_t set_handle, const CountDistinctDescriptor &count_distinct_desc)
Definition: CountDistinct.h:75
Definition: sqldefs.h:71
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:116
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
#define AGGREGATE_ONE_NULLABLE_VALUE(agg_kind__, val_ptr__, other_ptr__, init_val__, chosen_bytes__, agg_info__)
#define AGGREGATE_ONE_COUNT(val_ptr__, other_ptr__, chosen_bytes__)
Definition: sqldefs.h:71
#define AGGREGATE_ONE_NULLABLE_COUNT(val_ptr__, other_ptr__, init_val__, chosen_bytes__, agg_info__)
#define AGGREGATE_ONE_NULLABLE_VALUE_SMALL(agg_kind__, val_ptr__, other_ptr__, init_val__, chosen_bytes__, agg_info__)
Definition: sqldefs.h:71
Definition: sqldefs.h:71
int32_t getTargetIdxForKey() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ResultSetStorage::rewriteAggregateBufferOffsets ( const std::vector< std::string > &  serialized_varlen_buffer) const

Definition at line 508 of file ResultSetReduction.cpp.

References advance_slot(), advance_target_ptr_row_wise(), align_to_int64(), buff_, CHECK(), CHECK_GT, CHECK_LT, QueryMemoryDescriptor::didOutputColumnar(), get_key_bytes_rowwise(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), isEmptyEntry(), kSAMPLE, query_mem_desc_, row_ptr_rowwise(), and targets_.

509  {
510  if (serialized_varlen_buffer.empty()) {
511  return;
512  }
513 
515  auto entry_count = query_mem_desc_.getEntryCount();
516  CHECK_GT(entry_count, size_t(0));
517  CHECK(buff_);
518 
519  // Row-wise iteration, consider moving to separate function
520  for (size_t i = 0; i < entry_count; ++i) {
521  if (isEmptyEntry(i, buff_)) {
522  continue;
523  }
524  const auto key_bytes = get_key_bytes_rowwise(query_mem_desc_);
525  const auto key_bytes_with_padding = align_to_int64(key_bytes);
526  auto rowwise_targets_ptr =
527  row_ptr_rowwise(buff_, query_mem_desc_, i) + key_bytes_with_padding;
528  size_t target_slot_idx = 0;
529  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
530  ++target_logical_idx) {
531  const auto& target_info = targets_[target_logical_idx];
532  if (target_info.sql_type.is_varlen() && target_info.is_agg) {
533  CHECK(target_info.agg_kind == kSAMPLE);
534  auto ptr1 = rowwise_targets_ptr;
535  auto slot_idx = target_slot_idx;
536  auto ptr2 = ptr1 + query_mem_desc_.getPaddedSlotWidthBytes(slot_idx);
537  auto offset = *reinterpret_cast<const int64_t*>(ptr1);
538 
539  const auto& elem_ti = target_info.sql_type.get_elem_type();
540  size_t length_to_elems =
541  target_info.sql_type.is_string() || target_info.sql_type.is_geometry()
542  ? 1
543  : elem_ti.get_size();
544  if (target_info.sql_type.is_geometry()) {
545  for (int j = 0; j < target_info.sql_type.get_physical_coord_cols(); j++) {
546  if (j > 0) {
547  ptr1 = ptr2 + query_mem_desc_.getPaddedSlotWidthBytes(slot_idx + 1);
548  ptr2 = ptr1 + query_mem_desc_.getPaddedSlotWidthBytes(slot_idx + 2);
549  slot_idx += 2;
550  length_to_elems = 4;
551  }
552  CHECK_LT(static_cast<size_t>(offset), serialized_varlen_buffer.size());
553  const auto& varlen_bytes_str = serialized_varlen_buffer[offset++];
554  const auto str_ptr =
555  reinterpret_cast<const int8_t*>(varlen_bytes_str.c_str());
556  CHECK(ptr1);
557  *reinterpret_cast<int64_t*>(ptr1) = reinterpret_cast<const int64_t>(str_ptr);
558  CHECK(ptr2);
559  *reinterpret_cast<int64_t*>(ptr2) =
560  static_cast<int64_t>(varlen_bytes_str.size() / length_to_elems);
561  }
562  } else {
563  CHECK_LT(static_cast<size_t>(offset), serialized_varlen_buffer.size());
564  const auto& varlen_bytes_str = serialized_varlen_buffer[offset];
565  const auto str_ptr = reinterpret_cast<const int8_t*>(varlen_bytes_str.c_str());
566  CHECK(ptr1);
567  *reinterpret_cast<int64_t*>(ptr1) = reinterpret_cast<const int64_t>(str_ptr);
568  CHECK(ptr2);
569  *reinterpret_cast<int64_t*>(ptr2) =
570  static_cast<int64_t>(varlen_bytes_str.size() / length_to_elems);
571  }
572  }
573 
574  rowwise_targets_ptr = advance_target_ptr_row_wise(
575  rowwise_targets_ptr, target_info, target_slot_idx, query_mem_desc_, false);
576  target_slot_idx = advance_slot(target_slot_idx, target_info, false);
577  }
578  }
579 
580  return;
581 }
bool isEmptyEntry(const size_t entry_idx, const int8_t *buff) const
const std::vector< TargetInfo > targets_
Definition: ResultSet.h:196
T advance_target_ptr_row_wise(T target_ptr, const TargetInfo &target_info, const size_t slot_idx, const QueryMemoryDescriptor &query_mem_desc, const bool separate_varlen_storage)
#define CHECK_GT(x, y)
Definition: Logger.h:202
size_t advance_slot(const size_t j, const TargetInfo &target_info, const bool separate_varlen_storage)
CHECK(cgen_state)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
T row_ptr_rowwise(T buff, const QueryMemoryDescriptor &query_mem_desc, const size_t entry_idx)
#define CHECK_LT(x, y)
Definition: Logger.h:200
int8_t * buff_
Definition: ResultSet.h:198
size_t get_key_bytes_rowwise(const QueryMemoryDescriptor &query_mem_desc)
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

void ResultSetStorage::updateEntryCount ( const size_t  new_entry_count)
inline

Definition at line 108 of file ResultSet.h.

References query_mem_desc_, and QueryMemoryDescriptor::setEntryCount().

108  {
109  query_mem_desc_.setEntryCount(new_entry_count);
110  }
void setEntryCount(const size_t val)
QueryMemoryDescriptor query_mem_desc_
Definition: ResultSet.h:197

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class ResultSet
friend

Definition at line 208 of file ResultSet.h.

friend class ResultSetManager
friend

Definition at line 209 of file ResultSet.h.

Member Data Documentation

const bool ResultSetStorage::buff_is_provided_
private

Definition at line 199 of file ResultSet.h.

std::unordered_map<int64_t, int64_t> ResultSetStorage::count_distinct_sets_mapping_
private

Definition at line 206 of file ResultSet.h.

Referenced by addCountDistinctSetPointerMapping(), and mappedPtr().

std::vector<int64_t> ResultSetStorage::target_init_vals_
private
const std::vector<TargetInfo> ResultSetStorage::targets_
private

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