Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
YufeiCh authored Jan 10, 2022
2 parents 2aa0489 + 3610c83 commit 1b062bc
Show file tree
Hide file tree
Showing 51 changed files with 769 additions and 374 deletions.
8 changes: 4 additions & 4 deletions bindinfo/session_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func (h *SessionHandle) CreateBindRecord(sctx sessionctx.Context, record *BindRe
// DropBindRecord drops a BindRecord in the cache.
func (h *SessionHandle) DropBindRecord(originalSQL, db string, binding *Binding) error {
db = strings.ToLower(db)
oldRecord := h.GetBindRecord(originalSQL, db)
hash := parser.DigestNormalized(originalSQL).String()
oldRecord := h.GetBindRecord(hash, originalSQL, db)
var newRecord *BindRecord
record := &BindRecord{OriginalSQL: originalSQL, Db: db}
if binding != nil {
Expand All @@ -79,14 +80,13 @@ func (h *SessionHandle) DropBindRecord(originalSQL, db string, binding *Binding)
} else {
newRecord = record
}
h.ch.setBindRecord(parser.DigestNormalized(record.OriginalSQL).String(), newRecord)
h.ch.setBindRecord(hash, newRecord)
updateMetrics(metrics.ScopeSession, oldRecord, newRecord, false)
return nil
}

// GetBindRecord return the BindMeta of the (normdOrigSQL,db) if BindMeta exist.
func (h *SessionHandle) GetBindRecord(normdOrigSQL, db string) *BindRecord {
hash := parser.DigestNormalized(normdOrigSQL).String()
func (h *SessionHandle) GetBindRecord(hash, normdOrigSQL, db string) *BindRecord {
bindRecords := h.ch[hash]
for _, bindRecord := range bindRecords {
if bindRecord.OriginalSQL == normdOrigSQL {
Expand Down
6 changes: 4 additions & 2 deletions bindinfo/session_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tidb/bindinfo"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/auth"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session/txninfo"
Expand Down Expand Up @@ -121,7 +122,8 @@ func TestSessionBinding(t *testing.T) {
require.Equal(t, testSQL.memoryUsage, pb.GetGauge().GetValue())

handle := tk.Session().Value(bindinfo.SessionBindInfoKeyType).(*bindinfo.SessionHandle)
bindData := handle.GetBindRecord(testSQL.originSQL, "test")
hash := parser.DigestNormalized(testSQL.originSQL).String()
bindData := handle.GetBindRecord(hash, testSQL.originSQL, "test")
require.NotNil(t, bindData)
require.Equal(t, testSQL.originSQL, bindData.OriginalSQL)
bind := bindData.Bindings[0]
Expand Down Expand Up @@ -158,7 +160,7 @@ func TestSessionBinding(t *testing.T) {

_, err = tk.Exec("drop session " + testSQL.dropSQL)
require.NoError(t, err)
bindData = handle.GetBindRecord(testSQL.originSQL, "test")
bindData = handle.GetBindRecord(hash, testSQL.originSQL, "test")
require.NotNil(t, bindData)
require.Equal(t, testSQL.originSQL, bindData.OriginalSQL)
require.Len(t, bindData.Bindings, 0)
Expand Down
Loading

0 comments on commit 1b062bc

Please sign in to comment.