Fix validations for sort pattern when the field value is decimal

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Execution
    • Query 2020-05-18
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      It look like we don't disallow decimals between 1.0 and 2.0 for sort parameter is find. We also don't use an index to sort for such sort patterns. This seems like a bug.

      Note that we also allow and persist any numeric values for an index field.

      
      $ db.c.find().sort({a: 2.0})
      Error: error: {
      	"ok" : 0,
      	"errmsg" : "$sort key ordering must be 1 (for ascending) or -1 (for
      descending)",
      	"code" : 15975,
      	"codeName" : "Location15975"
      }
      $ db.c.find().sort({a: 1.9}).explain()
      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "test.c",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      
      		},
      		"queryHash" : "3344645B",
      		"planCacheKey" : "3344645B",
      		"winningPlan" : {
      			"stage" : "SORT",
      			"sortPattern" : {
      				"a" : 1
      			},
      			"memLimit" : 104857600,
      			"type" : "simple",
      			"inputStage" : {
      				"stage" : "COLLSCAN",
      				"direction" : "forward"
      			}
      		},
      		"rejectedPlans" : [ ]
      	}
      }
      $ db.c.find().sort({a: 1.0}).explain()
      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "test.c",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      
      		},
      		"queryHash" : "3344645B",
      		"planCacheKey" : "3344645B",
      		"winningPlan" : {
      			"stage" : "FETCH",
      			"inputStage" : {
      				"stage" : "IXSCAN",
      				"keyPattern" : {
      					"a" : 1
      				},
      				"indexName" : "a_1",
      				"isMultiKey" : false,
      				"multiKeyPaths" : {
      					"a" : [ ]
      				},
      				"isUnique" : false,
      				"isSparse" : false,
      				"isPartial" : false,
      				"indexVersion" : 2,
      				"direction" : "forward",
      				"indexBounds" : {
      					"a" : [
      						"[MinKey, MaxKey]"
      					]
      				}
      			}
      		},
      		"rejectedPlans" : [ ]
      	}
      }
      

      Additionally the server should also reject the following sort specification objects as invalid:

      {"a.": 1}
      {$x: 1}
      {a: 1, $natural: 1}
      

            Assignee:
            [DO NOT USE] Backlog - Query Execution
            Reporter:
            Arun Banala
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: