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

Explain displays incorrect cost for some ABT nodes

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • Hide
      // mongosh -f explain_bug.js
      
      let db = connect('mongodb://localhost/test');
      
      db.adminCommand({'setParameter': 1, 'internalQueryFrameworkControl': 'forceBonsai'});
      db.adminCommand({'configureFailPoint': 'enableExplainInBonsai', 'mode': 'alwaysOn'});
      
      const costModelOverride = {
          scanStartupCost: 10.5,
          scanIncrementalCost: 2.7,
          filterStartupCost: 30.3,
          filterIncrementalCost: 1.9
      };
      
      db.adminCommand(
          {'setParameter': 1, 'internalCostModelCoefficients': JSON.stringify(costModelOverride)});
      
      const documents = [];
      
      for (let i = 0; i < 1000; ++i) {
          documents.push({a: i, b: i % 23})
      }
      
      db.testExplain.drop();
      db.testExplain.insertMany(documents);
      
      const explain = db.testExplain.explain('executionStats').find({b: 10});
      
      console.log(explain);
      

      The code above displays the following stats:

      PhysicalScan

                  nodeType: 'PhysicalScan',
                  properties: {
                    cost: 4640.8,
                    localCost: 4640.8,
                    adjustedCE: 1000,
      

      However, for physicalScan we would expect

      localCost = scanStartupCost + scanIncrementalCost * adjustedCE = 10.5 + 2.7*1000 = 2710.5

      but got 4640.8 instead.

      Filter

                nodeType: 'Filter',
                properties: {
                  cost: 4640.8,
                  localCost: 4640.8,
                  adjustedCE: 1000,
      

      For filter's localCost we would expect

      localCost = filterStartupCost + filterIncrementalCost*adjustedCE = 30.3 + 1.9 * 1000 = 1930.3

      but we got 4640.8 instead

      for the cost we would expect
      cost = filterLocalCost + scanLocalCost = 2710.5 + 1930.3 = 4640.8

      and we got 4640.8 as expected.

      The fact that filter localCost includes PhysicalScan;'s localCost might be treated as expected behaviour, since the filter's cost includes its child's cost in the current implementaion of the CostEstimator, however, it does not look convinient.

      Show
      // mongosh -f explain_bug.js let db = connect( 'mongodb: //localhost/test' ); db.adminCommand({ 'setParameter' : 1, 'internalQueryFrameworkControl' : 'forceBonsai' }); db.adminCommand({ 'configureFailPoint' : 'enableExplainInBonsai' , 'mode' : 'alwaysOn' }); const costModelOverride = { scanStartupCost: 10.5, scanIncrementalCost: 2.7, filterStartupCost: 30.3, filterIncrementalCost: 1.9 }; db.adminCommand( { 'setParameter' : 1, 'internalCostModelCoefficients' : JSON.stringify(costModelOverride)}); const documents = []; for (let i = 0; i < 1000; ++i) { documents.push({a: i, b: i % 23}) } db.testExplain.drop(); db.testExplain.insertMany(documents); const explain = db.testExplain.explain( 'executionStats' ).find({b: 10}); console.log(explain); The code above displays the following stats: PhysicalScan nodeType: 'PhysicalScan' , properties: { cost: 4640.8, localCost: 4640.8, adjustedCE: 1000, However, for physicalScan we would expect localCost = scanStartupCost + scanIncrementalCost * adjustedCE = 10.5 + 2.7*1000 = 2710.5 but got 4640.8 instead. Filter nodeType: 'Filter' , properties: { cost: 4640.8, localCost: 4640.8, adjustedCE: 1000, For filter's localCost we would expect localCost = filterStartupCost + filterIncrementalCost*adjustedCE = 30.3 + 1.9 * 1000 = 1930.3 but we got 4640.8 instead for the cost we would expect cost = filterLocalCost + scanLocalCost = 2710.5 + 1930.3 = 4640.8 and we got 4640.8 as expected. The fact that filter localCost includes PhysicalScan;'s localCost might be treated as expected behaviour, since the filter's cost includes its child's cost in the current implementaion of the CostEstimator, however, it does not look convinient.
    • QO 2023-01-09, QO 2023-01-23

      If an ABT node is an inner node of a group in the Bonsai, instead of its cost explain display the cost of the root node of the group.

            Assignee:
            svilen.mihaylov@mongodb.com Svilen Mihaylov (Inactive)
            Reporter:
            alexander.ignatyev@mongodb.com Alexander Ignatyev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: