mysql> analyze table test.e01;
+----------+---------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+----------+---------+----------+----------+
| test.e01 | analyze | status | OK |
+----------+---------+----------+----------+
session 3
mysql> select * from test.e01;
# 被堵塞了
此时堵塞的情形就是Waiting for table flush
二、analyze触发了什么
analyze table 除了更新我们的统计数据,实际上最后做了一个操作如下(栈):
#0 TABLE_SHARE::clear_version (this=0x7ffeec00ee38) at /opt/mysql/mysql-
8.0.21/sql/table.cc:518
#1 0x0000000003680a4d in <lambda(std::unordered_map<std::__cxx11::basic_string<char>, std::uni
que_ptr<TABLE_SHARE, Table_share_deleter>, std::hash<std::__cxx11::basic_string<char> >, std::e
qual_to<std::__cxx11::basic_string<char> >, Malloc_allocator<std::pair<const std::__cxx11::basi
c_string<char>, std::unique_ptr<TABLE_SHARE, Table_share_deleter> > > >::iterator)>::operator()
(std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<cha
r> >, std::unique_ptr<TABLE_SHARE, Table_share_deleter>, std::hash<std::__cxx11::basic_string<c
har, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string
<char, std::char_traits<char>, std::allocator<char> > >, Malloc_allocator<std::pair<std::__cxx1
1::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::unique_ptr<TAB
LE_SHARE, Table_share_deleter> > > >::iterator) const (__closure=0x7fff600ce8a0,
my_it=...) at /opt/mysql/mysql-8.0.21/sql/sql_base.cc:9831
#2 0x0000000003680d0c in tdc_remove_table (thd=0x7ffed8094550, remove_type=TDC_RT_REMOVE_UNUSE
D, db=0x7ffed80c4a08 "test", table_name=0x7ffed80c4a20 "e01", has_lock=false)
at /opt/mysql/mysql-8.0.21/sql/sql_base.cc:9844
#3 0x0000000003d890a9 in mysql_admin_table (thd=0x7ffed8094550, tables=0x7ffed80c4cb8, check_o
pt=0x7ffed80ba370, operator_name=0x61c06e7 "analyze", lock_type=TL_READ_NO_INSERT,
open_for_modify=true, repair_table_use_frm=false, extra_open_options=0, prepare_func=0x0, o
perator_func=
(int (handler::*)
(handler * const, THD *, HA_CHECK_OPT *)) 0x3accc64 <handler::ha_analyze(THD*, HA_CHECK_OPT*)>,
check_view=0, alter_info=0x7ffed80c4b28,
need_to_acquire_shared_backup_lock=true) at /opt/mysql/mysql-8.0.21/sql/sql_admin.cc:1296
大概看一下做了什么,如下:
评论