-
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
*: support default expression value for sequence #14589
Conversation
table/column.go
Outdated
var defaultExpr ast.ExprNode | ||
expr := fmt.Sprintf("select %s", x) | ||
charset, collation := charset.GetDefaultCharsetAndCollate() | ||
stmts, _, err := parser.New().Parse(expr, charset, collation) |
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 is enough to pass empty strings to charset and collation.
A question: is it necessary to parse the expression once again?
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.
- nice idea.
- Actually we can do the expr cache like
colDefaultVals
does, Given the sequence function hasn't been implemented now, it's hard to do the test, so I push it to the next PR.
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 addressed
table/column.go
Outdated
var defaultExpr ast.ExprNode | ||
expr := fmt.Sprintf("select %s", x) | ||
charset, collation := charset.GetDefaultCharsetAndCollate() | ||
stmts, _, err := parser.New().Parse(expr, charset, collation) |
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.
- nice idea.
- Actually we can do the expr cache like
colDefaultVals
does, Given the sequence function hasn't been implemented now, it's hard to do the test, so I push it to the next PR.
/rebuild |
/build |
Value: types.NewDatum(v.Name.L), | ||
RetType: types.NewFieldType(mysql.TypeString), | ||
} | ||
er.ctxStackAppend(val, types.EmptyName) |
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.
Does any place use this element in the stack?
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.
only nextval / lastval / setval function will take it as string arg. (this function will be added in next pr)
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.
Should we guarantee the stack empty at the end of the rewrite stage? If we should, does this element break our guarantee?
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 we can, take nextval(tableName)
for example, tableName will be rewritten as a constant string, then the upper FuncCallExpr
will consume it.
/run-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.
LGTM
/merge |
/run-all-tests |
@AilinKid merge failed. |
/run-integration-common-test |
/build |
/run-integration-common-test |
1 similar comment
/run-integration-common-test |
/run-unit-test |
/run-all-tests |
/run-unit-test |
/merge |
Your auto merge job has been accepted, waiting for 14682 |
/run-all-tests |
What problem does this PR solve?
linked Parser PR: #731
Problem 1:
before this pr, when we create a table with sequence's next value as it's default value like
will get a crash on expression rewrite.
Problem 2:
In some cases, the default value is dynamic, needing to be evaluated every time be called.
Problem 3:
Now, the static default value will be cache in the case like
insert into t values (),(),()...
.What is changed and how it works?
1: rewrite the tableName (specified sequence to constant string args)
2: store the expr_string in default value as the generated column does.
3: parser the expr_string and evaluate it every time call it
4: when
DefaultIsExpr
is true, we should ignore the default cache in insert cases and evaluate the value every time be called.Check List
Tests
Release note