* Save statistics into the cdbexplainbuf for EXPLAIN ANALYZE */
| 5240 | * Save statistics into the cdbexplainbuf for EXPLAIN ANALYZE |
| 5241 | */ |
| 5242 | void |
| 5243 | agg_hash_explain_extra_message(AggState *aggstate) |
| 5244 | { |
| 5245 | /* |
| 5246 | * Check cdbexplain_depositStatsToNode(), Greenplum only saves extra |
| 5247 | * message text for the most interesting winning qExecs. |
| 5248 | */ |
| 5249 | StringInfo hbuf = aggstate->ss.ps.cdbexplainbuf; |
| 5250 | uint64 sum_num_expansions = 0; |
| 5251 | uint64 sum_output_groups = 0; |
| 5252 | uint64 sum_spill_parts = 0; |
| 5253 | uint64 sum_chain_length_total = 0; |
| 5254 | uint64 sum_chain_count = 0; |
| 5255 | uint32 chain_length_max = 0; |
| 5256 | uint64 sum_bucket_used = 0; |
| 5257 | uint64 sum_bucket_total = 0; |
| 5258 | |
| 5259 | Assert(hbuf); |
| 5260 | |
| 5261 | appendStringInfo(hbuf, "hash table(s): %d", aggstate->num_hashes); |
| 5262 | |
| 5263 | /* Scan all perhashs and collect statistic info */ |
| 5264 | for (int setno = 0; setno < aggstate->num_hashes; setno++) |
| 5265 | { |
| 5266 | AggStatePerHash perhash = &aggstate->perhash[setno]; |
| 5267 | |
| 5268 | /* spill statistic info */ |
| 5269 | if (aggstate->hash_ever_spilled) |
| 5270 | { |
| 5271 | sum_output_groups += perhash->num_output_groups; |
| 5272 | sum_spill_parts += perhash->num_spill_parts; |
| 5273 | } |
| 5274 | |
| 5275 | /* inner hash table statistic info */ |
| 5276 | if (perhash->chain_count > 0) |
| 5277 | { |
| 5278 | sum_chain_length_total += perhash->chain_length_total; |
| 5279 | sum_chain_count += perhash->chain_count; |
| 5280 | if (perhash->chain_length_max > chain_length_max) |
| 5281 | chain_length_max = perhash->chain_length_max; |
| 5282 | sum_bucket_used = perhash->bucket_used; |
| 5283 | sum_bucket_total = perhash->bucket_total; |
| 5284 | sum_num_expansions += perhash->num_expansions; |
| 5285 | } |
| 5286 | } |
| 5287 | |
| 5288 | if (aggstate->hash_ever_spilled) |
| 5289 | { |
| 5290 | appendStringInfo(hbuf, |
| 5291 | "; " UINT64_FORMAT " groups total in %d batches, " UINT64_FORMAT |
| 5292 | " spill partitions; disk usage: " INT64_FORMAT "KB", |
| 5293 | sum_output_groups, |
| 5294 | aggstate->hash_batches_used, |
| 5295 | sum_spill_parts, |
| 5296 | aggstate->hash_disk_used); |
| 5297 | } |
| 5298 | |
| 5299 | if (sum_chain_count > 0) |
no test coverage detected