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

isSparse field differs in explain of wildcard index based on SBE flag

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 8.0.5
    • Component/s: None
    • Query Optimization
    • ALL
    • Hide

      db.coll.drop()

      db.coll.insertMany([\{a: 1}, \{a: 2}, \{a: "3"}, \{a: 4, b: 3}, \{b: 7}])

      db.coll.createIndex({"$**": 1})

      db.runCommand({explain: {distinct: "coll", key: "a", query: { "b" :

      { "$lt" : 5 }

      }}})

      Show
      db.coll.drop() db.coll.insertMany( [\{a: 1}, \{a: 2}, \{a: "3"}, \{a: 4, b: 3}, \{b: 7}] ) db.coll.createIndex({"$**": 1}) db.runCommand({explain: {distinct: "coll", key: "a", query: { "b" : { "$lt" : 5 } }}})
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Found an odd difference in explain output for featureFlagSBEFull true vs false. The isSparse field for a wildcard index has a different value, even though we pick an index scan on the same wildcard index in both cases. The only difference I can see is that in the first case we use a classic plan (isSparse: true) and in the second case we use an SBE plan (isSparse: false). See steps to reproduce below.

      trySBERestricted:

      winningPlan: {                                                                                                       
            isCached: false,                                                                                                   
            stage: 'FETCH',                                                                                                    
            inputStage: {                                                                                                      
              stage: 'IXSCAN',                                                                                                 
              keyPattern: { '$_path': 1, b: 1 },                                                                               
              indexName: '$**_1',                                                                                              
              isMultiKey: false,                                                                                               
              multiKeyPaths: { '$_path': [], b: [] },                                                                          
              isUnique: false,                                                                                                 
              isSparse: false,                                                                                                 
              isPartial: false,                                                                                                
              indexVersion: 2,                                                                                                 
              direction: 'forward',                                                                                            
              indexBounds: { '$_path': [ '["b", "b"]' ], b: [ '[-inf.0, 5)' ] }                                                
            }                                                                                                                  
          },

      trySBEFull output:

      winningPlan: {                                                                                                       
            isCached: false,                                                                                                   
            queryPlan: {                                                                                                       
              stage: 'FETCH',                                                                                                  
              planNodeId: 2,                                                                                                   
              inputStage: {                                                                                                    
                stage: 'IXSCAN',                                                                                               
                planNodeId: 1,                                                                                                 
                keyPattern: { '$_path': 1, b: 1 },                                                                             
                indexName: '$**_1',                                                                                            
                isMultiKey: false,                                                                                             
                multiKeyPaths: { '$_path': [], b: [] },                                                                        
                isUnique: false,                                                                                               
                isSparse: true,                                                                                                
                isPartial: false,                                                                                              
                indexVersion: 2,                                                                                               
                direction: 'forward',                                                                                          
                indexBounds: { '$_path': [ '["b", "b"]' ], b: [ '[-inf.0, 5)' ] }                                              
              }                                                                                                                
            },                                                                                                                 
            slotBasedPlan: {                                                                                                   
              slots: '$$RESULT=s8 env: { s1 = KS(3C62001F000000000000000001), s2 = KS(3C62002B0A01), s7 = {"$_path" : 1, "b" : 1} }',
              stages: '[2] nlj inner [] [s3, s6, s4, s5, s7] \n' +                                                             
                '    left \n' +                                                                                                
                '        [1] cfilter {(exists(s1) && exists(s2))} \n' +                                                        
                '        [1] ixseek s1 s2 s5 s3 s6 s4 [] @"31cf022a-7d45-47fe-8701-4c78a69d0b27" @"$**_1" true \n' +           
                '    right \n' +                                                                                               
                '        [2] limit 1ll \n' +                                                                                   
                '        [2] seek s3 s8 s9 s6 s4 s5 s7 none none [] @"31cf022a-7d45-47fe-8701-4c78a69d0b27" true false \n'     
            }

       

       

       

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            alya.berciu@mongodb.com Alya Berciu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None