| 309 | } |
| 310 | |
| 311 | Status TopNNode::Open(RuntimeState* state) { |
| 312 | SCOPED_TIMER(runtime_profile_->total_time_counter()); |
| 313 | ScopedOpenEventAdder ea(this); |
| 314 | RETURN_IF_ERROR(ExecNode::Open(state)); |
| 315 | RETURN_IF_CANCELLED(state); |
| 316 | RETURN_IF_ERROR(QueryMaintenance(state)); |
| 317 | |
| 318 | RETURN_IF_ERROR(child(0)->Open(state)); |
| 319 | |
| 320 | RETURN_IF_ERROR( |
| 321 | order_cmp_->Open(pool_, state, expr_perm_pool(), expr_results_pool())); |
| 322 | RETURN_IF_ERROR(ScalarExprEvaluator::Open(output_tuple_expr_evals_, state)); |
| 323 | if (is_partitioned()) { |
| 324 | // Set up state required by partitioned top-N implementation. Claim reservation |
| 325 | // after the child has been opened to reduce the peak reservation requirement. |
| 326 | if (!buffer_pool_client()->is_registered()) { |
| 327 | RETURN_IF_ERROR(ClaimBufferReservation(state)); |
| 328 | } |
| 329 | RETURN_IF_ERROR( |
| 330 | partition_cmp_->Open(pool_, state, expr_perm_pool(), expr_results_pool())); |
| 331 | RETURN_IF_ERROR(intra_partition_order_cmp_->Open( |
| 332 | pool_, state, expr_perm_pool(), expr_results_pool())); |
| 333 | RETURN_IF_ERROR(sorter_->Open()); |
| 334 | } |
| 335 | |
| 336 | // Allocate memory for a temporary tuple. |
| 337 | tmp_tuple_ = reinterpret_cast<Tuple*>( |
| 338 | tuple_pool_->Allocate(output_tuple_desc_->byte_size())); |
| 339 | |
| 340 | // Limit of 0, no need to fetch anything from children. |
| 341 | const TopNPlanNode& pnode = static_cast<const TopNPlanNode&>(plan_node_); |
| 342 | if (pnode.heap_capacity() != 0) { |
| 343 | RowBatch batch(child(0)->row_desc(), state->batch_size(), mem_tracker()); |
| 344 | bool eos; |
| 345 | do { |
| 346 | batch.Reset(); |
| 347 | RETURN_IF_ERROR(child(0)->GetNext(state, &batch, &eos)); |
| 348 | { |
| 349 | SCOPED_TIMER(insert_batch_timer_); |
| 350 | TopNPlanNode::InsertBatchFn insert_batch_fn = codegend_insert_batch_fn_.load(); |
| 351 | if (insert_batch_fn != nullptr) { |
| 352 | insert_batch_fn(this, state, &batch); |
| 353 | } else if (is_partitioned()) { |
| 354 | InsertBatchPartitioned(state, &batch); |
| 355 | } else { |
| 356 | InsertBatchUnpartitioned(state, &batch); |
| 357 | } |
| 358 | DCHECK(is_partitioned() || heap_->DCheckConsistency()); |
| 359 | if (is_partitioned()) { |
| 360 | if (partition_heaps_.size() > FLAGS_partitioned_topn_in_mem_partitions_limit || |
| 361 | tuple_pool_->total_reserved_bytes() > |
| 362 | FLAGS_partitioned_topn_soft_limit_bytes) { |
| 363 | RETURN_IF_ERROR(EvictPartitions(state, /*evict_final=*/false)); |
| 364 | } |
| 365 | } else if (rows_to_reclaim_ > 2 * unpartitioned_capacity()) { |
| 366 | RETURN_IF_ERROR(ReclaimTuplePool(state)); |
| 367 | } |
| 368 | } |
nothing calls this directly
no test coverage detected