Problem
The query plan download buttons in the drill-down windows (QueryStatsHistoryWindow, QueryStoreHistoryWindow) go directly to the live SQL Server to fetch plans:
- Query Stats:
FetchQueryPlanOnDemandAsync() → sys.dm_exec_query_stats + dm_exec_text_query_plan() by query_hash
- Query Store:
FetchQueryStorePlanAsync() → Query Store by plan_id
Meanwhile, we already collect and store query_plan_xml in the query_stats DuckDB table during every collection cycle. This data persists in DuckDB hot tables and in Parquet archives — but the download button completely ignores it.
Impact
If a plan gets evicted from the plan cache between collection and when the user clicks "Download," they get "Plan Not Found" despite us having a perfectly good copy in DuckDB. The plan cache is notoriously unstable — memory pressure, recompiles, and service restarts all evict plans.
Proposed Fix
- Download button tries DuckDB first (lookup by
query_hash / plan_id in v_query_stats / v_query_store_stats)
- If DuckDB has the plan XML, use it immediately — no network round-trip needed
- Only fall back to the live server if DuckDB doesn't have the plan (e.g., newly compiled query not yet collected)
- Consider showing the source in the save dialog or status: "Plan from collected data" vs "Plan from live server"
Files
Lite/Windows/QueryStatsHistoryWindow.xaml.cs — DownloadPlan_Click (line ~122)
Lite/Windows/QueryStoreHistoryWindow.xaml.cs — DownloadPlan_Click (line ~122)
Lite/Services/LocalDataService.QueryStats.cs — FetchQueryPlanOnDemandAsync (line ~235), already stores query_plan_xml in grid query
Problem
The query plan download buttons in the drill-down windows (
QueryStatsHistoryWindow,QueryStoreHistoryWindow) go directly to the live SQL Server to fetch plans:FetchQueryPlanOnDemandAsync()→sys.dm_exec_query_stats+dm_exec_text_query_plan()byquery_hashFetchQueryStorePlanAsync()→ Query Store byplan_idMeanwhile, we already collect and store
query_plan_xmlin thequery_statsDuckDB table during every collection cycle. This data persists in DuckDB hot tables and in Parquet archives — but the download button completely ignores it.Impact
If a plan gets evicted from the plan cache between collection and when the user clicks "Download," they get "Plan Not Found" despite us having a perfectly good copy in DuckDB. The plan cache is notoriously unstable — memory pressure, recompiles, and service restarts all evict plans.
Proposed Fix
query_hash/plan_idinv_query_stats/v_query_store_stats)Files
Lite/Windows/QueryStatsHistoryWindow.xaml.cs—DownloadPlan_Click(line ~122)Lite/Windows/QueryStoreHistoryWindow.xaml.cs—DownloadPlan_Click(line ~122)Lite/Services/LocalDataService.QueryStats.cs—FetchQueryPlanOnDemandAsync(line ~235), already storesquery_plan_xmlin grid query