[SERVER-51072] $skip and $limit stages silently round large doubles to MAX_LONG Created: 21/Sep/20  Updated: 29/Oct/23  Resolved: 29/Apr/21

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 4.4.1
Fix Version/s: 5.0.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Nikita Lapkov (Inactive) Assignee: Denis Grebennicov
Resolution: Fixed Votes: 0
Labels: neweng, qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Documented
is documented by DOCS-14394 Investigate changes in SERVER-51072: ... Closed
Gantt End to End
Backwards Compatibility: Minor Change
Sprint: Query Execution 2021-04-19, Query Execution 2021-05-03
Participants:

 Description   

$skip and $limit stages do not raise any validation errors when numbers larger than MAX_LONG are passed as their arguments. Instead, they truncate arguments to MAX_LONG which could be confusing.

A few examples:

> db.test.explain().aggregate([{$sort: {x: -1}}, {$skip: 18446744073709552000}, {$limit: 6}])
{
	"stages" : [
		{
			"$cursor" : {
				"queryPlanner" : {
					"plannerVersion" : 1,
					"namespace" : "test.test",
					"indexFilterSet" : false,
					"parsedQuery" : {
 
					},
					"queryHash" : "CF095775",
					"planCacheKey" : "CF095775",
					"winningPlan" : {
						"stage" : "SORT",
						"sortPattern" : {
							"x" : -1
						},
						"memLimit" : 104857600,
						"type" : "simple",
						"inputStage" : {
							"stage" : "COLLSCAN",
							"direction" : "forward"
						}
					},
					"rejectedPlans" : [ ]
				}
			}
		},
		{
			"$skip" : NumberLong("9223372036854775807")
		},
		{
			"$limit" : NumberLong(6)
		}
	],
	"serverInfo" : {
		"host" : "laplab-work-mac.local",
		"port" : 27017,
		"version" : "4.4.1",
		"gitVersion" : "ad91a93a5a31e175f5cbf8c69561e788bbc55ce1"
	},
	"ok" : 1
}

> db.test.explain().aggregate([{$sort: {x: -1}}, {$skip: 6}, {$limit: 18446744073709552000}])
{
	"stages" : [
		{
			"$cursor" : {
				"queryPlanner" : {
					"plannerVersion" : 1,
					"namespace" : "test.test",
					"indexFilterSet" : false,
					"parsedQuery" : {
 
					},
					"queryHash" : "CF095775",
					"planCacheKey" : "CF095775",
					"winningPlan" : {
						"stage" : "SORT",
						"sortPattern" : {
							"x" : -1
						},
						"memLimit" : 104857600,
						"type" : "simple",
						"inputStage" : {
							"stage" : "COLLSCAN",
							"direction" : "forward"
						}
					},
					"rejectedPlans" : [ ]
				}
			}
		},
		{
			"$skip" : NumberLong(6)
		},
		{
			"$limit" : NumberLong("9223372036854775807")
		}
	],
	"serverInfo" : {
		"host" : "laplab-work-mac.local",
		"port" : 27017,
		"version" : "4.4.1",
		"gitVersion" : "ad91a93a5a31e175f5cbf8c69561e788bbc55ce1"
	},
	"ok" : 1
}



 Comments   
Comment by Nikita Lapkov (Inactive) [ 30/Apr/21 ]

denis.grebennicov, changing "Downstream team attention" to "Needed" since we have slightly changed query operator behaviour. Feel free to review this page for guidance on when to notify teams about changes in the Query engine.

Comment by Githook User [ 28/Apr/21 ]

Author:

{'name': 'Denis Grebennicov', 'email': 'denis.grebennicov@mongodb.com', 'username': 'denis631'}

Message: SERVER-51072 $skip and $limit stages silently round large doubles to MAX_LONG
Branch: master
https://github.com/mongodb/mongo/commit/bf5ff3ee53d1c85f5bc039735945a6a0cb512a93

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