-
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
expression,planner: support non-deterministic functions (e.g., now) in the prepared plan cache #8105
expression,planner: support non-deterministic functions (e.g., now) in the prepared plan cache #8105
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
/run-all-tests |
@dbjoa Thanks! |
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 work, LGTM.
expression/scalar_function.go
Outdated
@@ -70,8 +70,8 @@ func (sf *ScalarFunction) MarshalJSON() ([]byte, error) { | |||
return []byte(fmt.Sprintf("\"%s\"", sf)), nil | |||
} | |||
|
|||
// NewFunction creates a new scalar function or constant. | |||
func NewFunction(ctx sessionctx.Context, funcName string, retType *types.FieldType, args ...Expression) (Expression, error) { | |||
// newFunction creates a new scalar function or constant. |
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/newFunction/newFunctionImpl
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.
Thank you for the comment. I've updated the PR.
planner/core/prepare_test.go
Outdated
"github.com/pingcap/tidb/planner/core" | ||
"github.com/pingcap/tidb/util/testkit" | ||
"github.com/pingcap/tidb/util/testleak" | ||
dto "github.com/prometheus/client_model/go" | ||
"time" |
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.
put this line to line 17 and leave a blank line behind it.
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.
Thank you for the detailed comment. I've updated the PR.
expression/scalar_function.go
Outdated
// NewFunction creates a new scalar function or constant. | ||
func NewFunction(ctx sessionctx.Context, funcName string, retType *types.FieldType, args ...Expression) (Expression, error) { | ||
// newFunctionImpl creates a new scalar function or constant. | ||
func newFunctionImpl(fold bool, ctx sessionctx.Context, funcName string, retType *types.FieldType, args ...Expression) (Expression, error) { |
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.
ctx
is always the first argument of a function,
we'd better keep this style.
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.
Thank you for the detailed comment. I've updated the PR.
MySQL: mysql> prepare stmt from "select now(), sleep(1), now(), sleep(1), now()";
Query OK, 0 rows affected (0.00 sec)
Statement prepared
mysql> execute stmt;
+---------------------+----------+---------------------+----------+----------------$----+
| now() | sleep(1) | now() | sleep(1) | now()
|
+---------------------+----------+---------------------+----------+----------------$----+
| 2018-10-31 16:00:14 | 0 | 2018-10-31 16:00:14 | 0 | 2018-10-31 16:0$:14 |
+---------------------+----------+---------------------+----------+----------------$----+
1 row in set (2.01 sec)
mysql> execute stmt;
+---------------------+----------+---------------------+----------+----------------$----+
| now() | sleep(1) | now() | sleep(1) | now()
|
+---------------------+----------+---------------------+----------+----------------$----+
| 2018-10-31 16:00:19 | 0 | 2018-10-31 16:00:19 | 0 | 2018-10-31 16:0$:19 |
+---------------------+----------+---------------------+----------+----------------$----+
1 row in set (2.01 sec) In MySQL, |
@XuHuaiyu, Thank you for the comment. The updated PR should address the issue. |
/run-all-tests |
1 similar comment
/run-all-tests |
I should also handle the synonyms of |
/run-all-tests |
The updated PR should handle the synonyms of |
/run-all-tests |
planner/core/prepare_test.go
Outdated
@@ -14,7 +14,13 @@ | |||
package core_test | |||
|
|||
import ( | |||
dto "github.com/prometheus/client_model/go" |
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.
please move this package to the lower block. separate it from the golang standard packages.
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.
Thank you for the comment. I've updated the PR.
expression/function_traits.go
Outdated
@@ -52,6 +41,23 @@ var unFoldableFunctions = map[string]struct{}{ | |||
ast.GetParam: {}, | |||
} | |||
|
|||
// DeferredFunctions stores non-deterministic functions which can be deferred. |
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.
How adding another comment to specify that the deferred functions take effects only when plan cache is enabled?
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.
Thank you for the comment. I've added the comment to the updated the 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.
LGTM
/run-all-tests |
What problem does this PR solve?
Support non-deterministic functions (e.g., now) in the prepared plan cache.
What is changed and how it works?
Make a non-deterministic function expression to be a constant expression with the deferred expression (i.e., the non-deterministic function expression).
Check List
Tests
Code changes
Side effects
Related changes