avamingli opened a new pull request, #1305:
URL: https://github.com/apache/cloudberry/pull/1305

   
   Fix issue https://github.com/apache/cloudberry/issues/1301
   
   For partition tables, cdb_pull_up_eclass will call get_eclass_for_sort_expr 
to find an existing equivalence class it is a member of. It will fail and build 
a new single-member EquivalenceClass for it when there is RelabelType. That 
will cause cdbpath_match_preds_to_both_distkeys return false even the locus are 
compatible because the RestrictInfo's left_ec/right_ec and rel's distribution 
key's dk_eclasses are two different pointers.
   And unnecessary Motions will be added in that case.
   ```sql
   CREATE TABLE t1 (id varchar(32), date date) DISTRIBUTED BY (id) PARTITION BY 
RANGE (date)
   (START (date '2016-01-01') INCLUSIVE END (date '2016-01-02') EXCLUSIVE EVERY 
(INTERVAL '1 day')); CREATE TABLE t2 (id varchar(32)) DISTRIBUTED BY (id); 
EXPLAIN(COSTS OFF) SELECT COUNT(*) FROM t1 JOIN t2 USING(id);
                               QUERY PLAN
   ------------------------------------------------------------------
    Aggregate
      ->  Gather Motion 3:1  (slice1; segments: 3)
            ->  Hash Join
                  Hash Cond: ((t1.id)::text = (t2.id)::text)
                  ->  Redistribute Motion 3:3  (slice2; segments: 3)
                        Hash Key: t1.id
                        ->  Seq Scan on t1_1_prt_1 t1
                  ->  Hash
                        ->  Seq Scan on t2
    Optimizer: Postgres query optimizer
   (10 rows)
   ```
   cdbpullup_findEclassInTargetList() will ignore the presence or absence of a 
RelabelType node atop either expr in determining whether an EC member expr 
matches a targetlist expr. But get_eclass_for_sort_expr() didn't handle 
additional RelabelType and a new EC may be generated. We should not disturb 
get_eclass_for_sort_expr() as it's used at many places and UPSTREAM didn't add 
RelabelType to EC for that case.
   If find a sub_distkeyexpr from cdbpullup_findEclassInTargetList and we know 
that there is RelabelType stripped inside, we don't need to try to fetch or 
generate new EC in get_eclass_for_sort_expr(). So, add options for 
cdb_pull_up_eclass to ignore RelabelType when needed.
   
   Authored-by: Zhang Mingli [email protected]
   
   <!-- Thank you for your contribution to Apache Cloudberry (Incubating)! -->
   
   Fixes #ISSUE_Number
   
   ### What does this PR do?
   <!-- Brief overview of the changes, including any major features or fixes -->
   
   ### Type of Change
   - [ ] Bug fix (non-breaking change)
   - [ ] New feature (non-breaking change)
   - [ ] Breaking change (fix or feature with breaking changes)
   - [ ] Documentation update
   
   ### Breaking Changes
   <!-- Remove if not applicable. If yes, explain impact and migration path -->
   
   ### Test Plan
   <!-- How did you test these changes? -->
   - [ ] Unit tests added/updated
   - [ ] Integration tests added/updated
   - [ ] Passed `make installcheck`
   - [ ] Passed `make -C src/test installcheck-cbdb-parallel`
   
   ### Impact
   <!-- Remove sections that don't apply -->
   **Performance:**
   <!-- Any performance implications? -->
   
   **User-facing changes:**
   <!-- Any changes visible to users? -->
   
   **Dependencies:**
   <!-- New dependencies or version changes? -->
   
   ### Checklist
   - [ ] Followed [contribution 
guide](https://cloudberry.apache.org/contribute/code)
   - [ ] Added/updated documentation
   - [ ] Reviewed code for security implications
   - [ ] Requested review from [cloudberry 
committers](https://github.com/orgs/apache/teams/cloudberry-committers)
   
   ### Additional Context
   <!-- Any other information that would help reviewers? Remove if none -->
   
   ### CI Skip Instructions
   <!--
   To skip CI builds, add the appropriate CI skip identifier to your PR title.
   The identifier must:
   - Be in square brackets []
   - Include the word "ci" and either "skip" or "no"
   - Only use for documentation-only changes or when absolutely necessary
   -->
   
   ---
   <!-- Join our community:
   - Mailing list: 
[[email protected]](https://lists.apache.org/[email protected])
 (subscribe: [email protected])
   - Discussions: https://github.com/apache/cloudberry/discussions -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to