diff options
Diffstat (limited to 'src/mongo/db/query/index_tag.cpp')
-rw-r--r-- | src/mongo/db/query/index_tag.cpp | 126 |
1 files changed, 62 insertions, 64 deletions
diff --git a/src/mongo/db/query/index_tag.cpp b/src/mongo/db/query/index_tag.cpp index 7b81a23f556..c1dceec6b02 100644 --- a/src/mongo/db/query/index_tag.cpp +++ b/src/mongo/db/query/index_tag.cpp @@ -35,81 +35,79 @@ namespace mongo { - // TODO: Move out of the enumerator and into the planner. - - const size_t IndexTag::kNoIndex = std::numeric_limits<size_t>::max(); - - void tagForSort(MatchExpression* tree) { - if (!Indexability::nodeCanUseIndexOnOwnField(tree)) { - size_t myTagValue = IndexTag::kNoIndex; - for (size_t i = 0; i < tree->numChildren(); ++i) { - MatchExpression* child = tree->getChild(i); - tagForSort(child); - IndexTag* childTag = static_cast<IndexTag*>(child->getTag()); - if (NULL != childTag) { - myTagValue = std::min(myTagValue, childTag->index); - } - } - if (myTagValue != IndexTag::kNoIndex) { - tree->setTag(new IndexTag(myTagValue)); +// TODO: Move out of the enumerator and into the planner. + +const size_t IndexTag::kNoIndex = std::numeric_limits<size_t>::max(); + +void tagForSort(MatchExpression* tree) { + if (!Indexability::nodeCanUseIndexOnOwnField(tree)) { + size_t myTagValue = IndexTag::kNoIndex; + for (size_t i = 0; i < tree->numChildren(); ++i) { + MatchExpression* child = tree->getChild(i); + tagForSort(child); + IndexTag* childTag = static_cast<IndexTag*>(child->getTag()); + if (NULL != childTag) { + myTagValue = std::min(myTagValue, childTag->index); } } + if (myTagValue != IndexTag::kNoIndex) { + tree->setTag(new IndexTag(myTagValue)); + } } +} - bool TagComparison(const MatchExpression* lhs, const MatchExpression* rhs) { - IndexTag* lhsTag = static_cast<IndexTag*>(lhs->getTag()); - size_t lhsValue = (NULL == lhsTag) ? IndexTag::kNoIndex : lhsTag->index; - size_t lhsPos = (NULL == lhsTag) ? IndexTag::kNoIndex : lhsTag->pos; +bool TagComparison(const MatchExpression* lhs, const MatchExpression* rhs) { + IndexTag* lhsTag = static_cast<IndexTag*>(lhs->getTag()); + size_t lhsValue = (NULL == lhsTag) ? IndexTag::kNoIndex : lhsTag->index; + size_t lhsPos = (NULL == lhsTag) ? IndexTag::kNoIndex : lhsTag->pos; - IndexTag* rhsTag = static_cast<IndexTag*>(rhs->getTag()); - size_t rhsValue = (NULL == rhsTag) ? IndexTag::kNoIndex : rhsTag->index; - size_t rhsPos = (NULL == rhsTag) ? IndexTag::kNoIndex : rhsTag->pos; + IndexTag* rhsTag = static_cast<IndexTag*>(rhs->getTag()); + size_t rhsValue = (NULL == rhsTag) ? IndexTag::kNoIndex : rhsTag->index; + size_t rhsPos = (NULL == rhsTag) ? IndexTag::kNoIndex : rhsTag->pos; - // First, order on indices. - if (lhsValue != rhsValue) { - // This relies on kNoIndex being larger than every other possible index. - return lhsValue < rhsValue; - } - - // Next, order so that if there's a GEO_NEAR it's first. - if (MatchExpression::GEO_NEAR == lhs->matchType()) { - return true; - } - else if (MatchExpression::GEO_NEAR == rhs->matchType()) { - return false; - } + // First, order on indices. + if (lhsValue != rhsValue) { + // This relies on kNoIndex being larger than every other possible index. + return lhsValue < rhsValue; + } - // Ditto text. - if (MatchExpression::TEXT == lhs->matchType()) { - return true; - } - else if (MatchExpression::TEXT == rhs->matchType()) { - return false; - } + // Next, order so that if there's a GEO_NEAR it's first. + if (MatchExpression::GEO_NEAR == lhs->matchType()) { + return true; + } else if (MatchExpression::GEO_NEAR == rhs->matchType()) { + return false; + } - // Next, order so that the first field of a compound index appears first. - if (lhsPos != rhsPos) { - return lhsPos < rhsPos; - } + // Ditto text. + if (MatchExpression::TEXT == lhs->matchType()) { + return true; + } else if (MatchExpression::TEXT == rhs->matchType()) { + return false; + } - // Next, order on fields. - int cmp = lhs->path().compare(rhs->path()); - if (0 != cmp) { - return 0; - } + // Next, order so that the first field of a compound index appears first. + if (lhsPos != rhsPos) { + return lhsPos < rhsPos; + } - // Finally, order on expression type. - return lhs->matchType() < rhs->matchType(); + // Next, order on fields. + int cmp = lhs->path().compare(rhs->path()); + if (0 != cmp) { + return 0; } - void sortUsingTags(MatchExpression* tree) { - for (size_t i = 0; i < tree->numChildren(); ++i) { - sortUsingTags(tree->getChild(i)); - } - std::vector<MatchExpression*>* children = tree->getChildVector(); - if (NULL != children) { - std::sort(children->begin(), children->end(), TagComparison); - } + // Finally, order on expression type. + return lhs->matchType() < rhs->matchType(); +} + +void sortUsingTags(MatchExpression* tree) { + for (size_t i = 0; i < tree->numChildren(); ++i) { + sortUsingTags(tree->getChild(i)); + } + std::vector<MatchExpression*>* children = tree->getChildVector(); + if (NULL != children) { + std::sort(children->begin(), children->end(), TagComparison); } +} -} // namespace mongo +} // namespace mongo |