|
14 | 14 | package domain
|
15 | 15 |
|
16 | 16 | import (
|
| 17 | + "sync/atomic" |
17 | 18 | "time"
|
18 | 19 |
|
19 | 20 | . "github.com/pingcap/check"
|
20 | 21 | "github.com/pingcap/parser/ast"
|
21 | 22 | "github.com/pingcap/parser/charset"
|
22 | 23 | "github.com/pingcap/parser/model"
|
23 | 24 | "github.com/pingcap/parser/mysql"
|
| 25 | + "github.com/pingcap/tidb/sessionctx/variable" |
24 | 26 | "github.com/pingcap/tidb/store/mockstore"
|
25 | 27 | "github.com/pingcap/tidb/types"
|
26 | 28 | "github.com/pingcap/tidb/util/chunk"
|
@@ -96,3 +98,47 @@ func getResultField(colName string, id, offset int) *ast.ResultField {
|
96 | 98 | DBName: model.NewCIStr("test"),
|
97 | 99 | }
|
98 | 100 | }
|
| 101 | + |
| 102 | +func (gvcSuite *testGVCSuite) TestCheckEnableStmtSummary(c *C) { |
| 103 | + defer testleak.AfterTest(c)() |
| 104 | + testleak.BeforeTest() |
| 105 | + |
| 106 | + store, err := mockstore.NewMockTikvStore() |
| 107 | + c.Assert(err, IsNil) |
| 108 | + defer store.Close() |
| 109 | + ddlLease := 50 * time.Millisecond |
| 110 | + dom := NewDomain(store, ddlLease, 0, mockFactory) |
| 111 | + err = dom.Init(ddlLease, sysMockFactory) |
| 112 | + c.Assert(err, IsNil) |
| 113 | + defer dom.Close() |
| 114 | + |
| 115 | + gvc := dom.GetGlobalVarsCache() |
| 116 | + |
| 117 | + rf := getResultField("c", 1, 0) |
| 118 | + rf1 := getResultField("c1", 2, 1) |
| 119 | + ft := &types.FieldType{ |
| 120 | + Tp: mysql.TypeString, |
| 121 | + Charset: charset.CharsetBin, |
| 122 | + Collate: charset.CollationBin, |
| 123 | + } |
| 124 | + ft1 := &types.FieldType{ |
| 125 | + Tp: mysql.TypeString, |
| 126 | + Charset: charset.CharsetBin, |
| 127 | + Collate: charset.CollationBin, |
| 128 | + } |
| 129 | + |
| 130 | + atomic.StoreInt32(&variable.EnableStmtSummary, 0) |
| 131 | + ck := chunk.NewChunkWithCapacity([]*types.FieldType{ft, ft1}, 1024) |
| 132 | + ck.AppendString(0, variable.TiDBEnableStmtSummary) |
| 133 | + ck.AppendString(1, "1") |
| 134 | + row := ck.GetRow(0) |
| 135 | + gvc.Update([]chunk.Row{row}, []*ast.ResultField{rf, rf1}) |
| 136 | + c.Assert(atomic.LoadInt32(&variable.EnableStmtSummary), Equals, int32(1)) |
| 137 | + |
| 138 | + ck = chunk.NewChunkWithCapacity([]*types.FieldType{ft, ft1}, 1024) |
| 139 | + ck.AppendString(0, variable.TiDBEnableStmtSummary) |
| 140 | + ck.AppendString(1, "0") |
| 141 | + row = ck.GetRow(0) |
| 142 | + gvc.Update([]chunk.Row{row}, []*ast.ResultField{rf, rf1}) |
| 143 | + c.Assert(atomic.LoadInt32(&variable.EnableStmtSummary), Equals, int32(0)) |
| 144 | +} |
0 commit comments