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

Function cdbpathlocus_pull_above_projection

src/backend/cdb/cdbpathlocus.c:628–719  ·  view source on GitHub ↗

* cdbpathlocus_pull_above_projection * * Given a targetlist, and a locus evaluable before the projection is * applied, returns an equivalent locus evaluable after the projection. * Returns a strewn locus if the necessary inputs are not projected. * * 'relids' is the set of relids that may occur in the targetlist exprs. * 'targetlist' specifies the projection. It is a List of TargetEntry *

Source from the content-addressed store, hash-verified

626 * Ignored if 'newvarlist' is specified.
627 */
628CdbPathLocus
629cdbpathlocus_pull_above_projection(struct PlannerInfo *root,
630 CdbPathLocus locus,
631 Bitmapset *relids,
632 List *targetlist,
633 List *newvarlist,
634 Index newrelid,
635 bool parallel_aware)
636{
637 CdbPathLocus newlocus;
638
639 Assert(cdbpathlocus_is_valid(locus));
640
641 if (CdbPathLocus_IsHashed(locus) || CdbPathLocus_IsHashedOJ(locus) ||
642 (CdbPathLocus_IsHashedWorkers(locus) && parallel_aware))
643 {
644 ListCell *distkeycell;
645 List *newdistkeys = NIL;
646 int numsegments;
647
648 /*
649 * Keep the numsegments unchanged.
650 */
651 numsegments = CdbPathLocus_NumSegments(locus);
652
653 /* For each column of the distribution key... */
654 foreach(distkeycell, locus.distkey)
655 {
656 DistributionKey *olddistkey = (DistributionKey *) lfirst(distkeycell);
657 DistributionKey *newdistkey = NULL;
658
659 /* Get DistributionKey for key expr rewritten in terms of projection cols. */
660 ListCell *ec_cell;
661 EquivalenceClass *new_ec = NULL;
662
663 foreach(ec_cell, olddistkey->dk_eclasses)
664 {
665 EquivalenceClass *old_ec = (EquivalenceClass *) lfirst(ec_cell);
666
667 new_ec = cdb_pull_up_eclass(root,
668 old_ec,
669 relids,
670 targetlist,
671 newvarlist,
672 newrelid,
673 true /* ignore RelabelType */);
674 if (new_ec)
675 break;
676 }
677
678 /*
679 * NB: Targetlist might include columns from both sides of outer
680 * join "=" comparison, in which case cdb_pull_up_distribution_keys might
681 * succeed on keys from more than one distkeylist. The
682 * pulled-up locus could then be a HashedOJ locus, perhaps saving
683 * a Motion when an outer join is followed by UNION ALL followed
684 * by a join or aggregate. For now, don't bother.
685 */

Callers 1

set_append_path_locusFunction · 0.85

Calls 4

cdbpathlocus_is_validFunction · 0.85
cdb_pull_up_eclassFunction · 0.85
lappendFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected