8000 [WIP] Backport of #14525 · arangodb/arangodb@05551de · GitHub
[go: up one dir, main page]

Skip to content

Commit 05551de

Browse files
committed
[WIP] Backport of #14525
1 parent a33e95c commit 05551de

32 files changed

+965
-314
lines changed

arangod/Aql/AqlCall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct AqlCall {
191191
TRI_ASSERT(n <= i);
192192
i -= n;
193193
},
194-
[](auto) {},
194+
[](Infinity) {},
195195
};
196196
std::visit(minus, softLimit);
197197
std::visit(minus, hardLimit);

arangod/Aql/AqlExecuteResult.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include <map>
3737
#include <string_view>
38+
#include <utility>
3839

3940
using namespace arangodb;
4041
using namespace arangodb::aql;
@@ -49,7 +50,7 @@ auto getStringView(velocypack::Slice slice) -> std::string_view {
4950

5051
AqlExecuteResult::AqlExecuteResult(ExecutionState state, SkipResult skipped,
5152
SharedAqlItemBlockPtr&& block)
52-
: _state(state), _skipped(skipped), _block(std::move(block)) {
53+
: _state(state), _skipped(std::move(skipped)), _block(std::move(block)) {
5354
// Make sure we only produce a valid response
5455
// The block should have checked as well.
5556
// We must return skipped and/or data when reporting HASMORE

arangod/Aql/AqlItemBlock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ size_t AqlItemBlock::maxModifiedEntries() const noexcept { return _numRegisters
11691169

11701170
size_t AqlItemBlock::capacity() const noexcept { return _data.capacity(); }
11711171

1172-
bool AqlItemBlock::isShadowRow(size_t row) const {
1172+
bool AqlItemBlock::isShadowRow(size_t row) const noexcept {
11731173
return _shadowRows.is(row);
11741174
}
11751175

arangod/Aql/AqlItemBlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ class AqlItemBlock {
298298

299299
/// @brief test if the given row is a shadow row and conveys subquery
300300
/// information only. It should not be handed to any non-subquery executor.
301-
bool isShadowRow(size_t row) const;
301+
bool isShadowRow(size_t row) const noexcept;
302302

303303
/// @brief get the ShadowRowDepth
304304
/// Does only work if this row is a shadow row

arangod/Aql/AqlItemBlockInputMatrix.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ AqlItemBlockInputRange& AqlItemBlockInputMatrix::getInputRange() {
5656
if (_lastRange.hasDataRow()) {
5757
return _lastRange;
5858
}
59-
// Need initialze lastRange
59+
// Need initialize lastRange
6060
if (_aqlItemMatrix->numberOfBlocks() == 0) {
6161
_lastRange = {AqlItemBlockInputRange{upstreamState()}};
6262
} else {
@@ -69,7 +69,6 @@ AqlItemBlockInputRange& AqlItemBlockInputMatrix::getInputRange() {
6969

7070
std::pair<ExecutorState, AqlItemMatrix const*> AqlItemBlockInputMatrix::getMatrix() noexcept {
7171
TRI_ASSERT(_aqlItemMatrix != nullptr);
72-
TRI_ASSERT(!_shadowRow.isInitialized());
7372

7473
// We are always done. This InputMatrix
7574
// guarantees that we have all data in our hand at once.
@@ -95,7 +94,7 @@ bool AqlItemBlockInputMatrix::hasValidRow() const noexcept {
9594

9695
bool AqlItemBlockInputMatrix::hasDataRow() const noexcept {
9796
return _aqlItemMatrix != nullptr && !hasShadowRow() &&
98-
((_aqlItemMatrix->stoppedOnShadowRow()) ||
97+
(_aqlItemMatrix->stoppedOnShadowRow() ||
9998
(_aqlItemMatrix->size() > 0 && _finalState == ExecutorState::DONE));
10099
}
101100

arangod/Aql/AqlItemBlockInputMatrix.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class AqlItemBlockInputMatrix {
6363

6464
size_t skipAllShadowRowsOfDepth(size_t depth);
6565

66-
6766
// Will return HASMORE if we were able to increase the row index.
6867
// Otherwise will return DONE.
6968
ExecutorState incrBlockIndex();

arangod/Aql/AqlItemMatrix.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,94 @@ AqlItemMatrix::AqlItemMatrix(RegisterCount nrRegs)
245245
clear();
246246
return {skipped, ShadowAqlItemRow{CreateInvalidShadowRowHint()}};
247247
}
248+
249+
AqlItemMatrix::RowIterator AqlItemMatrix::begin() const {
250+
if (size() > 0) {
251+
return {this, 0, _startIndexInFirstBlock};
252+
} else {
253+
return end();
254+
}
255+
}
256+
257+
AqlItemMatrix::RowIterator AqlItemMatrix::end() const {
258+
return {this, this->numberOfBlocks(), 0};
259+
}
260+
261+
AqlItemMatrix::RowIterator::RowIterator(AqlItemMatrix const* matrix, size_t blockIndex, size_t rowIndex)
262+
: _matrix(matrix), _blockIndex(blockIndex), _rowIndex(rowIndex) {}
263+
264+
AqlItemMatrix::RowIterator::value_type AqlItemMatrix::RowIterator::next() noexcept {
265+
auto& it = *this;
266+
auto ret = *it;
267+
++it;
268+
return ret;
269+
}
270+
271+
auto AqlItemMatrix::RowIterator::isInitialized() const noexcept -> bool {
272+
return _matrix != nullptr;
273+
}
274+
275+
auto AqlItemMatrix::RowIterator::hasMore() const noexcept -> bool {
276+
// _blockIndex == _matrix->size() => _rowIndex == 0
277+
TRI_ASSERT((_matrix != nullptr && _blockIndex < _matrix->numberOfBlocks()) || _rowIndex == 0);
278+
// If _blockIndex is valid, _rowIndex must be, too.
279+
return ADB_LIKELY(_matrix != nullptr) && _blockIndex < _matrix->numberOfBlocks();
280+
}
281+
282+
AqlItemMatrix::RowIterator::value_type AqlItemMatrix::RowIterator::operator*() const noexcept {
283+
return {_matrix->getBlock(_blockIndex).first, _rowIndex};
284+
}
285+
286+
AqlItemMatrix::RowIterator& AqlItemMatrix::RowIterator::operator++() noexcept {
287+
// Assume ++ is only called on a valid and dereferenceable iterator
288+
TRI_ASSERT(_matrix != nullptr);
289+
TRI_ASSERT(_blockIndex < _matrix->numberOfBlocks());
290+
auto const* block = _matrix->getBlockRef(_blockIndex).first;
291+
TRI_ASSERT(_rowIndex < block->numRows());
292+
TRI_ASSERT(!block->isShadowRow(_rowIndex));
293+
294+
// Increase the row index
295+
++_rowIndex;
296+
if (_rowIndex >= block->numRows()) {
297+
// If the row index is invalid, move to the next block.
298+
// If the block index is now invalid, this is equal to the "end()"
299+
// iterator.
300+
++_blockIndex;
301+
_rowIndex = 0;
302+
}
303+
304+
if (_blockIndex < _matrix->numberOfBlocks()) {
305+
block = _matrix->getBlockRef(_blockIndex).first;
306+
if (block->isShadowRow(_rowIndex)) {
307+
// If we're at a shadow row, this must be the last block.
308+
TRI_ASSERT(_blockIndex + 1 == _matrix->numberOfBlocks());
309+
// This makes this equal to the "end()" iterator.
310+
++_blockIndex;
311+
_rowIndex = 0;
312+
}
313+
}
314+
315+
return *this;
316+
}
317+
318+
auto AqlItemMatrix::RowIterator::operator++(int) & noexcept -> AqlItemMatrix::RowIterator {
319+
auto tmp = *this;
320+
++(*this);
321+
return tmp;
322+
}
323+
324+
AqlItemMatrix::RowIterator::operator bool() const noexcept {
325+
return hasMore();
326+
}
327+
328+
bool aql::operator==(AqlItemMatrix::RowIterator const& a,
329+
AqlItemMatrix::RowIterator const& b) {
330+
return ADB_LIKELY(a._matrix == b._matrix) &&
331+
(ADB_UNLIKELY(a._matrix == nullptr /* => b._matrix == nullptr */) ||
332+
(ADB_LIKELY(a._blockIndex == b._blockIndex) && a._rowIndex == b._rowIndex));
333+
}
334+
335+
bool aql::operator!=(AqlItemMatrix::RowIterator const& a,
336+
AqlItemMatrix::RowIterator const& b) {
337+
return !(a == b);
338+
}

arangod/Aql/AqlItemMatrix.h

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
#include <utility>
3030
#include <vector>
3131

32-
namespace arangodb {
33-
namespace aql {
32+
namespace arangodb::aql {
3433

3534
class InputAqlItemRow;
3635
class SharedAqlItemBlockPtr;
@@ -119,6 +118,49 @@ class AqlItemMatrix {
119118
[[nodiscard]] auto skipAllShadowRowsOfDepth(size_t depth)
120119
-> std::tuple<size_t, ShadowAqlItemRow>;
121120

121+
class RowIterator {
122+
public:
123+
using value_type = InputAqlItemRow;
124+
125+
RowIterator() = default;
126+
RowIterator(AqlItemMatrix const* matrix, size_t blockIndex, size_t rowIndex);
127+
128+
// Returns the current value, and move the iterator to the next value
129+
value_type next() noexcept;
130+
131+
auto isInitialized() const noexcept -> bool;
132+
133+
// Returns whether the current value is valid, i.e. whether next() may be
134+
// called
135+
auto hasMore() const noexcept -> bool;
136+
137+
value_type operator*() const noexcept;
138+
139+
// This can't be implemented, as we can only create the InputAqlItemRow
140+
// on-the-fly.
141+
// pointer operator->();
142+
143+
// Prefix increment
144+
RowIterator& operator++() noexcept;
145+
146+
// Postfix increment.
147+
auto operator++(int) & noexcept -> RowIterator;
148+
149+
explicit operator bool() const noexcept;
150+
151+
friend bool operator==(RowIterator const& a, RowIterator const& b);
152+
friend bool operator!=(RowIterator const& a, RowIterator const& b);
153+
154+
private:
155+
AqlItemMatrix const* _matrix{};
156+
std::size_t _blockIndex{};
157+
// Invariant: _rowIndex is valid iff _blockIndex is valid.
158+
std::size_t _rowIndex{};
159+
};
160+
161+
[[nodiscard]] RowIterator begin() const;
162+
[[nodiscard]] RowIterator end() const;
163+
122164
private:
123165
std::vector<SharedAqlItemBlockPtr> _blocks;
124166

@@ -129,6 +171,7 @@ class AqlItemMatrix {
129171
size_t _stopIndexInLastBlock;
130172
};
131173

132-
} // namespace aql
133-
} // namespace arangodb
174+
bool operator==(AqlItemMatrix::RowIterator const& a, AqlItemMatrix::RowIterator const& b);
175+
bool operator!=(AqlItemMatrix::RowIterator const& a, AqlItemMatrix::RowIterator const& b);
134176

177+
} // namespace arangodb::aql

arangod/Aql/ClusterNodes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ std::unique_ptr<ExecutionBlock> SingleRemoteOperationNode::createBlock(
601601
std::move(writableOutputRegisters));
602602

603603
auto executorInfos = SingleRemoteModificationInfos(
604+
&engine,
604605
in, outputNew, outputOld, out, _plan->getAst()->query(), std::move(options),
605606
collection(), ConsultAqlWriteFilter(_options.consultAqlWriteFilter),
606607
IgnoreErrors(_options.ignoreErrors),< 3887 /div>

0 commit comments

Comments
 (0)
0