Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05dfb81

Browse files
committed
Fix bogus EXPLAIN output for Hash Aggregate
9bdb300 modified the EXPLAIN output for Hash Aggregate to show detailsfrom parallel workers. However, it neglected to consider that a givenparallel worker may not have assisted with the given Hash Aggregate. Thiscan occur when workers fail to start or during Parallel Append withenable_partitionwise_join enabled when only a single worker is working ona non-parallel aware sub-plan. It could also happen if a worker simplywasn't fast enough to get any work done before other processes went andfinished all the work.The bogus output came from the fact that ExplainOpenWorker() skippedshowing any details for non-initialized workers but show_hashagg_info()did show details from the worker. This meant that the worker propertiesthat were shown were not properly attributed to the worker that theybelong to.In passing, we also now don't show Hash Aggregate properties for theleader process when it did not contribute any work to the Hash Aggregate.This can occur either during Parallel Append when only a parallel workerworked on a given sub plan or with parallel_leader_participation set tooff. This aims to make the behavior of Hash Aggregate's EXPLAIN outputmore similar to Sort's.Reported-by: Justin PryzbyDiscussion:https://postgr.es/m/20200805012105.GZ28072%40telsasoft.comBackpatch-through: 13, where the original breakage was introduced
1 parentd0aa57d commit05dfb81

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

‎src/backend/commands/explain.c

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,15 +3063,19 @@ show_hashagg_info(AggState *aggstate, ExplainState *es)
30633063
ExplainPropertyInteger("Planned Partitions",NULL,
30643064
aggstate->hash_planned_partitions,es);
30653065

3066-
if (!es->analyze)
3067-
return;
3068-
3069-
/* EXPLAIN ANALYZE */
3070-
ExplainPropertyInteger("HashAgg Batches",NULL,
3071-
aggstate->hash_batches_used,es);
3072-
ExplainPropertyInteger("Peak Memory Usage","kB",memPeakKb,es);
3073-
ExplainPropertyInteger("Disk Usage","kB",
3074-
aggstate->hash_disk_used,es);
3066+
/*
3067+
* During parallel query the leader may have not helped out. We
3068+
* detect this by checking how much memory it used. If we find it
3069+
* didn't do any work then we don't show its properties.
3070+
*/
3071+
if (es->analyze&&aggstate->hash_mem_peak>0)
3072+
{
3073+
ExplainPropertyInteger("HashAgg Batches",NULL,
3074+
aggstate->hash_batches_used,es);
3075+
ExplainPropertyInteger("Peak Memory Usage","kB",memPeakKb,es);
3076+
ExplainPropertyInteger("Disk Usage","kB",
3077+
aggstate->hash_disk_used,es);
3078+
}
30753079
}
30763080
else
30773081
{
@@ -3085,26 +3089,32 @@ show_hashagg_info(AggState *aggstate, ExplainState *es)
30853089
gotone= true;
30863090
}
30873091

3088-
if (!es->analyze)
3092+
/*
3093+
* During parallel query the leader may have not helped out. We
3094+
* detect this by checking how much memory it used. If we find it
3095+
* didn't do any work then we don't show its properties.
3096+
*/
3097+
if (es->analyze&&aggstate->hash_mem_peak>0)
30893098
{
3090-
if (gotone)
3091-
appendStringInfoChar(es->str,'\n');
3092-
return;
3093-
}
3099+
if (!gotone)
3100+
ExplainIndentText(es);
3101+
else
3102+
appendStringInfoString(es->str," ");
30943103

3095-
if (!gotone)
3096-
ExplainIndentText(es);
3097-
else
3098-
appendStringInfoString(es->str," ");
3104+
appendStringInfo(es->str,"Batches: %d Memory Usage: "INT64_FORMAT"kB",
3105+
aggstate->hash_batches_used,memPeakKb);
3106+
gotone= true;
30993107

3100-
appendStringInfo(es->str,"Batches: %d Memory Usage: "INT64_FORMAT"kB",
3101-
aggstate->hash_batches_used,memPeakKb);
3108+
/* Only display disk usage if we spilled to disk */
3109+
if (aggstate->hash_batches_used>1)
3110+
{
3111+
appendStringInfo(es->str," Disk Usage: "UINT64_FORMAT"kB",
3112+
aggstate->hash_disk_used);
3113+
}
3114+
}
31023115

3103-
/* Only display disk usage if we spilled to disk */
3104-
if (aggstate->hash_batches_used>1)
3105-
appendStringInfo(es->str," Disk Usage: "UINT64_FORMAT"kB",
3106-
aggstate->hash_disk_used);
3107-
appendStringInfoChar(es->str,'\n');
3116+
if (gotone)
3117+
appendStringInfoChar(es->str,'\n');
31083118
}
31093119

31103120
/* Display stats for each parallel worker */
@@ -3117,6 +3127,9 @@ show_hashagg_info(AggState *aggstate, ExplainState *es)
31173127
inthash_batches_used;
31183128

31193129
sinstrument=&aggstate->shared_info->sinstrument[n];
3130+
/* Skip workers that didn't do anything */
3131+
if (sinstrument->hash_mem_peak==0)
3132+
continue;
31203133
hash_disk_used=sinstrument->hash_disk_used;
31213134
hash_batches_used=sinstrument->hash_batches_used;
31223135
memPeakKb= (sinstrument->hash_mem_peak+1023) /1024;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp