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

ddl: validate table info before doing ddl job to avoid load infoschema error #10464

Merged
merged 8 commits into from
May 20, 2019

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

Validate table info before doing ddl job to avoid load infoschema error.
eg1:

# Below SQL should return an error when creating table, but in old version tidb will return success, and then load schema will error. 
CREATE TABLE t1 (
	c0 int(11) ,
  	c1 int(11),
    c2 decimal(16,4) GENERATED ALWAYS AS ((case when (c0 = 0) then 0 when (c0 > 0) then (c1 / c0) end))
);

eg2:

create table t1 (a int,b int) partition by hash(a) partitions 4;
# Below SQL should return an error when alter table, but in old version tidb will return success, and then load schema will error. 
 alter table t1 drop column a;

What is changed and how it works?

Add check table info in create table and drop column.
Maybe add this check in other public path is better.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

  • Possible performance regression
    Related changes

  • Need to cherry-pick to the release branch

@crazycs520 crazycs520 added the type/bugfix This PR fixes a bug. label May 14, 2019
@crazycs520
Copy link
Contributor Author

/run-all-tests

1 similar comment
@crazycs520
Copy link
Contributor Author

/run-all-tests

ddl/column.go Outdated
@@ -242,6 +242,11 @@ func onDropColumn(t *meta.Meta, job *model.Job) (ver int64, _ error) {
colInfo.State = model.StateWriteOnly
// Set this column's offset to the last and reset all following columns' offsets.
adjustColumnInfoInDropColumn(tblInfo, colInfo.Offset)
err = checkTableInfoValid(tblInfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check if the tableInfo valid before we overwrite the tableInfo in TiKV.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. PTAL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have added check on line 265, why do it again?

@codecov
Copy link

codecov bot commented May 15, 2019

Codecov Report

Merging #10464 into master will increase coverage by 0.0248%.
The diff coverage is 88.8888%.

@@               Coverage Diff                @@
##             master     #10464        +/-   ##
================================================
+ Coverage   77.2657%   77.2906%   +0.0248%     
================================================
  Files           413        413                
  Lines         86979      86986         +7     
================================================
+ Hits          67205      67232        +27     
+ Misses        14608      14594        -14     
+ Partials       5166       5160         -6

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bb7133 bb7133 added component/DDL-need-LGT3 status/LGT2 Indicates that a PR has LGTM 2. labels May 20, 2019
Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add it to the operation of add index?

ddl/column.go Outdated
@@ -242,6 +242,11 @@ func onDropColumn(t *meta.Meta, job *model.Job) (ver int64, _ error) {
colInfo.State = model.StateWriteOnly
// Set this column's offset to the last and reset all following columns' offsets.
adjustColumnInfoInDropColumn(tblInfo, colInfo.Offset)
err = checkTableInfoValid(tblInfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have added check on line 265, why do it again?

@@ -1114,6 +1114,11 @@ func (d *ddl) CreateTableWithLike(ctx sessionctx.Context, ident, referIdent ast.
return errors.Trace(err)
}

func checkTableInfoValid(tblInfo *model.TableInfo) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add comments for it?

@crazycs520
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zimulala zimulala added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels May 20, 2019
@crazycs520 crazycs520 merged commit 2e9ddb2 into pingcap:master May 20, 2019
crazycs520 added a commit to crazycs520/tidb that referenced this pull request May 20, 2019
db-storage pushed a commit to db-storage/tidb that referenced this pull request May 29, 2019
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
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 status/LGT3 The PR has already had 3 LGTM. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants