Skip to content

Commit

Permalink
*: remove useless param (#46178)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Aug 17, 2023
1 parent 24122b5 commit 7d259bd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions planner/core/plan_cache_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (pr *paramReplacer) Reset() {
// GetParamSQLFromAST returns the parameterized SQL of this AST.
// NOTICE: this function does not modify the original AST.
// paramVals are copied from this AST.
func GetParamSQLFromAST(sctx sessionctx.Context, stmt ast.StmtNode) (paramSQL string, paramVals []types.Datum, err error) {
func GetParamSQLFromAST(stmt ast.StmtNode) (paramSQL string, paramVals []types.Datum, err error) {
var params []*driver.ValueExpr
paramSQL, params, err = ParameterizeAST(stmt)
if err != nil {
Expand All @@ -104,7 +104,7 @@ func GetParamSQLFromAST(sctx sessionctx.Context, stmt ast.StmtNode) (paramSQL st
p.Datum.Copy(&paramVals[i])
}

err = RestoreASTWithParams(sctx, stmt, params)
err = RestoreASTWithParams(stmt, params)
return
}

Expand Down Expand Up @@ -160,7 +160,7 @@ func (pr *paramRestorer) Reset() {

// RestoreASTWithParams restore this parameterized AST with specific parameters.
// e.g. `select * from t where a<? and b<?`, [10, 23] --> `select * from t where a<10 and b<23`.
func RestoreASTWithParams(_ sessionctx.Context, stmt ast.StmtNode, params []*driver.ValueExpr) error {
func RestoreASTWithParams(stmt ast.StmtNode, params []*driver.ValueExpr) error {
pr := paramRestorerPool.Get().(*paramRestorer)
defer func() {
pr.Reset()
Expand Down
5 changes: 2 additions & 3 deletions planner/core/plan_cache_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestGetParamSQLFromASTConcurrently(t *testing.T) {
wg.Add(1)
go func(id int) {
for i := 0; i < 1000; i++ {
_, vals, err := GetParamSQLFromAST(MockContext(), stmts[id])
_, vals, err := GetParamSQLFromAST(stmts[id])
require.Nil(t, err)
require.Equal(t, len(vals), 3)
require.Equal(t, vals[0].GetValue(), int64(id*3+0))
Expand Down Expand Up @@ -183,10 +183,9 @@ func BenchmarkGetParamSQL(b *testing.B) {
paymentInsertHistory := `INSERT INTO history (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) VALUES (1, 2, 3, 4, 5, 6, 7, 8)`
stmt, err := parser.New().ParseOneStmt(paymentInsertHistory, "", "")
require.Nil(b, err)
sctx := MockContext()

b.ResetTimer()
for i := 0; i < b.N; i++ {
GetParamSQLFromAST(sctx, stmt)
GetParamSQLFromAST(stmt)
}
}
2 changes: 1 addition & 1 deletion planner/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func getPlanFromNonPreparedPlanCache(ctx context.Context, sctx sessionctx.Contex
return nil, nil, false, nil
}

paramSQL, paramsVals, err := core.GetParamSQLFromAST(sctx, stmt)
paramSQL, paramsVals, err := core.GetParamSQLFromAST(stmt)
if err != nil {
return nil, nil, false, err
}
Expand Down

0 comments on commit 7d259bd

Please sign in to comment.