-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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, planner, types: add M>=D checking for decimal column definition with default value #21845
Conversation
@TszKitLo40 please take a look at: |
But the grammar check method here is private |
@TszKitLo40 I mean grammar check such as M >= D can put in planner/core/preprocess.go in |
It is reasonable. If we add this check in |
Yes! |
Do you think we should keep the logic I changed? I think we shouldn't ignore the err in |
I think yes. |
planner/core/preprocess.go
Outdated
@@ -935,6 +935,9 @@ func checkColumn(colDef *ast.ColumnDef) error { | |||
return types.ErrTooBigDisplayWidth.GenWithStackByArgs(colDef.Name.Name.O, mysql.MaxFloatingTypeWidth) | |||
} | |||
} | |||
if tp.Flen < tp.Decimal { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below code should move into upper else block. float type can only provide Flen
and the Decimal
is -1
. So current code could break f float(64)
.
Rest LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I have moved it into the upper else block.
It seems this PR can also close #21063 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
ddl/ddl_api.go
Outdated
@@ -953,6 +953,9 @@ func checkDefaultValue(ctx sessionctx.Context, c *table.Column, hasDefaultValue | |||
return nil | |||
} | |||
if _, err := table.GetColDefaultValue(ctx, c.ToInfo()); err != nil { | |||
if types.ErrMBiggerThanD.Equal(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I have removed it.
types/datum.go
Outdated
@@ -1294,6 +1294,10 @@ func (d *Datum) convertToMysqlDecimal(sc *stmtctx.StatementContext, target *Fiel | |||
if err == nil && err1 != nil { | |||
err = err1 | |||
} | |||
if err != nil { | |||
ret.SetMysqlDecimal(dec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the logic in ddl_api.go
, but it seems this error should be handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL @breeswish @lysu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added comment the this line. Do you think it is appropriate? PTAL @breeswish @lysu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a test to cover the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L242 in types/convert_test.go
can reach the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I remove your code here, the test can also pass...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you run the test TestConvertType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I did
Since we have processed in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
Your auto merge job has been accepted, waiting for:
|
/merge |
/run-all-tests |
@TszKitLo40 merge failed. |
/run-unit-test |
/merge |
Your auto merge job has been accepted, waiting for:
|
/merge |
/run-all-tests |
What problem does this PR solve?
Issue Number: close #21835
Problem Summary:
What is changed and how it works?
What's Changed:
add M>=D checking for decimal column definition with default value
How it Works:
return error if M >= D for decimal column definition
Related changes
Check List
Tests
Side effects
Release note