From ad1dafb013342faae7e998586a0c35b70ba75636 Mon Sep 17 00:00:00 2001 From: Jason Rassi Date: Fri, 19 Sep 2014 16:12:05 -0400 Subject: SERVER-15287 Can't use index key pattern plugin fields to provide sort --- src/mongo/db/query/query_solution.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'src/mongo/db/query/query_solution.cpp') diff --git a/src/mongo/db/query/query_solution.cpp b/src/mongo/db/query/query_solution.cpp index 3e042cb2b7c..34a98a46d9c 100644 --- a/src/mongo/db/query/query_solution.cpp +++ b/src/mongo/db/query/query_solution.cpp @@ -26,10 +26,12 @@ * it in the license file. */ -#include "mongo/db/index_names.h" #include "mongo/db/query/query_solution.h" -#include "mongo/db/query/lite_parsed_query.h" + +#include "mongo/db/index_names.h" #include "mongo/db/matcher/expression_geo.h" +#include "mongo/db/query/planner_analysis.h" +#include "mongo/db/query/query_planner_common.h" namespace mongo { @@ -454,23 +456,11 @@ namespace mongo { void IndexScanNode::computeProperties() { _sorts.clear(); - BSONObj sortPattern; - { - BSONObjBuilder sortBob; - BSONObj normalizedIndexKeyPattern(LiteParsedQuery::normalizeSortOrder(indexKeyPattern)); - BSONObjIterator it(normalizedIndexKeyPattern); - while (it.more()) { - BSONElement elt = it.next(); - // Zero is returned if elt is not a number. This happens when elt is hashed or - // 2dsphere, our two projection indices. We want to drop those from the sort - // pattern. - int val = elt.numberInt() * direction; - if (0 != val) { - sortBob.append(elt.fieldName(), val); - } - } - sortPattern = sortBob.obj(); + BSONObj sortPattern = QueryPlannerAnalysis::getSortPattern(indexKeyPattern); + if (direction == -1) { + sortPattern = QueryPlannerCommon::reverseSortObj(sortPattern); } + _sorts.insert(sortPattern); const int nFields = sortPattern.nFields(); -- cgit v1.2.1