1
0
Fork 0

only applying hash indexes if ranges indicate equality.

This commit is contained in:
James 2014-08-21 15:27:53 +02:00
parent 9cc85003ff
commit deaa8f1271
2 changed files with 56 additions and 39 deletions

View File

@ -564,7 +564,7 @@ namespace triagens {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get indexes with fields <attrs> or nullptr if none exist
/// @brief get vector of indexes with fields <attrs>
////////////////////////////////////////////////////////////////////////////////
vector<TRI_index_t*> getIndexes (vector<std::string> attrs) const {
@ -832,24 +832,25 @@ namespace triagens {
};
// 3-way comparison: a return of -1 indicates that left is
// tighter than right, 0 that they are equal, 1 that right is tighter than
// left. For example, (x<1) is tighter than (x<=1) and (x>1) is tighter
// than (x>=1) . . .
static int CompareRangeInfoBound (RangeInfoBound const* left, RangeInfoBound const* right) {
if (left == nullptr) {
return (right == nullptr ? 0 : 1);
}
if (right == nullptr) {
return -1;
}
// 3-way comparison: a return of -1 indicates that left is
// tighter than right, 0 that they are equal, 1 that right is tighter than
// left. For example, (x<1) is tighter than (x<=1) and (x>1) is tighter
// than (x>=1) . . .
static int CompareRangeInfoBound (RangeInfoBound const* left,
RangeInfoBound const* right) {
if (left == nullptr) {
return (right == nullptr ? 0 : 1);
}
if (right == nullptr) {
return -1;
}
int cmp = TRI_CompareValuesJson(left->_bound.json(), right->_bound.json());
if (cmp == 0 && (left->_include != right->_include)) {
cmp = (left->_include?-1:1);
}
return cmp;
};
int cmp = TRI_CompareValuesJson(left->_bound.json(), right->_bound.json());
if (cmp == 0 && (left->_include != right->_include)) {
cmp = (left->_include?-1:1);
}
return cmp;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief class to keep a vector of RangeInfos . . .

View File

@ -274,8 +274,6 @@ class CalculationNodeFinder : public WalkerWorker<ExecutionNode> {
if (map != nullptr) {
// check the first components of <map> against indexes of <node> . . .
// FIXME does this need to be done like this? Couldn't we keep track
// earlier?
std::vector<std::string> attrs;
std::vector<RangeInfo*> rangeInfo;
for (auto x : *map){
@ -284,28 +282,46 @@ class CalculationNodeFinder : public WalkerWorker<ExecutionNode> {
}
std::vector<TRI_index_t*> idxs = node->getIndexes(attrs);
//use make one new plan for every index in <idxs> that replaces the
//enumerate collection node with a RangeIndexNode . . .
// make one new plan for every index in <idxs> that replaces the
// enumerate collection node with a RangeIndexNode . . .
for (auto idx: idxs) {
std::cout << "FOUND INDEX!\n";
auto newPlan = _plan->clone();
ExecutionNode* newNode = nullptr;
try{
newNode = new IndexRangeNode( newPlan->nextId(), node->vocbase(),
node->collection(), node->outVariable(), idx, &rangeInfo);
newPlan->registerNode(newNode);
}
catch (...) {
if (newNode != nullptr) {
delete newNode;
bool stop = false;
if (idx->_type == TRI_IDX_TYPE_HASH_INDEX){
//only use a hash index if the corresponding rangeInfos are all
//equalities . . .
for(auto x : rangeInfo){
if (x->_low == nullptr || x->_high == nullptr ||
!TRI_CheckSameValueJson(x->_low->_bound.json(),
x->_high->_bound.json()) || x->_low->_include != false ||
x->_high->_include == false ) {
stop = true;
break;
}
}
delete newPlan;
throw;
}
newPlan->replaceNode(newPlan->getNodeById(node->id()), newNode,
newPlan->getNodeById(_prev->id()));
std::cout << newPlan->root()->toJson().toString() << "\n";
_out.push_back(newPlan);
if (!stop) {
std::cout << "FOUND INDEX!\n";
auto newPlan = _plan->clone();
ExecutionNode* newNode = nullptr;
try{
newNode = new IndexRangeNode( newPlan->nextId(), node->vocbase(),
node->collection(), node->outVariable(), idx, &rangeInfo);
newPlan->registerNode(newNode);
}
catch (...) {
if (newNode != nullptr) {
delete newNode;
}
delete newPlan;
throw;
}
newPlan->replaceNode(newPlan->getNodeById(node->id()), newNode,
newPlan->getNodeById(_prev->id()));
std::cout << newPlan->root()->toJson(TRI_UNKNOWN_MEM_ZONE, false).toString()
<< "\n";
_out.push_back(newPlan);
}
}
}
}