---------------------------------------------------------------- * ExecHashTableCreate * * create an empty hashtable data structure for hashjoin. * ---------------------------------------------------------------- */
| 536 | * ---------------------------------------------------------------- |
| 537 | */ |
| 538 | HashJoinTable |
| 539 | ExecHashTableCreate(HashState *state, HashJoinState *hjstate, |
| 540 | List *hashOperators, List *hashCollations, |
| 541 | bool keepNulls, uint64 operatorMemKB) |
| 542 | { |
| 543 | Hash *node; |
| 544 | HashJoinTable hashtable; |
| 545 | Plan *outerNode; |
| 546 | size_t space_allowed; |
| 547 | int nbuckets; |
| 548 | int nbatch; |
| 549 | double rows; |
| 550 | int num_skew_mcvs; |
| 551 | int log2_nbuckets; |
| 552 | int nkeys; |
| 553 | int i; |
| 554 | ListCell *ho; |
| 555 | ListCell *hc; |
| 556 | MemoryContext oldcxt; |
| 557 | |
| 558 | /* |
| 559 | * Get information about the size of the relation to be hashed (it's the |
| 560 | * "outer" subtree of this node, but the inner relation of the hashjoin). |
| 561 | * Compute the appropriate size of the hash table. |
| 562 | */ |
| 563 | node = (Hash *) state->ps.plan; |
| 564 | outerNode = outerPlan(node); |
| 565 | |
| 566 | /* |
| 567 | * If this is shared hash table with a partial plan, then we can't use |
| 568 | * outerNode->plan_rows to estimate its size. We need an estimate of the |
| 569 | * total number of rows across all copies of the partial plan. |
| 570 | */ |
| 571 | rows = node->plan.parallel_aware ? node->rows_total : outerNode->plan_rows; |
| 572 | |
| 573 | ExecChooseHashTableSize(rows, outerNode->plan_width, |
| 574 | OidIsValid(node->skewTable), |
| 575 | operatorMemKB, |
| 576 | state->parallel_state != NULL, |
| 577 | state->parallel_state != NULL ? |
| 578 | state->parallel_state->nparticipants - 1 : 0, |
| 579 | &space_allowed, |
| 580 | &nbuckets, &nbatch, &num_skew_mcvs); |
| 581 | |
| 582 | /* nbuckets must be a power of 2 */ |
| 583 | log2_nbuckets = my_log2(nbuckets); |
| 584 | Assert(nbuckets == (1 << log2_nbuckets)); |
| 585 | |
| 586 | /* |
| 587 | * Initialize the hash table control block. |
| 588 | * |
| 589 | * The hashtable control block is just palloc'd from the executor's |
| 590 | * per-query memory context. Everything else should be kept inside the |
| 591 | * subsidiary hashCxt or batchCxt. |
| 592 | */ |
| 593 | hashtable = (HashJoinTable) palloc0(sizeof(HashJoinTableData)); |
| 594 | hashtable->nbuckets = nbuckets; |
| 595 | hashtable->nbuckets_original = nbuckets; |
no test coverage detected