Skip to content

Download plan button should use stored DuckDB copy before falling back to live server #219

@erikdarlingdata

Description

@erikdarlingdata

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

  1. Download button tries DuckDB first (lookup by query_hash / plan_id in v_query_stats / v_query_store_stats)
  2. If DuckDB has the plan XML, use it immediately — no network round-trip needed
  3. Only fall back to the live server if DuckDB doesn't have the plan (e.g., newly compiled query not yet collected)
  4. Consider showing the source in the save dialog or status: "Plan from collected data" vs "Plan from live server"

Files

  • Lite/Windows/QueryStatsHistoryWindow.xaml.csDownloadPlan_Click (line ~122)
  • Lite/Windows/QueryStoreHistoryWindow.xaml.csDownloadPlan_Click (line ~122)
  • Lite/Services/LocalDataService.QueryStats.csFetchQueryPlanOnDemandAsync (line ~235), already stores query_plan_xml in grid query

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions