| 387 | } |
| 388 | |
| 389 | Status TopNNode::GetNextUnpartitioned( |
| 390 | RuntimeState* state, RowBatch* row_batch, bool* eos) { |
| 391 | DCHECK(!is_partitioned()); |
| 392 | RETURN_IF_CANCELLED(state); |
| 393 | RETURN_IF_ERROR(QueryMaintenance(state)); |
| 394 | while (!row_batch->AtCapacity() && (get_next_iter_ != sorted_top_n_.end())) { |
| 395 | if (num_rows_skipped_ < offset_) { |
| 396 | ++get_next_iter_; |
| 397 | ++num_rows_skipped_; |
| 398 | continue; |
| 399 | } |
| 400 | int row_idx = row_batch->AddRow(); |
| 401 | TupleRow* dst_row = row_batch->GetRow(row_idx); |
| 402 | Tuple* src_tuple = *get_next_iter_; |
| 403 | TupleRow* src_row = reinterpret_cast<TupleRow*>(&src_tuple); |
| 404 | row_batch->CopyRow(src_row, dst_row); |
| 405 | ++get_next_iter_; |
| 406 | row_batch->CommitLastRow(); |
| 407 | IncrementNumRowsReturned(1); |
| 408 | } |
| 409 | *eos = get_next_iter_ == sorted_top_n_.end(); |
| 410 | |
| 411 | // Transfer ownership of tuple data to output batch. |
| 412 | // TODO: To improve performance for small inputs when this node is run multiple times |
| 413 | // inside a subplan, we might choose to only selectively transfer, e.g., when the |
| 414 | // block(s) in the pool are all full or when the pool has reached a certain size. |
| 415 | if (*eos) row_batch->tuple_data_pool()->AcquireData(tuple_pool_.get(), false); |
| 416 | COUNTER_SET(rows_returned_counter_, rows_returned()); |
| 417 | return Status::OK(); |
| 418 | } |
| 419 | |
| 420 | Status TopNNode::GetNextPartitioned( |
| 421 | RuntimeState* state, RowBatch* batch, bool* eos) { |
nothing calls this directly
no test coverage detected