Re: WIP: [[Parallel] Shared] Hash
Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
> >> However, ExecHashIncreaseNumBatches() may change the >> number of buckets; the patch does not seem to account for spaceUsed changes >> because of that. > > That's what this hunk is intended to do: > > @@ -795,6 +808,12 @@ ExecHashIncreaseNumBuckets(HashJoinTable hashtable) > TRACE_POSTGRESQL_HASH_INCREASE_BUCKETS(hashtable->nbuckets, > > hashtable->nbuckets_optimal); > > + /* account for the increase in space that will be used by buckets */ > + hashtable->spaceUsed += sizeof(HashJoinTuple) * > + (hashtable->nbuckets_optimal - hashtable->nbuckets); > + if (hashtable->spaceUsed > hashtable->spacePeak) > + hashtable->spacePeak = hashtable->spaceUsed; > + Sorry, I missed that hunk. You are right, it's getting accounted for. >> >> In ExecHashTableReset(), do we want to update spacePeak while setting >> spaceUsed. > > I figured there was no way that the new spaceUsed value could be > bigger than spacePeak, because we threw out all chunks and have just > the bucket array, and we had that number of buckets before, so > spacePeak must at least have been set to a number >= this number > either when we expanded to this many buckets, or when we created the > hashtable in the first place. Perhaps I should > Assert(hashtable->spaceUsed <= hashtable->spacePeak). That would help, better if you explain this with a comment before Assert. > >> While this patch tracks space usage more accurately, I am afraid we might be >> overdoing it; a reason why we don't track space usage accurately now. But I >> think I will leave it to be judged by someone who is more familiar with the >> code and possibly has historical perspective. > > Well it's not doing more work; it doesn't make any practical > difference whatsoever but it's technically doing less work than > master, by doing memory accounting only when acquiring a new 32KB > chunk. This patch does more work while counting the space used by buckets, I guess. AFAIU, right now, that happens only after the hash table is built completely. But that's fine. I am not worried about whether the it's less work or more. > But if by overdoing it you mean that no one really cares about > the tiny increase in accuracy so the patch on its own is a bit of a > waste of time, you're probably right. This is what I meant by overdoing; you have spelled it better. > Depending on tuple size, you > could imagine something like 64 bytes of header and unused space per > 32KB chunk that we're not accounting for, and that's only 0.2%. So I > probably wouldn't propose this refactoring just on accuracy grounds > alone. > > This refactoring is intended to pave the way for shared memory > accounting in the later patches, which would otherwise generate ugly > IPC if done for every time a tuple is allocated. I considered using > atomic add to count space per tuple, or maintaining per-backend local > subtotals and periodically summing. Then I realised that switching to > per-chunk accounting would fix the IPC problem AND be justifiable on > theoretical grounds. When we allocate a new 32KB chunk, we really are > using 32KB more of your memory. +1. Thanks for considering the comments. -- Best Wishes, Ashutosh Bapat EnterpriseDB Corporation The Postgres Database Company
Commits
-
Add shared tuplestores.
- ab9e0e718acb 11.0 landed
-
Remove BufFile's isTemp flag.
- 11e264517dff 11.0 landed
-
Provide DSM segment to ExecXXXInitializeWorker functions.
- 7082e614c0dd 11.0 landed
-
Optimize joins when the inner relation can be proven unique.
- 9c7f5229ad68 10.0 cited
-
Fix failure to use clamp_row_est() for parallel joins.
- 1ea60ad602f9 10.0 cited
-
Document lack of validation when attaching foreign partitions.
- b54aad8e34bd 10.0 cited
-
Fix inclusions of c.h from .h files.
- a72f0365db41 10.0 landed
-
Fix inclusions of postgres_fe.h from .h files.
- 9722bb5757c5 10.0 landed
-
Bring plpgsql into line with header inclusion policy.
- 08da52859a1f 10.0 landed
-
Document intentional violations of header inclusion policy.
- d6b059ec740a 10.0 landed
-
Shut down Gather's children before shutting down Gather itself.
- acf555bc53ac 10.0 landed
-
btree: Support parallel index scans.
- 569174f1be92 10.0 cited
-
Add explicit ORDER BY to a few tests that exercise hash-join code.
- 7c5d8c16e12e 10.0 landed
-
Revise hash join code so that we can increase the number of batches
- 849074f9ae42 8.1.0 cited
-
Rewrite hash join to use simple linked lists instead of a
- 26069a58e8e4 7.1.1 cited