天天看點

MySQL setup_instruments中關于部分資訊不能修改

朋友告訴我如下操作不能修改

  1. mysql> update setup_instruments set enabled='no' where name='memory/performance_schema/table_handles';

  2. Query OK, 1 row affected (2.61 sec)

  3. Rows matched: 1 Changed: 1 Warnings: 0

  4. mysql> select * from setup_instruments where name='memory/performance_schema/table_handles';

  5. +-----------------------------------------+---------+-------+

  6. | NAME | ENABLED | TIMED |

  7. +-----------------------------------------+---------+-------+

  8. | memory/performance_schema/table_handles | YES | NO |

  9. +-----------------------------------------+---------+-------+

  10. 1 row in set (0.00 sec)

我測試發現所有memory/performance_schema/* 的值都不能更改,但是其他值可以更改。8.0.17依然如此。

既然不能修改則跟一下update接口,我一共跟蹤了:

  • table_setup_instruments::update_row_values:修改接口
  • table_setup_instruments::make_row:update_enabled 變量傳入值
  • table_setup_instruments::rnd_next():update_enabled 定義值

幾個接口。

一、為什麼不能修改

檢視table_setup_instruments::update_row_values函數你會發現memory/performance_schema/* 這幾行值這裡都會進入如下邏輯:

  1. case 1: /* ENABLED */

  2. /* Do not raise error if m_update_enabled is false, silently ignore. */

  3. if (m_row.m_update_enabled) //這裡是 false

  4. {

  5. value= (enum_yes_no) get_field_enum(f);

  6. m_row.m_instr_class->m_enabled= (value == ENUM_YES) ? true : false;

  7. }

  8. break;

因為m_row.m_update_enabled==false 是以不能修改。其他的值這裡是true。這裡我們也會看到實際上值隻有兩個YES或者是NO,不能是其他值。如果update修改為其他值會直接報錯。

二、mupdateenabled來源

也就是table_setup_instruments::rnd_next()函數進行判斷如果是VIEW_BUILTIN_MEMORY則會設定update_enabled為false,具體如下:

  1. case pos_setup_instruments::VIEW_BUILTIN_MEMORY:

  2. update_enabled= false;//這裡設定了false

  3. update_timed= false;

  4. ...

當然何為VIEW_BUILTIN_MEMORY,不太清楚,沒仔細看了。

最後本表通路是全表掃描方式。因為上層接口為handler::ha_rnd_next,其含義為如下:

  1. The number of requests to read the next row in the data file. This value is high if you are doing a lot of table scans. Generally this suggests that your tables are not properly indexed or that your queries are not written to take advantage of the indexes you have.

  2. 源碼函數解釋:Reads the next row in a table scan (also used to read the FIRST row in a table scan).

  3. 全表掃描通路下一條資料

debug會發現不斷的會通路下一條資料。最後performance_schema是一個獨立的引擎,雖然很簡單。

三、備用棧幀

1、修改資料

  1. #0 PFS_engine_table::update_row (this=0x7ffe7c1026c0, table=0x7ffe7c1b0370, old_buf=0x7ffe7c1b13f8 "'", new_buf=0x7ffe7c1b1270 "'", fields=0x7ffe7c1b1580)

  2. at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/perfschema/pfs_engine_table.cc:573

  3. #1 0x0000000001942680 in ha_perfschema::update_row (this=0x7ffe7c1b0d70, old_data=0x7ffe7c1b13f8 "'", new_data=0x7ffe7c1b1270 "'")

  4. at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/perfschema/ha_perfschema.cc:293

  5. #2 0x0000000000f90b70 in handler::ha_update_row (this=0x7ffe7c1b0d70, old_data=0x7ffe7c1b13f8 "'", new_data=0x7ffe7c1b1270 "'")

  6. at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/handler.cc:8509

  7. #3 0x000000000168ca00 in mysql_update (thd=0x7ffe7c012940, fields=..., values=..., limit=18446744073709551615, handle_duplicates=DUP_ERROR,

  8. found_return=0x7fffec0f4bd8, updated_return=0x7fffec0f4bd0) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_update.cc:887

  9. #4 0x0000000001692f28 in Sql_cmd_update::try_single_table_update (this=0x7ffe7c008f78, thd=0x7ffe7c012940, switch_to_multitable=0x7fffec0f4c7f)

  10. at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_update.cc:2896

  11. #5 0x0000000001693475 in Sql_cmd_update::execute (this=0x7ffe7c008f78, thd=0x7ffe7c012940) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_update.cc:3023

  12. #6 0x00000000015cc8e9 in mysql_execute_command (thd=0x7ffe7c012940, first_level=true) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:3756

  13. #7 0x00000000015d30c6 in mysql_parse (thd=0x7ffe7c012940, parser_state=0x7fffec0f6600) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:5901

  14. #8 0x00000000015c6c5a in dispatch_command (thd=0x7ffe7c012940, com_data=0x7fffec0f6d70, command=COM_QUERY)

  15. at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1490

2、讀取資料

  1. #0 table_setup_instruments::make_row (this=0x7ffe7c1026c0, klass=0x2f2e3c0, update_enabled=true, update_timed=true)

  2. at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/perfschema/table_setup_instruments.cc:260

  3. #1 0x00000000019a4b1f in table_setup_instruments::rnd_next (this=0x7ffe7c1026c0)

  4. at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/perfschema/table_setup_instruments.cc:172

  5. #2 0x0000000001942ab2 in ha_perfschema::rnd_next (this=0x7ffe7c1b0d70, buf=0x7ffe7c1b1270 "")

  6. at /root/mysqlall/percona-server-locks-detail-5.7.22/storage/perfschema/ha_perfschema.cc:351

  7. #3 0x0000000000f83812 in handler::ha_rnd_next (this=0x7ffe7c1b0d70, buf=0x7ffe7c1b1270 "") at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/handler.cc:3146

  8. #4 0x00000000014e2b3d in rr_sequential (info=0x7fffec0f4870) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/records.cc:521

  9. #5 0x000000000168c7b3 in mysql_update (thd=0x7ffe7c012940, fields=..., values=..., limit=18446744073709551615, handle_duplicates=DUP_ERROR,

  10. found_return=0x7fffec0f4bd8, updated_return=0x7fffec0f4bd0) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_update.cc:811

  11. #6 0x0000000001692f28 in Sql_cmd_update::try_single_table_update (this=0x7ffe7c008f78, thd=0x7ffe7c012940, switch_to_multitable=0x7fffec0f4c7f)

  12. at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_update.cc:2896

  13. #7 0x0000000001693475 in Sql_cmd_update::execute (this=0x7ffe7c008f78, thd=0x7ffe7c012940) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_update.cc:3023

  14. #8 0x00000000015cc8e9 in mysql_execute_command (thd=0x7ffe7c012940, first_level=true) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:3756

  15. #9 0x00000000015d30c6 in mysql_parse (thd=0x7ffe7c012940, parser_state=0x7fffec0f6600) at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:5901

  16. #10 0x00000000015c6c5a in dispatch_command (thd=0x7ffe7c012940, com_data=0x7fffec0f6d70, command=COM_QUERY)

  17. at /root/mysqlall/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1490