Skip to content

Commit

Permalink
free parser stmts (#16144)
Browse files Browse the repository at this point in the history
对parser解析之后的stmt进行free

Approved by: @qingxinhome
  • Loading branch information
daviszhen committed May 15, 2024
1 parent a6c1f3d commit a9d2a53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
5 changes: 5 additions & 0 deletions pkg/frontend/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9228,6 +9228,11 @@ func doInterpretCall(ctx context.Context, ses *Session, call *tree.CallStmt) ([]
if err != nil {
return nil, err
}
defer func() {
for _, st := range stmt {
st.Free()
}
}()

fmtctx := tree.NewFmtCtx(dialect.MYSQL, tree.WithQuoteString(true))

Expand Down
27 changes: 7 additions & 20 deletions pkg/frontend/back_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
"github.com/matrixorigin/matrixone/pkg/sql/compile"
"github.com/matrixorigin/matrixone/pkg/sql/parsers"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect/mysql"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
plan2 "github.com/matrixorigin/matrixone/pkg/sql/plan"
Expand Down Expand Up @@ -184,12 +183,6 @@ func (back *backExec) Clear() {
// execute query
func doComQueryInBack(backSes *backSession, execCtx *ExecCtx,
input *UserInput) (retErr error) {
//fmt.Fprintln(os.Stderr, "doComQueryInBack", input.getSql())
//defer func() {
// if retErr != nil {
// fmt.Fprintln(os.Stderr, "doComQueryInBack", retErr)
// }
//}()
backSes.GetTxnCompileCtx().SetExecCtx(execCtx)
backSes.SetSql(input.getSql())
//the ses.GetUserName returns the user_name with the account_name.
Expand Down Expand Up @@ -248,6 +241,7 @@ func doComQueryInBack(backSes *backSession, execCtx *ExecCtx,
execCtx.reqCtx, span = trace.Start(execCtx.reqCtx, "backExec.doComQueryInBack",
trace.WithKind(trace.SpanKindStatement))
defer span.End()
execCtx.input = input

proc.SessionInfo.User = userNameOnly
cws, err := GetComputationWrapperInBack(execCtx, backSes.proto.GetDatabaseName(),
Expand All @@ -269,6 +263,9 @@ func doComQueryInBack(backSes *backSession, execCtx *ExecCtx,
}()

defer func() {
execCtx.stmt = nil
execCtx.cw = nil
execCtx.cws = nil
for i := 0; i < len(cws); i++ {
cws[i].Free()
}
Expand Down Expand Up @@ -414,7 +411,7 @@ func executeStmtInBack(backSes *backSession,
return
}

var GetComputationWrapperInBack = func(exeCtx *ExecCtx, db string, input *UserInput, user string, eng engine.Engine, proc *process.Process, ses FeSession) ([]ComputationWrapper, error) {
var GetComputationWrapperInBack = func(execCtx *ExecCtx, db string, input *UserInput, user string, eng engine.Engine, proc *process.Process, ses FeSession) ([]ComputationWrapper, error) {
var cw []ComputationWrapper = nil

var stmts []tree.Statement = nil
Expand All @@ -424,23 +421,13 @@ var GetComputationWrapperInBack = func(exeCtx *ExecCtx, db string, input *UserIn
if input.getStmt() != nil {
stmts = append(stmts, input.getStmt())
} else if isCmdFieldListSql(input.getSql()) {
cmdFieldStmt, err = parseCmdFieldList(exeCtx.reqCtx, input.getSql())
cmdFieldStmt, err = parseCmdFieldList(execCtx.reqCtx, input.getSql())
if err != nil {
return nil, err
}
stmts = append(stmts, cmdFieldStmt)
} else {
var v interface{}
var origin interface{}
v, err = ses.GetGlobalVar(exeCtx.reqCtx, "lower_case_table_names")
if err != nil {
v = int64(1)
}
origin, err = ses.GetGlobalVar(exeCtx.reqCtx, "keep_user_target_list_in_result")
if err != nil {
origin = int64(0)
}
stmts, err = parsers.Parse(exeCtx.reqCtx, dialect.MYSQL, input.getSql(), v.(int64), origin.(int64))
stmts, err = parseSql(execCtx)
if err != nil {
return nil, err
}
Expand Down
20 changes: 0 additions & 20 deletions pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2695,12 +2695,6 @@ func executeStmt(ses *Session,

// execute query
func doComQuery(ses *Session, execCtx *ExecCtx, input *UserInput) (retErr error) {
//fmt.Fprintln(os.Stderr, "doComQuery", input.getSql())
//defer func() {
// if retErr != nil {
// fmt.Fprintln(os.Stderr, "doComQuery", retErr)
// }
//}()
ses.GetTxnCompileCtx().SetExecCtx(execCtx)
// set the batch buf for stream scan
var inMemStreamScan []*kafka.Message
Expand Down Expand Up @@ -2728,17 +2722,6 @@ func doComQuery(ses *Session, execCtx *ExecCtx, input *UserInput) (retErr error)
}(ses.tStmt)
ses.tStmt = nil

// proc := process.New(
// requestCtx,
// ses.GetMemPool(),
// getGlobalPu().TxnClient,
// nil,
// getGlobalPu().FileService,
// getGlobalPu().LockService,
// getGlobalPu().QueryClient,
// getGlobalPu().HAKeeperClient,
// getGlobalPu().UdfService,
// globalAicm)
proc := ses.proc
proc.Ctx = execCtx.reqCtx

Expand All @@ -2764,7 +2747,6 @@ func doComQuery(ses *Session, execCtx *ExecCtx, input *UserInput) (retErr error)
LogLevel: zapcore.InfoLevel, //TODO: need set by session level config
SessionId: ses.GetSessId(),
}
// proc.SetStmtProfile(&ses.stmtProfile)
proc.SetResolveVariableFunc(ses.txnCompileCtx.ResolveVariable)
proc.InitSeq()
// Copy curvalues stored in session to this proc.
Expand Down Expand Up @@ -2798,8 +2780,6 @@ func doComQuery(ses *Session, execCtx *ExecCtx, input *UserInput) (retErr error)

proc.SessionInfo.User = userNameOnly
proc.SessionInfo.QueryId = ses.getQueryId(input.isInternal())
// ses.txnCompileCtx.SetProcess(proc)
// ses.proc.SessionInfo = proc.SessionInfo

statsInfo := statistic.StatsInfo{ParseStartTime: beginInstant}
execCtx.reqCtx = statistic.ContextWithStatsInfo(execCtx.reqCtx, &statsInfo)
Expand Down

0 comments on commit a9d2a53

Please sign in to comment.