mirror of https://gitee.com/bigwinds/arangodb
some cleanup
This commit is contained in:
parent
958ae69479
commit
1003e52cf7
|
@ -1245,43 +1245,7 @@ bool IndexRangeBlock::initRanges () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort the conditions!
|
sortConditions();
|
||||||
|
|
||||||
// TODO this should also be done for hash indexes when
|
|
||||||
// they are lazy too, but only if they should be used to produce a sorted result
|
|
||||||
|
|
||||||
size_t const n = _condition->size();
|
|
||||||
// first sort by the prefix of the index
|
|
||||||
std::vector<std::vector<size_t>> prefix;
|
|
||||||
prefix.reserve(n);
|
|
||||||
|
|
||||||
if (! _sortCoords.empty()) {
|
|
||||||
_sortCoords.clear();
|
|
||||||
_sortCoords.reserve(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t s = 0; s < n; s++) {
|
|
||||||
_sortCoords.push_back(s);
|
|
||||||
std::vector<size_t> next;
|
|
||||||
next.reserve(en->_index->fields.size());
|
|
||||||
prefix.emplace_back(next);
|
|
||||||
// prefix[s][t] = position in _condition[s] corresponding to the <t>th index
|
|
||||||
// field
|
|
||||||
for (size_t t = 0; t < en->_index->fields.size(); t++) {
|
|
||||||
for (size_t u = 0; u < _condition->at(s).size(); u++) {
|
|
||||||
auto ri = _condition->at(s)[u];
|
|
||||||
if (en->_index->fields[t].compare(ri._attr) == 0) {
|
|
||||||
prefix.at(s).insert(prefix.at(s).begin() + t, u);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SortFunc sortFunc(prefix, _condition, en->_reverse);
|
|
||||||
|
|
||||||
// then sort by the values of the bounds
|
|
||||||
std::sort(_sortCoords.begin(), _sortCoords.end(), sortFunc);
|
|
||||||
_posInRanges = 0;
|
_posInRanges = 0;
|
||||||
|
|
||||||
getSkiplistIterator(_condition->at(_sortCoords[_posInRanges]));
|
getSkiplistIterator(_condition->at(_sortCoords[_posInRanges]));
|
||||||
|
@ -1292,6 +1256,49 @@ bool IndexRangeBlock::initRanges () {
|
||||||
LEAVE_BLOCK;
|
LEAVE_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// @brief: sorts the index range conditions and resets _posInRanges to 0
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void IndexRangeBlock::sortConditions () {
|
||||||
|
auto en = static_cast<IndexRangeNode const*>(getPlanNode());
|
||||||
|
|
||||||
|
size_t const n = _condition->size();
|
||||||
|
// first sort by the prefix of the index
|
||||||
|
std::vector<std::vector<size_t>> prefix;
|
||||||
|
prefix.reserve(n);
|
||||||
|
|
||||||
|
if (! _sortCoords.empty()) {
|
||||||
|
_sortCoords.clear();
|
||||||
|
_sortCoords.reserve(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t s = 0; s < n; s++) {
|
||||||
|
_sortCoords.push_back(s);
|
||||||
|
std::vector<size_t> next;
|
||||||
|
next.reserve(en->_index->fields.size());
|
||||||
|
prefix.emplace_back(next);
|
||||||
|
// prefix[s][t] = position in _condition[s] corresponding to the <t>th index
|
||||||
|
// field
|
||||||
|
for (size_t t = 0; t < en->_index->fields.size(); t++) {
|
||||||
|
for (size_t u = 0; u < _condition->at(s).size(); u++) {
|
||||||
|
auto ri = _condition->at(s)[u];
|
||||||
|
if (en->_index->fields[t].compare(ri._attr) == 0) {
|
||||||
|
prefix.at(s).insert(prefix.at(s).begin() + t, u);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SortFunc sortFunc(prefix, _condition, en->_reverse);
|
||||||
|
|
||||||
|
// then sort by the values of the bounds
|
||||||
|
std::sort(_sortCoords.begin(), _sortCoords.end(), sortFunc);
|
||||||
|
|
||||||
|
_posInRanges = 0;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// @brief: is _condition[i] < _condition[j]? these are IndexAndConditions.
|
// @brief: is _condition[i] < _condition[j]? these are IndexAndConditions.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -569,12 +569,6 @@ namespace triagens {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief free all dynamic bounds expressions
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void freeDynamicBoundsExpressions ();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief free _condition if it belongs to us
|
/// @brief free _condition if it belongs to us
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -642,6 +636,12 @@ namespace triagens {
|
||||||
|
|
||||||
void readSkiplistIndex (size_t atMost);
|
void readSkiplistIndex (size_t atMost);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// @brief: sorts the index range conditions and resets _posInRanges to 0
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void sortConditions ();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief andCombineRangeInfoVecs: combine the arguments into a single vector,
|
/// @brief andCombineRangeInfoVecs: combine the arguments into a single vector,
|
||||||
/// by intersecting every pair of range infos and inserting them in the returned
|
/// by intersecting every pair of range infos and inserting them in the returned
|
||||||
|
|
|
@ -1383,7 +1383,7 @@ IndexRangeNode::IndexRangeNode (ExecutionPlan* plan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutionNode::IndexMatch IndexRangeNode::MatchesIndex (IndexMatchVec const& pattern) const {
|
ExecutionNode::IndexMatch IndexRangeNode::matchesIndex (IndexMatchVec const& pattern) const {
|
||||||
return CompareIndex(_index, pattern);
|
return CompareIndex(_index, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1202,7 +1202,7 @@ namespace triagens {
|
||||||
/// @brief check whether the pattern matches this node's index
|
/// @brief check whether the pattern matches this node's index
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
IndexMatch MatchesIndex (IndexMatchVec const& pattern) const;
|
IndexMatch matchesIndex (IndexMatchVec const& pattern) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief whether or not a reverse index traversal is used
|
/// @brief whether or not a reverse index traversal is used
|
||||||
|
|
|
@ -2072,7 +2072,9 @@ public:
|
||||||
return std::make_pair(v, rangeInfo); // for now, no mixed support.
|
return std::make_pair(v, rangeInfo); // for now, no mixed support.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect the right data for the sorting:
|
// Collect the right data for the sorting:
|
||||||
|
v.reserve(_sortNodeData.size());
|
||||||
for (size_t j = 0; j < _sortNodeData.size(); j ++) {
|
for (size_t j = 0; j < _sortNodeData.size(); j ++) {
|
||||||
v.push_back(std::make_pair(_sortNodeData[j]->attributevec,
|
v.push_back(std::make_pair(_sortNodeData[j]->attributevec,
|
||||||
_sortNodeData[j]->ASC));
|
_sortNodeData[j]->ASC));
|
||||||
|
@ -2105,7 +2107,6 @@ class SortToIndexNode : public WalkerWorker<ExecutionNode> {
|
||||||
Optimizer::RuleLevel _level;
|
Optimizer::RuleLevel _level;
|
||||||
bool _modified;
|
bool _modified;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SortToIndexNode (ExecutionPlan* plan,
|
SortToIndexNode (ExecutionPlan* plan,
|
||||||
|
@ -2168,7 +2169,8 @@ class SortToIndexNode : public WalkerWorker<ExecutionNode> {
|
||||||
auto variableName = node->getVariablesSetHere()[0]->name;
|
auto variableName = node->getVariablesSetHere()[0]->name;
|
||||||
auto result = _sortNode->getAttrsForVariableName(variableName);
|
auto result = _sortNode->getAttrsForVariableName(variableName);
|
||||||
|
|
||||||
auto const& match = node->MatchesIndex(result.first);
|
auto const& match = node->matchesIndex(result.first);
|
||||||
|
|
||||||
if (match.doesMatch) {
|
if (match.doesMatch) {
|
||||||
if (match.reverse) {
|
if (match.reverse) {
|
||||||
node->reverse(true);
|
node->reverse(true);
|
||||||
|
|
Loading…
Reference in New Issue