[SERVER-71803] Explain displays incorrect cost for some ABT nodes Created: 02/Dec/22  Updated: 27/Oct/23  Resolved: 02/Feb/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alexander Ignatyev Assignee: Svilen Mihaylov (Inactive)
Resolution: Works as Designed Votes: 0
Labels: explain
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-75077 Suboptimal plan selection in Bonsai Backlog
Assigned Teams:
Query Optimization
Operating System: ALL
Steps To Reproduce:

// 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.

Sprint: QO 2023-01-09, QO 2023-01-23
Participants:

 Description   

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.


Generated at Thu Feb 08 06:20:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.