Skip to content

Query Insights: compute numeric selectivity and render low non-zero values as “below 0.1%”#763

Merged
tnaum-ms merged 11 commits into
mainfrom
copilot/fix-selectivity-display-issue
Jun 29, 2026
Merged

Query Insights: compute numeric selectivity and render low non-zero values as “below 0.1%”#763
tnaum-ms merged 11 commits into
mainfrom
copilot/fix-selectivity-display-issue

Conversation

Copilot AI commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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 same toLocaleString call as the production code, so they pass correctly under any locale.

Copilot AI changed the title [WIP] Fix Query Insights selectivity display for low ratios Query Insights: render low non-zero selectivity as “below 0.1%” Jun 26, 2026
Copilot AI requested a review from tnaum-ms June 26, 2026 15:45
isCoveringQuery: analyzed.isCovered,
concerns,
efficiencyAnalysis: {
selectivity: computeSelectivity(analyzed.nReturned, totalCollectionDocs),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 233621c and follow-up fix 4fdceb9. Selectivity is now a number | null from computation/transform, and formatting is handled in the webview presentation utility (below 0.1% or toFixed(1)), with telemetry and tests updated accordingly.

@tnaum-ms tnaum-ms marked this pull request as ready for review June 26, 2026 17:27
@tnaum-ms tnaum-ms requested a review from a team as a code owner June 26, 2026 17:27
Copilot AI review requested due to automatic review settings June 26, 2026 17:27
Copilot AI changed the title Query Insights: render low non-zero selectivity as “below 0.1%” Query Insights: compute numeric selectivity and render low non-zero values as “below 0.1%” Jun 26, 2026
Copilot AI requested a review from tnaum-ms June 26, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.selectivity from a percent string to a number | null percent value.
  • Added formatSelectivityForDisplay() and updated QueryInsightsTab to 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}%.

Comment thread src/documentdb/queryInsights/transformations.ts
Comment thread src/documentdb/queryInsights/staticAnalysisSummary.ts
@tnaum-ms

Copy link
Copy Markdown
Collaborator

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

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

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

Applied your requested follow-ups.

Addressed in fa6d889 and 38212db:

  • Updated stale selectivity comments to reflect raw numeric precision (no one-decimal implication).
  • Updated static analysis summary formatting to match UI threshold behavior (below 0.1% for 0 < x < 0.1).
  • Added coverage for the low non-zero threshold case in static summary tests.

Status of reviewer threads:

  • Numeric selectivity/model separation was already implemented earlier (233621c / 4fdceb9), so that core issue is no longer current.
  • The static summary drift concern is now fixed with the same threshold rule.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Code Quality Checks

Check Status How to fix
Localization (l10n) ✅ Passed
ESLint ✅ Passed
Prettier formatting ✅ Passed

This comment is updated automatically on each push.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Size Report

Metric Base (main) PR Delta
VSIX (vscode-documentdb-0.9.1.vsix) 8.01 MB 8.01 MB ⬆️ +0 KB (+0.0%)
Webview bundle (views.js) 5.88 MB 5.88 MB ⬆️ +0 KB (+0.0%)

Download artifact · updated automatically on each push.

@tnaum-ms tnaum-ms enabled auto-merge June 29, 2026 13:43
@tnaum-ms

Copy link
Copy Markdown
Collaborator

@microsoft-github-policy-service rerun

@tnaum-ms tnaum-ms merged commit c0b5be1 into main Jun 29, 2026
8 checks passed
@tnaum-ms tnaum-ms deleted the copilot/fix-selectivity-display-issue branch June 29, 2026 14:46
@tnaum-ms tnaum-ms added this to the 0.9.2 milestone Jun 29, 2026
@tnaum-ms tnaum-ms linked an issue Jun 29, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query Insights shows Selectivity at 0% for low selectivity ratios

4 participants