您好,登錄后才能下訂單哦!
不知道大家之前對類似MySQL8.0中invisible index特點及作用的文章有無了解,今天我在這里給大家再簡單的講講。感興趣的話就一起來看看正文部分吧,相信看完MySQL8.0中invisible index特點及作用你一定會有所收獲的。
invisible index特點
默認創建的索引都是visible,如果需要invisible索引創建的時候需要指定invisible參數。
默認無法使用invisible index索引,需要開啟參數optimizer_switch='use_invisible_indexes=on'才能使用;
使用force index也無法使用,會報錯;
索引的visible和invisible屬性可以相互轉換,即使表很大,這個過程也是很快的;
primary key不能改成invisible;
invisible index作用
在生產環境中,往往一個表是非常大的,我們想要測試一條SQL不使用某個索引的執行效率,如果直接刪除這個索引,可能代價比較大,但是把索引改成不可見模式,再去測試,時間是很快的。
mysql> create index idx_emp_no on t_group(emp_no) invisible; Query OK, 0 rows affected (0.22 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show index from t_group; +---------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | +---------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | t_group | 1 | idx_emp_no | 1 | emp_no | A | 10 | NULL | NULL | | BTREE | | | NO | NULL | +---------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ 1 row in set (0.08 sec) mysql> desc select * from t_group where emp_no=31112; +----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+ | 1 | SIMPLE | t_group | NULL | ALL | NULL | NULL | NULL | NULL | 10 | 10.00 | Using where | +----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+ 1 row in set, 1 warning (0.00 sec) mysql> desc select * from t_group force index(idx_emp_no) where emp_no=31112; ERROR 1176 (42000): Key 'idx_emp_no' doesn't exist in table 't_group' mysql> desc select /*+ set_var(optimizer_switch='use_invisible_indexes=on') */ * from t_group where emp_no=31112; +----+-------------+---------+------------+------+---------------+------------+---------+-------+------+----------+-------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+---------+------------+------+---------------+------------+---------+-------+------+----------+-------+ | 1 | SIMPLE | t_group | NULL | ref | idx_emp_no | idx_emp_no | 4 | const | 1 | 100.00 | NULL | +----+-------------+---------+------------+------+---------------+------------+---------+-------+------+----------+-------+ 1 row in set, 1 warning (0.00 sec)
看完MySQL8.0中invisible index特點及作用這篇文章,大家覺得怎么樣?如果想要了解更多相關,可以繼續關注我們的行業資訊板塊。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。