Skip to content

Commit

Permalink
*: avoid create new parser object in prepared exec (#24371)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Aug 30, 2021
1 parent dadca79 commit f7ddfc9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion executor/prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (e *PrepareExec) Next(ctx context.Context, req *chunk.Chunk) error {
)
if sqlParser, ok := e.ctx.(sqlexec.SQLParser); ok {
// FIXME: ok... yet another parse API, may need some api interface clean.
stmts, err = sqlParser.ParseSQL(e.sqlText, charset, collation)
stmts, _, err = sqlParser.ParseSQL(ctx, e.sqlText, charset, collation)
} else {
p := parser.New()
p.SetParserConfig(vars.BuildParserConfig())
Expand Down
2 changes: 2 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,8 @@ func (s *session) getTiDBTableValue(name, val string) (string, error) {
return validatedVal, nil
}

var _ sqlexec.SQLParser = &session{}

func (s *session) ParseSQL(ctx context.Context, sql, charset, collation string) ([]ast.StmtNode, []error, error) {
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
span1 := span.Tracer().StartSpan("session.ParseSQL", opentracing.ChildOf(span.Context()))
Expand Down
2 changes: 1 addition & 1 deletion util/sqlexec/restricted_sql_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type SQLExecutor interface {
// But a session already has a parser bind in it, so we define this interface and use session as its implementation,
// thus avoid allocating new parser. See session.SQLParser for more information.
type SQLParser interface {
ParseSQL(sql, charset, collation string) ([]ast.StmtNode, error)
ParseSQL(ctx context.Context, sql, charset, collation string) ([]ast.StmtNode, []error, error)
}

// Statement is an interface for SQL execution.
Expand Down

0 comments on commit f7ddfc9

Please sign in to comment.