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

*: check float/double display width and scale #6098

Merged
merged 3 commits into from
Mar 20, 2018

Conversation

XuHuaiyu
Copy link
Contributor

Before this commit:

tidb(127.0.0.1)> create table t(a double(256, 30));
ERROR 1063 (42000): Incorrect column specifier for column 'a'
tidb(127.0.0.1)> create table t(a double(255, 31));
ERROR 1063 (42000): Incorrect column specifier for column 'a'

After this commit:

tidb(127.0.0.1)> create table t(a double(256, 30));
ERROR 1426 (42000): Too big precision 256 specified for column 'a'. Maximum is 255.
tidb(127.0.0.1)> create table t(a double(255, 31));
ERROR 1425 (42000): Too big scale 31 specified for column 'a'. Maximum is 30.

PTAL @zz-jason @coocood

@XuHuaiyu
Copy link
Contributor Author

/run-all-tests

@@ -97,10 +97,6 @@ func (s *testValidatorSuite) TestValidator(c *C) {
errors.New("[types:1439]Display width out of range for column 'c' (max = 4294967295)")},
{"alter table t add column c float(4294967296)", true,
errors.New("[types:1439]Display width out of range for column 'c' (max = 4294967295)")},
{"create table t (c float(54))", true,
Copy link
Member

Choose a reason for hiding this comment

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

why remove this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

duplicated with the newly added cases.

@@ -227,6 +227,8 @@ const (

MaxIntWidth = 20
MaxRealWidth = 23
MaxFloatingTypeScale = 30
MaxFloatingTypeWidth = 255
Copy link
Member

Choose a reason for hiding this comment

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

is this consistent with mysql ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@@ -5532,7 +5532,7 @@ NumericType:
x := types.NewFieldType($1.(byte))
x.Flen = fopt.Flen
if x.Tp == mysql.TypeFloat {
if x.Flen > mysql.PrecisionForFloat {
if x.Flen > 24 {
Copy link
Member

Choose a reason for hiding this comment

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

should we extract 24 as to a variable like maxFloatScale ?

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 not define it as a constant to avoid being abused.
This is not a meaningful number got from MySQL manual,
but extracted from the behavior of MySQL. (#351 may be referred.)

@zz-jason
Copy link
Member

LGTM

@XuHuaiyu XuHuaiyu added status/LGT1 Indicates that a PR has LGTM 1. all-tests-passed labels Mar 20, 2018
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

@zimulala zimulala added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 20, 2018
@zz-jason zz-jason merged commit db7e6c5 into pingcap:master Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2. type/compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants