8000 using lookahead in zkd by romanatarango · Pull Request #14745 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

using lookahead in zkd #14745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 68 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
c19d549
Bootstrap zkd indexes. Now fill in the details.
Mar 3, 2021
60d6ceb
Added prototype for condition finder.
Mar 4, 2021
63fd0b7
Added helper for Range.
Mar 4, 2021
a43cf14
Fixed double conversion.
Mar 4, 2021
9305dbc
Added wrong but working nextImpl
Mar 5, 2021
14ba135
Extract bounds for iterator.
Mar 5, 2021
3d7d5fc
Fixed extraction logic with reversed operator usage.
Mar 5, 2021
db52b6d
Detect equal operator correctly.
Mar 5, 2021
ede46db
Implemented nextImpl
goedderz Mar 5, 2021
5c78b96
Removed log devel for hot path.
Mar 5, 2021
0b73dcf
Cleanup
goedderz Mar 5, 2021
4fb378c
Added support for partially unbounded queries.
Mar 5, 2021
6948eb6
Do not use index for full collection scans.
Mar 5, 2021
34117f4
Merge branch 'feature/zkd-index' of github.com:arangodb/arangodb into…
Mar 5, 2021
59fd78e
Added tests for ZkdHelper.
Mar 8, 2021
db392e3
Added functional test suite skeleton for zkd index
goedderz Mar 8, 2021
811e660
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
Mar 8, 2021
91f5651
Some fixes to double conversions
goedderz Mar 8, 2021
5be1cd2
Fixed bug in double to byte_string conversion.
Mar 8, 2021
34c4324
Added support for denormalized doubles and infinity.
Mar 9, 2021
e2977ff
Test all interesting double values.
Mar 9, 2021
c9042d2
Disallow Nan.
Mar 9, 2021
dd3b8f2
Added more js tests.
Mar 9, 2021
7b879dc
Added a lot of tests.
Mar 9, 2021
6fcf4d1
Cleaned up test.
Mar 9, 2021
5697c52
[zkd] Strict comparsion (#13673)
Mar 10, 2021
1d3522d
[zkd] Cluster support (#13677)
Mar 11, 2021
94dd02e
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
Mar 11, 2021
3d1ce4b
Added support for nested fields - excluding expansions. (#13681)
Mar 11, 2021
7618470
[zkd] Unique Constraints (#13691)
Mar 12, 2021
1d4928b
[zkd] Forward Compat (#13694)
Mar 15, 2021
8cabd6f
[zkd] Column Family (#13692)
Mar 15, 2021
bbf25b4
Added zkd index docu block. (#13698)
Mar 15, 2021
caa87ae
Fixed bug in RocksDBKeyBounds and using default cost estimation
Mar 16, 2021
6c6a34e
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
Mar 22, 2021
b81f948
[zkd] testInBox speedup (#13798)
Mar 24, 2021
aaddb71
Feature/zkd index speedup getnextzvalue (#13799)
goedderz Mar 25, 2021
10ed61a
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
May 25, 2021
5a1adc3
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
May 26, 2021
584f524
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
Jul 1, 2021
d650d3f
Updated CHANGELOG.
Jul 1, 2021
265ed5c
Merge branch 'devel' of github.com:arangodb/arangodb into feature/zkd…
goedderz Jul 6, 2021
3c73e3d
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
Jul 15, 2021
41ea5e2
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
Aug 5, 2021
fa7d8b0
Fixing iterator.
Aug 6, 2021
5f83c9f
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
Aug 12, 2021
dd48bf9
Added review suggestions.
Aug 20, 2021
875c5ae
using lookahead in zkd
romanatarango Sep 7, 2021
4b94de7
added forgotten declaration
romanatarango Sep 8, 2021
a49a331
added forgotten condering of the new option
romanatarango Sep 8, 2021
a55c4c6
Merge remote-tracking branch 'origin/devel' into feature/zkd-index
Sep 9, 2021
60473c5
Applied suggestions from review.
Sep 9, 2021
a185712
Merge branch 'devel' into feature/zkd-index
mchacki Sep 10, 2021
abc823e
Merge commit '8c2374f95334ba0d48ef72ca1fd0784c7150ad1c' into tmp
romanatarango Sep 13, 2021
98e09f4
Merge remote-tracking branch 'origin/feature/zkd-index' into feature/…
romanatarango Sep 13, 2021
3927a6c
Merge branch 'tmp' into feature/zkd-index-lookahead
romanatarango Sep 13, 2021
69311a0
Merge remote-tracking branch 'origin/devel' into feature/zkd-index-lo…
romanatarango Sep 13, 2021
95767fc
removed tryNewIndex option, now decided by lookahead==0
romanatarango Sep 13, 2021
703c6d4
Merge remote-tracking branch 'origin/devel' into feature/zkd-index-lo…
Oct 6, 2021
d4aa992
Merge remote-tracking branch 'origin' into feature/zkd-index-lookahead
romanatarango Nov 5, 2021
8fca628
Merge branch 'feature/zkd-index-lookahead' of github.com:arangodb/ara…
romanatarango Nov 5, 2021
723d0a8
Merge remote-tracking branch 'origin' into feature/zkd-index-lookahead
romanatarango Nov 5, 2021
40673ae
unified default lookaheads for zkd to 1, made one of them const
romanatarango Nov 5, 2021
fac0505
added testing with lookahead 32 in aql-optimizer-zkdindex-multi.js
romanatarango Nov 8, 2021
0fac8b7
Merge commit 'dc6bbbf2dc552fba751e7f818a69d851393b496a' into feature/…
Jan 4, 2022
87a7a5f
Applied clang-format
Jan 4, 2022
2884250
Merge commit 'a6bd3ccd6f622fab2a288d2e3a06ab8e338d3ec1' into feature/…
Jan 4, 2022
3380e72
Merge branch 'devel' of github.com:arangodb/arangodb into feature/zkd…
Jan 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arangod/Aql/ConditionFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ bool ConditionFinder::before(ExecutionNode* en) {
// will clear out usedIndexes
IndexIteratorOptions opts;
opts.ascending = !descending;
opts.lookahead = node->hint().getLookahead();
TRI_IF_FAILURE("ConditionFinder::insertIndexNode") {
THROW_ARANGO_EXCEPTION(TRI_ERROR_DEBUG);
}
Expand Down
9 changes: 9 additions & 0 deletions arangod/Aql/IndexHint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ IndexHint::IndexHint(QueryContext& query, AstNode const* node) : IndexHint() {
_forced = value->value.value._bool;
handled = true;
}
} else if (name == "lookahead") {
TRI_ASSERT(child->numMembers() > 0);
AstNode const* value = child->getMember(0);

if (value->type == AstNodeType::NODE_TYPE_VALUE &&
value->value.type == AstNodeValueType::VALUE_TYPE_INT) {
_lookahead = value->value.value._int;
handled = true;
}
}

if (!handled) {
Expand Down
3 changes: 3 additions & 0 deletions arangod/Aql/IndexHint.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ class IndexHint {
std::string typeName() const;
std::string toString() const;

size_t getLookahead() const noexcept { return _lookahead; }

private:
HintType _type;
bool _forced;
size_t _lookahead = 1;

// actual hint is a recursive structure, with the data type determined by the
// _type above; in the case of a nested IndexHint, the value of isForced() is
Expand Down
3 changes: 3 additions & 0 deletions arangod/Indexes/IndexIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ struct IndexIteratorOptions {
bool evaluateFCalls = true;
/// @brief enable caching
bool enableCache = true;
/// @brief number of lookahead elements considered before computing the next
/// intersection of the Z-curve with the search range
size_t lookahead = 1;
};

/// index estimate map, defined here because it was convenient
Expand Down
39 changes: 34 additions & 5 deletions arangod/RocksDBEngine/RocksDBZkdIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ class RocksDBZkdIndexIterator final : public IndexIterator {
RocksDBZkdIndexIterator(LogicalCollection* collection,
RocksDBZkdIndexBase* index, transaction::Methods* trx,
zkd::byte_string min, zkd::byte_string max,
std::size_t dim, ReadOwnWrites readOwnWrites)
std::size_t dim, ReadOwnWrites readOwnWrites,
size_t lookahead)
: IndexIterator(collection, trx, readOwnWrites),
_bound(RocksDBKeyBounds::ZkdIndex(index->objectId())),
_min(std::move(min)),
_max(std::move(max)),
_dim(dim),
_index(index) {
_index(index),
_lookahead(lookahead) {
_cur = _min;
_upperBound = _bound.end();

Expand All @@ -85,6 +87,12 @@ class RocksDBZkdIndexIterator final : public IndexIterator {
char const* typeName() const override { return "rocksdb-zkd-index-iterator"; }

protected:
size_t numNextTries()
const noexcept { // may depend on the number of dimensions
// and the limits of the query
return _lookahead;
}

bool nextImpl(LocalDocumentIdCallback const& callback,
size_t limit) override {
for (auto i = size_t{0}; i < limit;) {
Expand All @@ -105,7 +113,26 @@ class RocksDBZkdIndexIterator final : public IndexIterator {
case IterState::CHECK_CURRENT_ITER: {
auto const rocksKey = _iter->key();
auto const byteStringKey = RocksDBKey::zkdIndexValue(rocksKey);
if (!zkd::testInBox(byteStringKey, _min, _max, _dim)) {

bool foundNextZValueInBox =
zkd::testInBox(byteStringKey, _min, _max, _dim);
for (size_t numTried = 0;
!foundNextZValueInBox && numTried < numNextTries(); ++numTried) {
_iter->Next();
if (!_iter->Valid()) {
arangodb::rocksutils::checkIteratorStatus(_iter.get());
_iterState = IterState::DONE;
break; // for loop
}
foundNextZValueInBox =
zkd::testInBox(byteStringKey, _min, _max, _dim);
}

if (_iterState == IterState::DONE) {
break; // case CHECK_CURRENT_ITER
}

if (!foundNextZValueInBox) {
_cur = byteStringKey;

zkd::compareWithBoxInto(_cur, _min, _max, _dim, _compareResult);
Expand Down Expand Up @@ -164,6 +191,8 @@ class RocksDBZkdIndexIterator final : public IndexIterator {
std::unique_ptr<rocksdb::Iterator> _iter;
RocksDBZkdIndexBase* _index = nullptr;

const size_t _lookahead;

std::vector<zkd::CompareResult> _compareResult;
};

Expand Down Expand Up @@ -526,7 +555,7 @@ arangodb::RocksDBZkdIndexBase::iteratorForCondition(

return std::make_unique<RocksDBZkdIndexIterator<false>>(
&_collection, this, trx, std::move(min), std::move(max), fields().size(),
readOwnWrites);
readOwnWrites, opts.lookahead);
}

std::unique_ptr<IndexIterator>
Expand All @@ -538,7 +567,7 @@ arangodb::RocksDBUniqueZkdIndex::iteratorForCondition(

return std::make_unique<RocksDBZkdIndexIterator<true>>(
&_collection, this, trx, std::move(min), std::move(max), fields().size(),
readOwnWrites);
readOwnWrites, opts.lookahead);
}

arangodb::Result arangodb::RocksDBUniqueZkdIndex::insert(
Expand Down
43 changes: 22 additions & 21 deletions tests/js/server/aql/aql-optimizer-zkdindex-multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,33 +122,34 @@ function optimizerRuleZkd2dIndexTestSuite() {
if (x === "none" && y === "none" && z === "none" && w === "none") {
continue; // does not use the index
}

testObject[["testCase", x, y, z, w].join("_")] = function () {
const query = `
FOR d IN ${colName}
for (let addLookahead of ["", " OPTIONS {lookahead: 32}"]) {
testObject[["testCase", x, y, z, w].join("_")] = function () {
const query = `
FOR d IN ${colName} ${addLookahead}
FILTER ${conditionForVariable(x, "d.x")}
FILTER ${conditionForVariable(y, "d.y")}
FILTER ${conditionForVariable(z, "d.z")}
FILTER ${conditionForVariable(w, "d.a.w")}
RETURN [d.x, d.y, d.z, d.a.w]
`;
const explainRes = AQL_EXPLAIN(query);
const appliedRules = explainRes.plan.rules;
const nodeTypes = explainRes.plan.nodes.map(n => n.type).filter(n => !["GatherNode", "RemoteNode"].includes(n));
assertEqual(["SingletonNode", "IndexNode", "CalculationNode", "ReturnNode"], nodeTypes);
assertTrue(appliedRules.includes(useIndexes));

const conds = [x, y, z, w];
if (!conds.includes("lt") && !conds.includes("gt") && !conds.includes("legt")) {
assertTrue(appliedRules.includes(removeFilterCoveredByIndex));
}
const executeRes = AQL_EXECUTE(query);
const res = executeRes.json;
const expected = productSet(x, y, z, w);
res.sort();
expected.sort();
assertEqual(expected, res, JSON.stringify({query}));
};
const explainRes = AQL_EXPLAIN(query);
const appliedRules = explainRes.plan.rules;
const nodeTypes = explainRes.plan.nodes.map(n => n.type).filter(n => !["GatherNode", "RemoteNode"].includes(n));
assertEqual(["SingletonNode", "IndexNode", "CalculationNode", "ReturnNode"], nodeTypes);
assertTrue(appliedRules.includes(useIndexes));

const conds = [x, y, z, w];
if (!conds.includes("lt") && !conds.includes("gt") && !conds.includes("legt")) {
assertTrue(appliedRules.includes(removeFilterCoveredByIndex));
}
const executeRes = AQL_EXECUTE(query);
const res = executeRes.json;
const expected = productSet(x, y, z, w);
res.sort();
expected.sort();
assertEqual(expected, res, JSON.stringify({query}));
};
}
}
}
}
Expand Down
0