Skip to content

kishore09876/sql-statistics-parser

Repository files navigation

SQL Statistics Parser

A VS Code extension for analysing SET STATISTICS IO and SET STATISTICS TIME output from SQL Server. Paste raw output from SSMS or Azure Data Studio and get an instant, prioritised breakdown of which tables are costing the most — and what to do about it. Or run queries directly from VS Code with the live connection and get results, statistics, and plan analysis in one panel.


How to use

  1. Run your query in SSMS or Azure Data Studio with SET STATISTICS IO, TIME ON
  2. Copy the output from the Messages pane
  3. In VS Code, open a file containing the output (or select the text)
  4. Run SQL: Parse Statistics from the Command Palette or right-click menu — it auto-detects whether the selection is IO/TIME text or ShowPlanXML
  5. The results panel opens beside your editor

Statistics Panel

The Statistics panel is shown when parsing manually pasted output, or as the Statistics tab in the live connection result panel.

Metric badges

A row of pill badges at the top gives an at-a-glance summary:

Badge What it shows
Elapsed Total elapsed time in ms
CPU Total CPU time in ms
Tables Number of tables touched
Logical reads Total logical reads (with delta vs last run if available)
Physical reads Shown in orange — disk I/O detected
Read-ahead Pre-fetch reads (signals sequential scan)
Cache hit (logical − physical) / logical × 100% — green ≥ 95 %, yellow ≥ 80 %, red below

Key Issues callouts

Appears automatically when thresholds are exceeded. Each entry names one issue (Logical Reads, Physical Reads, Scan Count, Read-Ahead) and gives:

  • What is likely causing it
  • What to do about it

No raw numbers in the callouts — those are in the table rows below. The callouts are purely diagnostic.

Priority View (default)

Tables sorted by severity score, worst first. Each row shows:

  • Rank badge coloured by severity
  • Access method badge from the execution plan (e.g. Index Seek, Table Scan)
  • Inline stats: Logical, % of Total, Scans, Physical, Read-Ahead
  • Expand the row to see all six metrics with sub-labels

Severity filter pills — Critical / High / Medium / Low / OK. Click a pill to filter to just that severity; click again to clear.

Table View

Click Table View in the toggle above the list to switch to a flat, sortable table of every table touched. Click any column header to sort:

  • Logical Reads (default, descending)
  • Physical Reads
  • Scan Count
  • Read-Ahead
  • LOB Reads
  • % of Total
  • Severity

Each Logical Reads cell includes an inline bar scaled to the highest-read table. Totals row is pinned at the bottom.


Standalone Parse View (paste mode)

When parsing manually pasted statistics output the panel has four tabs:

Summary tab

Key Issues banner, severity pills, and expandable per-table rows — same as Priority View above.

Details tab

Sortable flat table of all tables. Same columns as Table View above.

Charts tab

Vertical bar chart of all tables by IO metric. Toggle between Logical Reads, Physical Reads, and Scan Count. Bars are coloured by severity.

Compare tab

Paste before statistics (before the optimisation) and click Compare. The current result is treated as after.

  • Summary banner shows overall Logical Reads, Physical Reads, and Scan Count change
  • Changed tables shown with dual before/after bars for each metric that changed
  • Unchanged tables collapsed in a separate section

Plan Tab

Available in the live connection result panel when an execution plan is captured (SET STATISTICS XML ON). Also accessible standalone by running SQL: Parse Statistics on a ShowPlanXML document — the command detects plan XML automatically.

Seek / Scan / Lookup ratio strip

A colour-coded horizontal bar at the top of the Plan tab shows the proportion of operators by category:

  • Green — Index Seek / Clustered Index Seek
  • Red — Table Scan / Index Scan
  • Orange — Key Lookup

A plan dominated by green seeks is healthy. Scans and lookups are the primary targets for index optimisation.

Key Lookup callout

When any Key Lookup operator is detected, a highlighted callout explains the fix: add the missing columns to the non-clustered index as INCLUDE columns to eliminate the extra clustered index access and reduce logical reads significantly.

Top Operators by Cost

A table of the most expensive operators, sorted by cost percentage:

Column Description
Operator Physical operator with colour-coded badge (green = seek, red = scan, orange = lookup)
Table Table or index the operator accesses
Cost % Share of total query cost with an inline bar
Est Rows Optimizer's row estimate
Act Rows Actual rows at runtime (requires STATISTICS XML ON at runtime)
Est Error Ratio of actual to estimated: Nx under or Nx over, coloured red ≥ 10×, orange ≥ 3×, yellow otherwise

Plan Warnings

Each warning is shown with a description of what it means and what to do:

Warning Meaning
Implicit Conversion Data type mismatch on every row — prevents index seeks, forces full scans. Fix the parameter or column type.
Spill to TempDB Operator ran out of its memory grant and spilled to disk. Reduce sort/hash input size or update statistics.
No Join Predicate A join with no ON clause — cross product producing N×M rows.

Missing Index Recommendations

Index recommendations from the query optimizer appear in the Plan tab with estimated improvement percentage and a copyable CREATE INDEX DDL statement.


Execution Plan Diagram

Run SQL: Parse Statistics with a ShowPlanXML document open or selected.

  • SVG tree diagram, left-to-right layout with bezier connector lines
  • Each node shows: operator name, cost %, estimated vs actual rows, table/index name
  • Colour-coded by cost severity with glow on critical nodes
  • Pan (drag) and zoom (scroll wheel), fit-to-view on load
  • Tabs: Diagram · Top Operations · Missing Indexes · Warnings

SQL Editor Decorations

After a parse, table names in open .sql files get inline annotations on the lines where they appear:

  • ⚠ 1.2M reads — critical (> 200 k logical reads)
  • ↑ 450K reads — high (> 100 k)
  • · 75K reads — medium (> 50 k)

Hover for full detail. Annotations update on each parse.


Inlay Hints

After a parse, .sql files show read counts as inlay hints next to table names in the editor. Requires editor.inlayHints.enabled in VS Code settings.


Export

Export any parsed result from the Command Palette:

  • SQL: Export Statistics as CSV
  • SQL: Export Statistics as JSON
  • SQL: Export Statistics as Markdown

Run History

Every parse is saved automatically (up to 50 entries). Run SQL: Show Run History to review past runs with timestamp, severity, top table, and total reads. Select two entries and click Compare Selected to diff them.


Live SQL Server Connection

Run SQL: Run with Live Connection to execute a query directly from VS Code. The result panel shows three tabs:

  • Results — query result set with sortable columns and CSV / JSON copy
  • Statistics — IO and time statistics with Priority / Table view toggle, callouts, and cache hit rate
  • Plan — seek/scan strip, Key Lookup detection, top operators with row estimate error, warnings, and missing index DDL

Connection management

Connections are saved profiles picked from a quick-pick list, with inline Edit and Delete buttons per entry. The connection editor supports:

  • Authentication: SQL Server (username + password), Windows (current user), Azure AD — VS Code Sign-in (interactive, no password stored), Azure AD Password (legacy, no MFA)
  • Encrypt and Trust server certificate toggles
  • Test Connection button to validate settings before saving

Azure AD interactive sign-in reuses your VS Code Microsoft account session and acquires a fresh access token per run — nothing beyond SQL/Windows credentials is written to disk.

Known limitation: Live connection stability varies by environment. Manual paste is recommended for reliable results.


Requirements

  • VS Code 1.85.0 +
  • SQL Server statistics output (SET STATISTICS IO, TIME ON)
  • For plan analysis: SET STATISTICS XML ON output in ShowPlanXML format
  • For live connections: SQL Server reachable from your machine (SQL auth, Windows auth, or Azure AD)

Extension Settings

Setting Default Description
sqlStatisticsParser.liveConnection.enabled false Enable the SQL: Run with Live Connection command. Set to true once a server connection is configured.

Connection credentials are stored via VS Code SecretStorage — never written to disk in plain text.


What is not yet supported

Feature Status
Graphical .sqlplan file format Not supported — use ShowPlanXML text output
Visual diff UI in Run History Planned
Live connection stability Known issues — prefer manual paste
Multiple simultaneous plan panels Single plan panel only

Changelog

1.0.1

Statistics panel:

  • Replaced separate "Details" sub-tab with an inline Priority / Table view toggle — one panel, two view modes
  • Removed "Per Statement" sub-tab (data is visible in the aggregate priority list)
  • Removed "Indexes" sub-tab from Statistics — index recommendations consolidated into the Plan tab
  • Added Cache Hit Rate badge: (logical − physical) / logical × 100% coloured by threshold (green / yellow / red)

Plan tab (live connection):

  • Added Seek / Scan / Lookup ratio strip — instant visual read on whether the plan is index-friendly
  • Added Key Lookup callout — fires whenever a Key Lookup operator is detected; explains the INCLUDE column fix
  • Expanded Top Operators table with separate Est Rows, Act Rows, and Est Error columns (ratio of actual to estimated rows, colour-coded by severity)
  • Expanded Plan Warnings with actionable descriptions per warning type (Implicit Conversion, Spill to TempDB, No Join Predicate)
  • Missing Index recommendations moved here from the Statistics Indexes sub-tab; copyable CREATE INDEX DDL
  • Added .op-lookup badge style (orange) distinct from scan (red) and seek (green)

Live connection:

  • Added Azure AD authentication — interactive VS Code Microsoft sign-in (token acquired per run, nothing stored) and legacy Azure AD username/password
  • Added Test Connection button and Encrypt / Trust server certificate toggles to the connection editor
  • Connection quick-pick now supports inline Edit and Delete per saved profile

Commands:

  • Merged SQL: Parse Statistics IO/Time Output and SQL: Parse Execution Plan XML into a single SQL: Parse Statistics command that auto-detects ShowPlanXML vs. IO/TIME text

1.0.0

Initial release.

Parser & UI: Multi-statement IO/TIME parser. Summary tab with key-issues diagnostic banner, severity filter pills, expandable metric rows. Sortable Details table with inline bars. Vertical bar chart with metric toggle. Before/after Compare tab with dual-bar visualisation.

Editor integration: Inline read-count decorations on SQL file table references. Inlay hints.

Plan viewer: SVG plan tree with pan/zoom, missing index DDL, operator warnings.

Tooling: CSV/JSON/Markdown export, run history, live connection (experimental).

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors