-
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
executor: remove some useless code and avoid some redundancy check #7639
Conversation
92f7af0
to
001b219
Compare
/run-all-tests |
/run-all-tests |
/run-all-tests tidb-test=pr/623 |
PTAL @coocood |
@@ -338,7 +338,7 @@ func (t *testTableSuite) TestGetDefaultValue(c *C) { | |||
}, | |||
}, | |||
true, | |||
types.Datum{}, | |||
types.NewIntDatum(0), |
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.
Is this a bug fix?
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.
No, it a unit test for function GetColDefaultValue
. It is changed due to the behavior of GetColDefaultValue
was changed.
table/column.go
Outdated
@@ -339,7 +353,7 @@ func getColDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo, defaultVa | |||
|
|||
func getColDefaultValueFromNil(ctx sessionctx.Context, col *model.ColumnInfo) (types.Datum, error) { | |||
if !mysql.HasNotNullFlag(col.Flag) { | |||
return types.Datum{}, nil |
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.
types.Datum{}
is better than types.NewDatum(nil)
table/column.go
Outdated
return GetZeroValue(col), nil | ||
} | ||
if col.IsGenerated() { | ||
return types.NewDatum(nil), nil |
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.
What if the generated column have a not null flag ?
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.
It will be checked in HandleBadNull
.
// For NOT NULL column, it will return error or use zero value based on sql_mode. | ||
func (e *InsertValues) initDefaultValues(row []types.Datum, hasValue []bool) error { | ||
func (e *InsertValues) fillRow(cols []*table.Column, row []types.Datum, hasValue []bool, valLen int) ([]types.Datum, error) { | ||
for i, c := range e.Table.Cols() { |
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.
There are cols
from caller and e.Table.Cols()
, which one should we use?
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.
Good catch! I think it may contain some bugs.
executor/insert_common.go
Outdated
|
||
// Evaluate the generated columns. | ||
if c.IsGenerated() { | ||
for i, expr := range e.GenExprs { |
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.
s/i/j
executor/insert_common.go
Outdated
return types.Datum{}, errors.Trace(err) | ||
} | ||
return d, nil | ||
} else if !hasValue { |
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.
s/else if/ if
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.
The "not auto increment" && "not has value case".
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.
If not auto increment and not has value, we could return the datum directly.
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.
So, when "not auto increment" && "not has value case", the returned value is NULL
, rather then a column default value, even the column has default value defined?
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.
else if can be changed to if, rest LGTM
/run-common-test tidb-test=pr/623 |
LGTM |
PTAL @tiancaiamao |
PTAL @coocood |
LGTM |
PTAL @coocood |
PTAL @coocood |
1 similar comment
PTAL @coocood |
PTAL @lysu |
PTAL @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.
LGTM
/run-all-tests |
/run-all-tests |
/run-all-tests tidb-test=pr/623 |
1 similar comment
/run-all-tests tidb-test=pr/623 |
What problem does this PR solve?
Remove some useless code and avoid some redundancy check.
What is changed and how it works?
Remove
finished
in all DMLs. Avoid once null check when filling the rows.Check List
Tests
Code changes
PTAL @coocood
Merge it with https://github.com/pingcap/tidb-test/pull/623