-
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
planner: add more test cases for non-prep plan cache #43083
Changes from 1 commit
88a6d9c
29075d8
876583e
1bdcd24
1a46daa
1bb7784
95d200c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,8 @@ func (pr *paramReplacer) Enter(in ast.Node) (out ast.Node, skipChildren bool) { | |
} | ||
case *driver.ValueExpr: | ||
pr.params = append(pr.params, n) | ||
param := ast.NewParamMarkerExpr(len(pr.params) - 1) // offset is used as order in non-prepared plan cache. | ||
param.(*driver.ParamMarkerExpr).Datum = *n.Datum.Clone() // init the ParamMakerExpr's Datum | ||
param := ast.NewParamMarkerExpr(len(pr.params) - 1) // offset is used as order in non-prepared plan cache. | ||
n.Datum.Copy(¶m.(*driver.ParamMarkerExpr).Datum) // init the ParamMakerExpr's Datum | ||
Comment on lines
+75
to
+76
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. Reduce one time of data copy. |
||
return param, true | ||
} | ||
return in, false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,6 +186,7 @@ func GeneratePlanCacheStmtWithAST(ctx context.Context, sctx sessionctx.Context, | |
// Put the parameters that may affect the plan in planCacheValue. | ||
// However, due to some compatibility reasons, we will temporarily keep some system variable-related values in planCacheKey. | ||
// At the same time, because these variables have a small impact on plan, we will move them to PlanCacheValue later if necessary. | ||
// TODO: maintain a sync.pool for this structure. | ||
type planCacheKey struct { | ||
database string | ||
connID uint64 | ||
|
@@ -215,8 +216,8 @@ type planCacheKey struct { | |
func (key *planCacheKey) Hash() []byte { | ||
if len(key.hash) == 0 { | ||
var ( | ||
dbBytes = hack.Slice(key.database) | ||
bufferSize = len(dbBytes) + 8*6 + 3*8 | ||
dbBytes = hack.Slice(key.stmtText) | ||
bufferSize = len(dbBytes) * 2 | ||
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. Reduce times of buffer re-allocation. |
||
) | ||
if key.hash == nil { | ||
key.hash = make([]byte, 0, bufferSize) | ||
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 may use 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. Yes, I add a TODO comment there. |
||
|
@@ -496,6 +497,12 @@ func (checker *matchOptsExtractor) Enter(in ast.Node) (out ast.Node, skipChildre | |
} | ||
tStats := getStatsTable(checker.sctx, t.Meta(), t.Meta().ID) | ||
checker.statsVersionHash += tableStatsVersionForPlanCache(tStats) // use '+' as the hash function for simplicity | ||
case *ast.InsertStmt: | ||
if node.Select != nil { | ||
node.Select.Accept(checker) | ||
} | ||
// skip node.Table for performance. | ||
return in, true | ||
} | ||
return in, false | ||
} | ||
|
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.
Prepare to enable this switch by default in the future.