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

Add index to the stored generated column whose expression contains the column added by "add column" #9372

Closed
zimulala opened this issue Feb 20, 2019 · 2 comments
Labels
sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.

Comments

@zimulala
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
create table t(id int);
insert into t values(1);
ALTER TABLE t ADD COLUMN a int as (id+1) stored;
select * from t;
  1. What did you expect to see?
mysql> create table t(id int);
Query OK, 0 rows affected (0.03 sec)
mysql> insert into t values(1);
Query OK, 1 row affected (0.00 sec)
mysql> ALTER TABLE t ADD COLUMN a int as (id+1) stored;
Query OK, 1 row affected (0.03 sec)
Records: 1  Duplicates: 0  Warnings: 0
mysql> select * from t;
+------+------+
| id   | a    |
+------+------+
|    1 |    2 |
+------+------+
1 row in set (0.01 sec)
  1. What did you see instead?
tidb> create table t(id int);
Query OK, 0 rows affected (0.00 sec)
tidb> insert into t values(1);
Query OK, 1 row affected (0.00 sec)
tidb> ALTER TABLE t ADD COLUMN a int as (id+1) stored;
Query OK, 0 rows affected (0.02 sec)
tidb> select * from t;
+------+------+
| id   | a    |
+------+------+
|    1 | NULL |
+------+------+
1 row in set (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
    Release Version: v3.0.0-beta-69-g84d1513b0
    Git Commit Hash: 84d1513
    Git Branch: master
@zimulala zimulala added type/bugfix This PR fixes a bug. component/DDL-need-LGT3 type/bug The issue is confirmed as a bug. type/new-feature and removed type/bugfix This PR fixes a bug. type/bug The issue is confirmed as a bug. labels Feb 20, 2019
@zimulala
Copy link
Contributor Author

You cannot add the generated column in the storage type of STORED through ALTER TABLE.
You cannot create an index on the generated column through ALTER TABLE.

Refer to https://github.com/pingcap/docs/blob/master/sql/generated-columns.md#limitations

@wjhuang2016
Copy link
Member

Duplicate with #9288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants