You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

461 lines
18 KiB

  1. // Copyright 2016 PingCAP, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. package perfschema
  14. import (
  15. "github.com/juju/errors"
  16. "github.com/pingcap/tidb/kv"
  17. "github.com/pingcap/tidb/meta"
  18. "github.com/pingcap/tidb/meta/autoid"
  19. "github.com/pingcap/tidb/model"
  20. "github.com/pingcap/tidb/mysql"
  21. "github.com/pingcap/tidb/table"
  22. "github.com/pingcap/tidb/table/tables"
  23. "github.com/pingcap/tidb/util/charset"
  24. "github.com/pingcap/tidb/util/types"
  25. )
  26. type columnInfo struct {
  27. tp byte
  28. size int
  29. flag uint
  30. deflt interface{}
  31. elems []string
  32. }
  33. var setupActorsCols = []columnInfo{
  34. {mysql.TypeString, 60, mysql.NotNullFlag, `%`, nil},
  35. {mysql.TypeString, 32, mysql.NotNullFlag, `%`, nil},
  36. {mysql.TypeString, 16, mysql.NotNullFlag, `%`, nil},
  37. {mysql.TypeEnum, -1, mysql.NotNullFlag, "YES", []string{"YES", "NO"}},
  38. {mysql.TypeEnum, -1, mysql.NotNullFlag, "YES", []string{"YES", "NO"}},
  39. }
  40. var setupObjectsCols = []columnInfo{
  41. {mysql.TypeEnum, -1, mysql.NotNullFlag, "TABLE", []string{"EVENT", "FUNCTION", "TABLE"}},
  42. {mysql.TypeVarchar, 64, 0, `%`, nil},
  43. {mysql.TypeVarchar, 64, mysql.NotNullFlag, `%`, nil},
  44. {mysql.TypeEnum, -1, mysql.NotNullFlag, "YES", []string{"YES", "NO"}},
  45. {mysql.TypeEnum, -1, mysql.NotNullFlag, "YES", []string{"YES", "NO"}},
  46. }
  47. var setupInstrumentsCols = []columnInfo{
  48. {mysql.TypeVarchar, 128, mysql.NotNullFlag, nil, nil},
  49. {mysql.TypeEnum, -1, mysql.NotNullFlag, nil, []string{"YES", "NO"}},
  50. {mysql.TypeEnum, -1, mysql.NotNullFlag, nil, []string{"YES", "NO"}},
  51. }
  52. var setupConsumersCols = []columnInfo{
  53. {mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
  54. {mysql.TypeEnum, -1, mysql.NotNullFlag, nil, []string{"YES", "NO"}},
  55. }
  56. var setupTimersCols = []columnInfo{
  57. {mysql.TypeVarchar, 64, mysql.NotNullFlag, nil, nil},
  58. {mysql.TypeEnum, -1, mysql.NotNullFlag, nil, []string{"NANOSECOND", "MICROSECOND", "MILLISECOND"}},
  59. }
  60. var stmtsCurrentCols = []columnInfo{
  61. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  62. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  63. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  64. {mysql.TypeVarchar, 128, mysql.NotNullFlag, nil, nil},
  65. {mysql.TypeVarchar, 64, 0, nil, nil},
  66. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  67. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  68. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  69. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  70. {mysql.TypeLongBlob, -1, 0, nil, nil},
  71. {mysql.TypeVarchar, 32, 0, nil, nil},
  72. {mysql.TypeLongBlob, -1, 0, nil, nil},
  73. {mysql.TypeVarchar, 64, 0, nil, nil},
  74. {mysql.TypeVarchar, 64, 0, nil, nil},
  75. {mysql.TypeVarchar, 64, 0, nil, nil},
  76. {mysql.TypeVarchar, 64, 0, nil, nil},
  77. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  78. {mysql.TypeLong, 11, 0, nil, nil},
  79. {mysql.TypeVarchar, 5, 0, nil, nil},
  80. {mysql.TypeVarchar, 128, 0, nil, nil},
  81. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  82. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  83. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  84. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  85. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  86. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  87. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  88. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  89. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  90. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  91. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  92. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  93. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  94. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  95. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  96. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  97. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  98. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  99. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  100. {mysql.TypeEnum, -1, 0, nil, []string{"TRANSACTION", "STATEMENT", "STAGE"}},
  101. {mysql.TypeLong, 11, 0, nil, nil},
  102. }
  103. var preparedStmtsInstancesCols = []columnInfo{
  104. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  105. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  106. {mysql.TypeVarchar, 64, 0, nil, nil},
  107. {mysql.TypeLongBlob, -1, mysql.NotNullFlag, nil, nil},
  108. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  109. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  110. {mysql.TypeEnum, -1, 0, nil, []string{"EVENT", "FUNCTION", "TABLE"}},
  111. {mysql.TypeVarchar, 64, 0, nil, nil},
  112. {mysql.TypeVarchar, 64, 0, nil, nil},
  113. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  114. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  115. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  116. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  117. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  118. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  119. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  120. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  121. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  122. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  123. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  124. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  125. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  126. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  127. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  128. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  129. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  130. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  131. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  132. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  133. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  134. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  135. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  136. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  137. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  138. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  139. }
  140. var transCurrentCols = []columnInfo{
  141. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  142. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  143. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  144. {mysql.TypeVarchar, 128, mysql.NotNullFlag, nil, nil},
  145. {mysql.TypeEnum, -1, 0, nil, []string{"ACTIVE", "COMMITTED", "ROLLED BACK"}},
  146. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  147. {mysql.TypeVarchar, 64, 0, nil, nil},
  148. {mysql.TypeLong, 11, 0, nil, nil},
  149. {mysql.TypeVarchar, 130, 0, nil, nil},
  150. {mysql.TypeVarchar, 130, 0, nil, nil},
  151. {mysql.TypeVarchar, 64, 0, nil, nil},
  152. {mysql.TypeVarchar, 64, 0, nil, nil},
  153. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  154. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  155. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  156. {mysql.TypeEnum, -1, 0, nil, []string{"READ ONLY", "READ WRITE"}},
  157. {mysql.TypeVarchar, 64, 0, nil, nil},
  158. {mysql.TypeEnum, -1, mysql.NotNullFlag, nil, []string{"YES", "NO"}},
  159. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  160. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  161. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  162. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  163. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  164. {mysql.TypeEnum, -1, 0, nil, []string{"TRANSACTION", "STATEMENT", "STAGE"}},
  165. }
  166. var stagesCurrentCols = []columnInfo{
  167. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  168. {mysql.TypeLonglong, 20, mysql.NotNullFlag | mysql.UnsignedFlag, nil, nil},
  169. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  170. {mysql.TypeVarchar, 128, mysql.NotNullFlag, nil, nil},
  171. {mysql.TypeVarchar, 64, 0, nil, nil},
  172. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  173. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  174. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  175. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  176. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  177. {mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil},
  178. {mysql.TypeEnum, -1, 0, nil, []string{"TRANSACTION", "STATEMENT", "STAGE"}},
  179. }
  180. func setColumnID(meta *model.TableInfo, store kv.Storage) error {
  181. var err error
  182. for _, c := range meta.Columns {
  183. c.ID, err = genGlobalID(store)
  184. if err != nil {
  185. return errors.Trace(err)
  186. }
  187. }
  188. return nil
  189. }
  190. func genGlobalID(store kv.Storage) (int64, error) {
  191. var globalID int64
  192. err := kv.RunInNewTxn(store, true, func(txn kv.Transaction) error {
  193. var err error
  194. globalID, err = meta.NewMeta(txn).GenGlobalID()
  195. return errors.Trace(err)
  196. })
  197. return globalID, errors.Trace(err)
  198. }
  199. func createMemoryTable(meta *model.TableInfo, alloc autoid.Allocator) (table.Table, error) {
  200. tbl, _ := tables.MemoryTableFromMeta(alloc, meta)
  201. return tbl, nil
  202. }
  203. func (ps *perfSchema) buildTables() error {
  204. tbls := make([]*model.TableInfo, 0, len(ps.tables))
  205. ps.mTables = make(map[string]table.Table, len(ps.tables))
  206. dbID, err := genGlobalID(ps.store)
  207. if err != nil {
  208. return errors.Trace(err)
  209. }
  210. // Set PKIsHandle
  211. // TableStmtsCurrent use THREAD_ID as PK and handle
  212. tb := ps.tables[TableStmtsHistory]
  213. tb.PKIsHandle = true
  214. tb.Columns[0].Flag = tb.Columns[0].Flag | mysql.PriKeyFlag
  215. var tbl table.Table
  216. for name, meta := range ps.tables {
  217. tbls = append(tbls, meta)
  218. meta.ID, err = genGlobalID(ps.store)
  219. if err != nil {
  220. return errors.Trace(err)
  221. }
  222. err = setColumnID(meta, ps.store)
  223. if err != nil {
  224. return errors.Trace(err)
  225. }
  226. alloc := autoid.NewMemoryAllocator(dbID)
  227. tbl, err = createMemoryTable(meta, alloc)
  228. if err != nil {
  229. return errors.Trace(err)
  230. }
  231. ps.mTables[name] = tbl
  232. }
  233. ps.dbInfo = &model.DBInfo{
  234. ID: dbID,
  235. Name: model.NewCIStr(Name),
  236. Charset: mysql.DefaultCharset,
  237. Collate: mysql.DefaultCollationName,
  238. Tables: tbls,
  239. }
  240. return nil
  241. }
  242. func (ps *perfSchema) buildModel(tbName string, colNames []string, cols []columnInfo) {
  243. rcols := make([]*model.ColumnInfo, len(cols))
  244. for i, col := range cols {
  245. var ci *model.ColumnInfo
  246. if col.elems == nil {
  247. ci = buildUsualColumnInfo(i, colNames[i], col.tp, col.size, col.flag, col.deflt)
  248. } else {
  249. ci = buildEnumColumnInfo(i, colNames[i], col.elems, col.flag, col.deflt)
  250. }
  251. rcols[i] = ci
  252. }
  253. ps.tables[tbName] = &model.TableInfo{
  254. Name: model.NewCIStr(tbName),
  255. Charset: "utf8",
  256. Collate: "utf8",
  257. Columns: rcols,
  258. }
  259. }
  260. func buildUsualColumnInfo(offset int, name string, tp byte, size int, flag uint, def interface{}) *model.ColumnInfo {
  261. mCharset := charset.CharsetBin
  262. mCollation := charset.CharsetBin
  263. if tp == mysql.TypeString || tp == mysql.TypeVarchar || tp == mysql.TypeBlob || tp == mysql.TypeLongBlob {
  264. mCharset = mysql.DefaultCharset
  265. mCollation = mysql.DefaultCollationName
  266. }
  267. if def == nil {
  268. flag |= mysql.NoDefaultValueFlag
  269. }
  270. // TODO: does TypeLongBlob need size?
  271. fieldType := types.FieldType{
  272. Charset: mCharset,
  273. Collate: mCollation,
  274. Tp: tp,
  275. Flen: size,
  276. Flag: uint(flag),
  277. }
  278. colInfo := &model.ColumnInfo{
  279. Name: model.NewCIStr(name),
  280. Offset: offset,
  281. FieldType: fieldType,
  282. DefaultValue: def,
  283. State: model.StatePublic,
  284. }
  285. return colInfo
  286. }
  287. func buildEnumColumnInfo(offset int, name string, elems []string, flag uint, def interface{}) *model.ColumnInfo {
  288. mCharset := charset.CharsetBin
  289. mCollation := charset.CharsetBin
  290. if def == nil {
  291. flag |= mysql.NoDefaultValueFlag
  292. }
  293. fieldType := types.FieldType{
  294. Charset: mCharset,
  295. Collate: mCollation,
  296. Tp: mysql.TypeEnum,
  297. Flag: uint(flag),
  298. Elems: elems,
  299. }
  300. colInfo := &model.ColumnInfo{
  301. Name: model.NewCIStr(name),
  302. Offset: offset,
  303. FieldType: fieldType,
  304. DefaultValue: def,
  305. State: model.StatePublic,
  306. }
  307. return colInfo
  308. }
  309. func (ps *perfSchema) initRecords(tbName string, records [][]types.Datum) error {
  310. tbl, ok := ps.mTables[tbName]
  311. if !ok {
  312. return errors.Errorf("Unknown PerformanceSchema table: %s", tbName)
  313. }
  314. for _, rec := range records {
  315. _, err := tbl.AddRecord(nil, rec)
  316. if err != nil {
  317. return errors.Trace(err)
  318. }
  319. }
  320. return nil
  321. }
  322. var setupTimersRecords [][]types.Datum
  323. func (ps *perfSchema) initialize() (err error) {
  324. ps.tables = make(map[string]*model.TableInfo)
  325. allColDefs := [][]columnInfo{
  326. setupActorsCols,
  327. setupObjectsCols,
  328. setupInstrumentsCols,
  329. setupConsumersCols,
  330. setupTimersCols,
  331. stmtsCurrentCols,
  332. stmtsCurrentCols, // same as above
  333. stmtsCurrentCols, // same as above
  334. preparedStmtsInstancesCols,
  335. transCurrentCols,
  336. transCurrentCols, // same as above
  337. transCurrentCols, // same as above
  338. stagesCurrentCols,
  339. stagesCurrentCols, // same as above
  340. stagesCurrentCols, // same as above
  341. }
  342. allColNames := [][]string{
  343. ColumnSetupActors,
  344. ColumnSetupObjects,
  345. ColumnSetupInstruments,
  346. ColumnSetupConsumers,
  347. ColumnSetupTimers,
  348. ColumnStmtsCurrent,
  349. ColumnStmtsHistory,
  350. ColumnStmtsHistoryLong,
  351. ColumnPreparedStmtsInstances,
  352. ColumnStmtsCurrent,
  353. ColumnStmtsHistory,
  354. ColumnStmtsHistoryLong,
  355. ColumnStagesCurrent,
  356. ColumnStagesHistory,
  357. ColumnStagesHistoryLong,
  358. }
  359. // initialize all table, column and result field definitions
  360. for i, def := range allColDefs {
  361. ps.buildModel(PerfSchemaTables[i], allColNames[i], def)
  362. }
  363. err = ps.buildTables()
  364. if err != nil {
  365. return errors.Trace(err)
  366. }
  367. setupActorsRecords := [][]types.Datum{
  368. types.MakeDatums(`%`, `%`, `%`, mysql.Enum{Name: "YES", Value: 1}, mysql.Enum{Name: "YES", Value: 1}),
  369. }
  370. err = ps.initRecords(TableSetupActors, setupActorsRecords)
  371. if err != nil {
  372. return errors.Trace(err)
  373. }
  374. setupObjectsRecords := [][]types.Datum{
  375. types.MakeDatums(mysql.Enum{Name: "EVENT", Value: 1}, "mysql", `%`, mysql.Enum{Name: "NO", Value: 2}, mysql.Enum{Name: "NO", Value: 2}),
  376. types.MakeDatums(mysql.Enum{Name: "EVENT", Value: 1}, "performance_schema", `%`, mysql.Enum{Name: "NO", Value: 2}, mysql.Enum{Name: "NO", Value: 2}),
  377. types.MakeDatums(mysql.Enum{Name: "EVENT", Value: 1}, "information_schema", `%`, mysql.Enum{Name: "NO", Value: 2}, mysql.Enum{Name: "NO", Value: 2}),
  378. types.MakeDatums(mysql.Enum{Name: "EVENT", Value: 1}, `%`, `%`, mysql.Enum{Name: "YES", Value: 1}, mysql.Enum{Name: "YES", Value: 1}),
  379. types.MakeDatums(mysql.Enum{Name: "FUNCTION", Value: 2}, "mysql", `%`, mysql.Enum{Name: "NO", Value: 2}, mysql.Enum{Name: "NO", Value: 2}),
  380. types.MakeDatums(mysql.Enum{Name: "FUNCTION", Value: 2}, "performance_schema", `%`, mysql.Enum{Name: "NO", Value: 2}, mysql.Enum{Name: "NO", Value: 2}),
  381. types.MakeDatums(mysql.Enum{Name: "FUNCTION", Value: 2}, "information_schema", `%`, mysql.Enum{Name: "NO", Value: 2}, mysql.Enum{Name: "NO", Value: 2}),
  382. types.MakeDatums(mysql.Enum{Name: "FUNCTION", Value: 2}, `%`, `%`, mysql.Enum{Name: "YES", Value: 1}, mysql.Enum{Name: "YES", Value: 1}),
  383. types.MakeDatums(mysql.Enum{Name: "TABLE", Value: 3}, "mysql", `%`, mysql.Enum{Name: "NO", Value: 2}, mysql.Enum{Name: "NO", Value: 2}),
  384. types.MakeDatums(mysql.Enum{Name: "TABLE", Value: 3}, "performance_schema", `%`, mysql.Enum{Name: "NO", Value: 2}, mysql.Enum{Name: "NO", Value: 2}),
  385. types.MakeDatums(mysql.Enum{Name: "TABLE", Value: 3}, "information_schema", `%`, mysql.Enum{Name: "NO", Value: 2}, mysql.Enum{Name: "NO", Value: 2}),
  386. types.MakeDatums(mysql.Enum{Name: "TABLE", Value: 3}, `%`, `%`, mysql.Enum{Name: "YES", Value: 1}, mysql.Enum{Name: "YES", Value: 1}),
  387. }
  388. err = ps.initRecords(TableSetupObjects, setupObjectsRecords)
  389. if err != nil {
  390. return errors.Trace(err)
  391. }
  392. setupConsumersRecords := [][]types.Datum{
  393. types.MakeDatums("events_stages_current", mysql.Enum{Name: "NO", Value: 2}),
  394. types.MakeDatums("events_stages_history", mysql.Enum{Name: "NO", Value: 2}),
  395. types.MakeDatums("events_stages_history_long", mysql.Enum{Name: "NO", Value: 2}),
  396. types.MakeDatums("events_statements_current", mysql.Enum{Name: "YES", Value: 1}),
  397. types.MakeDatums("events_statements_history", mysql.Enum{Name: "YES", Value: 1}),
  398. types.MakeDatums("events_statements_history_long", mysql.Enum{Name: "NO", Value: 2}),
  399. types.MakeDatums("events_transactions_current", mysql.Enum{Name: "YES", Value: 1}),
  400. types.MakeDatums("events_transactions_history", mysql.Enum{Name: "YES", Value: 1}),
  401. types.MakeDatums("events_transactions_history_long", mysql.Enum{Name: "YES", Value: 1}),
  402. types.MakeDatums("global_instrumentation", mysql.Enum{Name: "YES", Value: 1}),
  403. types.MakeDatums("thread_instrumentation", mysql.Enum{Name: "YES", Value: 1}),
  404. types.MakeDatums("statements_digest", mysql.Enum{Name: "YES", Value: 1}),
  405. }
  406. err = ps.initRecords(TableSetupConsumers, setupConsumersRecords)
  407. if err != nil {
  408. return errors.Trace(err)
  409. }
  410. setupTimersRecords = [][]types.Datum{
  411. types.MakeDatums("stage", mysql.Enum{Name: "NANOSECOND", Value: 1}),
  412. types.MakeDatums("statement", mysql.Enum{Name: "NANOSECOND", Value: 1}),
  413. types.MakeDatums("transaction", mysql.Enum{Name: "NANOSECOND", Value: 1}),
  414. }
  415. err = ps.initRecords(TableSetupTimers, setupTimersRecords)
  416. if err != nil {
  417. return errors.Trace(err)
  418. }
  419. return nil
  420. }
  421. func (ps *perfSchema) GetDBMeta() *model.DBInfo {
  422. return ps.dbInfo
  423. }
  424. func (ps *perfSchema) GetTable(name string) (table.Table, bool) {
  425. tbl, ok := ps.mTables[name]
  426. return tbl, ok
  427. }