From 2a64571bef876ccb0fedabc7766d080b52fe964a Mon Sep 17 00:00:00 2001 From: yixiutt <102007456+yixiutt@users.noreply.github.com> Date: Thu, 8 Sep 2022 12:09:02 +0800 Subject: [PATCH] [enhancement](generic_iterator) fix num check and add some notes (#12434) Co-authored-by: yixiutt --- be/src/vec/olap/vgeneric_iterators.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/be/src/vec/olap/vgeneric_iterators.cpp b/be/src/vec/olap/vgeneric_iterators.cpp index dd9fd28963..9f50040b2e 100644 --- a/be/src/vec/olap/vgeneric_iterators.cpp +++ b/be/src/vec/olap/vgeneric_iterators.cpp @@ -187,11 +187,18 @@ public: return result; } - // `advanced = false` when current block finished + // there is two situation in copy_rows: + // 1... `advanced = false` when current block finished, we should copy block before advance(iterator) + // If we iterator a block from start to end, _index_in_block=rows()-1, and _cur_batch_num=rows, + // so we should copy from (_index_in_block - _cur_batch_num + 1) + + // 2... `advanced = true` when current block not finished and we advanced to next block, now + // cur_batch_num = (pre_block iteraotr num) + 1, but actually pre_block iterator num is cur_batch_num -1 + // so we have a ` if (advanced) start -- ` void copy_rows(vectorized::Block* block, bool advanced = true) { vectorized::Block& src = _block; vectorized::Block& dst = *block; - if (_cur_batch_num == 0 || _index_in_block - _cur_batch_num < 0) { + if (_cur_batch_num == 0) { return; }