[SERVER-12934] Performance regression with $where queries Created: 27/Feb/14  Updated: 08/Jan/24

Status: Backlog
Project: Core Server
Component/s: JavaScript, Querying
Affects Version/s: 2.6.0-rc0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ben Becker Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: performance, platforms-re-triaged, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
Assigned Teams:
Query Execution
Operating System: ALL
Steps To Reproduce:

db.t.insert({a:1});
db.t.find({a:0, $where:'sleep(1000)'});

Note that neither version actually executes the $where clause.

Participants:

 Description   

A $where query in v2.6rc0 always creates a V8Scope, even if other operators do not match. v2.4.9 doesn't create a scope unless other operators match.

For some queries, this results in v2.6rc0 running slower by two orders of magnitude; e.g.:

{
	"_id" : ObjectId("530f6bad7e6c53525919dfa9"),
	"deltaRatio" : "92.31",
	"deltaUs" : 11094.5,
	"v249Avg" : "121.50",
	"v249Results" : [
		121,
		123,
		122,
		120,
		121,
		122
	],
	"rc0Avg" : "11216.00",
	"rc0Results" : [
		11398,
		11187,
		11164,
		11220,
		11181,
		11146
	],
	"testId" : "GeneratedTests::GeneratedQuery761[Compound2]",
	"qry" : "{ query: { arrayField: null, d: { $mod: [ 314159265, 314159215 ] }, $where: \"function myFunction() { return String(this.a || this.b || this.c || this.d).length > 9; }\", _id: //d?[A-E]*// }, orderby: { d: 1 } }",
	"proj" : "{ b: 1, a: 1 }",
	"idx" : "Compound2",
	"rc0Count" : 0,
	"v249Count" : 0,
	"countsMatch" : true
}


Generated at Thu Feb 08 03:30:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.