Skip to content

Commit be88ec8

Browse files
committed
In BuildGroupedRows, after building the leaf children for each intermediate row, the code now picks the QueryText from the top representative leaf row (the one with IsTopRepresentative == true, falling back to the first available leaf) and assigns it to the parent's QueryStorePlan.QueryText. This is done at two levels:
1. Intermediate rows (PlanHash in QueryHash mode, QueryHash in Module mode): Gets the query text from the top representative leaf within that specific group. 2. Root rows (QueryHash level, Module level): Gets the query text from the top representative leaf across all leaves in that root group. No additional database queries are made — the text comes entirely from grouped.LeafRows which was already fetched.
1 parent 8b25fee commit be88ec8

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/PlanViewer.App/Controls/QueryStoreGridControl.axaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ private List<QueryStoreRow> BuildGroupedRows(QueryStoreGroupedResult grouped)
473473
leafChildren = leafChildren.OrderByDescending(r => metricAccessor(r)).ToList();
474474

475475
var midPlan = GroupedRowToPlan(mid);
476+
// Populate QueryText from the top representative leaf for this plan hash
477+
var topLeafForMid = leaves.FirstOrDefault(l => l.IsTopRepresentative) ?? leaves.FirstOrDefault();
478+
if (topLeafForMid != null && !string.IsNullOrEmpty(topLeafForMid.QueryText))
479+
midPlan.QueryText = topLeafForMid.QueryText;
476480
midChildren.Add(new QueryStoreRow(midPlan, 1, mid.QueryPlanHash, leafChildren));
477481
}
478482

@@ -481,6 +485,13 @@ private List<QueryStoreRow> BuildGroupedRows(QueryStoreGroupedResult grouped)
481485

482486
// Aggregate metrics at QueryHash level
483487
var aggPlan = AggregateGroupedRows(intermediateRows, qhKey, intermediateRows.FirstOrDefault()?.ModuleName ?? "");
488+
// Populate QueryText from the top representative leaf across all leaves in this query hash group
489+
var topLeafForRoot = grouped.LeafRows
490+
.Where(l => l.QueryHash == qhKey && l.IsTopRepresentative && !string.IsNullOrEmpty(l.QueryText))
491+
.FirstOrDefault()
492+
?? grouped.LeafRows.FirstOrDefault(l => l.QueryHash == qhKey && !string.IsNullOrEmpty(l.QueryText));
493+
if (topLeafForRoot != null)
494+
aggPlan.QueryText = topLeafForRoot.QueryText;
484495
roots.Add(new QueryStoreRow(aggPlan, 0, qhKey, midChildren));
485496
}
486497
}
@@ -516,6 +527,10 @@ private List<QueryStoreRow> BuildGroupedRows(QueryStoreGroupedResult grouped)
516527
leafChildren = leafChildren.OrderByDescending(r => metricAccessor(r)).ToList();
517528

518529
var midPlan = GroupedRowToPlan(mid);
530+
// Populate QueryText from the top representative leaf for this query hash
531+
var topLeafForMid = leaves.FirstOrDefault(l => l.IsTopRepresentative) ?? leaves.FirstOrDefault();
532+
if (topLeafForMid != null && !string.IsNullOrEmpty(topLeafForMid.QueryText))
533+
midPlan.QueryText = topLeafForMid.QueryText;
519534
midChildren.Add(new QueryStoreRow(midPlan, 1, mid.QueryHash, leafChildren));
520535
}
521536

@@ -524,6 +539,13 @@ private List<QueryStoreRow> BuildGroupedRows(QueryStoreGroupedResult grouped)
524539

525540
// Aggregate metrics at Module level
526541
var aggPlan = AggregateGroupedRows(intermediateRows, "", modKey);
542+
// Populate QueryText from the top representative leaf across all leaves in this module group
543+
var topLeafForRoot = grouped.LeafRows
544+
.Where(l => l.ModuleName == modKey && l.IsTopRepresentative && !string.IsNullOrEmpty(l.QueryText))
545+
.FirstOrDefault()
546+
?? grouped.LeafRows.FirstOrDefault(l => l.ModuleName == modKey && !string.IsNullOrEmpty(l.QueryText));
547+
if (topLeafForRoot != null)
548+
aggPlan.QueryText = topLeafForRoot.QueryText;
527549
roots.Add(new QueryStoreRow(aggPlan, 0, modKey, midChildren));
528550
}
529551
}

0 commit comments

Comments
 (0)