8000 cheapify IN lookups on unsorted arrays by jsteemann · Pull Request #11342 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

cheapify IN lookups on unsorted arrays #11342

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 “Sig 8000 n 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 2 commits into from
Mar 31, 2020
Merged
Changes from 1 commit
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
41 changes: 32 additions & 9 deletions arangod/Aql/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "Basics/StringBuffer.h"
#include "Basics/VPackStringBufferAdapter.h"
#include "Basics/VelocyPackHelper.h"
#include "Transaction/Context.h"
#include "Transaction/Helpers.h"
#include "Transaction/Methods.h"
#include "V8/v8-globals.h"
Expand Down Expand Up @@ -261,18 +262,40 @@ bool Expression::findInArray(AqlValue const& left, AqlValue const& right,
}
// fall-through to linear search
}

// use linear search
for (size_t i = 0; i < n; ++i) {
bool mustDestroy;
AqlValue a = right.at(i, mustDestroy, false);
AqlValueGuard guard(a, mustDestroy);

int compareResult = AqlValue::Compare(trx, left, a, false);
if (!right.isDocvec() && !right.isRange() &&
!left.isDocvec() && !left.isRange()) {
// optimization for the case in which rhs is a Velocypack array, and we
// can simply use a VelocyPack iterator to walk through it. this will
// be a lot more efficient than using right.at(i) in case the array is
// of type Compact (without any index tables)
VPackSlice const lhs(left.slice());

VPackOptions const* options = trx->transactionContextPtr()->getVPackOptions();
VPackArrayIterator it(right.slice());
while (it.valid()) {
int compareResult = arangodb::basics::VelocyPackHelper::compare(lhs, it.value(), false, options);

if (compareResult == 0) {
// item found in the list
return true;
}
it.next();
}
} else {
for (size_t i = 0; i < n; ++i) {
bool mustDestroy;
AqlValue a = right.at(i, mustDestroy, false);
AqlValueGuard guard(a, mustDestroy);

int compareResult = AqlValue::Compare(trx, left, a, false);

if (compareResult == 0) {
// item found in the list
return true;
if (compareResult == 0) {
// item found in the list
return true;
}
}
}

Expand Down
0