1. Clear the Buffer Pool
When drop table
, the innodb
engine will clean up the table in each buffer pool
instance For the corresponding data block pages in the middle, in order to avoid impact on the system, the clearing operation here is not really flush
, but the involved pages are removed from the flush
queue. But during the removal process, the deletion process will hold the global lock of each buffer pool
, and then search for the corresponding page in this buffer pool
in order to remove it from the flush list
Delete in. If there are too many pages that need to be searched and deleted in buffer pool
, the traversal time will increase, which will cause other transaction operations to be blocked, and in severe cases, the database may be locked.
(Recommended course: MySQL tutorial)
There is one more thing you need to pay attention to here. If the buffer pool
of the database is set to a large size, the traversal time will change. long
When cleaning buffer pool
, it also includes cleaning AHI
containing the data of this table. The function of AHI
will not be discussed here, mainly when When the level of b tree
becomes higher, in order to avoid b tree
searching layer by layer, AHI
can directly query the corresponding data page based on a certain search condition, skipping the layer-by-layer search. Layer positioning steps. Secondly, AHI will occupy 1/16 of the buffer pool
size. If the online table data is not particularly large and the concurrency is not ultra-high, it is not recommended to turn on AHI. You may consider turning off the AHI
function.
mysql> SHOW GLOBAL VARIABLES LIKE 'innodb_adaptive_hash_index'; +----------------------------+-------+ | Variable_name | Value | +----------------------------+-------+ | innodb_adaptive_hash_index | ON | +----------------------------+-------+ 1 row in set (0.01 sec) mysql> SET GLOBAL innodb_adaptive_hash_index=OFF; Query OK, 0 rows affected (0.00 sec) mysql> SHOW GLOBAL VARIABLES LIKE 'innodb_adaptive_hash_index'; +----------------------------+-------+ | Variable_name | Value | +----------------------------+-------+ | innodb_adaptive_hash_index | OFF | +----------------------------+-------+ 1 row in set (0.01 sec)
2. Delete the corresponding disk data file ibd
When deleting the data file, if the data file is too large, the deletion process will generate a large amount of IO
And consume more time, causing disk IO
overhead to soar, CPU
load is too high, affecting the operation of other programs. A good friend of mine once deleted a 1TB table from the online database. As a result, the database became unresponsive for 20 minutes, and finally the database crashed and restarted.
Now that we know that drop table
has done 2 things, then optimize the above 2 things
In clearing the Buffer Pool
buffer, In order to reduce the size of a buffer pool
, you can set the innodb_buffer_pool_instances
parameter appropriately, reduce the buffer pool
data block list scanning time, and turn off AHI## at the same time. #Function
linux to delay deletion of real physical files.
INODE at the same time, the number of references to this
INODE is N>1, and deleting any one of the file names will be very fast. Because The direct physical file block has not been deleted. Just a pointer has been deleted; when the reference number of
INODE is N=1, deleting the file requires clearing all the data blocks related to the file, so it will be compared. Time-consuming;
.ibd file of the database table, when the table is deleted, when the physical file is deleted, what is actually deleted is a pointer to the physical file, so the deletion The operation response speed will be very fast, about less than 1 second.
先创建表文件的硬链接 ln t_test.ibd t_test.ibd.bak 删除表 drop table t_test;The last step is to actually delete the physical file and release the disk space occupied by the file. , then the question is, if you delete physical files gracefully, here I recommend you
coreutilstruncate
command in the tool set
wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.29.tar.xz 使用非root进行解压 tar -xvJf coreutils-8.29.tar.xz cd coreutils-8.29 ./configure make 使用root进行make installis installed, you can write a script to delete large files very elegantly and distributedly.
${i}G means that each time you delete 10G
#!/bin/bash TRUNCATE=/usr/local/bin/truncate for i in `seq 2194 -10 10 `; do sleep 2 $TRUNCATE -s ${i}G /data/mysql/t_test.ibd.hdlk done rm -rf /data/mysql/t_test.ibd.hdlk ;
The above is the detailed content of How to drop the 1TB form in the mysql library. For more information, please follow other related articles on the PHP Chinese website!

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.