aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/explain.c
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2021-04-30 14:46:42 +1200
committerDavid Rowley <drowley@postgresql.org>2021-04-30 14:46:42 +1200
commit3c80e96dffd4df7f66fffa5f265cbd87becb7ef5 (patch)
tree745967211e6a7f7bc00af8997cbb3b9debdf4ea2 /src/backend/commands/explain.c
parent51ef9173030cc196c6633ae82b7b32f404b0f768 (diff)
downloadpostgresql-3c80e96dffd4df7f66fffa5f265cbd87becb7ef5.tar.gz
postgresql-3c80e96dffd4df7f66fffa5f265cbd87becb7ef5.zip
Adjust EXPLAIN output for parallel Result Cache plans
Here we adjust the EXPLAIN ANALYZE output for Result Cache so that we don't show any Result Cache stats for parallel workers who don't contribute anything to Result Cache plan nodes. I originally had ideas that workers who don't help could still have their Result Cache stats displayed. The idea with that was so that I could write some parallel Result Cache regression tests that show the EXPLAIN ANALYZE output. However, I realized a little too late that such tests would just not be possible to have run in a stable way on the buildfarm. With that knowledge, before 9eacee2e6 went in, I had removed all of the tests that were showing the EXPLAIN ANALYZE output of a parallel Result Cache plan, however, I forgot to put back the code that adjusts the EXPLAIN output to hide the Result Cache stats for parallel workers who were not fast enough to help out before query execution was over. All other nodes behave this way and so should Result Cache. Additionally, with this change, it now seems safe enough to remove the SET force_parallel_mode = off that I had added to the regression tests. Also, perform some cleanup in the partition_prune tests. I had adjusted the explain_parallel_append() function to sanitize the Result Cache EXPLAIN ANALYZE output. However, since I didn't actually include any parallel Result Cache tests that show their EXPLAIN ANALYZE output, that code does nothing and can be removed. In passing, move the setting of memPeakKb into the scope where it's used. Reported-by: Amit Khandekar Author: David Rowley, Amit Khandekar Discussion: https://postgr.es/m/CAJ3gD9d8SkfY95GpM1zmsOtX2-Ogx5q-WLsf8f0ykEb0hCRK3w@mail.gmail.com
Diffstat (limited to 'src/backend/commands/explain.c')
-rw-r--r--src/backend/commands/explain.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 3d5198e2345..8ab7bca866b 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -3144,17 +3144,17 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
if (!es->analyze)
return;
- /*
- * mem_peak is only set when we freed memory, so we must use mem_used when
- * mem_peak is 0.
- */
- if (rcstate->stats.mem_peak > 0)
- memPeakKb = (rcstate->stats.mem_peak + 1023) / 1024;
- else
- memPeakKb = (rcstate->mem_used + 1023) / 1024;
-
if (rcstate->stats.cache_misses > 0)
{
+ /*
+ * mem_peak is only set when we freed memory, so we must use mem_used
+ * when mem_peak is 0.
+ */
+ if (rcstate->stats.mem_peak > 0)
+ memPeakKb = (rcstate->stats.mem_peak + 1023) / 1024;
+ else
+ memPeakKb = (rcstate->mem_used + 1023) / 1024;
+
if (es->format != EXPLAIN_FORMAT_TEXT)
{
ExplainPropertyInteger("Cache Hits", NULL, rcstate->stats.cache_hits, es);
@@ -3186,6 +3186,13 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
si = &rcstate->shared_info->sinstrument[n];
+ /*
+ * Skip workers that didn't do any work. We needn't bother checking
+ * for cache hits as a miss will always occur before a cache hit.
+ */
+ if (si->cache_misses == 0)
+ continue;
+
if (es->workers_state)
ExplainOpenWorker(n, es);