[SERVER-47805] Fix validations for sort pattern when the field value is decimal Created: 27/Apr/20  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Arun Banala Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-20048 Server should validate keys in sort s... Backlog
Assigned Teams:
Query Execution
Sprint: Query 2020-05-18
Participants:

 Description   

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}



 Comments   
Comment by Arun Banala [ 27/May/20 ]

This ticket is different from SERVER-20048, which is about validating the 'keys' and might need '.' and '$' escaping. Keeping both the tickets separate.

Comment by Craig Homa [ 28/Apr/20 ]

The team will investigate whether this ticket or SERVER-20048 should remain in the backlog.

Generated at Thu Feb 08 05:15:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.