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);
|
||||
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
|
||||
std::vector<PermutationState> permutationStates;
|
||||
permutationStates.reserve(n);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "PathBasedIndex.h"
|
||||
#include "Aql/AstNode.h"
|
||||
#include "Basics/logging.h"
|
||||
|
||||
using namespace triagens::arango;
|
||||
|
@ -36,6 +37,25 @@ using namespace triagens::arango;
|
|||
// --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
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -39,15 +39,44 @@
|
|||
|
||||
class VocShaper;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class PathBasedIndex
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace triagens {
|
||||
namespace aql {
|
||||
enum AstNodeType : uint32_t;
|
||||
}
|
||||
|
||||
namespace arango {
|
||||
|
||||
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
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -1140,10 +1140,10 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
|||
// We found an access for this field
|
||||
if (comp->type == triagens::aql::NODE_TYPE_OPERATOR_BINARY_EQ) {
|
||||
// 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) {
|
||||
permutationStates.emplace_back(PermutationState(comp, value, 0, value->numMembers()));
|
||||
permutationStates.emplace_back(PermutationState(comp->type, value, usedFields, 0, value->numMembers()));
|
||||
}
|
||||
else {
|
||||
// This is a one-sided range
|
||||
|
@ -1261,7 +1261,7 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
|||
rangeOperator.reset(TRI_CreateIndexOperator(TRI_AND_INDEX_OPERATOR,
|
||||
rangeOperator.release(),
|
||||
tmpOp.release(),
|
||||
parameter,
|
||||
nullptr,
|
||||
_shaper,
|
||||
2));
|
||||
}
|
||||
|
@ -1293,7 +1293,7 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
|||
std::unique_ptr<TRI_index_operator_t> tmpOp(TRI_CreateIndexOperator(TRI_EQ_INDEX_OPERATOR,
|
||||
nullptr,
|
||||
nullptr,
|
||||
parameter,
|
||||
parameter.get(),
|
||||
_shaper,
|
||||
usedFields));
|
||||
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,
|
||||
rangeOperator.get(),
|
||||
tmpOp.get(),
|
||||
parameter,
|
||||
nullptr,
|
||||
_shaper,
|
||||
2));
|
||||
tmpOp.release();
|
||||
|
@ -1314,6 +1314,7 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
|||
}
|
||||
}
|
||||
|
||||
size_t current = 0;
|
||||
// now permute
|
||||
while (true) {
|
||||
if (++permutationStates[current].current < permutationStates[current].n) {
|
||||
|
@ -1324,7 +1325,7 @@ IndexIterator* SkiplistIndex::iteratorForCondition (IndexIteratorContext* contex
|
|||
|
||||
permutationStates[current].current = 0;
|
||||
|
||||
if (++current >= n) {
|
||||
if (++current >= usedFields) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue