Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-33303

Modifying indexes impacts application of index filters

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.5
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
    • Fully Compatible
    • ALL
    • v4.0, v3.6
    • Hide
      db.version()
      db.foo.drop()
      db.foo.createIndexes( [{x:1}, {x:1,y:1} ])
      db.runCommand( {  planCacheSetFilter: 'foo', query: {"x" : 3}, indexes: [ {x:1,y:1} ] } )
      db.runCommand( {  planCacheListFilters: 'foo' } )
      db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet
      db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan
      db.foo.dropIndex({x:1,y:1})
      db.runCommand( {  planCacheListFilters: 'foo' } )
      db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet
      db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan
      db.foo.createIndex({x:1, z:1})
      db.runCommand( {  planCacheListFilters: 'foo' } )
      db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet
      db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan
      

      Output of running those commands:

      MongoDB Enterprise > db.version()
      3.6.2
      MongoDB Enterprise > db.foo.drop()
      true
      MongoDB Enterprise > db.foo.createIndexes( [{x:1}, {x:1,y:1} ])
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 3,
      	"ok" : 1
      }
      MongoDB Enterprise > db.runCommand( {  planCacheSetFilter: 'foo', query: {"x" : 3}, indexes: [ {x:1,y:1} ] } )
      { "ok" : 1 }
      MongoDB Enterprise > db.runCommand( {  planCacheListFilters: 'foo' } )
      {
      	"filters" : [
      		{
      			"query" : {
      				"x" : 3
      			},
      			"sort" : {
      				
      			},
      			"projection" : {
      				
      			},
      			"indexes" : [
      				{
      					"x" : 1,
      					"y" : 1
      				}
      			]
      		}
      	],
      	"ok" : 1
      }
      MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet
      true
      MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan
      {
      	"stage" : "FETCH",
      	"inputStage" : {
      		"stage" : "IXSCAN",
      		"keyPattern" : {
      			"x" : 1,
      			"y" : 1
      		},
      		"indexName" : "x_1_y_1",
      		"isMultiKey" : false,
      		"multiKeyPaths" : {
      			"x" : [ ],
      			"y" : [ ]
      		},
      		"isUnique" : false,
      		"isSparse" : false,
      		"isPartial" : false,
      		"indexVersion" : 2,
      		"direction" : "forward",
      		"indexBounds" : {
      			"x" : [
      				"[3.0, 3.0]"
      			],
      			"y" : [
      				"[MinKey, MaxKey]"
      			]
      		}
      	}
      }
      MongoDB Enterprise > db.foo.dropIndex({x:1,y:1})
      { "nIndexesWas" : 3, "ok" : 1 }
      MongoDB Enterprise > db.runCommand( {  planCacheListFilters: 'foo' } )
      {
      	"filters" : [
      		{
      			"query" : {
      				"x" : 3
      			},
      			"sort" : {
      				
      			},
      			"projection" : {
      				
      			},
      			"indexes" : [
      				{
      					"x" : 1,
      					"y" : 1
      				}
      			]
      		}
      	],
      	"ok" : 1
      }
      MongoDB Enterprise > // Filter is still present above, expect it to be applied below but it is not: 
      MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet
      false
      MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan
      {
      	"stage" : "FETCH",
      	"inputStage" : {
      		"stage" : "IXSCAN",
      		"keyPattern" : {
      			"x" : 1
      		},
      		"indexName" : "x_1",
      		"isMultiKey" : false,
      		"multiKeyPaths" : {
      			"x" : [ ]
      		},
      		"isUnique" : false,
      		"isSparse" : false,
      		"isPartial" : false,
      		"indexVersion" : 2,
      		"direction" : "forward",
      		"indexBounds" : {
      			"x" : [
      				"[3.0, 3.0]"
      			]
      		}
      	}
      }
      MongoDB Enterprise > db.foo.createIndex({x:1, z:1})
      {
      	"createdCollectionAutomatically" : false,
      	"numIndexesBefore" : 2,
      	"numIndexesAfter" : 3,
      	"ok" : 1
      }
      MongoDB Enterprise > db.runCommand( {  planCacheListFilters: 'foo' } )
      {
      	"filters" : [
      		{
      			"query" : {
      				"x" : 3
      			},
      			"sort" : {
      				
      			},
      			"projection" : {
      				
      			},
      			"indexes" : [
      				{
      					"x" : 1,
      					"y" : 1
      				}
      			]
      		}
      	],
      	"ok" : 1
      }
      MongoDB Enterprise > // Nothing has changed with the index filter.  But now after creating a new index it is being applied again (as originally expected):
      MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet
      true
      MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan
      {
      	"stage" : "COLLSCAN",
      	"filter" : {
      		"x" : {
      			"$eq" : 3
      		}
      	},
      	"direction" : "forward"
      }
      
      Show
      db.version() db.foo.drop() db.foo.createIndexes( [{x:1}, {x:1,y:1} ]) db.runCommand( { planCacheSetFilter: 'foo', query: {"x" : 3}, indexes: [ {x:1,y:1} ] } ) db.runCommand( { planCacheListFilters: 'foo' } ) db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan db.foo.dropIndex({x:1,y:1}) db.runCommand( { planCacheListFilters: 'foo' } ) db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan db.foo.createIndex({x:1, z:1}) db.runCommand( { planCacheListFilters: 'foo' } ) db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan Output of running those commands: MongoDB Enterprise > db.version() 3.6.2 MongoDB Enterprise > db.foo.drop() true MongoDB Enterprise > db.foo.createIndexes( [{x:1}, {x:1,y:1} ]) { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 3, "ok" : 1 } MongoDB Enterprise > db.runCommand( { planCacheSetFilter: 'foo', query: {"x" : 3}, indexes: [ {x:1,y:1} ] } ) { "ok" : 1 } MongoDB Enterprise > db.runCommand( { planCacheListFilters: 'foo' } ) { "filters" : [ { "query" : { "x" : 3 }, "sort" : { }, "projection" : { }, "indexes" : [ { "x" : 1, "y" : 1 } ] } ], "ok" : 1 } MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet true MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan { "stage" : "FETCH", "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "x" : 1, "y" : 1 }, "indexName" : "x_1_y_1", "isMultiKey" : false, "multiKeyPaths" : { "x" : [ ], "y" : [ ] }, "isUnique" : false, "isSparse" : false, "isPartial" : false, "indexVersion" : 2, "direction" : "forward", "indexBounds" : { "x" : [ "[3.0, 3.0]" ], "y" : [ "[MinKey, MaxKey]" ] } } } MongoDB Enterprise > db.foo.dropIndex({x:1,y:1}) { "nIndexesWas" : 3, "ok" : 1 } MongoDB Enterprise > db.runCommand( { planCacheListFilters: 'foo' } ) { "filters" : [ { "query" : { "x" : 3 }, "sort" : { }, "projection" : { }, "indexes" : [ { "x" : 1, "y" : 1 } ] } ], "ok" : 1 } MongoDB Enterprise > // Filter is still present above, expect it to be applied below but it is not: MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet false MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan { "stage" : "FETCH", "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "x" : 1 }, "indexName" : "x_1", "isMultiKey" : false, "multiKeyPaths" : { "x" : [ ] }, "isUnique" : false, "isSparse" : false, "isPartial" : false, "indexVersion" : 2, "direction" : "forward", "indexBounds" : { "x" : [ "[3.0, 3.0]" ] } } } MongoDB Enterprise > db.foo.createIndex({x:1, z:1}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 2, "numIndexesAfter" : 3, "ok" : 1 } MongoDB Enterprise > db.runCommand( { planCacheListFilters: 'foo' } ) { "filters" : [ { "query" : { "x" : 3 }, "sort" : { }, "projection" : { }, "indexes" : [ { "x" : 1, "y" : 1 } ] } ], "ok" : 1 } MongoDB Enterprise > // Nothing has changed with the index filter. But now after creating a new index it is being applied again (as originally expected): MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.indexFilterSet true MongoDB Enterprise > db.foo.explain().find({x:3}).finish().queryPlanner.winningPlan { "stage" : "COLLSCAN", "filter" : { "x" : { "$eq" : 3 } }, "direction" : "forward" }
    • Query 2018-10-22, Query 2018-11-05, Query 2018-11-19
    • 13

      According to the documentation:

      Index filters exist for the duration of the server process and do not persist after shutdown. MongoDB also provides a command to manually remove filters.

      While a given index filter does persist across index creation and drops, its application towards queries does seem to be influenced by such actions.

            Assignee:
            ian.boros@mongodb.com Ian Boros
            Reporter:
            christopher.harris@mongodb.com Chris Harris
            Votes:
            5 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: