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: Refine error message about "Invalid default value" #6333

Merged
merged 22 commits into from
May 20, 2018

Conversation

spongedu
Copy link
Contributor

@spongedu spongedu commented Apr 22, 2018

Fix #6303.

tidb> create table t(c1 decimal default 1.7976931348623157E308);
ERROR 1067 (42000): Invalid default value for 'c1'

@sre-bot
Copy link
Contributor

sre-bot commented Apr 22, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@shenli shenli added contribution This PR is from a community contributor. DDL labels Apr 22, 2018
@shenli
Copy link
Member

shenli commented Apr 22, 2018

/run-all-tests

ddl/ddl_api.go Outdated
@@ -471,7 +471,10 @@ func checkDefaultValue(ctx sessionctx.Context, c *table.Column, hasDefaultValue
if types.ErrTruncated.Equal(err) {
return types.ErrInvalidDefault.GenByArgs(c.Name)
}
return errors.Trace(err)
if err != nil {
Copy link
Contributor

@alivxxx alivxxx Apr 23, 2018

Choose a reason for hiding this comment

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

Why not combine it with the upper if? Should all errors be considered as invalid default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lamxTyler It's a bit complicate here I found. Illegal default value doesn't necessary result in ErrInvalidDefault, actually. For example:

In MySQL:

mysql> create table t(a decimal(3) default 1.25567);
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> show warnings;
+-------+------+----------------------------------------+
| Level | Code | Message                                |
+-------+------+----------------------------------------+
| Note  | 1265 | Data truncated for column 'a' at row 1 |
+-------+------+----------------------------------------+
1 row in set (0.00 sec)

In TiDB:

tidb> create table t(a decimal(3) default 1.25567);
ERROR 1067 (42000): Invalid default value for 'a'

But if default value check if set in ALTER TABLE situation(ddl/ddl_db_test.go: line 1139), The
ErrInvalidDefault error is raised.

another example:

Im MySQL:

mysql> create table t ( a date default '2012-01-01 01:01:01');
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> show warnings;
+-------+------+---------------------------------------------------------------------+
| Level | Code | Message                                                             |
+-------+------+---------------------------------------------------------------------+
| Note  | 1292 | Incorrect date value: '2012-01-01 01:01:01' for column 'a' at row 1 |
+-------+------+---------------------------------------------------------------------+
1 row in set (0.00 sec)

In TiDB:

create table t ( a date default '2012-01-01 01:01:01');
Query OK, 0 rows affected (0.01 sec)

I think in case #6303 , we can fix the error message by throwing out ErrInvalidDefault in all means, and Fix the corner cases or situations in extra one or more prs ..

@zz-jason zz-jason changed the title DDL: Refine errmsg for default value check when create table DDL: Refine error message about "Invalid default value" Apr 23, 2018
@ciscoxll
Copy link
Contributor

/run-all-tests

ddl/ddl_api.go Outdated
if types.ErrTruncated.Equal(err) {
return types.ErrInvalidDefault.GenByArgs(c.Name)
if _, err := table.GetColDefaultValue(ctx, c.ToInfo()); err != nil {
return errors.Trace(types.ErrInvalidDefault.GenByArgs(c.Name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why trace the error? And please add a test for the fix.

@shenli
Copy link
Member

shenli commented Apr 26, 2018

/run-all-tests

ctx sessionctx.Context
}

func (s *testIntegrationSuite) cleanEnv(c *C) {
Copy link
Member

Choose a reason for hiding this comment

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

we can use TearDownTest to avoid calling cleanEnv in every tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we'd better clearEnv after every case. It's common that different cases use the same database name and table name. test.t for example. We'd better clean them as soon as possible.

Copy link
Member

Choose a reason for hiding this comment

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

TearDownTest will be called automatically after every test case, we can rename cleanEnv to TearDownTest to avoid manually calling this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@@ -0,0 +1,88 @@
// Copyright 2015 PingCAP, Inc.
Copy link
Member

Choose a reason for hiding this comment

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

s/2015/2018/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok


import (
"fmt"
"github.com/juju/errors"
Copy link
Contributor

Choose a reason for hiding this comment

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

add a blank line between line 17 and line 18

Copy link
Member

Choose a reason for hiding this comment

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

@spongedu please address this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -467,11 +467,10 @@ func checkDefaultValue(ctx sessionctx.Context, c *table.Column, hasDefaultValue
}

if c.DefaultValue != nil {
_, err := table.GetColDefaultValue(ctx, c.ToInfo())
if types.ErrTruncated.Equal(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd better not remove this check totally,
it may be safer to add another check for err here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@XuHuaiyu as I commented above, it's a bit complicate here I found. Illegal default value doesn't necessary result in ErrInvalidDefault, actually. For example:

In MySQL:

mysql> create table t(a decimal(3) default 1.25567);
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> show warnings;
+-------+------+----------------------------------------+
| Level | Code | Message                                |
+-------+------+----------------------------------------+
| Note  | 1265 | Data truncated for column 'a' at row 1 |
+-------+------+----------------------------------------+
1 row in set (0.00 sec)

In TiDB:

tidb> create table t(a decimal(3) default 1.25567);
ERROR 1067 (42000): Invalid default value for 'a'

But if default value check if set in ALTER TABLE situation(ddl/ddl_db_test.go: line 1139), The
ErrInvalidDefault error is raised.

another example:

Im MySQL:

mysql> create table t ( a date default '2012-01-01 01:01:01');
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> show warnings;
+-------+------+---------------------------------------------------------------------+
| Level | Code | Message                                                             |
+-------+------+---------------------------------------------------------------------+
| Note  | 1292 | Incorrect date value: '2012-01-01 01:01:01' for column 'a' at row 1 |
+-------+------+---------------------------------------------------------------------+
1 row in set (0.00 sec)

In TiDB:

create table t ( a date default '2012-01-01 01:01:01');
Query OK, 0 rows affected (0.01 sec)

I think in case #6303 , we can fix the error message by throwing out ErrInvalidDefault in all means, ignore the error check, and Fix the corner cases or situations in extra one or more prs ..

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

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label May 7, 2018
@shenli
Copy link
Member

shenli commented May 8, 2018

/run-all-tests

@shenli
Copy link
Member

shenli commented May 8, 2018

LGTM

@shenli
Copy link
Member

shenli commented May 8, 2018

@zimulala PTAL

@shenli shenli added status/LGT2 Indicates that a PR has LGTM 2. require-LGT3 Indicates that the PR requires three LGTM. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 8, 2018
@zimulala zimulala removed the require-LGT3 Indicates that the PR requires three LGTM. label May 9, 2018
@zz-jason
Copy link
Member

zz-jason commented May 9, 2018

@zimulala @coocood @winkyao @jackysp PTAL

Copy link
Member

@coocood coocood left a comment

Choose a reason for hiding this comment

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

LGTM

@coocood coocood added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels May 18, 2018
@tiancaiamao
Copy link
Contributor

/run-all-tests

@tiancaiamao tiancaiamao merged commit b4c0e6c into pingcap:master May 20, 2018
@spongedu spongedu deleted the fix_6303 branch May 27, 2018 09:59
@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
contribution This PR is from a community contributor. sig/sql-infra SIG: SQL Infra status/LGT3 The PR has already had 3 LGTM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ErrDataOutOfRange is not bounded with args