@@ -17,13 +17,18 @@ import (
17
17
"fmt"
18
18
"os"
19
19
"strconv"
20
+ "strings"
20
21
21
22
. "github.com/pingcap/check"
22
23
"github.com/pingcap/parser/auth"
24
+ "github.com/pingcap/parser/mysql"
25
+ "github.com/pingcap/tidb/domain"
23
26
"github.com/pingcap/tidb/infoschema"
27
+ "github.com/pingcap/tidb/kv"
24
28
"github.com/pingcap/tidb/session"
25
29
"github.com/pingcap/tidb/statistics"
26
30
"github.com/pingcap/tidb/store/mockstore"
31
+ "github.com/pingcap/tidb/util"
27
32
"github.com/pingcap/tidb/util/testkit"
28
33
"github.com/pingcap/tidb/util/testleak"
29
34
"github.com/pingcap/tidb/util/testutil"
@@ -87,6 +92,18 @@ func (s *testSuite) TestInfoschemaFieldValue(c *C) {
87
92
}, nil , nil ), IsTrue )
88
93
89
94
tk1 .MustQuery ("select distinct(table_schema) from information_schema.tables" ).Check (testkit .Rows ("INFORMATION_SCHEMA" ))
95
+
96
+ // Fix issue 9836
97
+ sm := & mockSessionManager {make (map [uint64 ]* util.ProcessInfo , 1 )}
98
+ sm .processInfoMap [1 ] = & util.ProcessInfo {
99
+ ID : 1 ,
100
+ User : "root" ,
101
+ Host : "127.0.0.1" ,
102
+ Command : mysql .ComQuery ,
103
+ StmtCtx : tk .Se .GetSessionVars ().StmtCtx ,
104
+ }
105
+ tk .Se .SetSessionManager (sm )
106
+ tk .MustQuery ("SELECT user,host,command FROM information_schema.processlist;" ).Check (testkit .Rows ("root 127.0.0.1 Query" ))
90
107
}
91
108
92
109
func (s * testSuite ) TestDataForTableStatsField (c * C ) {
@@ -227,6 +244,98 @@ func (s *testSuite) TestCharacterSetCollations(c *C) {
227
244
tk .MustExec ("DROP DATABASE charset_collate_test" )
228
245
}
229
246
247
+ var _ = Suite (& testTableSuite {})
248
+
249
+ type testTableSuite struct {
250
+ store kv.Storage
251
+ dom * domain.Domain
252
+ }
253
+
254
+ func (s * testTableSuite ) SetUpSuite (c * C ) {
255
+ testleak .BeforeTest ()
256
+
257
+ var err error
258
+ s .store , err = mockstore .NewMockTikvStore ()
259
+ c .Assert (err , IsNil )
260
+ session .SetStatsLease (0 )
261
+ s .dom , err = session .BootstrapSession (s .store )
262
+ c .Assert (err , IsNil )
263
+ }
264
+
265
+ func (s * testTableSuite ) TearDownSuite (c * C ) {
266
+ defer testleak .AfterTest (c )()
267
+ s .dom .Close ()
268
+ s .store .Close ()
269
+ }
270
+
271
+ type mockSessionManager struct {
272
+ processInfoMap map [uint64 ]* util.ProcessInfo
273
+ }
274
+
275
+ func (sm * mockSessionManager ) ShowProcessList () map [uint64 ]* util.ProcessInfo { return sm .processInfoMap }
276
+
277
+ func (sm * mockSessionManager ) GetProcessInfo (id uint64 ) (* util.ProcessInfo , bool ) {
278
+ rs , ok := sm .processInfoMap [id ]
279
+ return rs , ok
280
+ }
281
+
282
+ func (sm * mockSessionManager ) Kill (connectionID uint64 , query bool ) {}
283
+
284
+ func (s * testTableSuite ) TestSomeTables (c * C ) {
285
+ tk := testkit .NewTestKit (c , s .store )
286
+
287
+ tk .MustQuery ("select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY where COLLATION_NAME='utf8mb4_bin';" ).Check (
288
+ testkit .Rows ("utf8mb4_bin utf8mb4" ))
289
+ tk .MustQuery ("select * from information_schema.SESSION_VARIABLES where VARIABLE_NAME='tidb_retry_limit';" ).Check (testkit .Rows ("tidb_retry_limit 10" ))
290
+ // cherry-pick https://github.com/pingcap/tidb/pull/7831
291
+ //tk.MustQuery("select * from information_schema.ENGINES;").Check(testkit.Rows("InnoDB DEFAULT Supports transactions, row-level locking, and foreign keys YES YES YES"))
292
+ tk .MustQuery ("select * from information_schema.TABLE_CONSTRAINTS where TABLE_NAME='gc_delete_range';" ).Check (testkit .Rows ("def mysql delete_range_index mysql gc_delete_range UNIQUE" ))
293
+ tk .MustQuery ("select * from information_schema.KEY_COLUMN_USAGE where TABLE_NAME='stats_meta' and COLUMN_NAME='table_id';" ).Check (
294
+ testkit .Rows ("def mysql tbl def mysql stats_meta table_id 1 <nil> <nil> <nil> <nil>" ))
295
+ // https://github.com/pingcap/tidb/pull/9898
296
+ //tk.MustQuery("select * from information_schema.STATISTICS where TABLE_NAME='columns_priv' and COLUMN_NAME='Host';").Check(
297
+ // testkit.Rows("def mysql columns_priv 0 mysql PRIMARY 1 Host A <nil> <nil> <nil> BTREE "))
298
+ tk .MustQuery ("select * from information_schema.USER_PRIVILEGES where PRIVILEGE_TYPE='Select';" ).Check (testkit .Rows ("'root'@'%' def Select YES" ))
299
+
300
+ sm := & mockSessionManager {make (map [uint64 ]* util.ProcessInfo , 2 )}
301
+ sm .processInfoMap [1 ] = & util.ProcessInfo {
302
+ ID : 1 ,
303
+ User : "user-1" ,
304
+ Host : "localhost" ,
305
+ DB : "information_schema" ,
306
+ Command : byte (1 ),
307
+ State : 1 ,
308
+ Info : "do something" ,
309
+ StmtCtx : tk .Se .GetSessionVars ().StmtCtx ,
310
+ }
311
+ sm .processInfoMap [2 ] = & util.ProcessInfo {
312
+ ID : 2 ,
313
+ User : "user-2" ,
314
+ Host : "localhost" ,
315
+ DB : "test" ,
316
+ Command : byte (2 ),
317
+ State : 2 ,
318
+ Info : strings .Repeat ("x" , 101 ),
319
+ StmtCtx : tk .Se .GetSessionVars ().StmtCtx ,
320
+ }
321
+ tk .Se .SetSessionManager (sm )
322
+ tk .MustQuery ("select * from information_schema.PROCESSLIST order by ID;" ).Sort ().Check (
323
+ testkit .Rows (
324
+ fmt .Sprintf ("1 user-1 localhost information_schema Quit 9223372036 1 %s 0" , "do something" ),
325
+ fmt .Sprintf ("2 user-2 localhost test Init DB 9223372036 2 %s 0" , strings .Repeat ("x" , 101 )),
326
+ ))
327
+ tk .MustQuery ("SHOW PROCESSLIST;" ).Sort ().Check (
328
+ testkit .Rows (
329
+ fmt .Sprintf ("1 user-1 localhost information_schema Quit 9223372036 1 %s" , "do something" ),
330
+ fmt .Sprintf ("2 user-2 localhost test Init DB 9223372036 2 %s" , strings .Repeat ("x" , 100 )),
331
+ ))
332
+ tk .MustQuery ("SHOW FULL PROCESSLIST;" ).Sort ().Check (
333
+ testkit .Rows (
334
+ fmt .Sprintf ("1 user-1 localhost information_schema Quit 9223372036 1 %s" , "do something" ),
335
+ fmt .Sprintf ("2 user-2 localhost test Init DB 9223372036 2 %s" , strings .Repeat ("x" , 101 )),
336
+ ))
337
+ }
338
+
230
339
func (s * testSuite ) TestSchemataCharacterSet (c * C ) {
231
340
testleak .BeforeTest ()
232
341
defer testleak .AfterTest (c )()
0 commit comments