Skip to content

Commit

Permalink
cherry pick pingcap#33519 to release-5.3
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
lcwangchao authored and ti-srebot committed Mar 30, 2022
1 parent 459917c commit 67fd7ef
Show file tree
Hide file tree
Showing 3 changed files with 524 additions and 20 deletions.
1 change: 0 additions & 1 deletion planner/core/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ func NewPSTMTPlanCacheValue(plan Plan, names []*types.FieldName, srcMap map[*mod
type CachedPrepareStmt struct {
PreparedAst *ast.Prepared
VisitInfos []visitInfo
ColumnInfos interface{}
Executor interface{}
NormalizedSQL string
NormalizedPlan string
Expand Down
25 changes: 6 additions & 19 deletions server/driver_tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ func (ts *TiDBStatement) Execute(ctx context.Context, args []types.Datum) (rs Re
return
}
rs = &tidbResultSet{
recordSet: tidbRecordset,
preparedStmt: ts.ctx.GetSessionVars().PreparedStmts[ts.id].(*core.CachedPrepareStmt),
recordSet: tidbRecordset,
}
return
}
Expand Down Expand Up @@ -291,11 +290,10 @@ func (tc *TiDBContext) Prepare(sql string) (statement PreparedStatement, columns
}

type tidbResultSet struct {
recordSet sqlexec.RecordSet
columns []*ColumnInfo
rows []chunk.Row
closed int32
preparedStmt *core.CachedPrepareStmt
recordSet sqlexec.RecordSet
columns []*ColumnInfo
rows []chunk.Row
closed int32
}

func (trs *tidbResultSet) NewChunk() *chunk.Chunk {
Expand Down Expand Up @@ -337,23 +335,12 @@ func (trs *tidbResultSet) Columns() []*ColumnInfo {
if trs.columns != nil {
return trs.columns
}
// for prepare statement, try to get cached columnInfo array
if trs.preparedStmt != nil {
ps := trs.preparedStmt
if colInfos, ok := ps.ColumnInfos.([]*ColumnInfo); ok {
trs.columns = colInfos
}
}

if trs.columns == nil {
fields := trs.recordSet.Fields()
for _, v := range fields {
trs.columns = append(trs.columns, convertColumnInfo(v))
}
if trs.preparedStmt != nil {
// if ColumnInfo struct has allocated object,
// here maybe we need deep copy ColumnInfo to do caching
trs.preparedStmt.ColumnInfos = trs.columns
}
}
return trs.columns
}
Expand Down
Loading

0 comments on commit 67fd7ef

Please sign in to comment.