10000 Fix IN lookup by jsteemann · Pull Request #19153 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Fix IN lookup #19153

New issue

Have a question about this project? Sign up for a free GitHub account to o 8000 pen 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 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
v3.11.1 (XXXX-XX-XX)
--------------------

* OASIS-25262: Fixed undefined behavior in IN lookup in unique indexes when the
lookup array had to be rebuilt in memory.

* Invalid keys are now reported as individual errors for batch insert operations
and no longer abort the whole batch.

Expand Down
1 change: 1 addition & 0 deletions arangod/RocksDBEngine/RocksDBVPackIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class RocksDBVPackIndexInIterator final : public IndexIterator {

_searchValues.clear();
_searchValues.add(rewriteBuilder->slice());
_current = velocypack::ArrayIterator(_searchValues.slice());
}

void adjustIterator() {
Expand Down
98 changes: 98 additions & 0 deletions tests/js/server/aql/aql-index-rearming.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,88 @@ function VPackIndexRearmingSuite (unique) {
};
}

function VPackIndexInRearmingSuite (unique) {
const cn = "UnitTestsCollection";
const n = 100;

return {
setUpAll : function () {
db._drop(cn);
let c = db._create(cn);

let docs = [];
for (let i = 0; i < n; ++i) {
docs.push({ value1: String(i).padStart(3, "0") });
}
c.insert(docs);
c.ensureIndex({ type: "persistent", fields: ["value1"], name: "UnitTestsIndex", unique });
},

tearDownAll : function () {
db._drop(cn);
},

testVPackLookupBySingleAttributeUsingInLongLists : function () {
for (let i = 1; i < 60; i += 1) {
const values = [];
for (let j = 0; j < i; ++j) {
values.push(String(j).padStart(3, "0"));
}
const q = `LET values = @values FOR doc IN ${cn} FILTER doc.value1 IN values RETURN doc`;

const opts = {};

let nodes = AQL_EXPLAIN(q, {values}, opts).plan.nodes;
let indexNodes = nodes.filter((node) => node.type === 'IndexNode');
assertEqual(1, indexNodes.length);
assertEqual(1, indexNodes[0].indexes.length);
assertEqual("UnitTestsIndex", indexNodes[0].indexes[0].name);

let qr = db._query(q, {values}, opts);
let stats = qr.getExtra().stats;
assertEqual(1, stats.cursorsCreated);
assertEqual(0, stats.cursorsRearmed);
let results = qr.toArray();
assertEqual(i, results.length);

for (let j = 0; j < i; ++j) {
let doc = results[j];
assertEqual(String(j).padStart(3, "0"), doc.value1);
}
}
},

testVPackLookupBySingleAttributeUsingInLongListsRearm : function () {
const q = `FOR i IN 1..60 LET values = (FOR j IN 0..(i - 1) RETURN CONCAT(SUBSTRING('000', 0, 3 - LENGTH(TO_STRING(j))), j)) FOR doc IN ${cn} FILTER doc.value1 IN values RETURN doc`;

const opts = { optimizer: { rules: ["-interchange-adjacent-enumerations"] } };

let nodes = AQL_EXPLAIN(q, null, opts).plan.nodes;
let indexNodes = nodes.filter((node) => node.type === 'IndexNode');
assertEqual(1, indexNodes.length);
assertEqual(1, indexNodes[0].indexes.length);
assertEqual("UnitTestsIndex", indexNodes[0].indexes[0].name);

let qr = db._query(q, null, opts);
let stats = qr.getExtra().stats;
assertEqual(1, stats.cursorsCreated);
assertEqual(59, stats.cursorsRearmed);
let results = qr.toArray();
// 1830 = 1 + 2 + 3 + 4 + 5 ... + 60
assertEqual(1830, results.length);

let it = 0;
for (let i = 1; i <= 60; ++i) {
for (let j = 0; j < i; ++j) {
let doc = results[it++];
assertEqual(String(j).padStart(3, "0"), doc.value1);
}
}
},

};
}

function VPackIndexUniqueSuite() {
'use strict';
let suite = {};
Expand All @@ -708,9 +790,25 @@ function VPackIndexNonUniqueSuite() {
return suite;
}

function VPackIndexInUniqueSuite() {
'use strict';
let suite = {};
deriveTestSuite(VPackIndexInRearmingSuite(/*unique*/ true), suite, '_in_unique');
return suite;
}

function VPackIndexInNonUniqueSuite() {
'use strict';
let suite = {};
deriveTestSuite(VPackIndexInRearmingSuite(/*unique*/ false), suite, '_in_nonUnique');
return suite;
}

jsunity.run(PrimaryIndexSuite);
jsunity.run(EdgeIndexSuite);
jsunity.run(VPackIndexUniqueSuite);
jsunity.run(VPackIndexNonUniqueSuite);
jsunity.run(VPackIndexInUniqueSuite);
jsunity.run(VPackIndexInNonUniqueSuite);

return jsunity.done();
0