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

ALTER TABLE t CHANGE a b (rename column) does not work for generated columns #38988

Closed
mjonss opened this issue Nov 8, 2022 · 2 comments · Fixed by #43350
Closed

ALTER TABLE t CHANGE a b (rename column) does not work for generated columns #38988

mjonss opened this issue Nov 8, 2022 · 2 comments · Fixed by #43350
Assignees
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@mjonss
Copy link
Contributor

mjonss commented Nov 8, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t (a int, b int as (a+3));
alter table t change a c int not null;

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

Success (propagate the rename into the generated column expression) or this MySQL compatible error:

mysql> create table t (a int, b int as (a+3));
Query OK, 0 rows affected (0,03 sec)

mysql> alter table t change a c int not null;
ERROR 3108 (HY000): Column 'a' has a generated column dependency.

3. What did you see instead (Required)

tidb> create table t (a int, b int as (a+3));
Query OK, 0 rows affected (0,08 sec)

tidb> alter table t change a c int not null;
ERROR 1054 (42S22): Unknown column 'a' in 'generated column function'

4. What is your TiDB version? (Required)

tidb_version(): Release Version: v6.5.0-alpha
Edition: Community
Git Commit Hash: 18cb721079e96e973bf1fc56b5583bc75455b4ba
Git Branch: heads/refs/tags/v6.5.0-alpha
UTC Build Time: 2022-11-08 14:32:53
GoVersion: go1.19.2
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv
@mjonss mjonss added the type/bug The issue is confirmed as a bug. label Nov 8, 2022
@mjonss
Copy link
Contributor Author

mjonss commented Nov 8, 2022

Somewhat related to #38932 (i.e. rename of column with dependency of other expression).

@bb7133
Copy link
Member

bb7133 commented Nov 11, 2022

I've checked the behavior of PG & CRDB, they would rewrite the column name in the expression index, thus allowing the rename of the column name.

So I think it's fine to just report the error, or allow the rename like PG & CRDB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
4 participants