mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Fix EXPLAIN ANALYZE of hash join when the leader doesn't participate.
If a hash join appears in a parallel query, there may be no hash table
available for explain.c to inspect even though a hash table may have
been built in other processes.  This could happen either because
parallel_leader_participation was set to off or because the leader
happened to hit the end of the outer relation immediately (even though
the complete relation is not empty) and decided not to build the hash
table.
Commit bf11e7ee introduced a way for workers to exchange
instrumentation via the DSM segment for Sort nodes even though they
are not parallel-aware.  This commit does the same for Hash nodes, so
that explain.c has a way to find instrumentation data from an
arbitrary participant that actually built the hash table.
Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm%3D3DUQC2-z252N55eOcZBer6DPdM%3DFzrxH9dZc5vYLsjaA%40mail.gmail.com
			
			
This commit is contained in:
		@@ -1980,6 +1980,29 @@ typedef struct GatherMergeState
 | 
			
		||||
	struct binaryheap *gm_heap; /* binary heap of slot indices */
 | 
			
		||||
} GatherMergeState;
 | 
			
		||||
 | 
			
		||||
/* ----------------
 | 
			
		||||
 *	 Values displayed by EXPLAIN ANALYZE
 | 
			
		||||
 * ----------------
 | 
			
		||||
 */
 | 
			
		||||
typedef struct HashInstrumentation
 | 
			
		||||
{
 | 
			
		||||
	int			nbuckets;		/* number of buckets at end of execution */
 | 
			
		||||
	int			nbuckets_original;	/* planned number of buckets */
 | 
			
		||||
	int			nbatch;			/* number of batches at end of execution */
 | 
			
		||||
	int			nbatch_original;	/* planned number of batches */
 | 
			
		||||
	size_t		space_peak;		/* speak memory usage in bytes */
 | 
			
		||||
} HashInstrumentation;
 | 
			
		||||
 | 
			
		||||
/* ----------------
 | 
			
		||||
 *	 Shared memory container for per-worker hash information
 | 
			
		||||
 * ----------------
 | 
			
		||||
 */
 | 
			
		||||
typedef struct SharedHashInfo
 | 
			
		||||
{
 | 
			
		||||
	int			num_workers;
 | 
			
		||||
	HashInstrumentation hinstrument[FLEXIBLE_ARRAY_MEMBER];
 | 
			
		||||
} SharedHashInfo;
 | 
			
		||||
 | 
			
		||||
/* ----------------
 | 
			
		||||
 *	 HashState information
 | 
			
		||||
 * ----------------
 | 
			
		||||
@@ -1990,6 +2013,9 @@ typedef struct HashState
 | 
			
		||||
	HashJoinTable hashtable;	/* hash table for the hashjoin */
 | 
			
		||||
	List	   *hashkeys;		/* list of ExprState nodes */
 | 
			
		||||
	/* hashkeys is same as parent's hj_InnerHashKeys */
 | 
			
		||||
 | 
			
		||||
	SharedHashInfo *shared_info;	/* one entry per worker */
 | 
			
		||||
	HashInstrumentation *hinstrument;	/* this worker's entry */
 | 
			
		||||
} HashState;
 | 
			
		||||
 | 
			
		||||
/* ----------------
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user