当前位置:网站首页>Hidden index and descending index in MySQL 8.0 (new feature)
Hidden index and descending index in MySQL 8.0 (new feature)
2022-07-27 01:00:00 【PeakXYH】
MySQL8.0 Hidden index in
Overview of hidden indexes
Hiding the index means hiding the index , Query in progress 、 When sorting and other operations, the system will directly ignore the index , Hidden index can be understood as soft deletion of index , That is, the index is set to invalid , But in fact, the corresponding index is not deleted , It avoids the accidental deletion of the index , The system reconstruction index needs to consume a lot of time and system resources , Set the hidden index to be visible when necessary , The index returns to its original function
Why should there be hidden indexes ?
In short : It avoids the accidental deletion of the index , The system reconstruction index needs to consume a lot of time and system resources ( You can deeply experience it through the following two specific situations ), stay MySQL5.7 You can only rebuild the index , stay MySQL8.0 You can use the hidden index to solve
Scenario analysis 1:
When we delete an index , However, it was found that the performance was seriously affected or some errors occurred after deletion , Then we need to rebuild the index , But in the case of a large amount of data , Rebuilding the index is very time-consuming , So if you can make the index temporarily invalid without deleting the index , Then when an error is found, you don't need to rebuild the index, but restore the index to be valid .
Scenario analysis 2:
When we don't know whether our index is valid , Then delete the index , Whether the index is invalid can be judged by comparing whether there is a difference between the before and after operations . If there is no difference , Then deletion is correct ( Because maintaining indexes requires resources ), If you find that deleting the index seriously affects the query performance , Then you need to rebuild the deleted index . But delete the index 、 Rebuilding the index requires system resources , So if we can make the index temporarily invalid , Then the above problems can be avoided .
Hide the usage scenario of the index
- When the index needs to be deleted , First, it can be set to hide the index , At this time, the index is invalid , Then you can test , If it is set to hide the index, it has no effect , Then you can use hard deletion , Otherwise, it can be set as non hidden .
- If you want to verify the impact of query performance after an index is deleted , You can temporarily set the index to hidden .
Considerations for hiding indexes
- The primary key cannot be set to hide the index
- When the index is set to hidden, the index is unavailable ( invalid ), But its content will still be updated
- Hidden indexes are invisible to the optimizer , But it can also be visible to the optimizer through parameter settings
- because InnoDB The storage engine is built with primary keys B+ Trees store data , Therefore, the primary key cannot be set to invalid , Otherwise, the storage engine will reselect a field as the primary key , Rebuild the entire table B+ Trees store data
- Although the index is set to hidden , But its content is still updated , It's just that indexes won't be used when querying and other operations , So if an index is to be hidden for a long time , Then you'd better delete it , Because it will affect the update of data 、 Efficiency of operations such as deletion
Hidden use code demonstration
- Set hidden indexes when creating tables
CREATE TABLE xiaoyuanhao(
id INT,
username INT,
PASSWORD INT,
INDEX password_index(PASSWORD) invisible
)
-- By default visible, If you are using invisible Then it's invisible
- Set the index in the table to hidden
ALTER TABLE xiaoyuanhao ALTER INDEX password_index invisible;
MySQL8.0 Descending index in
Overview of descending index
stay MySQL4.0 Although it supports the creation of descending indexes in syntax , however InnoDB The underlying implementation is still the architecture of indexing in ascending order ( Both ascending and descending indexes are built in ascending order ), In the specific implementation, it is realized by reverse scanning , But this will greatly reduce the efficiency of the database , stay MySQL8.0 Supports the construction of descending index , That is, the underlying index structure is arranged in descending order of index columns
Use and test of descending index
- Create an ascending index , Query in descending order
CREATE TABLE xiaoyuanhao (id INT,PASSWORD INT,username VARCHAR(20));
-- Create a table
CREATE INDEX username_index ON xiaoyuanhao(username);
-- In ascending order username Create index
EXPLAIN SELECT username FROM xiaoyuanhao ORDER BY username DESC;
-- Query in descending order

It can be seen that there is a reverse scan , inefficiency
- Create a descending index , Query in descending order at the same time
DROP INDEX username_index ON xiaoyuanhao;
-- Delete the previous ascending order used
CREATE INDEX username_index ON xiaoyuanhao(username DESC);
-- Create a descending index
EXPLAIN SELECT username FROM xiaoyuanhao ORDER BY username DESC;
-- Query in descending order

It can be seen here that the index is used directly , No reverse scanning , It can be seen that Mysql8.0 The bottom layer of supports the creation of descending indexes , It improves the efficiency of descending query
边栏推荐
- flink需求之—ProcessFunction(需求:如果30秒内温度连续上升就报警)
- MySQL索引优化:哪些情况下需要建立索引(适合构建索引的几种情况)
- [ciscn2019 southeast China division]double secret
- One of the Flink requirements - processfunction (requirement: alarm if the temperature rises continuously within 30 seconds)
- JSCORE day_ 01(6.30) RegExp 、 Function
- 2022.7.10DAY602
- SparkSql之编程方式
- Yolo of Darknet_ Forward of layer_ yolo_ Layer comments
- MYSQL 使用及实现排名函数RANK、DENSE_RANK和ROW_NUMBER
- Status management in Flink
猜你喜欢
![[CTF 真题] 2018-网鼎杯-Web-Unfinish](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[CTF 真题] 2018-网鼎杯-Web-Unfinish

Checked status in El checkbox 2021-08-02

通过FlinkCDC将MySQL中变更的数据写入到kafka(DataStream方式)

Solve the problem of direct blue screen restart when VMware Workstation virtual machine starts
![[NPUCTF2020]ezinclude](/img/24/ee1a6d49a74ce09ec721c1a3b5dce4.png)
[NPUCTF2020]ezinclude

14 web vulnerability: types of SQL injection and submission injection

Flink 滑动窗口理解&具体业务场景介绍

JSCORE day_ 02(7.1)

分区的使用及案例

BUUCTF-随便注、Exec、EasySQL、Secret File
随机推荐
VMware Workstation 虚拟机启动就直接蓝屏重启问题解决
Spark数据倾斜解决办法
10 - CentOS 7 上部署MySql
JSCORE day_ 05(7.6)
[漏洞实战] 逻辑漏洞挖掘
2022.7.13
Flink面试常见的25个问题(无答案)
Consistency inspection and evaluation method kappa
Flink checkpoint源码理解
Detailed explanation of CSRF forged user request attack
Neo4j基础指南(安装,节点和关系数据导入,数据查询)
Flink 1.15实现 Sql 脚本从savepointh恢复数据
js中this指向详解
2022.7.18DAY608
Select query topic exercise
[HarekazeCTF2019]encode_and_encode
[CISCN2019 华东南赛区]Double Secret
2022.7.14DAY604
Doris或StarRocks Jmeter压测
[Network Research Institute] attackers scan 1.6 million WordPress websites to find vulnerable plug-ins