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: allow insert default into generated columns #11901

Merged
merged 8 commits into from
Aug 30, 2019

Conversation

Deardrops
Copy link
Contributor

@Deardrops Deardrops commented Aug 28, 2019

What problem does this PR solve?

In MySQL document,

For INSERT, REPLACE, and UPDATE, if a generated column is inserted into, replaced, or updated explicitly, the only permitted value is DEFAULT.

create table t (a int, b int as (a + 1))
insert into t value (1, default)
MySQL: Query OK (0.191 sec)
TiDB: Error 3105: The value specified for generated column 'b' in table 't' is not allowed.

What is changed and how it works?

Allow use the DEFAULT keyword when insert into the generated columns.

When build the insert plan, check if

  • the target column is generated column,
  • and the insert expression is DEFAULT

Skip add this column's expression into this insert plan.

Because we can't insert value into generated clumns directly, it's acceptable to ignore the generated column in insert plan.

Check List

Tests

  • Intergration test

Release note

  • Allow use the DEFAULT keyword when insert into the generated columns.

@codecov
Copy link

codecov bot commented Aug 28, 2019

Codecov Report

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

@@             Coverage Diff             @@
##             master     #11901   +/-   ##
===========================================
  Coverage   81.3215%   81.3215%           
===========================================
  Files           443        443           
  Lines         95286      95286           
===========================================
  Hits          77488      77488           
  Misses        12309      12309           
  Partials       5489       5489

@Deardrops Deardrops closed this Aug 29, 2019
@Deardrops Deardrops reopened this Aug 29, 2019
@Deardrops
Copy link
Contributor Author

/run-all-tests

@Deardrops
Copy link
Contributor Author

/run-all-tests

@wjhuang2016
Copy link
Member

LGTM

@wjhuang2016 wjhuang2016 added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 30, 2019
Copy link
Contributor

@tangenta tangenta left a comment

Choose a reason for hiding this comment

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

LGTM

@tangenta tangenta added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Aug 30, 2019
@tangenta
Copy link
Contributor

@Deardrops Do we have the plan to support insert into t set a = 1, b = default?

@Deardrops
Copy link
Contributor Author

@tangenta

@Deardrops Do we have the plan to support insert into t set a = 1, b = default?

Yes, we have open a issue for this problem #11939

@Deardrops
Copy link
Contributor Author

/run-all-tests

@Deardrops Deardrops merged commit bb84d1b into pingcap:master Aug 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants