@@ -76,9 +76,13 @@ static void show_sort_keys(SortState *sortstate, List *ancestors,
7676ExplainState * es );
7777static void show_merge_append_keys (MergeAppendState * mstate ,List * ancestors ,
7878ExplainState * es );
79- static void show_sort_keys_common (PlanState * planstate ,
80- int nkeys ,AttrNumber * keycols ,
81- List * ancestors ,ExplainState * es );
79+ static void show_agg_keys (AggState * astate ,List * ancestors ,
80+ ExplainState * es );
81+ static void show_group_keys (GroupState * gstate ,List * ancestors ,
82+ ExplainState * es );
83+ static void show_sort_group_keys (PlanState * planstate ,const char * qlabel ,
84+ int nkeys ,AttrNumber * keycols ,
85+ List * ancestors ,ExplainState * es );
8286static void show_sort_info (SortState * sortstate ,ExplainState * es );
8387static void show_hash_info (HashState * hashstate ,ExplainState * es );
8488static void show_instrumentation_count (const char * qlabel ,int which ,
@@ -1341,7 +1345,14 @@ ExplainNode(PlanState *planstate, List *ancestors,
13411345planstate ,es );
13421346break ;
13431347case T_Agg :
1348+ show_agg_keys ((AggState * )planstate ,ancestors ,es );
1349+ show_upper_qual (plan -> qual ,"Filter" ,planstate ,ancestors ,es );
1350+ if (plan -> qual )
1351+ show_instrumentation_count ("Rows Removed by Filter" ,1 ,
1352+ planstate ,es );
1353+ break ;
13441354case T_Group :
1355+ show_group_keys ((GroupState * )planstate ,ancestors ,es );
13451356show_upper_qual (plan -> qual ,"Filter" ,planstate ,ancestors ,es );
13461357if (plan -> qual )
13471358show_instrumentation_count ("Rows Removed by Filter" ,1 ,
@@ -1693,9 +1704,9 @@ show_sort_keys(SortState *sortstate, List *ancestors, ExplainState *es)
16931704{
16941705Sort * plan = (Sort * )sortstate -> ss .ps .plan ;
16951706
1696- show_sort_keys_common ((PlanState * )sortstate ,
1697- plan -> numCols ,plan -> sortColIdx ,
1698- ancestors ,es );
1707+ show_sort_group_keys ((PlanState * )sortstate , "Sort Key" ,
1708+ plan -> numCols ,plan -> sortColIdx ,
1709+ ancestors ,es );
16991710}
17001711
17011712/*
@@ -1707,14 +1718,56 @@ show_merge_append_keys(MergeAppendState *mstate, List *ancestors,
17071718{
17081719MergeAppend * plan = (MergeAppend * )mstate -> ps .plan ;
17091720
1710- show_sort_keys_common ((PlanState * )mstate ,
1711- plan -> numCols ,plan -> sortColIdx ,
1712- ancestors ,es );
1721+ show_sort_group_keys ((PlanState * )mstate , "Sort Key" ,
1722+ plan -> numCols ,plan -> sortColIdx ,
1723+ ancestors ,es );
17131724}
17141725
1726+ /*
1727+ * Show the grouping keys for an Agg node.
1728+ */
1729+ static void
1730+ show_agg_keys (AggState * astate ,List * ancestors ,
1731+ ExplainState * es )
1732+ {
1733+ Agg * plan = (Agg * )astate -> ss .ps .plan ;
1734+
1735+ if (plan -> numCols > 0 )
1736+ {
1737+ /* The key columns refer to the tlist of the child plan */
1738+ ancestors = lcons (astate ,ancestors );
1739+ show_sort_group_keys (outerPlanState (astate ),"Group Key" ,
1740+ plan -> numCols ,plan -> grpColIdx ,
1741+ ancestors ,es );
1742+ ancestors = list_delete_first (ancestors );
1743+ }
1744+ }
1745+
1746+ /*
1747+ * Show the grouping keys for a Group node.
1748+ */
1749+ static void
1750+ show_group_keys (GroupState * gstate ,List * ancestors ,
1751+ ExplainState * es )
1752+ {
1753+ Group * plan = (Group * )gstate -> ss .ps .plan ;
1754+
1755+ /* The key columns refer to the tlist of the child plan */
1756+ ancestors = lcons (gstate ,ancestors );
1757+ show_sort_group_keys (outerPlanState (gstate ),"Group Key" ,
1758+ plan -> numCols ,plan -> grpColIdx ,
1759+ ancestors ,es );
1760+ ancestors = list_delete_first (ancestors );
1761+ }
1762+
1763+ /*
1764+ * Common code to show sort/group keys, which are represented in plan nodes
1765+ * as arrays of targetlist indexes
1766+ */
17151767static void
1716- show_sort_keys_common (PlanState * planstate ,int nkeys ,AttrNumber * keycols ,
1717- List * ancestors ,ExplainState * es )
1768+ show_sort_group_keys (PlanState * planstate ,const char * qlabel ,
1769+ int nkeys ,AttrNumber * keycols ,
1770+ List * ancestors ,ExplainState * es )
17181771{
17191772Plan * plan = planstate -> plan ;
17201773List * context ;
@@ -1748,7 +1801,7 @@ show_sort_keys_common(PlanState *planstate, int nkeys, AttrNumber *keycols,
17481801result = lappend (result ,exprstr );
17491802}
17501803
1751- ExplainPropertyList ("Sort Key" ,result ,es );
1804+ ExplainPropertyList (qlabel ,result ,es );
17521805}
17531806
17541807/*