mirror of https://gitee.com/bigwinds/arangodb
Unified the Permutation State for Skiplist and HashIndex
This commit is contained in:
parent
f7d3304db7
commit
7d4f1f3005
|
@ -801,36 +801,6 @@ IndexIterator* HashIndex::iteratorForCondition (IndexIteratorContext* context,
|
||||||
triagens::aql::AstNode* allVals = matcher.getAll(ast, this, node, reference);
|
triagens::aql::AstNode* allVals = matcher.getAll(ast, this, node, reference);
|
||||||
TRI_ASSERT(allVals->numMembers() == n);
|
TRI_ASSERT(allVals->numMembers() == n);
|
||||||
|
|
||||||
struct PermutationState {
|
|
||||||
PermutationState (triagens::aql::AstNodeType type, triagens::aql::AstNode const* value, size_t attributePosition, size_t current, size_t n)
|
|
||||||
: type(type),
|
|
||||||
value(value),
|
|
||||||
attributePosition(attributePosition),
|
|
||||||
current(current),
|
|
||||||
n(n) {
|
|
||||||
}
|
|
||||||
|
|
||||||
triagens::aql::AstNode const* getValue () const {
|
|
||||||
if (type == triagens::aql::NODE_TYPE_OPERATOR_BINARY_EQ) {
|
|
||||||
TRI_ASSERT(current == 0);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
else if (type == triagens::aql::NODE_TYPE_OPERATOR_BINARY_IN) {
|
|
||||||
TRI_ASSERT(current < n);
|
|
||||||
return value->getMember(current);
|
|
||||||
}
|
|
||||||
|
|
||||||
TRI_ASSERT(false);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
triagens::aql::AstNodeType type;
|
|
||||||
triagens::aql::AstNode const* value;
|
|
||||||
size_t const attributePosition;
|
|
||||||
size_t current;
|
|
||||||
size_t const n;
|
|
||||||
};
|
|
||||||
|
|
||||||
// initialize permutations
|
// initialize permutations
|
||||||
std::vector<PermutationState> permutationStates;
|
std::vector<PermutationState> permutationStates;
|
||||||
permutationStates.reserve(n);
|
permutationStates.reserve(n);
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "PathBasedIndex.h"
|
#include "PathBasedIndex.h"
|
||||||
|
#include "Aql/AstNode.h"
|
||||||
#include "Basics/logging.h"
|
#include "Basics/logging.h"
|
||||||
|
|
||||||
using namespace triagens::arango;
|
using namespace triagens::arango;
|
||||||
|
@ -36,6 +37,25 @@ using namespace triagens::arango;
|
||||||
// --SECTION-- class PathBasedIndex
|
// --SECTION-- class PathBasedIndex
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- struct PermutationState
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
triagens::aql::AstNode const* PathBasedIndex::PermutationState::getValue () const {
|
||||||
|
if (type == triagens::aql::NODE_TYPE_OPERATOR_BINARY_EQ) {
|
||||||
|
TRI_ASSERT(current == 0);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
else if (type == triagens::aql::NODE_TYPE_OPERATOR_BINARY_IN) {
|
||||||
|
TRI_ASSERT(current < n);
|
||||||
|
return value->getMember(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
TRI_ASSERT(false);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- constructors and destructors
|
// --SECTION-- constructors and destructors
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -39,15 +39,44 @@
|
||||||
|
|
||||||
class VocShaper;
|
class VocShaper;
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- class PathBasedIndex
|
// --SECTION-- class PathBasedIndex
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace triagens {
|
namespace triagens {
|
||||||
|
namespace aql {
|
||||||
|
enum AstNodeType : uint32_t;
|
||||||
|
}
|
||||||
|
|
||||||
namespace arango {
|
namespace arango {
|
||||||
|
|
||||||
class PathBasedIndex : public Index {
|
class PathBasedIndex : public Index {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
struct PermutationState {
|
||||||
|
PermutationState (triagens::aql::AstNodeType type, triagens::aql::AstNode const* value, size_t attributePosition, size_t current, size_t n)
|
||||||
|
: type(type),
|
||||||
|
value(value),
|
||||||
|
attributePosition(attributePosition),
|
||||||
|
current(current),
|
||||||
|
n(n) {
|
||||||
|
}
|
||||||
|
|
||||||
|
triagens::aql::AstNode const* getValue () const;
|
||||||
|
|
||||||
|
triagens::aql::AstNodeType type;
|
||||||
|
triagens::aql::AstNode const* value;
|
||||||
|
size_t const attributePosition;
|
||||||
|
size_t current;
|
||||||
|
size_t const n;
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- shared Permuation struct
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- constructors / destructors
|
// --SECTION-- constructors / destructors
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -1140,10 +1140,10 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
||||||
// We found an access for this field
|
// We found an access for this field
|
||||||
if (comp->type == triagens::aql::NODE_TYPE_OPERATOR_BINARY_EQ) {
|
if (comp->type == triagens::aql::NODE_TYPE_OPERATOR_BINARY_EQ) {
|
||||||
// This is an equalityCheck, we can continue with the next field
|
// This is an equalityCheck, we can continue with the next field
|
||||||
permutationStates.emplace_back(PermutationState(comp, value, 0, 1));
|
permutationStates.emplace_back(PermutationState(comp->type, value, usedFields, 0, 1));
|
||||||
}
|
}
|
||||||
else if (comp->type == triagens::aql::NODE_TYPE_OPERATOR_BINARY_IN) {
|
else if (comp->type == triagens::aql::NODE_TYPE_OPERATOR_BINARY_IN) {
|
||||||
permutationStates.emplace_back(PermutationState(comp, value, 0, value->numMembers()));
|
permutationStates.emplace_back(PermutationState(comp->type, value, usedFields, 0, value->numMembers()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// This is a one-sided range
|
// This is a one-sided range
|
||||||
|
@ -1261,7 +1261,7 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
||||||
rangeOperator.reset(TRI_CreateIndexOperator(TRI_AND_INDEX_OPERATOR,
|
rangeOperator.reset(TRI_CreateIndexOperator(TRI_AND_INDEX_OPERATOR,
|
||||||
rangeOperator.release(),
|
rangeOperator.release(),
|
||||||
tmpOp.release(),
|
tmpOp.release(),
|
||||||
parameter,
|
nullptr,
|
||||||
_shaper,
|
_shaper,
|
||||||
2));
|
2));
|
||||||
}
|
}
|
||||||
|
@ -1293,7 +1293,7 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
||||||
std::unique_ptr<TRI_index_operator_t> tmpOp(TRI_CreateIndexOperator(TRI_EQ_INDEX_OPERATOR,
|
std::unique_ptr<TRI_index_operator_t> tmpOp(TRI_CreateIndexOperator(TRI_EQ_INDEX_OPERATOR,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
parameter,
|
parameter.get(),
|
||||||
_shaper,
|
_shaper,
|
||||||
usedFields));
|
usedFields));
|
||||||
if (rangeOperator != nullptr) {
|
if (rangeOperator != nullptr) {
|
||||||
|
@ -1301,7 +1301,7 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
||||||
std::unique_ptr<TRI_index_operator_t> combinedOp(TRI_CreateIndexOperator(TRI_AND_INDEX_OPERATOR,
|
std::unique_ptr<TRI_index_operator_t> combinedOp(TRI_CreateIndexOperator(TRI_AND_INDEX_OPERATOR,
|
||||||
rangeOperator.get(),
|
rangeOperator.get(),
|
||||||
tmpOp.get(),
|
tmpOp.get(),
|
||||||
parameter,
|
nullptr,
|
||||||
_shaper,
|
_shaper,
|
||||||
2));
|
2));
|
||||||
tmpOp.release();
|
tmpOp.release();
|
||||||
|
@ -1314,6 +1314,7 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t current = 0;
|
||||||
// now permute
|
// now permute
|
||||||
while (true) {
|
while (true) {
|
||||||
if (++permutationStates[current].current < permutationStates[current].n) {
|
if (++permutationStates[current].current < permutationStates[current].n) {
|
||||||
|
@ -1324,7 +1325,7 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
||||||
|
|
||||||
permutationStates[current].current = 0;
|
permutationStates[current].current = 0;
|
||||||
|
|
||||||
if (++current >= n) {
|
if (++current >= usedFields) {
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue