Skip to content

Commit

Permalink
planner: the recursive cte will make UPDATE's result wrong (#49400) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Feb 1, 2024
1 parent 634602f commit bac49de
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7729,6 +7729,10 @@ func (b *PlanBuilder) buildRecursiveCTE(ctx context.Context, cte ast.ResultSetNo
// Build seed part plan.
saveSelect := x.SelectList.Selects
x.SelectList.Selects = x.SelectList.Selects[:i]
// We're rebuilding the seed part, so we pop the result we built previously.
for _i := 0; _i < i; _i++ {
b.handleHelper.popMap()
}
p, err = b.buildSetOpr(ctx, x)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,22 @@ IndexReader 250.00 root index:Selection
select * from t1 use index (ia) where a like 'xxx_';
a
xxx
drop view if exists v1;
create view v1(id) as
with recursive cte(a) as (select 1 union select a+1 from cte where a<3)
select * from cte;
create table test2(id int,value int);
insert into test2 values(1,1),(2,2),(3,3),(4,4),(5,5);
update test2
set value=0
where test2.id in
(
select * from v1
);
select * from test2;
id value
1 0
2 0
3 0
4 4
5 5
17 changes: 17 additions & 0 deletions tests/integrationtest/t/planner/core/issuetest/planner_issue.test
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,20 @@ select *,length(a) from t1 where a like '测试 %';
select *,length(a) from t1 where a like '测试';
explain format = brief select * from t1 use index (ia) where a like 'xxx_';
select * from t1 use index (ia) where a like 'xxx_';

# https://github.com/pingcap/tidb/issues/48969
drop view if exists v1;
create view v1(id) as
with recursive cte(a) as (select 1 union select a+1 from cte where a<3)
select * from cte;

create table test2(id int,value int);
insert into test2 values(1,1),(2,2),(3,3),(4,4),(5,5);

update test2
set value=0
where test2.id in
(
select * from v1
);
select * from test2;

0 comments on commit bac49de

Please sign in to comment.