Skip to content

Commit

Permalink
planner: standardize some terminologies in binding pkg (#48957)
Browse files Browse the repository at this point in the history
ref #48875
  • Loading branch information
qw4990 committed Nov 28, 2023
1 parent c741119 commit 46d4231
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 163 deletions.
20 changes: 10 additions & 10 deletions pkg/bindinfo/bind_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ func (c *bindCache) delete(key bindCacheKey) bool {
return false
}

// GetBindRecord gets the BindRecord from the cache.
// GetBinding gets the BindRecord from the cache.
// The return value is not read-only, but it shouldn't be changed in the caller functions.
// The function is thread-safe.
func (c *bindCache) GetBindRecord(sqlDigest, normalizedSQL, _ string) *BindRecord {
func (c *bindCache) GetBinding(sqlDigest, normalizedSQL, _ string) *BindRecord {
c.lock.Lock()
defer c.lock.Unlock()
bindRecords := c.get(bindCacheKey(sqlDigest))
Expand All @@ -146,10 +146,10 @@ func (c *bindCache) GetBindRecord(sqlDigest, normalizedSQL, _ string) *BindRecor
return nil
}

// GetBindRecordBySQLDigest gets the BindRecord from the cache.
// GetBindingBySQLDigest gets the BindRecord from the cache.
// The return value is not read-only, but it shouldn't be changed in the caller functions.
// The function is thread-safe.
func (c *bindCache) GetBindRecordBySQLDigest(sqlDigest string) (*BindRecord, error) {
func (c *bindCache) GetBindingBySQLDigest(sqlDigest string) (*BindRecord, error) {
c.lock.Lock()
defer c.lock.Unlock()
bindings := c.get(bindCacheKey(sqlDigest))
Expand All @@ -163,10 +163,10 @@ func (c *bindCache) GetBindRecordBySQLDigest(sqlDigest string) (*BindRecord, err
return bindings[0], nil
}

// GetAllBindRecords return all the bindRecords from the bindCache.
// GetAllBindings return all the bindRecords from the bindCache.
// The return value is not read-only, but it shouldn't be changed in the caller functions.
// The function is thread-safe.
func (c *bindCache) GetAllBindRecords() []*BindRecord {
func (c *bindCache) GetAllBindings() []*BindRecord {
c.lock.Lock()
defer c.lock.Unlock()
values := c.cache.Values()
Expand All @@ -178,9 +178,9 @@ func (c *bindCache) GetAllBindRecords() []*BindRecord {
return bindRecords
}

// SetBindRecord sets the BindRecord to the cache.
// SetBinding sets the BindRecord to the cache.
// The function is thread-safe.
func (c *bindCache) SetBindRecord(sqlDigest string, meta *BindRecord) (err error) {
func (c *bindCache) SetBinding(sqlDigest string, meta *BindRecord) (err error) {
c.lock.Lock()
defer c.lock.Unlock()
cacheKey := bindCacheKey(sqlDigest)
Expand All @@ -194,9 +194,9 @@ func (c *bindCache) SetBindRecord(sqlDigest string, meta *BindRecord) (err error
return
}

// RemoveBindRecord removes the BindRecord which has same originSQL with specified BindRecord.
// RemoveBinding removes the BindRecord which has same originSQL with specified BindRecord.
// The function is thread-safe.
func (c *bindCache) RemoveBindRecord(sqlDigest string, meta *BindRecord) {
func (c *bindCache) RemoveBinding(sqlDigest string, meta *BindRecord) {
c.lock.Lock()
defer c.lock.Unlock()
metas := c.getCopiedVal(bindCacheKey(sqlDigest))
Expand Down
6 changes: 3 additions & 3 deletions pkg/bindinfo/capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func TestBindingSource(t *testing.T) {
tk.MustExec("create global binding for select * from t where a > 10 using select * from t ignore index(idx_a) where a > 10")
bindHandle := dom.BindHandle()
sql, sqlDigest := internal.UtilNormalizeWithDefaultDB(t, "select * from t where a > ?")
bindData := bindHandle.GetBindRecord(sqlDigest, sql, "test")
bindData := bindHandle.GetGlobalBinding(sqlDigest, sql, "test")
require.NotNil(t, bindData)
require.Equal(t, "select * from `test` . `t` where `a` > ?", bindData.OriginalSQL)
require.Len(t, bindData.Bindings, 1)
Expand All @@ -341,7 +341,7 @@ func TestBindingSource(t *testing.T) {
tk.MustQuery("select * from t where a > 10")
bindHandle.SaveEvolveTasksToStore()
sql, sqlDigest = internal.UtilNormalizeWithDefaultDB(t, "select * from t where a > ?")
bindData = bindHandle.GetBindRecord(sqlDigest, sql, "test")
bindData = bindHandle.GetGlobalBinding(sqlDigest, sql, "test")
require.NotNil(t, bindData)
require.Equal(t, "select * from `test` . `t` where `a` > ?", bindData.OriginalSQL)
require.Len(t, bindData.Bindings, 2)
Expand All @@ -362,7 +362,7 @@ func TestBindingSource(t *testing.T) {
tk.MustExec("admin capture bindings")
bindHandle.CaptureBaselines()
sql, sqlDigest = internal.UtilNormalizeWithDefaultDB(t, "select * from t where a < ?")
bindData = bindHandle.GetBindRecord(sqlDigest, sql, "test")
bindData = bindHandle.GetGlobalBinding(sqlDigest, sql, "test")
require.NotNil(t, bindData)
require.Equal(t, "select * from `test` . `t` where `a` < ?", bindData.OriginalSQL)
require.Len(t, bindData.Bindings, 1)
Expand Down
Loading

0 comments on commit 46d4231

Please sign in to comment.