-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
dml: support default expression cache when insert #15216
Merged
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6aa6247
default expr cache
AilinKid 1f136c7
fmt
AilinKid 7dc9eb6
.
AilinKid e7251c7
fmt
AilinKid c970760
Merge branch 'master' into lazy_default_seq_expr
AilinKid b2995b6
.
AilinKid b7f4ebd
Merge branch 'master' into lazy_default_seq_expr
AilinKid 71fadbb
Merge branch 'master' into lazy_default_seq_expr
AilinKid dc10b0d
Merge branch 'master' into lazy_default_seq_expr
AilinKid d770a45
Merge branch 'master' into lazy_default_seq_expr
AilinKid bbb0ac5
benchmark test under gocheck
AilinKid bccb785
Merge branch 'master' into lazy_default_seq_expr
AilinKid 8842b95
cache default expr node in column(tableCommon)
AilinKid 89b7a22
Merge branch 'master' into lazy_default_seq_expr
AilinKid f50b24a
fmt
AilinKid 9254493
fmt
AilinKid 9bf6ef1
.
AilinKid eaa6caa
Merge branch 'master' into lazy_default_seq_expr
sre-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,10 @@ type InsertValues struct { | |
} | ||
|
||
type defaultVal struct { | ||
// common default value is a constant. | ||
val types.Datum | ||
// default expr(nextval(seq)) should be evaluated row by row. | ||
expr ast.ExprNode | ||
// valid indicates whether the val is evaluated. We evaluate the default value lazily. | ||
valid bool | ||
} | ||
|
@@ -508,16 +511,36 @@ func (e *InsertValues) getRowInPlace(ctx context.Context, vals []types.Datum, ro | |
|
||
// getColDefaultValue gets the column default value. | ||
func (e *InsertValues) getColDefaultValue(idx int, col *table.Column) (d types.Datum, err error) { | ||
if !col.DefaultIsExpr && e.colDefaultVals != nil && e.colDefaultVals[idx].valid { | ||
return e.colDefaultVals[idx].val, nil | ||
if e.colDefaultVals != nil && e.colDefaultVals[idx].valid { | ||
if !col.DefaultIsExpr { | ||
return e.colDefaultVals[idx].val, nil | ||
} | ||
return table.EvalColDefaultExpr(e.ctx, col.ToInfo(), e.colDefaultVals[idx].expr) | ||
} | ||
var ( | ||
defaultVal types.Datum | ||
defaultExpr ast.ExprNode | ||
) | ||
if !col.DefaultIsExpr { | ||
defaultVal, err = table.GetColDefaultValue(e.ctx, col.ToInfo()) | ||
} else { | ||
defaultExpr, err = table.GetColDefaultExpr(col.ToInfo()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about cache the default expression in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's practicable, but i think it's ok here |
||
if err != nil { | ||
return types.Datum{}, err | ||
} | ||
defaultVal, err = table.EvalColDefaultExpr(e.ctx, col.ToInfo(), defaultExpr) | ||
} | ||
defaultVal, err := table.GetColDefaultValue(e.ctx, col.ToInfo()) | ||
if err != nil { | ||
return types.Datum{}, err | ||
} | ||
if initialized := e.lazilyInitColDefaultValBuf(); initialized && !col.DefaultIsExpr { | ||
e.colDefaultVals[idx].val = defaultVal | ||
e.colDefaultVals[idx].valid = true | ||
if initialized := e.lazilyInitColDefaultValBuf(); initialized { | ||
if !col.DefaultIsExpr { | ||
e.colDefaultVals[idx].val = defaultVal | ||
e.colDefaultVals[idx].valid = true | ||
} else { | ||
e.colDefaultVals[idx].expr = defaultExpr | ||
e.colDefaultVals[idx].valid = true | ||
} | ||
} | ||
|
||
return defaultVal, nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this test is quite slow, it will cost more than 1 minute. Maybe we only need to run it in bench test instead of unit test?
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.
Make sense, thank u every much, addressed.