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

Can't find column when update with CTE #35758

Closed
chrysan opened this issue Jun 27, 2022 · 3 comments · Fixed by #35854
Closed

Can't find column when update with CTE #35758

chrysan opened this issue Jun 27, 2022 · 3 comments · Fixed by #35854
Assignees
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@chrysan
Copy link
Contributor

chrysan commented Jun 27, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t1 (a int, b int);
create table t2 (c int, d int);
create table t3 (e int, f int);
explain update t1
inner join (
	select t2.c from t2
	inner join
		(with temp as (select e from t3 where t3.f = 1234)
		select e from temp) tt
	on 
		t2.d = tt.e
	) t
on t1.a = t.c
set
t1.b = 4321;

2. What did you expect to see? (Required)

Workable plan

3. What did you see instead (Required)

ERROR 1105 (HY000): Can't find column test.t2._tidb_rowid in schema Column: [test.t1.a,test.t1.b,test.t1._tidb_rowid,test.t2.c] Unique key: []

4. What is your TiDB version? (Required)

v5.3.0 ~ master

@chrysan chrysan added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner severity/major labels Jun 27, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 labels Jun 27, 2022
@chrysan
Copy link
Contributor Author

chrysan commented Jun 27, 2022

Maybe it's because we lack popMap() for tryBuildCTE. We do have it for subquery:
https://github.com/pingcap/tidb/blob/v5.3.0/planner/core/planbuilder.go#L477-L485
https://github.com/pingcap/tidb/blob/v5.3.0/planner/core/expression_rewriter.go#L334

@ChenPeng2013 ChenPeng2013 added affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 labels Jun 28, 2022
@ti-chi-bot ti-chi-bot removed may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 labels Jun 28, 2022
@AilinKid AilinKid removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. labels Jun 30, 2022
@elsa0520
Copy link
Contributor

If the CTE is inline in the update or delete statement, this problem will still be triggered.

update t1 inner join (select t2.c from t2 inner join (with temp as (select /*+ merge() */ e from t3 where t3.f = 1234) select e from temp) tt on t2.d = tt.e) t on t1.a = t.c set t1.b = 4321; 
Error 1105: Can't find column test.t2._tidb_rowid in schema Column: [test.t1.a,test.t1.b,test.t1._tidb_rowid,test.t2.c]

Please reopen this issue

@chrysan
Copy link
Contributor Author

chrysan commented Sep 28, 2022

If the CTE is inline in the update or delete statement, this problem will still be triggered.

update t1 inner join (select t2.c from t2 inner join (with temp as (select /*+ merge() */ e from t3 where t3.f = 1234) select e from temp) tt on t2.d = tt.e) t on t1.a = t.c set t1.b = 4321; 
Error 1105: Can't find column test.t2._tidb_rowid in schema Column: [test.t1.a,test.t1.b,test.t1._tidb_rowid,test.t2.c]

Please reopen this issue

@elsa0520 you can create a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants