Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 236
Implement Parallel-aware Hash Left Anti Semi (Not-In) Join#149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
my-ship-it
merged 1 commit into
apache:main
from
avamingli:implement_parallel_aware_lasj_hashjoinOct 10, 2023
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -324,6 +324,14 @@ MultiExecParallelHash(HashState *node) | ||
| { | ||
| bool hashkeys_null = false; | ||
| /* CBDB_PARALLEL: Siblings must have found null value. */ | ||
| if (pstate->phs_lasj_has_null) | ||
| { | ||
| node->hs_hashkeys_null = true; | ||
| ExecSquelchNode(outerNode); | ||
| break; | ||
| } | ||
| slot = ExecProcNode(outerNode); | ||
| if (TupIsNull(slot)) | ||
| break; | ||
| @@ -333,14 +341,40 @@ MultiExecParallelHash(HashState *node) | ||
| &hashvalue, &hashkeys_null)) | ||
| ExecParallelHashTableInsert(hashtable, slot, hashvalue); | ||
| hashtable->partialTuples++; | ||
| if (node->hs_quit_if_hashkeys_null && hashkeys_null) | ||
| { | ||
| /* CBDB_PARALLEL: | ||
| * If we are LASJ and found NULL value by ourself or sibling processes had | ||
| * found NULL values, quit and tell siblings to quit if possible. | ||
| * | ||
| * It's safe to fetch and set phs_lasj_has_null without lock here and at | ||
| * other places. As it's a atomic boolean value. And we should avoid more locks in HashJion Impl. | ||
| * If other processes miss it here and some others set it at the same time, just bypass | ||
| * and we may get it at the next Hash batch. | ||
| * If we missed it across all batches, we will know it when PHJ_BUILD_HASHING_INNER | ||
| * ends with the help of build_barrier. | ||
| * If we never participated in building hash table, check it when hash table | ||
| * creation job is finished. | ||
| */ | ||
| pstate->phs_lasj_has_null = true; | ||
| pg_write_barrier(); | ||
| node->hs_hashkeys_null = true; | ||
| ExecSquelchNode(outerNode); | ||
| break; | ||
| } | ||
| } | ||
| /* CBDB_PARALLEL: No need to flush tuples if phs_lasj_has_null. */ | ||
| /* | ||
| * Make sure that any tuples we wrote to disk are visible to | ||
| * others before anyone tries to load them. | ||
| */ | ||
| for (i = 0; i < hashtable->nbatch; ++i) | ||
| sts_end_write(hashtable->batches[i].inner_tuples); | ||
| if (!pstate->phs_lasj_has_null) | ||
| { | ||
| for (i = 0; i < hashtable->nbatch; ++i) | ||
| sts_end_write(hashtable->batches[i].inner_tuples); | ||
| } | ||
| /* | ||
| * Update shared counters. We need an accurate total tuple count | ||
| @@ -366,9 +400,23 @@ MultiExecParallelHash(HashState *node) | ||
| * skew). | ||
| */ | ||
| pstate->growth = PHJ_GROWTH_DISABLED; | ||
| /* In case we didn't find null values ourself. */ | ||
| if (pstate->phs_lasj_has_null) | ||
| { | ||
| node->hs_hashkeys_null = true; | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| /* In case we didn't participate in PHJ_BUILD_HASHING_INNER */ | ||
| pg_memory_barrier(); | ||
avamingli marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (pstate->phs_lasj_has_null) | ||
| { | ||
| node->hs_hashkeys_null = true; | ||
| return; | ||
| } | ||
| /* | ||
| * We're not yet attached to a batch. We all agree on the dimensions and | ||
| * number of inner tuples (for the empty table optimization). | ||
| @@ -3779,7 +3827,12 @@ ExecHashTableDetachBatch(HashJoinTable hashtable) | ||
| sts_end_parallel_scan(hashtable->batches[curbatch].outer_tuples); | ||
| /* Detach from the batch we were last working on. */ | ||
| if (BarrierArriveAndDetach(&batch->batch_barrier)) | ||
| /* | ||
| * CBDB_PARALLEL: Parallel Hash Left Anti Semi (Not-In) Join(parallel-aware) | ||
| * If phs_lasj_has_null is true, that means we have found null when building hash table, | ||
| * there were no batches to detach. | ||
| */ | ||
| if (!hashtable->parallel_state->phs_lasj_has_null && BarrierArriveAndDetach(&batch->batch_barrier)) | ||
my-ship-it marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| { | ||
| /* | ||
| * Technically we shouldn't access the barrier because we're no | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -286,6 +286,7 @@ typedef struct ParallelHashJoinState | ||
| Barrier grow_buckets_barrier; | ||
| Barrier sync_barrier; | ||
| Barrier batch0_barrier; | ||
| volatile bool phs_lasj_has_null; /* LASJ has found null value, identify early quit */ | ||
yjhjstz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| pg_atomic_uint32 distributor; /* counter for load balancing */ | ||
| SharedFileSet fileset; /* space for shared temporary files */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.