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

type/compatibility: check `KEY` option for generated column. #9529

Merged
merged 7 commits into from Apr 10, 2019

Conversation

Projects
None yet
5 participants
@pingyu
Copy link
Contributor

pingyu commented Mar 3, 2019

What problem does this PR solve?

check KEY option for generated column in create table

TiDB:

mysql> CREATE TABLE t1 (id INT NOT NULL,
    ->   c1 VARCHAR(20) AS ('foo') VIRTUAL KEY NULL, PRIMARY KEY (id));
ERROR 1068 (42000): Multiple primary key defined
mysql> CREATE TABLE t1 (id INT NOT NULL,
    ->   c1 VARCHAR(20) AS ('foo') VIRTUAL KEY NOT NULL, PRIMARY KEY (id));
ERROR 1068 (42000): Multiple primary key defined

MySQL:

mysql> CREATE TABLE t1 (id INT NOT NULL,
    ->   c1 VARCHAR(20) AS ('foo') VIRTUAL KEY NULL, PRIMARY KEY (id));
ERROR 3106 (HY000): 'Defining a virtual generated column as primary key' is not supported for generated columns.
mysql> CREATE TABLE t1 (id INT NOT NULL,
    ->   c1 VARCHAR(20) AS ('foo') VIRTUAL KEY NOT NULL, PRIMARY KEY (id));
ERROR 3106 (HY000): 'Defining a virtual generated column as primary key' is not supported for generated columns.
mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 5.7.25-0ubuntu0.18.04.2 |
+-------------------------+
1 row in set (0.00 sec)

mysql> 

related issue: #9464

What is changed and how it works?

add checking of KEY option on generated column for CREATE TABLE

Check List

Tests

  • Manual Test
mysql> CREATE TABLE t1 (id INT NOT NULL,
    ->   c1 VARCHAR(20) AS ('foo') VIRTUAL KEY NULL, PRIMARY KEY (id));
ERROR 3106 (HY000): 'Defining a virtual generated column as primary key' is not supported for generated columns.
mysql> CREATE TABLE t1 (id INT NOT NULL,
    ->   c1 VARCHAR(20) AS ('foo') VIRTUAL KEY NOT NULL, PRIMARY KEY (id));
ERROR 3106 (HY000): 'Defining a virtual generated column as primary key' is not supported for generated columns.
mysql> select TiDB_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| TiDB_version()                                                                                                                                                                                                                                                                                                                             |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v3.0.0-beta-144-g560e8cfe5-dirty
Git Commit Hash: 560e8cfe57d102d52918fd609e4e865ebdfb7159
Git Branch: master
UTC Build Time: 2019-03-03 05:20:02
GoVersion: go version go1.11.2 darwin/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> 
  • Unit test
@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Mar 3, 2019

Codecov Report

Merging #9529 into master will decrease coverage by 0.0187%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master      #9529        +/-   ##
================================================
- Coverage   78.1198%   78.1011%   -0.0188%     
================================================
  Files           405        405                
  Lines         82006      82018        +12     
================================================
- Hits          64063      64057         -6     
- Misses        13245      13256        +11     
- Partials       4698       4705         +7

@shenli shenli added the contribution label Mar 3, 2019

@pingyu pingyu force-pushed the pingyu:check_key_for_virtual_column branch from 10d8b7e to 90e5ede Mar 10, 2019

@imtbkcat
Copy link
Contributor

imtbkcat left a comment

rest LGTM

func checkColumnOptions(ops []*ast.ColumnOption) (int, error) {
isPrimary := 0
isGenerated := 0

This comment has been minimized.

Copy link
@imtbkcat

imtbkcat Apr 1, 2019

Contributor

isPrimary, isGenerated := 0, 0 is better

This comment has been minimized.

Copy link
@pingyu

pingyu Apr 1, 2019

Author Contributor

@imtbkcat PTAL. Thanks.

@pingyu pingyu force-pushed the pingyu:check_key_for_virtual_column branch from 3ac80a2 to 6b3827e Apr 1, 2019

@imtbkcat
Copy link
Contributor

imtbkcat left a comment

LGTM

@imtbkcat imtbkcat added the status/LGT1 label Apr 2, 2019

Show resolved Hide resolved planner/core/preprocess.go Outdated
@lamxTyler
Copy link
Member

lamxTyler left a comment

LGTM

@lamxTyler

This comment has been minimized.

Copy link
Member

lamxTyler commented Apr 3, 2019

/run-all-tests

@lamxTyler lamxTyler added status/LGT2 and removed status/LGT1 labels Apr 3, 2019

@lamxTyler

This comment has been minimized.

Copy link
Member

lamxTyler commented Apr 4, 2019

/run-common-test

@lamxTyler

This comment has been minimized.

Copy link
Member

lamxTyler commented Apr 4, 2019

The test failed because the sql create table t (a DOUBLE NULL, b_sto DOUBLE GENERATED ALWAYS AS (a + 2) STORED UNIQUE KEY NOT NULL PRIMARY KEY); could be successfully executed in MySQL, while it raises an error in this PR.

@pingyu

This comment has been minimized.

Copy link
Contributor Author

pingyu commented Apr 4, 2019

Let me see see.

@pingyu pingyu force-pushed the pingyu:check_key_for_virtual_column branch from 5bc063d to 5ceccb5 Apr 5, 2019

@pingyu

This comment has been minimized.

Copy link
Contributor Author

pingyu commented Apr 5, 2019

Bug fixed. Primary key for "stored generated column" is permitted.
@lamxTyler PTAL. Thanks.

@pingyu

This comment has been minimized.

Copy link
Contributor Author

pingyu commented Apr 5, 2019

mysql> create table t (a DOUBLE NULL, b_sto DOUBLE GENERATED ALWAYS AS (a + 2) STORED UNIQUE KEY NOT NULL PRIMARY KEY);
Query OK, 0 rows affected (0.01 sec)

mysql> show create table t;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                      |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `a` double DEFAULT NULL,
  `b_sto` double GENERATED ALWAYS AS (`a` + 2) STORED NOT NULL,
  UNIQUE KEY `b_sto` (`b_sto`),
  PRIMARY KEY (`b_sto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select tidb_version();
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                                                                    |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v3.0.0-beta.1-48-g0561316ac-dirty
Git Commit Hash: 0561316ac18ab9a96b036f8f3de2daac86edeace
Git Branch: check_key_for_virtual_column
UTC Build Time: 2019-04-05 07:34:29
GoVersion: go version go1.11.2 darwin/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> 
@pingyu

This comment has been minimized.

Copy link
Contributor Author

pingyu commented Apr 6, 2019

/run-common-test

@lamxTyler

This comment has been minimized.

Copy link
Member

lamxTyler commented Apr 9, 2019

@pingyu Please resolve the conflicts.

@pingyu pingyu force-pushed the pingyu:check_key_for_virtual_column branch from 5ceccb5 to 660b232 Apr 9, 2019

@pingyu

This comment has been minimized.

Copy link
Contributor Author

pingyu commented Apr 9, 2019

@lamxTyler Conflicts resolved. PTAL. Thanks.

@lamxTyler

This comment has been minimized.

Copy link
Member

lamxTyler commented Apr 10, 2019

/run-all-tests

@lamxTyler

This comment has been minimized.

Copy link
Member

lamxTyler commented Apr 10, 2019

/run-common-test
/run-integration-common-test

@lamxTyler

This comment has been minimized.

Copy link
Member

lamxTyler commented Apr 10, 2019

/rebuild

@lamxTyler lamxTyler merged commit f778a0c into pingcap:master Apr 10, 2019

5 of 6 checks passed

ci/circleci Your tests are queued behind your running builds
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
idc-jenkins-ci-tidb/build Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/check_dev Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/code_coverage Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.