|
7 | 7 | * Portions Copyright (c) 1994-5, Regents of the University of California
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.199 2010/01/15 22:36:29 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.200 2010/02/01 15:43:35 rhaas Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
|
20 | 20 | #include "commands/explain.h"
|
21 | 21 | #include "commands/prepare.h"
|
22 | 22 | #include "commands/trigger.h"
|
| 23 | +#include "executor/hashjoin.h" |
23 | 24 | #include "executor/instrument.h"
|
24 | 25 | #include "optimizer/clauses.h"
|
25 | 26 | #include "optimizer/planner.h"
|
@@ -67,6 +68,7 @@ static void show_upper_qual(List *qual, const char *qlabel, Plan *plan,
|
67 | 68 | ExplainState *es);
|
68 | 69 | static void show_sort_keys(Plan *sortplan, ExplainState *es);
|
69 | 70 | static void show_sort_info(SortState *sortstate, ExplainState *es);
|
| 71 | +static void show_hash_info(HashState *hashstate, ExplainState *es); |
70 | 72 | static const char *explain_get_index_name(Oid indexId);
|
71 | 73 | static void ExplainScanTarget(Scan *plan, ExplainState *es);
|
72 | 74 | static void ExplainMemberNodes(List *plans, PlanState **planstate,
|
@@ -1052,6 +1054,9 @@ ExplainNode(Plan *plan, PlanState *planstate,
|
1052 | 1054 | "One-Time Filter", plan, es);
|
1053 | 1055 | show_upper_qual(plan->qual, "Filter", plan, es);
|
1054 | 1056 | break;
|
| 1057 | + case T_Hash: |
| 1058 | + show_hash_info((HashState *) planstate, es); |
| 1059 | + break; |
1055 | 1060 | default:
|
1056 | 1061 | break;
|
1057 | 1062 | }
|
@@ -1404,6 +1409,47 @@ show_sort_info(SortState *sortstate, ExplainState *es)
|
1404 | 1409 | }
|
1405 | 1410 | }
|
1406 | 1411 |
|
| 1412 | +/* |
| 1413 | + * Show information on hash buckets/batches. |
| 1414 | + */ |
| 1415 | +static void |
| 1416 | +show_hash_info(HashState *hashstate, ExplainState *es) |
| 1417 | +{ |
| 1418 | + HashJoinTable hashtable; |
| 1419 | + |
| 1420 | + Assert(IsA(hashstate, HashState)); |
| 1421 | + hashtable = hashstate->hashtable; |
| 1422 | + |
| 1423 | + if (hashtable) |
| 1424 | + { |
| 1425 | + long spacePeakKb = (hashtable->spacePeak + 1023) / 1024; |
| 1426 | + if (es->format != EXPLAIN_FORMAT_TEXT) |
| 1427 | + { |
| 1428 | + ExplainPropertyLong("Hash Buckets", hashtable->nbuckets, es); |
| 1429 | + ExplainPropertyLong("Hash Batches", hashtable->nbatch, es); |
| 1430 | + ExplainPropertyLong("Original Hash Batches", |
| 1431 | + hashtable->nbatch_original, es); |
| 1432 | + ExplainPropertyLong("Peak Memory Usage", spacePeakKb, es); |
| 1433 | + } |
| 1434 | + else if (hashtable->nbatch_original != hashtable->nbatch) |
| 1435 | + { |
| 1436 | + appendStringInfoSpaces(es->str, es->indent * 2); |
| 1437 | + appendStringInfo(es->str, |
| 1438 | + "Buckets: %d Batches: %d (originally %d) Memory Usage: %ldkB\n", |
| 1439 | + hashtable->nbuckets, hashtable->nbatch, |
| 1440 | + hashtable->nbatch_original, spacePeakKb); |
| 1441 | + } |
| 1442 | + else |
| 1443 | + { |
| 1444 | + appendStringInfoSpaces(es->str, es->indent * 2); |
| 1445 | + appendStringInfo(es->str, |
| 1446 | + "Buckets: %d Batches: %d Memory Usage: %ldkB\n", |
| 1447 | + hashtable->nbuckets, hashtable->nbatch, |
| 1448 | + spacePeakKb); |
| 1449 | + } |
| 1450 | + } |
| 1451 | +} |
| 1452 | + |
1407 | 1453 | /*
|
1408 | 1454 | * Fetch the name of an index in an EXPLAIN
|
1409 | 1455 | *
|
|
0 commit comments