MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecReScanHashJoin

Function ExecReScanHashJoin

src/backend/executor/nodeHashjoin.c:1668–1768  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1666
1667
1668void
1669ExecReScanHashJoin(HashJoinState *node)
1670{
1671 /*
1672 * In a multi-batch join, we currently have to do rescans the hard way,
1673 * primarily because batch temp files may have already been released. But
1674 * if it's a single-batch join, and there is no parameter change for the
1675 * inner subnode, then we can just re-use the existing hash table without
1676 * rebuilding it.
1677 */
1678 if (node->hj_HashTable != NULL)
1679 {
1680 node->hj_HashTable->first_pass = false;
1681
1682 if (node->js.ps.righttree->chgParam == NULL &&
1683 !node->hj_HashTable->eagerlyReleased)
1684 {
1685 /*
1686 * Okay to reuse the hash table; needn't rescan inner, either.
1687 *
1688 * However, if it's a right/full join, we'd better reset the
1689 * inner-tuple match flags contained in the table.
1690 */
1691 if (HJ_FILL_INNER(node))
1692 ExecHashTableResetMatchFlags(node->hj_HashTable);
1693
1694 /*
1695 * Also, we need to reset our state about the emptiness of the
1696 * outer relation, so that the new scan of the outer will update
1697 * it correctly if it turns out to be empty this time. (There's no
1698 * harm in clearing it now because ExecHashJoin won't need the
1699 * info. In the other cases, where the hash table doesn't exist
1700 * or we are destroying it, we leave this state alone because
1701 * ExecHashJoin will need it the first time through.)
1702 */
1703 node->hj_OuterNotEmpty = false;
1704
1705 /* ExecHashJoin can skip the BUILD_HASHTABLE step */
1706 node->hj_JoinState = HJ_NEED_NEW_OUTER;
1707
1708 if (node->hj_HashTable->nbatch > 1)
1709 {
1710 /* Force reloading batch 0 upon next ExecHashJoin */
1711 node->hj_HashTable->curbatch = -1;
1712 }
1713 else
1714 {
1715 /* MPP-1600: reset the batch number */
1716 node->hj_HashTable->curbatch = 0;
1717 }
1718 }
1719 else
1720 {
1721 /* must destroy and rebuild hash table */
1722 if (!node->hj_HashTable->eagerlyReleased)
1723 {
1724 HashState *hashNode = castNode(HashState, innerPlanState(node));
1725

Callers 1

ExecReScanFunction · 0.85

Calls 6

ExecHashTableDestroyFunction · 0.85
ExecReScanFunction · 0.85
palloc0Function · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected