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/core: add DefaultExpr support for expressionRewriter #8540

Merged
merged 6 commits into from
Jan 2, 2019

Conversation

bb7133
Copy link
Member

@bb7133 bb7133 commented Dec 1, 2018

What problem does this PR solve?

This PR simply fix a compatibility issue about default() function in expressionRewriter:

mysql> create table t(a int default 5);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values (1);
Query OK, 1 row affected (0.00 sec)

mysql> select default(a) from t;
ERROR 1105 (HY000): UnknownType: *ast.DefaultExpr
mysql> update t set a=default(a);
ERROR 1105 (HY000): UnknownType: *ast.DefaultExpr

default() function should return the default value of a given column:
https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_default

What is changed and how it works?

In expressionRewriter, this PR adds a branch to handle ast.DefaultExpr to avoid the UnknownType error and fix this issue.

Check List

Tests

  • Integration test

Related changes

  • Nothing else

This change is Reviewable

@bb7133 bb7133 mentioned this pull request Dec 2, 2018
17 tasks
@zz-jason zz-jason added the sig/planner SIG: Planner label Dec 3, 2018
@eurekaka eurekaka added type/enhancement The issue or PR belongs to an enhancement. contribution This PR is from a community contributor. labels Dec 3, 2018
planner/core/expression_rewriter_test.go Show resolved Hide resolved
planner/core/expression_rewriter.go Outdated Show resolved Hide resolved
}

func hasCurrentTimestampDefault(col *table.Column) bool {
if col.Tp != mysql.TypeTimestamp && col.Tp != mysql.TypeDatetime {
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not really need this, check the name is enough and clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to check the types(for example, to avoid varchar column with 'current_timestamp' default string).
What's more, I just found timestamp and datetime behaves differently here, so a code update is needed, thanks anyway!

planner/core/expression_rewriter.go Outdated Show resolved Hide resolved
@bb7133
Copy link
Member Author

bb7133 commented Dec 13, 2018

hi @zz-jason , I've updated code, it looks much better now! Thank you very much

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

rest lgtm

planner/core/expression_rewriter.go Outdated Show resolved Hide resolved
@bb7133
Copy link
Member Author

bb7133 commented Dec 28, 2018

hi @winoros @eurekaka , I've updated the code, PTAL, thanks.

Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

@eurekaka eurekaka added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 29, 2018
@eurekaka
Copy link
Contributor

@zz-jason @winoros PTAL

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason
Copy link
Member

zz-jason commented Jan 2, 2019

/run-all-tests

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 2, 2019
@zz-jason zz-jason merged commit 1232db5 into pingcap:master Jan 2, 2019
@bb7133 bb7133 deleted the bb7133/fix_default_expr branch March 7, 2019 10:14
@SunRunAway
Copy link
Contributor

Closes #4054

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants