Query Insights: compute numeric selectivity and render low non-zero values as “below 0.1%”#763
Conversation
| isCoveringQuery: analyzed.isCovered, | ||
| concerns, | ||
| efficiencyAnalysis: { | ||
| selectivity: computeSelectivity(analyzed.nReturned, totalCollectionDocs), |
There was a problem hiding this comment.
@copilot we should not return selectivity as a string, let's return the actual number value. then computeSelectivity will not have to switch formatting for values <0.1%. This just looks like a bad design.
The presentation layer in the webview will format as needed (to 'below 0.1%' or to the actual string with fixed(1)). fix this from here into the computation and the presentation layer.
There was a problem hiding this comment.
Pull request overview
This PR improves Query Insights’ selectivity presentation by preventing very small non-zero values from rounding to 0%, which could mislead users about query efficiency. It shifts selectivity to a numeric value in the Stage 2 model and adds a UI-level formatter that renders 0 < selectivity < 0.1% as a localized threshold label (“below 0.1%”).
Changes:
- Changed Stage 2
efficiencyAnalysis.selectivityfrom a percent string to anumber | nullpercent value. - Added
formatSelectivityForDisplay()and updatedQueryInsightsTabto render low non-zero selectivity as a localized “below 0.1%” label. - Added l10n string and targeted unit tests for both the transform-layer selectivity computation and the UI formatter.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/webviews/documentdb/collectionView/utils/formatSelectivityForDisplay.ts | New UI formatter to map low non-zero selectivity to a threshold label and otherwise format as 1-decimal percent. |
| src/webviews/documentdb/collectionView/utils/formatSelectivityForDisplay.test.ts | Unit tests for the formatter behavior at key boundaries (0, <0.1, >=0.1, null/undefined). |
| src/webviews/documentdb/collectionView/types/queryInsights.ts | Updates Stage 2 selectivity type from formatted string to numeric percent. |
| src/webviews/documentdb/collectionView/queryInsights/queryInsightsRouter.ts | Adjusts telemetry measurement emission to use numeric selectivity directly. |
| src/webviews/documentdb/collectionView/components/queryInsightsTab/QueryInsightsTab.tsx | Uses the formatter in the Efficiency Analysis card and tooltip text. |
| src/documentdb/queryInsights/transformations.ts | Changes selectivity computation to return a numeric percent instead of a formatted string. |
| src/documentdb/queryInsights/transformations.test.ts | Adds tests ensuring low selectivity preserves precision and boundary behavior at 0.1%. |
| src/documentdb/queryInsights/staticAnalysisSummary.ts | Updates static summary to format numeric selectivity for inclusion in Stage 3 prompt context. |
| src/documentdb/queryInsights/staticAnalysisSummary.test.ts | Updates tests to reflect numeric selectivity in the Stage 2 response shape. |
| l10n/bundle.l10n.json | Adds localization entry for below {0}%. |
|
@copilot review my replies to the comments left by copilot reviewer and apply them as instructed. in case they reviewer comments are outdated, explain what has changed to the core of the issue flagged by these comments. |
Applied your requested follow-ups. Addressed in
Status of reviewer threads:
|
✅ Code Quality Checks
This comment is updated automatically on each push. |
📦 Build Size Report
Download artifact · updated automatically on each push. |
|
@microsoft-github-policy-service rerun |
For selectivity values that are greater than 0 but less than 0.1%, instead of rounding to
0.0%(which is misleading), we now display a threshold label — e.g.below 0.1%— formatted using the user's locale so the decimal separator is correct (e.g.below 0,1%in German).Tests that asserted exact locale-specific strings like
"5.0%"have been updated to compute expected values using the sametoLocaleStringcall as the production code, so they pass correctly under any locale.