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

In $graphLookup the query planner in mongo/master treats undefined and null as equivalent, while in 4.0 it does not

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Query Optimization
    • ALL
    • Hide
      (function() {
          "use strict";
      
          const coll = db.fuzzer_coll;
          coll.drop();
          assert.writeOK(coll.insert({_id: 293,obj: {}}));
          assert.writeOK(coll.insert({_id: 322,obj: {str: undefined}})); 
          assert.commandWorked(coll.createIndex( {"obj.str": 1}));
      
          const agg = {
              $graphLookup: {
                  from: 'fuzzer_coll', startWith: null, connectFromField: 'missing',
                  connectToField: 'obj.str', as: 'arrayAs'
              }
          }
      
          const res1 = coll.aggregate([agg]);
          print(tojson(res1.toArray()));
      }) ();
      
      Show
      (function() { "use strict"; const coll = db.fuzzer_coll; coll.drop(); assert.writeOK(coll.insert({_id: 293,obj: {}})); assert.writeOK(coll.insert({_id: 322,obj: {str: undefined}})); assert.commandWorked(coll.createIndex( {"obj.str": 1})); const agg = { $graphLookup: { from: 'fuzzer_coll', startWith: null, connectFromField: 'missing', connectToField: 'obj.str', as: 'arrayAs' } } const res1 = coll.aggregate([agg]); print(tojson(res1.toArray())); }) ();

      Aggregation output:

      4.0: 
      [
      	{
      		"_id" : 293,
      		"obj" : {
      
      		},
      		"arrayAs" : [
      			{
      				"_id" : 293,
      				"obj" : {
      
      				}
      			}
      		]
      	},
      	{
      		"_id" : 322,
      		"obj" : {
      			"str" : undefined
      		},
      		"arrayAs" : [
      			{
      				"_id" : 293,
      				"obj" : {
      
      				}
      			}
      		]
      	}
      ]
      
      master:
      [
      	{
      		"_id" : 293,
      		"obj" : {
      
      		},
      		"arrayAs" : [
      			{
      				"_id" : 293,
      				"obj" : {
      
      				}
      			},
      			{
      				"_id" : 322,
      				"obj" : {
      					"str" : undefined
      				}
      			}
      		]
      	},
      	{
      		"_id" : 322,
      		"obj" : {
      			"str" : undefined
      		},
      		"arrayAs" : [
      			{
      				"_id" : 293,
      				"obj" : {
      
      				}
      			},
      			{
      				"_id" : 322,
      				"obj" : {
      					"str" : undefined
      				}
      			}
      		]
      	}
      ]
      

      The query plan shows different index bounds in 4.0 and master:
      4.0:

      [js_test:ReproAgg] 2018-09-28T17:50:43.152-0500 d20021| ---------bounds = field #0['obj.str']: [null, null]
      

      master:

      [js_test:ReproAgg] 2018-09-28T17:50:43.147-0500 d20020| ---------bounds = field #0['obj.str']: [undefined, undefined], [null, null]
      

       

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            vlad.rachev@mongodb.com Vlad Rachev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: