Skip to content
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

Fix explain(locus) show NULL. #238

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

avamingli
Copy link
Contributor

@avamingli avamingli commented Oct 17, 2023

I found several plan show locus NULL when explain(locus).
And a assertion added after plan created show more like that.
There are caused by different reasons, this pr fix all.

Reproduce:

 Locus: NULL
explain (locus, costs off)
select * from
  (select count(id) from t1 where id > 10) ss
  right join (values (1),(2),(3)) v(x) on true;
                             QUERY PLAN                              
---------------------------------------------------------------------
 Nested Loop Left Join
   Locus: Entry
   ->  Values Scan on "*VALUES*"
         Locus: General
   ->  Materialize
         Locus: NULL
         ->  Finalize Aggregate
               Locus: SingleQE
               ->  Gather Motion 3:1  (slice1; segments: 3)
                     Locus: SingleQE
                     ->  Partial Aggregate
                           Locus: Hashed
                           ->  Index Only Scan using t1_id_idx on t1
                                 Locus: Hashed
                                 Index Cond: (id > 10)
 Optimizer: Postgres query optimizer
(16 rows)

explain(locus, costs off) select * from mrs_t1 where exists (select x from mrs_t1 where x < -1);
                    QUERY PLAN                    
--------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   Locus: Entry
   InitPlan 1 (returns $0)  (slice2)
     ->  Gather Motion 3:1  (slice3; segments: 3)
           Locus: Entry
           ->  Seq Scan on mrs_t1 mrs_t1_1
                 Locus: Hashed
                 Filter: (x < '-1'::integer)
   ->  Result
         Locus: Hashed
         One-Time Filter: $0
         ->  Seq Scan on mrs_t1
               Locus: NULL
 Optimizer: Postgres query optimizer
(14 rows)

explain(locus, costs off) select * from mrs_t1 where exists (select x from mrs_t1 where x = 1);
                    QUERY PLAN                    
--------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   Locus: Entry
   InitPlan 1 (returns $0)  (slice2)
     ->  Gather Motion 1:1  (slice3; segments: 1)
           Locus: Entry
           ->  Seq Scan on mrs_t1 mrs_t1_1
                 Locus: Hashed
                 Filter: (x = 1)
   ->  Result
         Locus: Hashed
         One-Time Filter: $0
         ->  Seq Scan on mrs_t1
               Locus: NULL
 Optimizer: Postgres query optimizer
(14 rows)

explain(locus, costs off) select * from mrs_t1 where x in (select x-95 from mrs_t1) or x < 5;
                        QUERY PLAN                         
-----------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   Locus: Entry
   ->  Seq Scan on mrs_t1
         Locus: Hashed
         Filter: ((hashed SubPlan 1) OR (x < 5))
         SubPlan 1
           ->  Broadcast Motion 3:3  (slice2; segments: 3)
                 Locus: NULL
                 ->  Seq Scan on mrs_t1 mrs_t1_1
                       Locus: Hashed
 Optimizer: Postgres query optimizer
(11 rows)

explain(locus, costs off) select * from pg_class where oid in (select x-95 from mrs_t1) or oid < 5;
                     QUERY PLAN                     
----------------------------------------------------
 Seq Scan on pg_class
   Locus: Entry
   Filter: ((hashed SubPlan 1) OR (oid < '5'::oid))
   SubPlan 1
     ->  Gather Motion 3:1  (slice1; segments: 3)
           Locus: Entry
           ->  Seq Scan on mrs_t1
                 Locus: Hashed
 Optimizer: Postgres query optimizer
(9 rows)

prepare t1_count(integer) as select count(*) from t1;
explain(locus, costs off) execute t1_count(1);
                   QUERY PLAN                   
------------------------------------------------
 Aggregate
   Locus: NULL
   ->  Gather Motion 3:1  (slice1; segments: 3)
         Locus: NULL
         ->  Seq Scan on t1
               Locus: NULL
 Optimizer: Postgres query optimizer
(7 rows)

explain(costs off, locus) select max(100) from t1;
                        QUERY PLAN                        
----------------------------------------------------------
 Result
   Locus: Entry
   InitPlan 1 (returns $0)  (slice1)
     ->  Limit
           Locus: NULL
           ->  Gather Motion 3:1  (slice2; segments: 3)
                 Locus: Entry
                 ->  Result
                       Locus: Hashed
                       One-Time Filter: (100 IS NOT NULL)
                       ->  Seq Scan on t1
                             Locus: NULL
 Optimizer: Postgres query optimizer
(13 rows)

Fix materialize locus is null when enable_material is off. When creating plan, make_material() is added directly besides a material path and lacks of locus info.
Add locus info for that material plan.

Fix locus is null under Subplan.
fix_subplan_motion() will add Motion by Flow, either Gather or Broadcast. Add locus according to Flow type.

Fix Result, One-Time Filter Result locus is null.
Result node will call create_scan_plan() itself if it's a simple RTE_RESULT base relation. Add locus for that.

Fix PREPARE EXECUTE statement locus null.
Plancache will copy PlannedStmt list if it's not a oneshot plan. Add files locustype and parallel in CopyPlanFields().

Authored-by: Zhang Mingli avamingli@gmail.com

closes: #ISSUE_Number


Change logs

Describe your change clearly, including what problem is being solved or what feature is being added.

If it has some breaking backward or forward compatibility, please clary.

Why are the changes needed?

Describe why the changes are necessary.

Does this PR introduce any user-facing change?

If yes, please clarify the previous behavior and the change this PR proposes.

How was this patch tested?

Please detail how the changes were tested, including manual tests and any relevant unit or integration tests.

Contributor's Checklist

Here are some reminders and checklists before/when submitting your pull request, please check them:

  • Make sure your Pull Request has a clear title and commit message. You can take git-commit template as a reference.
  • Sign the Contributor License Agreement as prompted for your first-time contribution(One-time setup).
  • Learn the coding contribution guide, including our code conventions, workflow and more.
  • List your communication in the GitHub Issues or Discussions (if has or needed).
  • Document changes.
  • Add tests for the change
  • Pass make installcheck
  • Pass make -C src/test installcheck-cbdb-parallel
  • Feel free to @cloudberrydb/dev team for review and approval when your PR is ready🥳

@avamingli avamingli force-pushed the explain_locus_null branch 2 times, most recently from 624a41e to 627fbd2 Compare October 17, 2023 02:49
@avamingli avamingli self-assigned this Oct 17, 2023
@avamingli avamingli requested a review from my-ship-it October 17, 2023 16:59
Fix materialize locus is null when enable_material is off.
When creating plan, make_material() is added directly besides
a material path and lacks of locus info.
Add locus info for that material plan.

Fix locus is null under Subplan.
fix_subplan_motion() will add Motion by Flow, either Gather or
Broadcast. Add locus according to Flow type.

Fix Result, One-Time Filter Result locus is null.
Result node will call create_scan_plan() itself if it's a simple
RTE_RESULT base relation. Add locus for that.

Fix PREPARE EXECUTE statement locus null.
Plancache will copy PlannedStmt list if it's not a oneshot plan.
Add files locustype and parallel in CopyPlanFields().

Authored-by: Zhang Mingli avamingli@gmail.com
Copy link
Contributor

@my-ship-it my-ship-it left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@my-ship-it my-ship-it merged commit 3d3cd68 into apache:main Nov 7, 2023
7 checks passed
baotingfang pushed a commit that referenced this pull request Dec 1, 2023
Fix materialize locus is null when enable_material is off.
When creating plan, make_material() is added directly besides
a material path and lacks of locus info.
Add locus info for that material plan.

Fix locus is null under Subplan.
fix_subplan_motion() will add Motion by Flow, either Gather or
Broadcast. Add locus according to Flow type.

Fix Result, One-Time Filter Result locus is null.
Result node will call create_scan_plan() itself if it's a simple
RTE_RESULT base relation. Add locus for that.

Fix PREPARE EXECUTE statement locus null.
Plancache will copy PlannedStmt list if it's not a oneshot plan.
Add files locustype and parallel in CopyPlanFields().

Authored-by: Zhang Mingli avamingli@gmail.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants