Skip to content

Commit

Permalink
Merge branch 'master' into gbk
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwener authored Nov 29, 2021
2 parents ae0249a + 352811d commit 396391a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
1 change: 1 addition & 0 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ func TestStrToDate(t *testing.T) {
{"15-01-2001 1:59:58.", "%d-%m-%Y %H:%i:%s.%f", true, types.KindMysqlTime, time.Date(2001, 1, 15, 1, 59, 58, 000000000, time.Local)},
{"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%s.%f", true, types.KindMysqlTime, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)},
{"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%S.%f", true, types.KindMysqlTime, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)},
{"2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f", true, types.KindMysqlTime, time.Date(2003, 1, 2, 10, 11, 12, 1200000, time.Local)},
{"2003-01-02 10:11:12 PM", "%Y-%m-%d %H:%i:%S %p", false, types.KindMysqlTime, time.Time{}},
{"10:20:10AM", "%H:%i:%S%p", false, types.KindMysqlTime, time.Time{}},
// test %@(skip alpha), %#(skip number), %.(skip punct)
Expand Down
39 changes: 7 additions & 32 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,7 @@ type StatementContext struct {

// stmtCache is used to store some statement-related values.
stmtCache map[StmtCacheKey]interface{}
// resourceGroupTagWithRow cache for the current statement resource group tag (with `Row` label).
resourceGroupTagWithRow atomic.Value
// resourceGroupTagWithIndex cache for the current statement resource group tag (with `Index` label).
resourceGroupTagWithIndex atomic.Value
// resourceGroupTagWithUnknown cache for the current statement resource group tag (with `Unknown` label).
resourceGroupTagWithUnknown atomic.Value

// Map to store all CTE storages of current SQL.
// Will clean up at the end of the execution.
CTEStorageMap interface{}
Expand Down Expand Up @@ -287,44 +282,24 @@ func (sc *StatementContext) GetPlanDigest() (normalized string, planDigest *pars
// GetResourceGroupTagger returns the implementation of tikvrpc.ResourceGroupTagger related to self.
func (sc *StatementContext) GetResourceGroupTagger() tikvrpc.ResourceGroupTagger {
return func(req *tikvrpc.Request) {
if req == nil {
return
}
req.ResourceGroupTag = sc.GetResourceGroupTagByLabel(
resourcegrouptag.GetResourceGroupLabelByKey(resourcegrouptag.GetFirstKeyFromRequest(req)))
}
}

// GetResourceGroupTagByLabel gets the resource group of the statement based on the label.
func (sc *StatementContext) GetResourceGroupTagByLabel(label tipb.ResourceGroupTagLabel) []byte {
switch label {
case tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow:
v := sc.resourceGroupTagWithRow.Load()
if v != nil {
return v.([]byte)
}
case tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex:
v := sc.resourceGroupTagWithIndex.Load()
if v != nil {
return v.([]byte)
}
case tipb.ResourceGroupTagLabel_ResourceGroupTagLabelUnknown:
v := sc.resourceGroupTagWithUnknown.Load()
if v != nil {
return v.([]byte)
}
if sc == nil {
return nil
}
normalized, sqlDigest := sc.SQLDigest()
if len(normalized) == 0 {
return nil
}
newTag := resourcegrouptag.EncodeResourceGroupTag(sqlDigest, sc.planDigest, label)
switch label {
case tipb.ResourceGroupTagLabel_ResourceGroupTagLabelRow:
sc.resourceGroupTagWithRow.Store(newTag)
case tipb.ResourceGroupTagLabel_ResourceGroupTagLabelIndex:
sc.resourceGroupTagWithIndex.Store(newTag)
case tipb.ResourceGroupTagLabel_ResourceGroupTagLabelUnknown:
sc.resourceGroupTagWithUnknown.Store(newTag)
}
return newTag
return resourcegrouptag.EncodeResourceGroupTag(sqlDigest, sc.planDigest, label)
}

// SetPlanDigest sets the normalized plan and plan digest.
Expand Down
2 changes: 1 addition & 1 deletion types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -3192,7 +3192,7 @@ func microSeconds(t *CoreTime, input string, ctx map[string]int) (string, bool)
t.setMicrosecond(0)
return input, true
}
for v > 0 && v*10 < 1000000 {
for i := step; i < 6; i++ {
v *= 10
}
t.setMicrosecond(uint32(v))
Expand Down

0 comments on commit 396391a

Please sign in to comment.