Lesson 11 of the SQL Optimization Course: How to test the performance of compressed tables?

For relational databases, the design of tables and SQL is written are particularly crucial. It wouldn’t be an exaggeration to say that they account for 90% of performance. So this time, specifically targeting these two major knowledge areas, we’ll conduct a detailed analysis for you, peeling back the layers.
This Series uses plain and understandable language and selects a large number of examples to elaborate on the subtleties for you.
🧑💻 Target audience:
We will use MySQL as the demonstration database.
In the previous issue, we discussed the concepts of compressed tables, the impact of index pages, and basic usage. This article focuses on how to monitor compressed tables.
SELECT Operations
These operations do not require decompression of compressed pages, making them very suitable for compressed tables.
INSERT Operations
These operations require decompression and recompression of secondary index pages. However, MySQL handles this process using the change buffer, which reduces the frequency of such operations.
DELETE Operations
MySQL marks rows for deletion and waits for the PURGE thread to clean up periodically. This makes compressed tables suitable for delete operations.
UPDATE Operations
Since compressed tables typically compress string data (e.g., TEXT, VARCHAR), updating such data can quickly fill the change buffer, leading to frequent decompression and recompression operations.
In general, compressed tables are suitable for read-intensive, read-only, or scenarios with minimal updates.
Monitoring data for compressed tables is stored in the INFORMATION_SCHEMA
under tables prefixed with INNODB_CMP
. These tables allow you to check the health of compressed tables, adjust compression page sizes, or determine if compressed tables are appropriate for your use case.
|
|
These tables track disk access data for compressed tables.
INNODB_CMP
stores historical data.INNODB_CMP_RESET
resets the historical data.Example of monitoring over one hour:
INNODB_CMP
.INNODB_CMP_RESET
.Field | Meaning | Notes |
---|---|---|
page_size | Represents the page size of the compressed table (1K/2K/4K/8K/16K). | The unit for page_size is bytes, while key_block_size is in KB. |
compress_ops | Represents the number of times pages of the corresponding page_size were compressed. | Increments by +1 for empty page creation or when the change buffer is full. |
compress_ops_ok | Represents the number of successful compressions for pages of the corresponding page_size . | Increments by +1 for successful compression. |
compress_time | Represents the time spent compressing pages of the corresponding page_size . | Unit is seconds. |
uncompress_ops | Represents the number of times pages of the corresponding page_size were decompressed. | Increments by +1 for failed compression or when the compressed page is not in the InnoDB buffer pool. |
uncompress_time | Represents the time spent decompressing pages of the corresponding page_size . |
Fields in INNODB_CMP
:
|
|
Note: The ratio of compress_ops_ok / compress_ops
is a key indicator of compressed table health. A normal ratio should be close to 1. If the ratio is consistently abnormal, consider adjusting the page size or avoiding compressed tables in that scenario.
These tables track access data for compressed tables in the InnoDB buffer pool.
INNODB_CMPMEM
stores historical data.INNODB_CMPMEM_RESET
resets the data.Fields in INNODB_CMPMEM
:
|
|
These tables track operations on primary keys and secondary indexes of compressed tables.
INNODB_CMP_PER_INDEX
stores historical data.INNODB_CMP_PER_INDEX_RESET
stores instantaneous data.Field | Meaning | Notes |
---|---|---|
database_name | Database name | |
table_name | Table name | |
index_name | Index name |
To enable monitoring:
|
|
Fields in INNODB_CMP_PER_INDEX
:
|
|
Two tables were created for comparison:
t1
: Uncompressed table.t2
: Compressed table with a page size of 4K.
|
|
SQL 1:
|
|
SQL 2:
|
|
SQL 3:
|
|
SQL 4:
|
|
Result: Compressed tables perform better for individual queries.
Deleting a row from t2
:
|
|
Monitoring data:
|
|
Updating a Small Amount of Data
|
|
Monitoring data:
|
|
Updating a Large Amount of Data
|
|
Monitoring data:
|
|
Compressed tables are best suited for read-intensive applications or scenarios with minimal updates or deletions. They are not recommended for write-heavy workloads.
In the next article, we will discuss table statistics calculation.
What MySQL technical topics would you like to learn more about? Let us know in the comments!
👋 See you in the next lesson.
SQLFlash is your AI-powered SQL Optimization Partner.
Based on AI models, we accurately identify SQL performance bottlenecks and optimize query performance, freeing you from the cumbersome SQL tuning process so you can fully focus on developing and implementing business logic.
Join us and experience the power of SQLFlash today!.