diff --git a/arangod/RocksDBEngine/RocksDBVPackIndex.cpp b/arangod/RocksDBEngine/RocksDBVPackIndex.cpp index c4a9be9feb..c4a51ec7b4 100644 --- a/arangod/RocksDBEngine/RocksDBVPackIndex.cpp +++ b/arangod/RocksDBEngine/RocksDBVPackIndex.cpp @@ -1044,17 +1044,11 @@ bool RocksDBVPackIndex::supportsFilterCondition( if (attributesCoveredByEquality == _fields.size() && unique()) { // index is unique and condition covers all attributes by equality - if (estimatedItems >= values) { - // reduce costs due to uniqueness - estimatedItems = values; - estimatedCost = static_cast(estimatedItems); - } else { - // cost is already low... now slightly prioritize the unique index - estimatedCost *= 0.995; - } + estimatedItems = values; + estimatedCost = 0.995 * values; return true; } - + if (attributesCovered > 0 && (!_sparse || attributesCovered == _fields.size())) { // if the condition contains at least one index attribute and is not @@ -1064,7 +1058,16 @@ bool RocksDBVPackIndex::supportsFilterCondition( // sparse indexes are contained in Index::canUseConditionPart) estimatedItems = static_cast((std::max)( static_cast(estimatedCost * values), static_cast(1))); - estimatedCost *= static_cast(values); + + // check if the index has a selectivity estimate ready + if (attributesCoveredByEquality == _fields.size()) { + StringRef ignore; + double estimate = this->selectivityEstimate(&ignore); + if (estimate > 0.0) { + estimatedItems = static_cast(1.0 / estimate); + } + } + estimatedCost = static_cast(estimatedItems); return true; }