cloudberry icon indicating copy to clipboard operation
cloudberry copied to clipboard

[Bug] ORCA generates wrong plan for select-for-update statement.

Open HuSen8891 opened this issue 8 months ago • 1 comments

Apache Cloudberry version

No response

What happened

when set optimizer to on, plan for select-for-update statement is not correct because LockRows is lacked.

postgres=# set optimizer to on;
SET
postgres=# explain select * from test for update;
                                  QUERY PLAN
------------------------------------------------------------------------------
 Gather Motion 2:1  (slice1; segments: 2)  (cost=0.00..431.00 rows=1 width=4)
   ->  Seq Scan on test  (cost=0.00..431.00 rows=1 width=4)
 Optimizer: GPORCA
(3 rows)

postgres=# set optimizer to off;
SET
postgres=# explain select * from test for update;
                                     QUERY PLAN
------------------------------------------------------------------------------------
 Gather Motion 2:1  (slice1; segments: 2)  (cost=0.00..2457.50 rows=96300 width=10)
   ->  LockRows  (cost=0.00..1013.00 rows=48150 width=10)
         ->  Seq Scan on test  (cost=0.00..531.50 rows=48150 width=10)
 Optimizer: Postgres query optimizer
(4 rows)

What you think should happen instead

No response

How to reproduce

set optimizer to on;

explain select * from test for update;

Operating System

centos

Anything else

No response

Are you willing to submit PR?

  • [ ] Yes, I am willing to submit a PR!

Code of Conduct

HuSen8891 avatar Apr 02 '25 08:04 HuSen8891

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

github-actions[bot] avatar Apr 02 '25 08:04 github-actions[bot]