| 534 | } |
| 535 | |
| 536 | void TableScan::estimateBytesPerRow( |
| 537 | const std::optional<RowVectorPtr>& dataOptional) { |
| 538 | if (!enableEstimateBytesPerRow_ || !dataOptional || !dataOptional.value()) { |
| 539 | return; |
| 540 | } |
| 541 | auto size = dataOptional.value()->size(); |
| 542 | if (size <= 0) { |
| 543 | return; |
| 544 | } |
| 545 | |
| 546 | auto batchByets = dataOptional.value()->usedSize(); |
| 547 | auto bytesPerRow = batchByets / size; |
| 548 | |
| 549 | auto adjustBatchSizeFactor = [this]() { |
| 550 | estimateBatchSizeFactor_ = |
| 551 | std::max(estimateBatchSizeFactor_ / 2, MinEstimateBatchSizeFactor); |
| 552 | }; |
| 553 | auto isLargeDiff = [this](int64_t l, int64_t r, int32_t multiples) -> bool { |
| 554 | return l * multiples / estimateBatchSizeFactor_ < r || |
| 555 | l > r * multiples / estimateBatchSizeFactor_; |
| 556 | }; |
| 557 | |
| 558 | if (bytesPerRowAverage_ > 0 && |
| 559 | isLargeDiff(bytesPerRow, bytesPerRowAverage_, 5)) { |
| 560 | adjustBatchSizeFactor(); |
| 561 | bytesPerRowAverage_ = 0; |
| 562 | } else if ( |
| 563 | bytesPerRowLastBatch_.has_value() && |
| 564 | isLargeDiff(bytesPerRow, bytesPerRowLastBatch_.value(), 3)) { |
| 565 | adjustBatchSizeFactor(); |
| 566 | } |
| 567 | bytesPerRowLastBatch_ = bytesPerRow; |
| 568 | } |
| 569 | |
| 570 | void TableScan::close() { |
| 571 | if (dataSource_) { |