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

planner: Fixup error when assign DEFAULT in INSERT/UPDATE/REPLACE ... SET ... statement #13211

Merged
merged 17 commits into from
Nov 19, 2019

Conversation

Deardrops
Copy link
Contributor

@Deardrops Deardrops commented Nov 6, 2019

What problem does this PR solve?

Fix #11939

create table t1 (a int default 1);
insert into t1 value (10);
update t1 set a = default; # <-- TiDB panic
replace t1 set a = default; # <-- TiDB panic
insert into t1 set a = default; # <-- TiDB panic

What is changed and how it works?

In statement update t1 set a = default, When we build Update logic plan, we do:

  1. For nongenerated columns, fill the defaultExpr.Name by assign.Column before rewrite its assignment expression.
  2. For generated columns,
    1. If assigned DEAFULT, just ignore this column.
    2. If assigned any other value, throw an error The value specified for generated column 'gc' in table 't' is not allowed.

Check List

Tests

  • Integration test

Code changes

  • None

Side effects

  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Support using DEAFULT in INSERT/UPDATE/REPLACE ... SET xxx=DEFAULT statement

@codecov
Copy link

codecov bot commented Nov 6, 2019

Codecov Report

Merging #13211 into master will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##            master    #13211   +/-   ##
=========================================
  Coverage   80.156%   80.156%           
=========================================
  Files          472       472           
  Lines       116786    116786           
=========================================
  Hits         93611     93611           
  Misses       15915     15915           
  Partials      7260      7260

@Deardrops Deardrops requested a review from a team as a code owner November 12, 2019 11:37
@ghost ghost requested review from qw4990 and XuHuaiyu and removed request for a team November 12, 2019 11:38
@Deardrops
Copy link
Contributor Author

/run-all-tests

@Deardrops Deardrops changed the title planner: Fixup error when assign DEFAULT in UPDATE statement planner: Fixup error when assign DEFAULT in INSERT/UPDATE/REPLACE ... SET ... statement Nov 12, 2019
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

The test case is clear, nice. Rest LGTM

planner/core/logical_plan_builder.go Outdated Show resolved Hide resolved
planner/core/logical_plan_builder.go Outdated Show resolved Hide resolved
@Deardrops
Copy link
Contributor Author

/run-all-tests

@Deardrops Deardrops added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 14, 2019
@djshow832
Copy link
Contributor

Did you test insert ... on duplicate key update?

@Deardrops
Copy link
Contributor Author

Did you test insert ... on duplicate key update?

@djshow832 Yes, In #13168, PTAL

Deardrops and others added 2 commits November 14, 2019 11:37
Co-Authored-By: djshow832 <873581766@qq.com>
Copy link
Member

@wjhuang2016 wjhuang2016 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
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@AilinKid AilinKid added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 15, 2019
@jackysp jackysp added the type/bugfix This PR fixes a bug. label Nov 15, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Nov 17, 2019

@AilinKid, @djshow832, @wjhuang2016, @lamxTyler, @qw4990, @XuHuaiyu, PTAL.

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

@Deardrops
Copy link
Contributor Author

/run-all-tests

@Deardrops Deardrops added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Nov 19, 2019
@Deardrops
Copy link
Contributor Author

/run-all-tests

@Deardrops Deardrops merged commit 380216e into pingcap:master Nov 19, 2019
@Deardrops Deardrops deleted the update-default branch November 19, 2019 10:23
@sre-bot
Copy link
Contributor

sre-bot commented Nov 19, 2019

cherry pick to release-3.0 failed

@sre-bot
Copy link
Contributor

sre-bot commented Nov 19, 2019

cherry pick to release-2.1 failed

@sre-bot
Copy link
Contributor

sre-bot commented Nov 19, 2019

cherry pick to release-3.1 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner 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.

Support using DEAFULT in INSERT/UPDATE/REPLACE ... SET xxx=DEFAULT statement
8 participants