diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-04-11 12:39:19 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-04-11 12:39:19 -0400 |
commit | 969f9d0b4ba574bb8df65683dbf7a09c030f3e67 (patch) | |
tree | fff0c61c0079b85371dd30bf9f30fa15bc8f1355 /src/backend/executor/nodeHashjoin.c | |
parent | 5c27bce7f39ded1f027475221b732bbbc31a2bfe (diff) | |
download | postgresql-969f9d0b4ba574bb8df65683dbf7a09c030f3e67.tar.gz postgresql-969f9d0b4ba574bb8df65683dbf7a09c030f3e67.zip |
Make EXPLAIN report maximum hashtable usage across multiple rescans.
Before discarding the old hash table in ExecReScanHashJoin, capture
its statistics, ensuring that we report the maximum hashtable size
across repeated rescans of the hash input relation. We can repurpose
the existing code for reporting hashtable size in parallel workers
to help with this, making the patch pretty small. This also ensures
that if rescans happen within parallel workers, we get the correct
maximums across all instances.
Konstantin Knizhnik and Tom Lane, per diagnosis by Thomas Munro
of a trouble report from Alvaro Herrera.
Discussion: https://postgr.es/m/20200323165059.GA24950@alvherre.pgsql
Diffstat (limited to 'src/backend/executor/nodeHashjoin.c')
-rw-r--r-- | src/backend/executor/nodeHashjoin.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c index 9e28ddd8951..cc8edacdd01 100644 --- a/src/backend/executor/nodeHashjoin.c +++ b/src/backend/executor/nodeHashjoin.c @@ -1338,8 +1338,16 @@ ExecReScanHashJoin(HashJoinState *node) /* must destroy and rebuild hash table */ HashState *hashNode = castNode(HashState, innerPlanState(node)); - /* for safety, be sure to clear child plan node's pointer too */ Assert(hashNode->hashtable == node->hj_HashTable); + /* accumulate stats from old hash table, if wanted */ + /* (this should match ExecShutdownHash) */ + if (hashNode->ps.instrument && !hashNode->hinstrument) + hashNode->hinstrument = (HashInstrumentation *) + palloc0(sizeof(HashInstrumentation)); + if (hashNode->hinstrument) + ExecHashAccumInstrumentation(hashNode->hinstrument, + hashNode->hashtable); + /* for safety, be sure to clear child plan node's pointer too */ hashNode->hashtable = NULL; ExecHashTableDestroy(node->hj_HashTable); |