-
Notifications
You must be signed in to change notification settings - Fork 21
Query Insights: compute numeric selectivity and render low non-zero values as “below 0.1%” #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
50f9716
Initial plan
Copilot 38daba6
Handle low selectivity display in query insights
Copilot ea9927a
Add localization string for low selectivity label
Copilot 233621c
Refactor selectivity to numeric model
Copilot 4fdceb9
Fix selectivity formatting types and summary output
Copilot fa6d889
Align selectivity comments and summary threshold formatting
Copilot 38212db
Document selectivity summary formatter behavior
Copilot 943db28
comments added
tnaum-ms 8ca7c8e
Enhance selectivity display by localizing numeric formatting and thre…
tnaum-ms 3bafb4c
Refactor selectivity formatting tests to use locale-agnostic helper f…
tnaum-ms 48a8bb8
fix: l10n
tnaum-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { type ExecutionStatsAnalysis } from './ExplainPlanAnalyzer'; | ||
| import { transformStage2Response } from './transformations'; | ||
|
|
||
| function createExecutionStatsAnalysis(overrides: Partial<ExecutionStatsAnalysis> = {}): ExecutionStatsAnalysis { | ||
| return { | ||
| executionTimeMillis: 12, | ||
| totalDocsExamined: 1, | ||
| totalKeysExamined: 1, | ||
| nReturned: 1, | ||
| efficiencyRatio: 1, | ||
| usedIndexes: ['idx_a'], | ||
| isCollectionScan: false, | ||
| isCovered: false, | ||
| hasInMemorySort: false, | ||
| isIndexScan: true, | ||
| performanceRating: { | ||
| score: 'excellent', | ||
| diagnostics: [], | ||
| }, | ||
| rawStats: {}, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe('transformStage2Response - selectivity formatting', () => { | ||
| it('preserves precision below 0.1% for non-zero selectivity', () => { | ||
| const analyzed = createExecutionStatsAnalysis({ | ||
| nReturned: 1, | ||
| }); | ||
|
|
||
| const result = transformStage2Response(analyzed, 12_000); | ||
|
|
||
| expect(result.efficiencyAnalysis.selectivity).toBe('0.008%'); | ||
| }); | ||
|
|
||
| it('keeps one-decimal formatting for selectivity at or above 0.1%', () => { | ||
| const analyzed = createExecutionStatsAnalysis({ | ||
| nReturned: 1, | ||
| }); | ||
|
|
||
| const result = transformStage2Response(analyzed, 1_000); | ||
|
|
||
| expect(result.efficiencyAnalysis.selectivity).toBe('0.1%'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/webviews/documentdb/collectionView/utils/formatSelectivityForDisplay.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { formatSelectivityForDisplay } from './formatSelectivityForDisplay'; | ||
|
|
||
| describe('formatSelectivityForDisplay', () => { | ||
| const belowThresholdText = 'below 0.1%'; | ||
|
|
||
| it('returns threshold text for non-zero selectivity below 0.1%', () => { | ||
| expect(formatSelectivityForDisplay('0.02%', belowThresholdText)).toBe(belowThresholdText); | ||
| expect(formatSelectivityForDisplay('0.008%', belowThresholdText)).toBe(belowThresholdText); | ||
| }); | ||
|
|
||
| it('preserves values at or above 0.1%', () => { | ||
| expect(formatSelectivityForDisplay('0.1%', belowThresholdText)).toBe('0.1%'); | ||
| expect(formatSelectivityForDisplay('5.0%', belowThresholdText)).toBe('5.0%'); | ||
| }); | ||
|
|
||
| it('preserves zero and unavailable values', () => { | ||
| expect(formatSelectivityForDisplay('0.0%', belowThresholdText)).toBe('0.0%'); | ||
| expect(formatSelectivityForDisplay(null, belowThresholdText)).toBeNull(); | ||
| expect(formatSelectivityForDisplay(undefined, belowThresholdText)).toBeUndefined(); | ||
| }); | ||
| }); |
30 changes: 30 additions & 0 deletions
30
src/webviews/documentdb/collectionView/utils/formatSelectivityForDisplay.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| /** | ||
| * Formats selectivity for UI display. | ||
| * | ||
| * For very low non-zero percentages (< 0.1%), we show a threshold label | ||
| * instead of a rounded numeric value. | ||
| */ | ||
| export function formatSelectivityForDisplay( | ||
| selectivity: string | null | undefined, | ||
| belowThresholdLabel: string, | ||
| ): string | null | undefined { | ||
| if (!selectivity) { | ||
| return selectivity; | ||
| } | ||
|
|
||
| const selectivityPercent = Number.parseFloat(selectivity); | ||
| if (Number.isNaN(selectivityPercent)) { | ||
| return selectivity; | ||
| } | ||
|
|
||
| if (selectivityPercent > 0 && selectivityPercent < 0.1) { | ||
| return belowThresholdLabel; | ||
| } | ||
|
|
||
| return selectivity; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.