Files
mongo/jstests/libs/query/cbr_utils.js
Ben Shteinfeld ff3984959e SERVER-98086 Implement $elemMatch for heuristic CE (#31648)
GitOrigin-RevId: 42a37d5ba7e2af9bf10680d5aa475e954cda405f
2025-01-31 17:46:36 +00:00

25 lines
815 B
JavaScript

/**
* Utilities for writing tests for the cost-based ranker (CBR).
*/
// Round the given number to the nearest 0.1
function round(num) {
return Math.round(num * 10) / 10;
}
// Compare two cardinality estimates with approximate equality. This is done so that our tests can
// be robust to floating point rounding differences but detect large changes in estimation
// indicating a real change in estimation behavior.
export function ceEqual(lhs, rhs) {
return Math.abs(round(lhs) - round(rhs)) < 0.1;
}
function planEstimateTypeIs(plan, type) {
return plan.estimatesMetadata.ceSource === type;
}
// Return true if the plan was estimated with a histogam estimation source. Return false otherwise.
export function planEstimatedWithHistogram(plan) {
return planEstimateTypeIs(plan, "Histogram");
}