Bug #116753 COMPRESSION_PERCENTAGE in binary_log_transaction_compression_stats is incorrect
Submitted: 22 Nov 5:03 Modified: 22 Nov 5:37
Reporter: Ke Yu (OCA) Email Updates:
Status: Analyzing Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:8.0.40 OS:Any
Assigned to: MySQL Verification Team CPU Architecture:Any

[22 Nov 5:03] Ke Yu
Description:
COMPRESSION_PERCENTAGE in binary_log_transaction_compression_stats is incorrect when the compression rate is very high.

How to repeat:
1. execute the following sql: 
mysql> select COMPRESSION_TYPE,TRANSACTION_COUNTER,COMPRESSED_BYTES_COUNTER,UNCOMPRESSED_BYTES_COUNTER,COMPRESSION_PERCENTAGE from performance_schema.binary_log_transaction_compression_stats;
+------------------+---------------------+--------------------------+----------------------------+------------------------+
| COMPRESSION_TYPE | TRANSACTION_COUNTER | COMPRESSED_BYTES_COUNTER | UNCOMPRESSED_BYTES_COUNTER | COMPRESSION_PERCENTAGE |
+------------------+---------------------+--------------------------+----------------------------+------------------------+
| ZSTD             |             6032130 |               1494533417 |              1165338872550 |                    100 |
| NONE             |               90144 |              28623075567 |                28623075567 |                      0 |
+------------------+---------------------+--------------------------+----------------------------+------------------------+
2 rows in set (0.00 sec)

2. The COMPRESSION_PERCENTAGE is 100, but UNCOMPRESSED_BYTES_COUNTER/COMPRESSED_BYTES_COUNTER = 779.
COMPRESSION_PERCENTAGE does not reflect the true compression rate.

Suggested fix:
I expect to change COMPRESSION_PERCENTAGE to UNCOMPRESSED_BYTES_COUNTER/COMPRESSED_BYTES_COUNTER not (1 - COMPRESSED_BYTES_COUNTER/UNCOMPRESSED_BYTES_COUNTER) * 100 .