deal uncached prepare qps

This commit is contained in:
hebo
2019-09-24 22:40:17 +08:00
parent 92e592ed73
commit a9f0ee309e
6 changed files with 159 additions and 89 deletions

View File

@@ -19,6 +19,8 @@ var (
coverRangePool = NewCoveragePool()
localStmtCache = model.NewSliceBufferPool("statement cache", MaxMysqlPacketLen)
PrepareStatement = []byte(":prepare")
)
func init() {

View File

@@ -258,7 +258,8 @@ func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
case ComStmtPrepare:
mqp = ms.composeQueryPiece()
querySQLInBytes = ms.cachedStmtBytes[1:]
querySQLInBytes = make([]byte, len(ms.cachedStmtBytes[1:]))
copy(querySQLInBytes, ms.cachedStmtBytes[1:])
querySQL := hack.String(querySQLInBytes)
mqp.QuerySQL = &querySQL
ms.cachedPrepareStmt[ms.prepareInfo.prepareStmtID] = querySQLInBytes
@@ -267,10 +268,15 @@ func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
case ComStmtExecute:
prepareStmtID := bytesToInt(ms.cachedStmtBytes[1:5])
mqp = ms.composeQueryPiece()
querySQLInBytes = ms.cachedPrepareStmt[prepareStmtID]
var ok bool
querySQLInBytes, ok = ms.cachedPrepareStmt[prepareStmtID]
if !ok {
querySQLInBytes = PrepareStatement
}
querySQL := hack.String(querySQLInBytes)
mqp.QuerySQL = &querySQL
log.Debugf("execute prepare statement:%d", prepareStmtID)
// log.Debugf("execute prepare statement:%d", prepareStmtID)
case ComStmtClose:
prepareStmtID := bytesToInt(ms.cachedStmtBytes[1:5])