8000 Feature/aql subquery splicing with gather by goedderz · Pull Request #10341 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Feature/aql subquery splicing with gather #10341

8000
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 28 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
58fede8
Per default, do not warn about deprecated functions
goedderz Nov 15, 2019
fb37db0
Fix pure virtual method call with fakeit
goedderz Nov 15, 2019
60f3c0d
Merge branch 'devel' of github.com:arangodb/arangodb into feature/aql…
goedderz Nov 15, 2019
f67e632
Revert all non-critical changes in order to move them into another PR
goedderz Nov 15, 2019
13e8a1d
Fixed Geo* tests
goedderz Nov 15, 2019
8090998
Added some comments
goedderz Nov 15, 2019
e1cbf79
Implemented UnsortingGatherExecutor::skipSome
goedderz Nov 15, 2019
8e66433
Re-enabled some tests
goedderz Nov 15, 2019
3f4d015
Fixed profiler tests
goedderz Nov 15, 2019
7f57b98
Removed unused code
goedderz Nov 15, 2019
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/Aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Aggregator.h"

#include "Aql/AqlValue.h"
#include "Aql/AqlValueMaterializer.h"
#include "Basics/VelocyPackHelper.h"
#include "Transaction/Context.h"
#include "Transaction/Helpers.h"
Expand Down
19 changes: 11 additions & 8 deletions arangod/Aql/AqlItemBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "Aql/SharedAqlItemBlockPtr.h"
#include "Basics/StaticStrings.h"
#include "Basics/VelocyPackHelper.h"
#include "Transaction/Context.h"
#include "Transaction/Methods.h"

#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
Expand Down Expand Up @@ -566,7 +568,7 @@ SharedAqlItemBlockPtr AqlItemBlock::steal(std::vector<size_t> const& chosen,
/// corresponding position
/// "raw": List of actual values, positions 0 and 1 are always null
/// such that actual indices start at 2
void AqlItemBlock::toVelocyPack(transaction::Methods* trx, VPackBuilder& result) const {
void AqlItemBl 10000 ock::toVelocyPack(velocypack::Options const* const trxOptions, VPackBuilder& result) const {
TRI_ASSERT(result.isOpenObject());
VPackOptions options(VPackOptions::Defaults);
options.buildUnindexedArrays = true;
Expand Down Expand Up @@ -650,7 +652,7 @@ void AqlItemBlock::toVelocyPack(transaction::Methods* trx, VPackBuilder& result)

if (it == table.end()) {
currentState = Next;
a.toVelocyPack(trx, raw, false);
a.toVelocyPack(trxOptions, raw, false);
table.try_emplace(a, pos++);
} else {
currentState = Positional;
Expand Down Expand Up @@ -699,28 +701,29 @@ void AqlItemBlock::toVelocyPack(transaction::Methods* trx, VPackBuilder& result)
result.add("raw", raw.slice());
}

void AqlItemBlock::rowToSimpleVPack(size_t const row, transaction::Methods* trx, arangodb::velocypack::Builder& builder) const {
void AqlItemBlock::rowToSimpleVPack(size_t const row, velocypack::Options const* options, arangodb::velocypack::Builder& builder) const {
VPackArrayBuilder rowBuilder{&builder};

if (isShadowRow(row)) {
getShadowRowDepth(row).toVelocyPack(trx, *rowBuilder, false);
getShadowRowDepth(row).toVelocyPack(options, *rowBuilder, false);
} else {
AqlValue{AqlValueHintNull{}}.toVelocyPack(trx, *rowBuilder, false);
AqlValue{AqlValueHintNull{}}.toVelocyPack(options, *rowBuilder, false);
}
for (RegisterId reg = 0; reg < getNrRegs(); ++reg) {
getValueReference(row, reg).toVelocyPack(trx, *rowBuilder, false);
getValueReference(row, reg).toVelocyPack(options, *rowBuilder, false);
}
}

void AqlItemBlock::toSimpleVPack(transaction::Methods* trx, arangodb::velocypack::Builder& builder) const {
void AqlItemBlock::toSimpleVPack(velocypack::Options const* options,
arangodb::velocypack::Builder& builder) const {
VPackObjectBuilder block{&builder};
block->add("nrItems", VPackValue(size()));
block->add("nrRegs", VPackValue(getNrRegs()));
block->add(VPackValue("matrix"));
{
VPackArrayBuilder matrixBuilder{block.builder};
for (size_t row = 0; row < size(); ++row) {
rowToSimpleVPack(row, trx, *matrixBuilder.builder);
rowToSimpleVPack(row, options, *matrixBuilder.builder);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions arangod/Aql/AqlItemBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class AqlItemBlock {

/// @brief toJson, transfer a whole AqlItemBlock to Json, the result can
/// be used to recreate the AqlItemBlock via the Json constructor
void toVelocyPack(transaction::Methods* trx, arangodb::velocypack::Builder&) const;
void toVelocyPack(velocypack::Options const*, arangodb::velocypack::Builder&) const;

/// @brief Creates a human-readable velocypack of the block. Adds an object
/// `{nrItems, nrRegs, matrix}` to the builder.
Expand All @@ -217,9 +217,9 @@ class AqlItemBlock {
// (of length nrRegs+1 (sic)). The first entry contains the shadow row depth,
// or `null` for data rows. The entries with indexes 1..nrRegs contain the
// registers 0..nrRegs-1, respectively.
void toSimpleVPack(transaction::Methods* trx, arangodb::velocypack::Builder&) const;
void toSimpleVPack(velocypack::Options const*, arangodb::velocypack::Builder&) const;

void rowToSimpleVPack(size_t row, transaction::Methods* trx,
void rowToSimpleVPack(size_t row, velocypack::Options const*,
velocypack::Builder& builder) const;

/// @brief test if the given row is a shadow row and conveys subquery
Expand Down
113 changes: 33 additions & 80 deletions arangod/Aql/AqlValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
#include <velocypack/StringRef.h>
#include <velocypack/velocypack-aliases.h>

#include <array>

using namespace arangodb;
using namespace arangodb::aql;

Expand Down Expand Up @@ -933,7 +931,7 @@ v8::Handle<v8::Value> AqlValue::toV8(v8::Isolate* isolate, transaction::Methods*
}

/// @brief materializes a value into the builder
void AqlValue::toVelocyPack(transaction::Methods* trx, arangodb::velocypack::Builder& builder,
void AqlValue::toVelocyPack(VPackOptions const* options, arangodb::velocypack::Builder& builder,
bool resolveExternals) const {
switch (type()) {
case VPACK_SLICE_POINTER:
Expand All @@ -949,7 +947,7 @@ void AqlValue::toVelocyPack(transaction::Methods* trx, arangodb::velocypack::Bui
bool const sanitizeCustom = true;
arangodb::basics::VelocyPackHelper::sanitizeNonClientTypes(
slice(), VPackSlice::noneSlice(), builder,
trx->transactionContextPtr()->getVPackOptions(), sanitizeExternals,
options, sanitizeExternals,
sanitizeCustom);
} else {
builder.add(slice());
Expand All @@ -961,7 +959,7 @@ void AqlValue::toVelocyPack(transaction::Methods* trx, arangodb::velocypack::Bui
for (auto const& it : *_data.docvec) {
size_t const n = it->size();
for (size_t i = 0; i < n; ++i) {
it->getValueReference(i, 0).toVelocyPack(trx, builder, resolveExternals);
it->getValueReference(i, 0).toVelocyPack(options, builder, resolveExternals);
}
}
builder.close();
Expand All @@ -980,8 +978,13 @@ void AqlValue::toVelocyPack(transaction::Methods* trx, arangodb::velocypack::Bui
}
}

void AqlValue::toVelocyPack(transaction::Methods* trx, arangodb::velocypack::Builder& builder,
bool resolveExternals) const {
toVelocyPack(trx->transactionContextPtr()->getVPackOptions(), builder, resolveExternals);
}

/// @brief materializes a value into the builder
AqlValue AqlValue::materialize(transaction::Methods* trx, bool& hasCopied,
AqlValue AqlValue::materialize(VPackOptions const* options, bool& hasCopied,
bool resolveExternals) const {
switch (type()) {
case VPACK_INLINE:
Expand All @@ -997,7 +1000,7 @@ AqlValue AqlValue::materialize(transaction::Methods* trx, bool& hasCopied,
ConditionalDeleter<VPackBuffer<uint8_t>> deleter(shouldDelete);
std::shared_ptr<VPackBuffer<uint8_t>> buffer(new VPackBuffer<uint8_t>, deleter);
VPackBuilder builder(buffer);
8000 toVelocyPack(trx, builder, resolveExternals);
toVelocyPack(options, builder, resolveExternals);
hasCopied = true;
return AqlValue(buffer.get(), shouldDelete);
}
Expand All @@ -1008,6 +1011,11 @@ AqlValue AqlValue::materialize(transaction::Methods* trx, bool& hasCopied,
return AqlValue();
}

AqlValue AqlValue::materialize(transaction::Methods* trx, bool& hasCopied,
bool resolveExternals) const {
return materialize(trx->transactionContextPtr()->getVPackOptions(), hasCopied, resolveExternals);
}

/// @brief clone a value
AqlValue AqlValue::clone() const {
switch (type()) {
Expand Down Expand Up @@ -1173,23 +1181,24 @@ AqlValue AqlValue::CreateFromBlocks(transaction::Methods* trx,
}

/// @brief comparison for AqlValue objects
int AqlValue::Compare(transaction::Methods* trx, AqlValue const& left,
int AqlValue::Compare(velocypack::Options const* options, AqlValue const& left,
AqlValue const& right, bool compareUtf8) {
AqlValue::AqlValueType const leftType = left.type();
AqlValue::AqlValueType const rightType = right.type();

if (leftType != rightType) {
// TODO implement this case more efficiently
if (leftType == RANGE || rightType == RANGE || leftType == DOCVEC || rightType == DOCVEC) {
// range|docvec against x
transaction::BuilderLeaser leftBuilder(trx);
left.toVelocyPack(trx, *leftBuilder.get(), false);
VPackBuilder leftBuilder;
left.toVelocyPack(options, leftBuilder, false);

transaction::BuilderLeaser rightBuilder(trx);
right.toVelocyPack(trx, *rightBuilder.get(), false);
VPackBuilder rightBuilder;
right.toVelocyPack(options, rightBuilder, false);

return arangodb::basics::VelocyPackHelper::compare(
leftBuilder->slice(), rightBuilder->slice(), compareUtf8,
trx->transactionContextPtr()->getVPackOptions());
return arangodb::basics::VelocyPackHelper::compare(leftBuilder.slice(),
rightBuilder.slice(),
compareUtf8, options);
}
// fall-through to other types intentional
}
Expand All @@ -1201,9 +1210,8 @@ int AqlValue::Compare(transaction::Methods* trx, AqlValue const& left,
case VPACK_SLICE_POINTER:
case VPACK_MANAGED_SLICE:
case VPACK_MANAGED_BUFFER: {
return arangodb::basics::VelocyPackHelper::compare(
left.slice(), right.slice(), compareUtf8,
trx->transactionContextPtr()->getVPackOptions());
return arangodb::basics::VelocyPackHelper::compare(left.slice(), right.slice(),
compareUtf8, options);
}
case DOCVEC: {
// use lexicographic ordering of AqlValues regardless of block,
Expand Down Expand Up @@ -1232,7 +1240,7 @@ int AqlValue::Compare(transaction::Methods* trx, AqlValue const& left,
AqlValue const& rval =
right._data.docvec->at(rblock)->getValueReference(ritem, 0);

int cmp = Compare(trx, lval, rval, compareUtf8);
int cmp = Compare(options, lval, rval, compareUtf8);

if (cmp != 0) {
return cmp;
Expand Down Expand Up @@ -1280,6 +1288,11 @@ int AqlValue::Compare(transaction::Methods* trx, AqlValue const& left,
return 0;
}

int AqlValue::Compare(transaction::Methods* trx, AqlValue const& left,
AqlValue const& right, bool compareUtf8) {
return Compare(trx->transactionContextPtr()->getVPackOptions(), left, right, compareUtf8);
}

AqlValue::AqlValue(std::vector<arangodb::aql::SharedAqlItemBlockPtr>* docvec) noexcept {
TRI_ASSERT(docvec != nullptr);
_data.docvec = docvec;
Expand Down Expand Up @@ -1610,68 +1623,8 @@ AqlValueGuard::~AqlValueGuard() {
}

void AqlValueGuard::steal() { _destroy = false; }
AqlValue& AqlValueGuard::value() { return _value; }
AqlValueMaterializer::AqlValueMaterializer(transaction::Methods* trx)
: trx(trx), materialized(), hasCopied(false) {}
AqlValueMaterializer::AqlValueMaterializer(AqlValueMaterializer const& other)
: trx(other.trx), materialized(other.materialized), hasCopied(other.hasCopied) {
if (other.hasCopied) {
// copy other's slice
materialized = other.materialized.clone();
}
}

AqlValueMaterializer& AqlValueMaterializer::operator=(AqlValueMaterializer const& other) {
if (this != &other) {
TRI_ASSERT(trx == other.trx); // must be from same transaction
trx = other.trx; // to shut up cppcheck
if (hasCopied) {
// destroy our own slice
materialized.destroy();
hasCopied = false;
}
// copy other's slice
materialized = other.materialized.clone();
hasCopied = other.hasCopied;
}
return *this;
}

AqlValueMaterializer::AqlValueMaterializer(AqlValueMaterializer&& other) noexcept
: trx(other.trx), materialized(other.materialized), hasCopied(other.hasCopied) {
// reset other
other.hasCopied = false;
// cppcheck-suppress *
other.materialized = AqlValue();
}

AqlValueMaterializer& AqlValueMaterializer::operator=(AqlValueMaterializer&& other) noexcept {
if (this != &other) {
TRI_ASSERT(trx == other.trx); // must be from same transaction
trx = other.trx; // to shut up cppcheck
if (hasCopied) {
// destroy our own slice
materialized.destroy();
}
// reset other
materialized = other.materialized;
hasCopied = other.hasCopied;
other.materialized = AqlValue();
}
return *this;
}

AqlValueMaterializer::~AqlValueMaterializer() {
if (hasCopied) {
materialized.destroy();
}
}

arangodb::velocypack::Slice AqlValueMaterializer::slice(AqlValue const& value,
bool resolveExternals) {
materialized = value.materialize(trx, hasCopied, resolveExternals);
return materialized.slice();
}
AqlValue& AqlValueGuard::value() { return _value; }

size_t std::hash<arangodb::aql::AqlValue>::operator()(arangodb::aql::AqlValue const& x) const
noexcept {
Expand Down
30 changes: 6 additions & 24 deletions arangod/Aql/AqlValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace velocypack {
template <typename T>
class Buffer;
class Builder;
struct Options;
class Slice;
class StringRef;
}
Expand Down Expand Up @@ -329,11 +330,12 @@ struct AqlValue final {
v8::Handle<v8::Value> toV8(v8::Isolate* isolate, transaction::Methods*) const;

/// @brief materializes a value into the builder
void toVelocyPack(transaction::Methods*, arangodb::velocypack::Builder& builder,
bool resolveExternals) const;
void toVelocyPack(velocypack::Options const*, arangodb::velocypack::Builder&, bool resolveExternals) const;
void toVelocyPack(transaction::Methods*, arangodb::velocypack::Builder&, bool resolveExternals) const;

/// @brief materialize a value into a new one. this expands docvecs and
/// ranges
AqlValue materialize(velocypack::Options const*, bool& hasCopied, bool resolveExternals) const;
AqlValue materialize(transaction::Methods*, bool& hasCopied, bool resolveExternals) const;

/// @brief return the slice for the value
Expand Down Expand Up @@ -364,6 +366,8 @@ struct AqlValue final {
arangodb::aql::RegisterId);

/// @brief compare function for two values
static int Compare(velocypack::Options const*, AqlValue const& left,
AqlValue const& right, bool useUtf8);
static int Compare(transaction::Methods*, AqlValue const& left,
AqlValue const& right, bool useUtf8);

Expand Down Expand Up @@ -399,28 +403,6 @@ class AqlValueGuard {
bool _destroy;
};

struct AqlValueMaterializer {
explicit AqlValueMaterializer(transaction::Methods* trx);

AqlValueMaterializer(AqlValueMaterializer const& other);

// cppcheck-suppress operatorEqVarError
AqlValueMaterializer& operator=(AqlValueMaterializer const& other);

AqlValueMaterializer(AqlValueMaterializer&& other) noexcept;

// cppcheck-suppress operatorEqVarError
AqlValueMaterializer&am 67C8 p; operator=(AqlValueMaterializer&& other) noexcept;

~AqlValueMaterializer();

arangodb::velocypack::Slice slice(AqlValue const& value, bool resolveExternals);

transaction::Methods* trx;
AqlValue materialized;
bool hasCopied;
};

static_assert(sizeof(AqlValue) == 16, "invalid AqlValue size");

} // namespace aql
Expand Down
Loading
0