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

[Bug] Plan with parameterized path may always be wrong #671

Open
1 of 2 tasks
jiaqizho opened this issue Oct 16, 2024 · 1 comment
Open
1 of 2 tasks

[Bug] Plan with parameterized path may always be wrong #671

jiaqizho opened this issue Oct 16, 2024 · 1 comment
Assignees
Labels
priority: Low This issue can probably be picked up by anyone looking to contribute to the project, as an entry fix type: Bug Something isn't working type: Orca only orca has the issue

Comments

@jiaqizho
Copy link
Contributor

Cloudberry Database version

All versions affected

Also GP7 have the same issue.

What happened

create table t1(v varchar(100));
insert into t1 values('abc~001');

create or replace function sameout 
	(in vc varchar) returns varchar AS $BODY$
begin
	return vc;
END;
$BODY$
LANGUAGE plpgsql;

set optimizer to off;
select (select sameout(v) t) from t1;  -- will coredump 

This case has nothing to do with the table itself and the custom function. Only relative the parameterized path.

ORCA also will got the same issue with other sql.

So the SQL select (select sameout(v) t) from t1; plan is

                                      QUERY PLAN
---------------------------------------------------------------------------------------
 Gather Motion 1:1  (slice1; segments: 1)  (cost=0.00..3928.00 rows=13200 width=32)
   Output: ((SubPlan 1))
   ->  Seq Scan on public.t1  (cost=0.00..3664.00 rows=13200 width=32)
         Output: (SubPlan 1)
         SubPlan 1
           ->  Materialize  (cost=0.00..0.00 rows=0 width=0)
                 Output: (sameout(t1.v))
                 ->  Broadcast Motion 1:1  (slice2)  (cost=0.00..0.26 rows=1 width=32)
                       Output: (sameout(t1.v))
                       ->  Result  (cost=0.00..0.26 rows=1 width=32)
                             Output: sameout(t1.v)
 Optimizer: Postgres query optimizer
(12 rows)

As u can see we do have a Motion node exist in subplan. Then in Result node won't get any tuple in this path.

I guess this case is caused by optimizer. The optimizer should not create the parameterized path with the motion.

What you think should happen instead

this sql can change to the select sameout(v) from t1; or a subquery select sameout(v) from (select v from t1) t;

The corrent plan should flat the parameterized path or become a subquery

                                      QUERY PLAN
---------------------------------------------------------------------------------------
 Gather Motion 1:1  (slice1; segments: 1)  (cost=0.00..3928.00 rows=13200 width=32)
   -> Output: (sameout(t1.v))
        ->  Broadcast Motion 1:1  (slice2)  (cost=0.00..0.26 rows=1 width=32)
            Output: (sameout(t1.v))
            ->  Seq Scan on public.t1  (cost=0.00..3664.00 rows=13200 width=32)

 Optimizer: Postgres query optimizer
(12 rows)

or no motion inside

                                                   QUERY PLAN
----------------------------------------------------------------------------------------------------------------
 Result  (cost=0.00..882732.09 rows=1 width=8)
   Output: (SubPlan 1)
   ->  Gather Motion 1:1  (slice1; segments: 1)  (cost=0.00..431.00 rows=1 width=8)
         Output: v
         ->  Seq Scan on public.t1  (cost=0.00..431.00 rows=1 width=8)
               Output: v
   SubPlan 1
           ->  Materialize  (cost=0.00..0.00 rows=0 width=0)
                 Output: (sameout(t1.v))
                 ->  Result  (cost=0.00..0.26 rows=1 width=32)
                       Output: sameout(t1.v)
(20 rows)

How to reproduce

above

Operating System

any

Anything else

No response

Are you willing to submit PR?

  • Yes, I am willing to submit a PR!

Code of Conduct

@jiaqizho jiaqizho added the type: Bug Something isn't working label Oct 16, 2024
Copy link

Hey, @jiaqizho welcome!🎊 Thanks for taking the time to point this out.🙌

@jiaqizho jiaqizho added type: Orca only orca has the issue priority: Low This issue can probably be picked up by anyone looking to contribute to the project, as an entry fix labels Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: Low This issue can probably be picked up by anyone looking to contribute to the project, as an entry fix type: Bug Something isn't working type: Orca only orca has the issue
Projects
None yet
Development

No branches or pull requests

1 participant