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

Modifying indexes impacts application of index filters

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.1.5
    • Component/s: Querying
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Backport Requested:
      v4.0, v3.6
    • Steps To Reproduce:
      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" }
    • Sprint:
      Query 2018-10-22, Query 2018-11-05, Query 2018-11-19
    • Case:
    • Linked BF Score:
      13

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ian.boros Ian Boros
              Reporter:
              christopher.harris Christopher Harris
              Participants:
              Votes:
              5 Vote for this issue
              Watchers:
              12 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: