@@ -120,7 +120,8 @@ static void show_sort_group_keys(PlanState *planstate, const char *qlabel,
120
120
List * ancestors , ExplainState * es );
121
121
static void show_sortorder_options (StringInfo buf , Node * sortexpr ,
122
122
Oid sortOperator , Oid collation , bool nullsFirst );
123
- static void show_storage_info (Tuplestorestate * tupstore , ExplainState * es );
123
+ static void show_storage_info (char * maxStorageType , int64 maxSpaceUsed ,
124
+ ExplainState * es );
124
125
static void show_tablesample (TableSampleClause * tsc , PlanState * planstate ,
125
126
List * ancestors , ExplainState * es );
126
127
static void show_sort_info (SortState * sortstate , ExplainState * es );
@@ -129,6 +130,11 @@ static void show_incremental_sort_info(IncrementalSortState *incrsortstate,
129
130
static void show_hash_info (HashState * hashstate , ExplainState * es );
130
131
static void show_material_info (MaterialState * mstate , ExplainState * es );
131
132
static void show_windowagg_info (WindowAggState * winstate , ExplainState * es );
133
+ static void show_ctescan_info (CteScanState * ctescanstate , ExplainState * es );
134
+ static void show_table_func_scan_info (TableFuncScanState * tscanstate ,
135
+ ExplainState * es );
136
+ static void show_recursive_union_info (RecursiveUnionState * rstate ,
137
+ ExplainState * es );
132
138
static void show_memoize_info (MemoizeState * mstate , List * ancestors ,
133
139
ExplainState * es );
134
140
static void show_hashagg_info (AggState * aggstate , ExplainState * es );
@@ -2046,6 +2052,8 @@ ExplainNode(PlanState *planstate, List *ancestors,
2046
2052
if (plan -> qual )
2047
2053
show_instrumentation_count ("Rows Removed by Filter" , 1 ,
2048
2054
planstate , es );
2055
+ if (IsA (plan , CteScan ))
2056
+ show_ctescan_info (castNode (CteScanState , planstate ), es );
2049
2057
break ;
2050
2058
case T_Gather :
2051
2059
{
@@ -2127,6 +2135,8 @@ ExplainNode(PlanState *planstate, List *ancestors,
2127
2135
if (plan -> qual )
2128
2136
show_instrumentation_count ("Rows Removed by Filter" , 1 ,
2129
2137
planstate , es );
2138
+ show_table_func_scan_info (castNode (TableFuncScanState ,
2139
+ planstate ), es );
2130
2140
break ;
2131
2141
case T_TidScan :
2132
2142
{
@@ -2278,6 +2288,10 @@ ExplainNode(PlanState *planstate, List *ancestors,
2278
2288
show_memoize_info (castNode (MemoizeState , planstate ), ancestors ,
2279
2289
es );
2280
2290
break ;
2291
+ case T_RecursiveUnion :
2292
+ show_recursive_union_info (castNode (RecursiveUnionState ,
2293
+ planstate ), es );
2294
+ break ;
2281
2295
default :
2282
2296
break ;
2283
2297
}
@@ -2901,14 +2915,9 @@ show_sortorder_options(StringInfo buf, Node *sortexpr,
2901
2915
* Show information on storage method and maximum memory/disk space used.
2902
2916
*/
2903
2917
static void
2904
- show_storage_info (Tuplestorestate * tupstore , ExplainState * es )
2918
+ show_storage_info (char * maxStorageType , int64 maxSpaceUsed , ExplainState * es )
2905
2919
{
2906
- char * maxStorageType ;
2907
- int64 maxSpaceUsed ,
2908
- maxSpaceUsedKB ;
2909
-
2910
- tuplestore_get_stats (tupstore , & maxStorageType , & maxSpaceUsed );
2911
- maxSpaceUsedKB = BYTES_TO_KILOBYTES (maxSpaceUsed );
2920
+ int64 maxSpaceUsedKB = BYTES_TO_KILOBYTES (maxSpaceUsed );
2912
2921
2913
2922
if (es -> format != EXPLAIN_FORMAT_TEXT )
2914
2923
{
@@ -3380,6 +3389,9 @@ show_hash_info(HashState *hashstate, ExplainState *es)
3380
3389
static void
3381
3390
show_material_info (MaterialState * mstate , ExplainState * es )
3382
3391
{
3392
+ char * maxStorageType ;
3393
+ int64 maxSpaceUsed ;
3394
+
3383
3395
Tuplestorestate * tupstore = mstate -> tuplestorestate ;
3384
3396
3385
3397
/*
@@ -3389,7 +3401,8 @@ show_material_info(MaterialState *mstate, ExplainState *es)
3389
3401
if (!es -> analyze || tupstore == NULL )
3390
3402
return ;
3391
3403
3392
- show_storage_info (tupstore , es );
3404
+ tuplestore_get_stats (tupstore , & maxStorageType , & maxSpaceUsed );
3405
+ show_storage_info (maxStorageType , maxSpaceUsed , es );
3393
3406
}
3394
3407
3395
3408
/*
@@ -3399,6 +3412,9 @@ show_material_info(MaterialState *mstate, ExplainState *es)
3399
3412
static void
3400
3413
show_windowagg_info (WindowAggState * winstate , ExplainState * es )
3401
3414
{
3415
+ char * maxStorageType ;
3416
+ int64 maxSpaceUsed ;
3417
+
3402
3418
Tuplestorestate * tupstore = winstate -> buffer ;
3403
3419
3404
3420
/*
@@ -3408,7 +3424,78 @@ show_windowagg_info(WindowAggState *winstate, ExplainState *es)
3408
3424
if (!es -> analyze || tupstore == NULL )
3409
3425
return ;
3410
3426
3411
- show_storage_info (tupstore , es );
3427
+ tuplestore_get_stats (tupstore , & maxStorageType , & maxSpaceUsed );
3428
+ show_storage_info (maxStorageType , maxSpaceUsed , es );
3429
+ }
3430
+
3431
+ /*
3432
+ * Show information on CTE Scan node, storage method and maximum memory/disk
3433
+ * space used.
3434
+ */
3435
+ static void
3436
+ show_ctescan_info (CteScanState * ctescanstate , ExplainState * es )
3437
+ {
3438
+ char * maxStorageType ;
3439
+ int64 maxSpaceUsed ;
3440
+
3441
+ Tuplestorestate * tupstore = ctescanstate -> leader -> cte_table ;
3442
+
3443
+ if (!es -> analyze || tupstore == NULL )
3444
+ return ;
3445
+
3446
+ tuplestore_get_stats (tupstore , & maxStorageType , & maxSpaceUsed );
3447
+ show_storage_info (maxStorageType , maxSpaceUsed , es );
3448
+ }
3449
+
3450
+ /*
3451
+ * Show information on Table Function Scan node, storage method and maximum
3452
+ * memory/disk space used.
3453
+ */
3454
+ static void
3455
+ show_table_func_scan_info (TableFuncScanState * tscanstate , ExplainState * es )
3456
+ {
3457
+ char * maxStorageType ;
3458
+ int64 maxSpaceUsed ;
3459
+
3460
+ Tuplestorestate * tupstore = tscanstate -> tupstore ;
3461
+
3462
+ if (!es -> analyze || tupstore == NULL )
3463
+ return ;
3464
+
3465
+ tuplestore_get_stats (tupstore , & maxStorageType , & maxSpaceUsed );
3466
+ show_storage_info (maxStorageType , maxSpaceUsed , es );
3467
+ }
3468
+
3469
+ /*
3470
+ * Show information on Recursive Union node, storage method and maximum
3471
+ * memory/disk space used.
3472
+ */
3473
+ static void
3474
+ show_recursive_union_info (RecursiveUnionState * rstate , ExplainState * es )
3475
+ {
3476
+ char * maxStorageType ,
3477
+ * tempStorageType ;
3478
+ int64 maxSpaceUsed ,
3479
+ tempSpaceUsed ;
3480
+
3481
+ if (!es -> analyze )
3482
+ return ;
3483
+
3484
+ /*
3485
+ * Recursive union node uses two tuplestores. We employ the storage type
3486
+ * from one of them which consumed more memory/disk than the other. The
3487
+ * storage size is sum of the two.
3488
+ */
3489
+ tuplestore_get_stats (rstate -> working_table , & tempStorageType ,
3490
+ & tempSpaceUsed );
3491
+ tuplestore_get_stats (rstate -> intermediate_table , & maxStorageType ,
3492
+ & maxSpaceUsed );
3493
+
3494
+ if (tempSpaceUsed > maxSpaceUsed )
3495
+ maxStorageType = tempStorageType ;
3496
+
3497
+ maxSpaceUsed += tempSpaceUsed ;
3498
+ show_storage_info (maxStorageType , maxSpaceUsed , es );
3412
3499
}
3413
3500
3414
3501
/*
0 commit comments