1
0
Fork 0

removed IndexRange*

This commit is contained in:
Jan Steemann 2015-10-13 15:12:32 +02:00
parent deb0a132ae
commit 197be68f7d
17 changed files with 18 additions and 2553 deletions

View File

@ -193,7 +193,6 @@ struct UserVarFinder final : public WalkerWorker<ExecutionNode> {
}
else if (en->getType() == ExecutionNode::ENUMERATE_COLLECTION ||
en->getType() == ExecutionNode::INDEX ||
en->getType() == ExecutionNode::INDEX_RANGE ||
en->getType() == ExecutionNode::ENUMERATE_LIST ||
en->getType() == ExecutionNode::AGGREGATE) {
depth += 1;

View File

@ -52,7 +52,6 @@ bool ConditionFinder::before (ExecutionNode* en) {
case EN::REMOTE:
case EN::SUBQUERY:
case EN::INDEX:
case EN::INDEX_RANGE:
case EN::INSERT:
case EN::REMOVE:
case EN::REPLACE:

View File

@ -40,7 +40,6 @@
#include "Aql/ExecutionNode.h"
#include "Aql/ExecutionPlan.h"
#include "Aql/IndexBlock.h"
#include "Aql/IndexRangeBlock.h"
#include "Aql/ModificationBlocks.h"
#include "Aql/QueryRegistry.h"
#include "Aql/SortBlock.h"
@ -66,9 +65,6 @@ static ExecutionBlock* CreateBlock (ExecutionEngine* engine,
case ExecutionNode::SINGLETON: {
return new SingletonBlock(engine, static_cast<SingletonNode const*>(en));
}
case ExecutionNode::INDEX_RANGE: {
return new IndexRangeBlock(engine, static_cast<IndexRangeNode const*>(en));
}
case ExecutionNode::INDEX: {
return new IndexBlock(engine, static_cast<IndexNode const*>(en));
}
@ -393,9 +389,6 @@ struct CoordinatorInstanciator : public WalkerWorker<ExecutionNode> {
if ((*en)->getType() == ExecutionNode::ENUMERATE_COLLECTION) {
collection = const_cast<Collection*>(static_cast<EnumerateCollectionNode*>((*en))->collection());
}
else if ((*en)->getType() == ExecutionNode::INDEX_RANGE) {
collection = const_cast<Collection*>(static_cast<IndexRangeNode*>((*en))->collection());
}
else if ((*en)->getType() == ExecutionNode::INDEX) {
collection = const_cast<Collection*>(static_cast<IndexNode*>((*en))->collection());
}

View File

@ -32,7 +32,6 @@
#include "Aql/Collection.h"
#include "Aql/ExecutionPlan.h"
#include "Aql/IndexNode.h"
#include "Aql/IndexRangeNode.h"
#include "Aql/ModificationNodes.h"
#include "Aql/SortNode.h"
#include "Aql/WalkerWorker.h"
@ -65,7 +64,6 @@ std::unordered_map<int, std::string const> const ExecutionNode::TypeNames{
{ static_cast<int>(ENUMERATE_COLLECTION), "EnumerateCollectionNode" },
{ static_cast<int>(ENUMERATE_LIST), "EnumerateListNode" },
{ static_cast<int>(INDEX), "IndexNode" },
{ static_cast<int>(INDEX_RANGE), "IndexRangeNode" },
{ static_cast<int>(LIMIT), "LimitNode" },
{ static_cast<int>(CALCULATION), "CalculationNode" },
{ static_cast<int>(SUBQUERY), "SubqueryNode" },
@ -234,8 +232,6 @@ ExecutionNode* ExecutionNode::fromJsonFactory (ExecutionPlan* plan,
return new ReturnNode(plan, oneNode);
case NORESULTS:
return new NoResultsNode(plan, oneNode);
case INDEX_RANGE:
return new IndexRangeNode(plan, oneNode);
case INDEX:
return new IndexNode(plan, oneNode);
case REMOTE:
@ -548,7 +544,6 @@ bool ExecutionNode::isInInnerLoop () const {
auto type = node->getType();
if (type == ENUMERATE_COLLECTION ||
type == INDEX_RANGE ||
type == INDEX ||
type == ENUMERATE_LIST) {
// we are contained in an outer loop
@ -836,21 +831,6 @@ void ExecutionNode::RegisterPlan::after (ExecutionNode* en) {
break;
}
case ExecutionNode::INDEX_RANGE: {
depth++;
nrRegsHere.emplace_back(1);
// create a copy of the last value here
// this is requried because back returns a reference and emplace/push_back may invalidate all references
RegisterId registerId = 1 + nrRegs.back();
nrRegs.emplace_back(registerId);
auto ep = static_cast<IndexRangeNode const*>(en);
TRI_ASSERT(ep != nullptr);
varInfo.emplace(ep->outVariable()->id, VarInfo(depth, totalNrRegs));
totalNrRegs++;
break;
}
case ExecutionNode::INDEX: {
depth++;
nrRegsHere.emplace_back(1);
@ -1642,11 +1622,11 @@ double FilterNode::estimateCost (size_t& nrItems) const {
// worst case the filter does not reduce the items at all. Furthermore,
// no optimizer rule introduces FilterNodes, thus it is not important
// that they appear to lower the costs. Note that contrary to this,
// an IndexRangeNode does lower the costs, it also has a better idea
// an IndexNode does lower the costs, it also has a better idea
// to what extent the number of items is reduced. On the other hand it
// is important that a FilterNode produces additional costs, otherwise
// the rule throwing away a FilterNode that is already covered by an
// IndexRangeNode cannot reduce the costs.
// IndexNode cannot reduce the costs.
return depCost + nrItems;
}

View File

@ -71,7 +71,7 @@ namespace triagens {
ILLEGAL = 0,
SINGLETON = 1,
ENUMERATE_COLLECTION = 2,
INDEX_RANGE = 3,
// INDEX_RANGE = 3, // not used anymore
ENUMERATE_LIST = 4,
FILTER = 5,
LIMIT = 6,

View File

@ -1849,8 +1849,7 @@ bool ExecutionPlan::isDeadSimple () const {
if (nodeType == ExecutionNode::SUBQUERY ||
nodeType == ExecutionNode::ENUMERATE_COLLECTION ||
nodeType == ExecutionNode::ENUMERATE_LIST ||
nodeType == ExecutionNode::INDEX ||
nodeType == ExecutionNode::INDEX_RANGE) {
nodeType == ExecutionNode::INDEX) {
// these node types are not simple
return false;
}

View File

@ -53,7 +53,7 @@ using Json = triagens::basics::Json;
#endif
// -----------------------------------------------------------------------------
// --SECTION-- class IndexRangeBlock
// --SECTION-- class IndexBlock
// -----------------------------------------------------------------------------
IndexBlock::IndexBlock (ExecutionEngine* engine,
@ -352,7 +352,7 @@ bool IndexBlock::readIndex (size_t atMost) {
// entire index when we only want a small number of documents.
if (_documents.empty()) {
TRI_IF_FAILURE("IndexRangeBlock::readIndex") {
TRI_IF_FAILURE("IndexBlock::readIndex") {
THROW_ARANGO_EXCEPTION(TRI_ERROR_DEBUG);
}
_documents.reserve(atMost);

View File

@ -81,7 +81,7 @@ namespace triagens {
};
// -----------------------------------------------------------------------------
// --SECTION-- IndexRangeBlock
// --SECTION-- IndexBlock
// -----------------------------------------------------------------------------
class IndexBlock : public ExecutionBlock {

File diff suppressed because it is too large Load Diff

View File

@ -1,357 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief AQL IndexRangeBlock
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2014 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Max Neunhoeffer
/// @author Copyright 2014, triagens GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_AQL_INDEX_RANGE_BLOCK_H
#define ARANGODB_AQL_INDEX_RANGE_BLOCK_H 1
#include "Aql/Collection.h"
#include "Aql/ExecutionBlock.h"
#include "Aql/IndexRangeNode.h"
#include "Indexes/HashIndex.h"
#include "Indexes/SkiplistIndex.h"
#include "Utils/AqlTransaction.h"
#include "VocBase/shaped-json.h"
struct TRI_doc_mptr_copy_t;
struct TRI_edge_index_iterator_t;
struct TRI_hash_index_element_multi_s;
namespace triagens {
namespace aql {
class AqlItemBlock;
class ExecutionEngine;
// -----------------------------------------------------------------------------
// --SECTION-- IndexRangeBlock
// -----------------------------------------------------------------------------
class IndexRangeBlock : public ExecutionBlock {
public:
IndexRangeBlock (ExecutionEngine* engine,
IndexRangeNode const* ep);
~IndexRangeBlock ();
////////////////////////////////////////////////////////////////////////////////
/// @brief initialize, here we fetch all docs from the database
////////////////////////////////////////////////////////////////////////////////
int initialize () override;
////////////////////////////////////////////////////////////////////////////////
/// @brief initializeCursor, here we release our docs from this collection
////////////////////////////////////////////////////////////////////////////////
int initializeCursor (AqlItemBlock* items, size_t pos) override;
AqlItemBlock* getSome (size_t atLeast, size_t atMost) override final;
////////////////////////////////////////////////////////////////////////////////
// skip between atLeast and atMost, returns the number actually skipped . . .
// will only return less than atLeast if there aren't atLeast many
// things to skip overall.
////////////////////////////////////////////////////////////////////////////////
size_t skipSome (size_t atLeast, size_t atMost) override final;
// -----------------------------------------------------------------------------
// --SECTION-- private methods
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not the high bound values should be taken into account
/// they can be ignored for indexes that only support equality conditions,
/// i.e. primary index, edge index and hash index
////////////////////////////////////////////////////////////////////////////////
bool useHighBounds () const;
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not one of the bounds expressions requires V8
////////////////////////////////////////////////////////////////////////////////
bool hasV8Expression () const;
////////////////////////////////////////////////////////////////////////////////
/// @brief build the bounds expressions
////////////////////////////////////////////////////////////////////////////////
void buildExpressions ();
////////////////////////////////////////////////////////////////////////////////
/// @brief free _condition if it belongs to us
////////////////////////////////////////////////////////////////////////////////
void freeCondition ();
////////////////////////////////////////////////////////////////////////////////
/// @brief continue fetching of documents
////////////////////////////////////////////////////////////////////////////////
bool readIndex (size_t atMost);
////////////////////////////////////////////////////////////////////////////////
/// @brief set up the index for reading. This should be called once per incoming
/// block.
////////////////////////////////////////////////////////////////////////////////
bool initRanges ();
////////////////////////////////////////////////////////////////////////////////
/// @brief read using the primary index
////////////////////////////////////////////////////////////////////////////////
void readPrimaryIndex (IndexOrCondition const&);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroy the hash index search value
////////////////////////////////////////////////////////////////////////////////
void destroyHashIndexSearchValues ();
////////////////////////////////////////////////////////////////////////////////
/// @brief set up a hash index search value
////////////////////////////////////////////////////////////////////////////////
bool setupHashIndexSearchValue (IndexAndCondition const&);
////////////////////////////////////////////////////////////////////////////////
/// @brief produce a reentrant hash index iterator
////////////////////////////////////////////////////////////////////////////////
void getHashIndexIterator (IndexAndCondition const&);
////////////////////////////////////////////////////////////////////////////////
/// @brief read using a hash index
////////////////////////////////////////////////////////////////////////////////
void readHashIndex (size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief this tries to create an edge iterator to read from the index.
////////////////////////////////////////////////////////////////////////////////
void getEdgeIndexIterator (IndexAndCondition const&);
////////////////////////////////////////////////////////////////////////////////
/// @brief read using an edge index
////////////////////////////////////////////////////////////////////////////////
void readEdgeIndex (size_t atMost);
////////////////////////////////////////////////////////////////////////////////
/// @brief this tries to create a skiplistIterator to read from the index.
////////////////////////////////////////////////////////////////////////////////
void getSkiplistIterator (IndexAndCondition const&);
////////////////////////////////////////////////////////////////////////////////
/// @brief read using a skiplist index
////////////////////////////////////////////////////////////////////////////////
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,
/// by intersecting every pair of range infos and inserting them in the returned
/// value if the intersection is valid.
////////////////////////////////////////////////////////////////////////////////
std::vector<RangeInfo> andCombineRangeInfoVecs (std::vector<RangeInfo> const&,
std::vector<RangeInfo> const&) const;
////////////////////////////////////////////////////////////////////////////////
/// @brief cartesian: form the cartesian product of the inner vectors. This is
/// required in case a dynamic bound evaluates to a list, then we have an
/// "and" condition containing an "or" condition, which we must then distribute.
////////////////////////////////////////////////////////////////////////////////
IndexOrCondition* cartesian (std::vector<std::vector<RangeInfo>> const&) const;
////////////////////////////////////////////////////////////////////////////////
/// @brief: subclass for comparing IndexAndConditions in _condition. Similar to
/// OurLessThan in the SortBlock
////////////////////////////////////////////////////////////////////////////////
class SortFunc {
public:
SortFunc (std::vector<std::vector<size_t>> const& prefix,
IndexOrCondition* condition,
bool reverse)
: _prefix(prefix),
_condition(condition),
_reverse(reverse) {
}
bool operator() (size_t const&,
size_t const&) const;
private:
std::vector<std::vector<size_t>> const& _prefix;
IndexOrCondition* _condition;
bool const _reverse;
};
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief collection
////////////////////////////////////////////////////////////////////////////////
Collection const* _collection;
////////////////////////////////////////////////////////////////////////////////
/// @brief document buffer
////////////////////////////////////////////////////////////////////////////////
std::vector<TRI_doc_mptr_copy_t> _documents;
////////////////////////////////////////////////////////////////////////////////
/// @brief current position in _allDocs
////////////////////////////////////////////////////////////////////////////////
size_t _posInDocs;
////////////////////////////////////////////////////////////////////////////////
/// @brief _allBoundsConstant, this indicates whether all given bounds
/// are constant
////////////////////////////////////////////////////////////////////////////////
std::vector<bool> _allBoundsConstant;
bool _anyBoundVariable;
////////////////////////////////////////////////////////////////////////////////
/// @brief _allBoundsConstant, this indicates whether all given bounds
/// are constant
////////////////////////////////////////////////////////////////////////////////
std::vector<Expression*> _allVariableBoundExpressions;
////////////////////////////////////////////////////////////////////////////////
/// @brief _inVars, a vector containing for each expression above
/// a vector of Variable*, used to execute the expression
/////////////////////////////////////////////////////////////////////////////////
std::vector<std::vector<Variable const*>> _inVars;
////////////////////////////////////////////////////////////////////////////////
/// @brief _inRegs, a vector containing for each expression above
/// a vector of RegisterId, used to execute the expression
////////////////////////////////////////////////////////////////////////////////
std::vector<std::vector<RegisterId>> _inRegs;
////////////////////////////////////////////////////////////////////////////////
/// @brief _skiplistIterator: holds the skiplist iterator found using
/// getSkiplistIterator (if any) so that it can be read in chunks and not
/// necessarily all at once.
////////////////////////////////////////////////////////////////////////////////
triagens::arango::SkiplistIterator* _skiplistIterator;
////////////////////////////////////////////////////////////////////////////////
/// @brief _edgeIterator: holds the edge iterator found using
/// getEdgeIndexIterator (if any) so that it can be read in chunks and not
/// necessarily all at once.
////////////////////////////////////////////////////////////////////////////////
struct TRI_edge_index_iterator_t* _edgeIndexIterator;
////////////////////////////////////////////////////////////////////////////////
/// @brief current search value for hash index lookup
////////////////////////////////////////////////////////////////////////////////
TRI_hash_index_search_value_t _hashIndexSearchValue;
////////////////////////////////////////////////////////////////////////////////
/// @brief reentrant hash index iterator state
////////////////////////////////////////////////////////////////////////////////
TRI_index_element_t* _hashNextElement;
////////////////////////////////////////////////////////////////////////////////
/// @brief reentrant edge index iterator state
////////////////////////////////////////////////////////////////////////////////
TRI_doc_mptr_copy_t* _edgeNextElement;
////////////////////////////////////////////////////////////////////////////////
/// @brief _condition: holds the IndexAndCondition for the current incoming block,
/// this is just the _ranges[_rangesPos] member of the plan node if _allBoundsConstant
/// otherwise it is reevaluated every time initIndex is called, i.e. once per
/// incoming block.
////////////////////////////////////////////////////////////////////////////////
IndexOrCondition* _condition;
////////////////////////////////////////////////////////////////////////////////
/// @brief _flag: since readIndex for primary, hash, edges indexes reads the
/// whole index, this is <true> if initIndex has been called but readIndex has
/// not been called, otherwise it is <false> to avoid rereading the entire index
/// with successive calls to readIndex.
//////////////////////////////////////////////////////////////////////////////////
bool _flag;
size_t _posInRanges;
std::vector<size_t> _sortCoords;
////////////////////////////////////////////////////////////////////////////////
/// @brief _freeCondition: whether or not the _condition is owned by the
/// IndexRangeBlock and must be freed
////////////////////////////////////////////////////////////////////////////////
bool _freeCondition;
bool _hasV8Expression;
};
} // namespace triagens::aql
} // namespace triagens
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -1,371 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief IndexRangeNode
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2014 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Max Neunhoeffer
/// @author Copyright 2014, triagens GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "Aql/IndexRangeNode.h"
#include "Aql/Collection.h"
#include "Aql/ExecutionPlan.h"
#include "Aql/WalkerWorker.h"
#include "Aql/Ast.h"
#include "Basics/StringBuffer.h"
using namespace std;
using namespace triagens::basics;
using namespace triagens::aql;
// -----------------------------------------------------------------------------
// --SECTION-- methods of IndexRangeNode
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief toJson, for IndexRangeNode
////////////////////////////////////////////////////////////////////////////////
void IndexRangeNode::toJsonHelper (triagens::basics::Json& nodes,
TRI_memory_zone_t* zone,
bool verbose) const {
triagens::basics::Json json(ExecutionNode::toJsonHelperGeneric(nodes, zone, verbose));
// call base class method
if (json.isEmpty()) {
return;
}
// put together the range info . . .
triagens::basics::Json ranges(triagens::basics::Json::Array, _ranges.size());
for (auto const& x : _ranges) {
triagens::basics::Json range(triagens::basics::Json::Array, x.size());
for(auto const& y : x) {
range.add(y.toJson());
}
ranges.add(range);
}
// Now put info about vocbase and cid in there
json("database", triagens::basics::Json(_vocbase->_name))
("collection", triagens::basics::Json(_collection->getName()))
("outVariable", _outVariable->toJson())
("ranges", ranges);
json("index", _index->toJson());
json("reverse", triagens::basics::Json(_reverse));
// And add it:
nodes(json);
}
ExecutionNode* IndexRangeNode::clone (ExecutionPlan* plan,
bool withDependencies,
bool withProperties) const {
std::vector<std::vector<RangeInfo>> ranges;
for (size_t i = 0; i < _ranges.size(); i++){
ranges.emplace_back(std::vector<RangeInfo>());
for (auto const& x : _ranges.at(i)) {
ranges.at(i).emplace_back(x);
}
}
auto outVariable = _outVariable;
if (withProperties) {
outVariable = plan->getAst()->variables()->createVariable(outVariable);
}
auto c = new IndexRangeNode(plan, _id, _vocbase, _collection,
outVariable, _index, ranges, _reverse);
cloneHelper(c, plan, withDependencies, withProperties);
return static_cast<ExecutionNode*>(c);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief constructor for IndexRangeNode from Json
////////////////////////////////////////////////////////////////////////////////
IndexRangeNode::IndexRangeNode (ExecutionPlan* plan,
triagens::basics::Json const& json)
: ExecutionNode(plan, json),
_vocbase(plan->getAst()->query()->vocbase()),
_collection(plan->getAst()->query()->collections()->get(JsonHelper::checkAndGetStringValue(json.json(), "collection"))),
_outVariable(varFromJson(plan->getAst(), json, "outVariable")),
_index(nullptr),
_ranges(),
_reverse(false) {
triagens::basics::Json rangeArrayJson(TRI_UNKNOWN_MEM_ZONE, JsonHelper::checkAndGetArrayValue(json.json(), "ranges"));
for (size_t i = 0; i < rangeArrayJson.size(); i++) { //loop over the ranges . . .
_ranges.emplace_back();
triagens::basics::Json rangeJson(rangeArrayJson.at(static_cast<int>(i)));
for (size_t j = 0; j < rangeJson.size(); j++) {
_ranges.at(i).emplace_back(rangeJson.at(static_cast<int>(j)));
}
}
// now the index . . .
// TODO the following could be a constructor method for
// an Index object when these are actually used
auto index = JsonHelper::checkAndGetObjectValue(json.json(), "index");
auto iid = JsonHelper::checkAndGetStringValue(index, "id");
_index = _collection->getIndex(iid);
_reverse = JsonHelper::checkAndGetBooleanValue(json.json(), "reverse");
if (_index == nullptr) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "index not found");
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief the cost of an index range node is a multiple of the cost of
/// its unique dependency
////////////////////////////////////////////////////////////////////////////////
double IndexRangeNode::estimateCost (size_t& nrItems) const {
static double const EqualityReductionFactor = 100.0;
size_t incoming = 0;
double const dependencyCost = _dependencies.at(0)->getCost(incoming);
size_t docCount = _collection->count();
TRI_ASSERT(! _ranges.empty());
if (_index->type == triagens::arango::Index::TRI_IDX_TYPE_PRIMARY_INDEX) {
// always an equality lookup
// selectivity of primary index is always 1
nrItems = incoming * _ranges.size();
return dependencyCost + nrItems;
}
if (_index->type == triagens::arango::Index::TRI_IDX_TYPE_EDGE_INDEX) {
// always an equality lookup
// check if the index can provide a selectivity estimate
if (! estimateItemsWithIndexSelectivity(incoming, nrItems)) {
// use hard-coded heuristic
nrItems = incoming * _ranges.size() * docCount / static_cast<size_t>(EqualityReductionFactor);
}
nrItems = (std::max)(nrItems, static_cast<size_t>(1));
return dependencyCost + nrItems;
}
if (_index->type == triagens::arango::Index::TRI_IDX_TYPE_HASH_INDEX) {
// always an equality lookup
// check if the index can provide a selectivity estimate
if (! estimateItemsWithIndexSelectivity(incoming, nrItems)) {
// use hard-coded heuristic
if (_index->unique) {
nrItems = incoming * _ranges.size();
}
else {
double cost = static_cast<double>(docCount) * incoming * _ranges.size();
// the more attributes are contained in the index, the more specific the lookup will be
for (size_t i = 0; i < _ranges.at(0).size(); ++i) {
cost /= EqualityReductionFactor;
}
nrItems = static_cast<size_t>(cost);
}
}
nrItems = (std::max)(nrItems, static_cast<size_t>(1));
// the more attributes an index matches, the better it is
double matchLengthFactor = _ranges.at(0).size() * 0.01;
// this is to prefer the hash index over skiplists if everything else is equal
return dependencyCost + ((static_cast<double>(nrItems) - matchLengthFactor) * 0.9999995);
}
if (_index->type == triagens::arango::Index::TRI_IDX_TYPE_SKIPLIST_INDEX) {
auto const count = _ranges.at(0).size();
if (count == 0) {
// no ranges? so this is unlimited -> has to be more expensive
nrItems = incoming * docCount;
return dependencyCost + nrItems;
}
if (_index->unique) {
bool allEquality = true;
for (auto const& x : _ranges) {
// check if we are using all indexed attributes in the query
if (x.size() != _index->fields.size()) {
allEquality = false;
break;
}
// check if this is an equality comparison
if (x.empty() || ! x.back().is1ValueRangeInfo()) {
allEquality = false;
break;
}
}
if (allEquality) {
// unique index, all attributes compared using eq (==) operator
nrItems = incoming * _ranges.size();
return dependencyCost + nrItems;
}
}
// build a total cost for the index usage by peeking into all ranges
double totalCost = 0.0;
for (auto const& x : _ranges) {
double cost = static_cast<double>(docCount) * incoming;
for (auto const& y : x) { //only doing the 1-d case so far
if (y.is1ValueRangeInfo()) {
// equality lookup
cost /= EqualityReductionFactor;
continue;
}
bool hasLowerBound = false;
bool hasUpperBound = false;
if (y._lowConst.isDefined() || y._lows.size() > 0) {
hasLowerBound = true;
}
if (y._highConst.isDefined() || y._highs.size() > 0) {
hasUpperBound = true;
}
if (hasLowerBound && hasUpperBound) {
// both lower and upper bounds defined
cost /= 10.0;
}
else if (hasLowerBound || hasUpperBound) {
// either only low or high bound defined
cost /= 2.0;
}
// each bound (const and dynamic) counts!
size_t const numBounds = y._lows.size() +
y._highs.size() +
(y._lowConst.isDefined() ? 1 : 0) +
(y._highConst.isDefined() ? 1 : 0);
for (size_t j = 0; j < numBounds; ++j) {
// each dynamic bound again reduces the cost
cost *= 0.95;
}
}
totalCost += cost;
}
totalCost = static_cast<double>((std::max)(static_cast<size_t>(totalCost), static_cast<size_t>(1)));
nrItems = static_cast<size_t>(totalCost);
return dependencyCost + totalCost;
}
// no index
nrItems = incoming * docCount;
return dependencyCost + nrItems;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief getVariablesUsedHere, returning a vector
////////////////////////////////////////////////////////////////////////////////
std::vector<Variable const*> IndexRangeNode::getVariablesUsedHere () const {
std::unordered_set<Variable const*> s;
// actual work is done by that method
getVariablesUsedHere(s);
// copy result into vector
std::vector<Variable const*> v;
v.reserve(s.size());
for (auto const& vv : s) {
v.emplace_back(const_cast<Variable*>(vv));
}
return v;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief getVariablesUsedHere, modifying the set in-place
////////////////////////////////////////////////////////////////////////////////
void IndexRangeNode::getVariablesUsedHere (std::unordered_set<Variable const*>& vars) const {
for (auto const& x : _ranges) {
for (RangeInfo const& y : x) {
for (RangeInfoBound const& z : y._lows) {
AstNode const* a = z.getExpressionAst(_plan->getAst());
Ast::getReferencedVariables(a, vars);
}
for (RangeInfoBound const& z : y._highs) {
AstNode const* a = z.getExpressionAst(_plan->getAst());
Ast::getReferencedVariables(a, vars);
}
}
}
}
// -----------------------------------------------------------------------------
// --SECTION-- private methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief provide an estimate for the number of items, using the index
/// selectivity info (if present)
////////////////////////////////////////////////////////////////////////////////
bool IndexRangeNode::estimateItemsWithIndexSelectivity (size_t incoming,
size_t& nrItems) const {
// check if the index can provide a selectivity estimate
if (! _index->hasSelectivityEstimate()) {
return false;
}
// use index selectivity estimate
double estimate = _index->selectivityEstimate();
if (estimate <= 0.0) {
// avoid DIV0
return false;
}
nrItems = static_cast<size_t>(incoming * _ranges.size() * (1.0 / estimate));
return true;
}
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -1,258 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief IndexRangeNode
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2014 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Max Neunhoeffer
/// @author Copyright 2014, triagens GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_AQL_INDEX_RANGE_NODE_H
#define ARANGODB_AQL_INDEX_RANGE_NODE_H 1
#include "Basics/Common.h"
#include "Aql/Ast.h"
#include "Aql/ExecutionNode.h"
#include "Aql/RangeInfo.h"
#include "Aql/types.h"
#include "Aql/Variable.h"
#include "Basics/JsonHelper.h"
#include "VocBase/voc-types.h"
#include "VocBase/vocbase.h"
namespace triagens {
namespace aql {
struct Collection;
class ExecutionBlock;
class ExecutionPlan;
struct Index;
////////////////////////////////////////////////////////////////////////////////
/// @brief class IndexRangeNode
////////////////////////////////////////////////////////////////////////////////
class IndexRangeNode : public ExecutionNode {
friend class ExecutionBlock;
friend class IndexRangeBlock;
////////////////////////////////////////////////////////////////////////////////
/// @brief constructor with a vocbase and a collection name
////////////////////////////////////////////////////////////////////////////////
// _ranges must correspond to a prefix of the fields of the index <index>, i.e.
// _ranges.at(i) is a range of values for idx->_fields._buffer[i].
public:
IndexRangeNode (ExecutionPlan* plan,
size_t id,
TRI_vocbase_t* vocbase,
Collection const* collection,
Variable const* outVariable,
Index const* index,
std::vector<std::vector<RangeInfo>> const& ranges,
bool reverse)
: ExecutionNode(plan, id),
_vocbase(vocbase),
_collection(collection),
_outVariable(outVariable),
_index(index),
_ranges(ranges),
_reverse(reverse) {
TRI_ASSERT(false);
TRI_ASSERT(_vocbase != nullptr);
TRI_ASSERT(_collection != nullptr);
TRI_ASSERT(_outVariable != nullptr);
TRI_ASSERT(_index != nullptr);
}
IndexRangeNode (ExecutionPlan*, triagens::basics::Json const& base);
~IndexRangeNode () {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return the type of the node
////////////////////////////////////////////////////////////////////////////////
NodeType getType () const override final {
return INDEX_RANGE;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return the database
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_t* vocbase () const {
return _vocbase;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return the collection
////////////////////////////////////////////////////////////////////////////////
Collection const* collection () const {
return _collection;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return out variable
////////////////////////////////////////////////////////////////////////////////
Variable const* outVariable () const {
return _outVariable;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return the ranges
////////////////////////////////////////////////////////////////////////////////
std::vector<std::vector<RangeInfo>> const& ranges () const {
return _ranges;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief export to JSON
////////////////////////////////////////////////////////////////////////////////
void toJsonHelper (triagens::basics::Json&,
TRI_memory_zone_t*,
bool) const override final;
////////////////////////////////////////////////////////////////////////////////
/// @brief clone ExecutionNode recursively
////////////////////////////////////////////////////////////////////////////////
ExecutionNode* clone (ExecutionPlan* plan,
bool withDependencies,
bool withProperties) const override final;
////////////////////////////////////////////////////////////////////////////////
/// @brief getVariablesSetHere
////////////////////////////////////////////////////////////////////////////////
std::vector<Variable const*> getVariablesSetHere () const override final {
return std::vector<Variable const*>{ _outVariable };
}
////////////////////////////////////////////////////////////////////////////////
/// @brief getVariablesUsedHere, returning a vector
////////////////////////////////////////////////////////////////////////////////
std::vector<Variable const*> getVariablesUsedHere () const override final;
////////////////////////////////////////////////////////////////////////////////
/// @brief getVariablesUsedHere, modifying the set in-place
////////////////////////////////////////////////////////////////////////////////
void getVariablesUsedHere (std::unordered_set<Variable const*>& vars) const override final;
////////////////////////////////////////////////////////////////////////////////
/// @brief estimateCost
////////////////////////////////////////////////////////////////////////////////
double estimateCost (size_t&) const override final;
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not a reverse index traversal is used
////////////////////////////////////////////////////////////////////////////////
void reverse (bool value) {
_reverse = value;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief getIndex, hand out the index used
////////////////////////////////////////////////////////////////////////////////
Index const* getIndex () {
return _index;
}
// -----------------------------------------------------------------------------
// --SECTION-- private methods
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief provide an estimate for the number of items, using the index
/// selectivity info (if present)
////////////////////////////////////////////////////////////////////////////////
bool estimateItemsWithIndexSelectivity (size_t,
size_t&) const;
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief the database
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_t* _vocbase;
////////////////////////////////////////////////////////////////////////////////
/// @brief collection
////////////////////////////////////////////////////////////////////////////////
Collection const* _collection;
////////////////////////////////////////////////////////////////////////////////
/// @brief output variable
////////////////////////////////////////////////////////////////////////////////
Variable const* _outVariable;
////////////////////////////////////////////////////////////////////////////////
/// @brief the index
////////////////////////////////////////////////////////////////////////////////
Index const* _index;
////////////////////////////////////////////////////////////////////////////////
/// @brief the range info
////////////////////////////////////////////////////////////////////////////////
std::vector<std::vector<RangeInfo>> _ranges;
////////////////////////////////////////////////////////////////////////////////
/// @brief use a reverse index scan
////////////////////////////////////////////////////////////////////////////////
bool _reverse;
};
} // namespace triagens::aql
} // namespace triagens
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -183,11 +183,8 @@ namespace triagens {
// remove redundant OR conditions
removeRedundantOrRule_pass6 = 820,
useIndexesRule_pass6 = 825,
useIndexesRule_pass6 = 830,
// try to find a filter after an enumerate collection and find an index . . .
useIndexRangeRule_pass6 = 830,
// try to remove filters covered by index ranges
removeFiltersCoveredByIndexRule_pass6 = 840,

View File

@ -34,11 +34,12 @@
#include "Aql/ExecutionNode.h"
#include "Aql/Function.h"
#include "Aql/IndexNode.h"
#include "Aql/IndexRangeNode.h"
#include "Aql/ModificationNodes.h"
#include "Aql/RangeInfo.h"
#include "Aql/SortNode.h"
#include "Aql/Variable.h"
#include "Aql/types.h"
#include "Basics/json-utilities.h"
#include <iostream>
@ -846,8 +847,7 @@ int triagens::aql::removeSortRandRule (Optimizer* opt,
case EN::FILTER:
case EN::SUBQUERY:
case EN::ENUMERATE_LIST:
case EN::INDEX:
case EN::INDEX_RANGE: {
case EN::INDEX: {
// if we found another SortNode, an AggregateNode, FilterNode, a SubqueryNode,
// an EnumerateListNode or an IndexNode
// this means we cannot apply our optimization
@ -1046,8 +1046,7 @@ int triagens::aql::moveCalculationsDownRule (Optimizer* opt,
// we found something interesting that justifies moving our node down
shouldMove = true;
}
else if (currentType == EN::INDEX_RANGE ||
currentType == EN::INDEX ||
else if (currentType == EN::INDEX ||
currentType == EN::ENUMERATE_COLLECTION ||
currentType == EN::ENUMERATE_LIST ||
currentType == EN::AGGREGATE ||
@ -1914,7 +1913,6 @@ struct SortToIndexNode final : public WalkerWorker<ExecutionNode> {
case EN::ENUMERATE_LIST:
case EN::SUBQUERY:
case EN::FILTER:
case EN::INDEX_RANGE:
return false; // skip. we don't care.
case EN::CALCULATION: {
@ -2165,6 +2163,9 @@ struct FilterCondition {
int triagens::aql::removeFiltersCoveredByIndexRule (Optimizer* opt,
ExecutionPlan* plan,
Optimizer::Rule const* rule) {
opt->addPlan(plan, rule, false);
return TRI_ERROR_NO_ERROR;
/*
std::unordered_set<ExecutionNode*> toUnlink;
std::vector<ExecutionNode*>&& nodes= plan->findNodesOfType(EN::FILTER, true);
@ -2233,6 +2234,7 @@ int triagens::aql::removeFiltersCoveredByIndexRule (Optimizer* opt,
opt->addPlan(plan, rule, ! toUnlink.empty());
return TRI_ERROR_NO_ERROR;
*/
}
////////////////////////////////////////////////////////////////////////////////
@ -2407,10 +2409,9 @@ int triagens::aql::scatterInClusterRule (Optimizer* opt,
if (triagens::arango::ServerState::instance()->isCoordinator()) {
// we are a coordinator. now look in the plan for nodes of type
// EnumerateCollectionNode and IndexRangeNode
// EnumerateCollectionNode and IndexNode
std::vector<ExecutionNode::NodeType> const types = {
ExecutionNode::ENUMERATE_COLLECTION,
ExecutionNode::INDEX_RANGE,
ExecutionNode::INDEX,
ExecutionNode::INSERT,
ExecutionNode::UPDATE,
@ -2444,10 +2445,6 @@ int triagens::aql::scatterInClusterRule (Optimizer* opt,
vocbase = static_cast<EnumerateCollectionNode*>(node)->vocbase();
collection = static_cast<EnumerateCollectionNode*>(node)->collection();
}
else if (nodeType == ExecutionNode::INDEX_RANGE) {
vocbase = static_cast<IndexRangeNode*>(node)->vocbase();
collection = static_cast<IndexRangeNode*>(node)->collection();
}
else if (nodeType == ExecutionNode::INDEX) {
vocbase = static_cast<IndexNode*>(node)->vocbase();
collection = static_cast<IndexNode*>(node)->collection();
@ -2777,7 +2774,6 @@ int triagens::aql::distributeFilternCalcToClusterRule (Optimizer* opt,
case EN::LIMIT:
case EN::SORT:
case EN::INDEX:
case EN::INDEX_RANGE:
case EN::ENUMERATE_COLLECTION:
//do break
stopSearching = true;
@ -2873,7 +2869,6 @@ int triagens::aql::distributeSortToClusterRule (Optimizer* opt,
case EN::ILLEGAL:
case EN::REMOTE:
case EN::LIMIT:
case EN::INDEX_RANGE:
case EN::INDEX:
case EN::ENUMERATE_COLLECTION:
// For all these, we do not want to pull a SortNode further down
@ -3148,8 +3143,7 @@ class RemoveToEnumCollFinder final : public WalkerWorker<ExecutionNode> {
case EN::ILLEGAL:
case EN::LIMIT:
case EN::SORT:
case EN::INDEX:
case EN::INDEX_RANGE: {
case EN::INDEX: {
// if we meet any of the above, then we abort . . .
}
}
@ -3691,7 +3685,6 @@ int triagens::aql::patchUpdateStatementsRule (Optimizer* opt,
if (type == EN::ENUMERATE_LIST ||
type == EN::INDEX ||
type == EN::INDEX_RANGE ||
type == EN::SUBQUERY) {
// not suitable
modified = false;

View File

@ -91,8 +91,6 @@ add_executable(
Aql/Index.cpp
Aql/IndexBlock.cpp
Aql/IndexNode.cpp
Aql/IndexRangeBlock.cpp
Aql/IndexRangeNode.cpp
Aql/ModificationBlocks.cpp
Aql/ModificationNodes.cpp
Aql/NodeFinder.cpp

View File

@ -34,8 +34,6 @@
#include "Indexes/Index.h"
#include "VocBase/vocbase.h"
#include <iostream>
using namespace triagens::arango;
// -----------------------------------------------------------------------------
@ -49,14 +47,6 @@ using namespace triagens::arango;
SimpleAttributeEqualityMatcher::SimpleAttributeEqualityMatcher (std::vector<std::vector<triagens::basics::AttributeName>> const& attributes)
: _attributes(attributes),
_found() {
std::cout << "SIMPLE ATT CTOR. ATTR SIZE: " << _attributes.size() << "\n";
for (auto& it : _attributes) {
std::cout << "OUTER ITER. INNER SIZE: " << it.size() << "\n";
for (auto& it2 : it) {
std::cout << "INNER: " << it2 << "\n";
}
}
}
// -----------------------------------------------------------------------------
@ -433,14 +423,7 @@ bool SimpleAttributeEqualityMatcher::accessFitsIndex (triagens::arango::Index co
triagens::aql::AstNode const* other,
triagens::aql::AstNode const* op,
triagens::aql::Variable const* reference) {
std::cout << "CHECKING CONDITION\n";
std::cout << "INDEX: " << index << "\n";
std::cout << "ACCESS: " << access << "\n";
std::cout << "OTHER: " << other << "\n";
std::cout << "OP: " << op << "\n";
if (! index->canUseConditionPart(access, other, op, reference)) {
std::cout << "CHECKING CONDITION - EXIT 1\n";
return false;
}
@ -459,26 +442,20 @@ bool SimpleAttributeEqualityMatcher::accessFitsIndex (triagens::arango::Index co
if (! what->isAttributeAccessForVariable(attributeData) ||
attributeData.first != reference) {
// this access is not referencing this collection
std::cout << "CHECKING CONDITION - EXIT 3\n";
return false;
}
std::vector<triagens::basics::AttributeName> const& fieldNames = attributeData.second;
std::cout << "INDEX _ATTRIBUTES ARE: " << _attributes << "\n";
std::cout << "FIELDNAMES ARE: " << fieldNames << "\n";
for (size_t i = 0; i < _attributes.size(); ++i) {
if (_attributes[i].size() != fieldNames.size()) {
// attribute path length differs
std::cout << "DIFFERENT LENGTHS: " << _attributes[i].size() << ", " << fieldNames.size() << "\n";
continue;
}
bool match = true;
for (size_t j = 0; j < _attributes[i].size(); ++j) {
if (_attributes[i][j] != fieldNames[j]) {
std::cout << "ATTRIBUTES DIFFER: " << _attributes[i][j] << " - " << fieldNames[j] << "\n";
match = false;
break;
}
@ -487,11 +464,9 @@ bool SimpleAttributeEqualityMatcher::accessFitsIndex (triagens::arango::Index co
if (match) {
// mark ith attribute as being covered
_found.emplace(i);
std::cout << "IS A MATCH--------------------------\n";
return true;
}
}
std::cout << "CHECKING CONDITION - EXIT 2\n";
return false;
}

View File

@ -50,8 +50,6 @@ arangod_libarangod_a_SOURCES = \
arangod/Aql/Index.cpp \
arangod/Aql/IndexBlock.cpp \
arangod/Aql/IndexNode.cpp \
arangod/Aql/IndexRangeBlock.cpp \
arangod/Aql/IndexRangeNode.cpp \
arangod/Aql/ModificationBlocks.cpp \
arangod/Aql/ModificationNodes.cpp \
arangod/Aql/NodeFinder.cpp \