| 1070 | } |
| 1071 | |
| 1072 | Status Sorter::Prepare(ObjectPool* obj_pool) { |
| 1073 | DCHECK(in_mem_tuple_sorter_ == nullptr) << "Already prepared"; |
| 1074 | // Page byte offsets are packed into uint32_t values, which limits the supported |
| 1075 | // page size. |
| 1076 | if (page_len_ > numeric_limits<uint32_t>::max()) { |
| 1077 | return Status(Substitute( |
| 1078 | "Page size $0 exceeded maximum supported in sorter ($1)", |
| 1079 | PrettyPrinter::PrintBytes(page_len_), |
| 1080 | PrettyPrinter::PrintBytes(numeric_limits<uint32_t>::max()))); |
| 1081 | } |
| 1082 | |
| 1083 | TupleDescriptor* sort_tuple_desc = output_row_desc_->tuple_descriptors()[0]; |
| 1084 | if (sort_tuple_desc->byte_size() > page_len_) { |
| 1085 | return Status(TErrorCode::MAX_ROW_SIZE, |
| 1086 | PrettyPrinter::Print(sort_tuple_desc->byte_size(), TUnit::BYTES), node_label_, |
| 1087 | PrettyPrinter::Print(state_->query_options().max_row_size, TUnit::BYTES)); |
| 1088 | } |
| 1089 | has_var_len_slots_ = sort_tuple_desc->HasVarlenSlots(); |
| 1090 | in_mem_tuple_sorter_.reset( |
| 1091 | new TupleSorter(this, *compare_less_than_, sort_tuple_desc->byte_size(), state_)); |
| 1092 | |
| 1093 | if (enable_spilling_) { |
| 1094 | initial_runs_counter_ = ADD_COUNTER(profile_, "InitialRunsCreated", TUnit::UNIT); |
| 1095 | spilled_runs_counter_ = ADD_COUNTER(profile_, "SpilledRuns", TUnit::UNIT); |
| 1096 | num_merges_counter_ = ADD_COUNTER(profile_, "TotalMergesPerformed", TUnit::UNIT); |
| 1097 | } else { |
| 1098 | initial_runs_counter_ = ADD_COUNTER(profile_, "RunsCreated", TUnit::UNIT); |
| 1099 | } |
| 1100 | in_mem_sort_timer_ = ADD_TIMER(profile_, "InMemorySortTime"); |
| 1101 | in_mem_merge_timer_ = ADD_TIMER(profile_, "InMemoryMergeTime"); |
| 1102 | sorted_data_size_ = ADD_COUNTER(profile_, "SortDataSize", TUnit::BYTES); |
| 1103 | run_sizes_ = ADD_SUMMARY_STATS_COUNTER(profile_, "NumRowsPerRun", TUnit::UNIT); |
| 1104 | |
| 1105 | RETURN_IF_ERROR(ScalarExprEvaluator::Create(sort_tuple_exprs_, state_, obj_pool, |
| 1106 | &expr_perm_pool_, &expr_results_pool_, &sort_tuple_expr_evals_)); |
| 1107 | return Status::OK(); |
| 1108 | } |
| 1109 | |
| 1110 | Status Sorter::Open() { |
| 1111 | DCHECK(in_mem_tuple_sorter_ != nullptr) << "Not prepared"; |