[SERVER-23202] Query planner does not trim certain bounds-generating inequality predicates from expression tree Created: 17/Mar/16  Updated: 23/Mar/18  Resolved: 15/Mar/18

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 3.7.4

Type: Improvement Priority: Major - P3
Reporter: Backlog - Query Team (Inactive) Assignee: Nicholas Zolnierz
Resolution: Done Votes: 2
Labels: asya
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-11476 Docs for SERVER-23202: Query planner ... Closed
Related
is related to SERVER-16622 RegEx query predicates using the | (v... Backlog
Backwards Compatibility: Fully Compatible
Sprint: Query 2018-03-12, Query 2018-03-26
Participants:

 Description   

The query planner does not trim bounds-generating inequality predicates from the expression tree, when the value being compared to is one of the following BSON types:

  • Object
  • Undefined
  • RegEx
  • DBRef
  • Code
  • Symbol
  • CodeWScope

As a result, such predicates are not eligible for covering behavior, and require an unnecessary additional match operation after the document is fetched from disk.

Reproduce as follows:

> db.foo.drop()
true
> db.foo.ensureIndex({a:1})
{
	"createdCollectionAutomatically" : true,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> db.foo.find({a:{$gte:function(){ return 0; }}}).explain('queryPlanner').queryPlanner.winningPlan
{
	"stage" : "FETCH",  // Unexpected: FETCH does not need a filter with $gte predicate here.
	"filter" : {
		"a" : {
			"$gte" : function (){ return 0; }
		}
	},
	"inputStage" : {
		"stage" : "IXSCAN",
		"keyPattern" : {
			"a" : 1
		},
		"indexName" : "a_1",
		"isMultiKey" : false,
		"isUnique" : false,
		"isSparse" : false,
		"isPartial" : false,
		"indexVersion" : 1,
		"direction" : "forward",
		"indexBounds" : {
			"a" : [
				"[function (){ return 0; }, CodeWScope( , {}))"
			]
		}
	}
}
> db.foo.find({a:{$eq:function(){ return 0; }}}).explain('queryPlanner').queryPlanner.winningPlan
{
	"stage" : "FETCH",  // Expected: No filter with $eq predicate here.
	"inputStage" : {
		"stage" : "IXSCAN",
		"keyPattern" : {
			"a" : 1
		},
		"indexName" : "a_1",
		"isMultiKey" : false,
		"isUnique" : false,
		"isSparse" : false,
		"isPartial" : false,
		"indexVersion" : 1,
		"direction" : "forward",
		"indexBounds" : {
			"a" : [
				"[function (){ return 0; }, function (){ return 0; }]"
			]
		}
	}
}
>



 Comments   
Comment by Githook User [ 15/Mar/18 ]

Author:

{'email': 'nicholas.zolnierz@mongodb.com', 'name': 'Nick Zolnierz', 'username': 'nzolnierzmdb'}

Message: SERVER-23202: Query planner does not trim certain bounds-generating inequality predicates from expression tree
Branch: master
https://github.com/mongodb/mongo/commit/0109767b6962d18b60d89a723c0087cf27d370e3

Generated at Thu Feb 08 04:02:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.