Debian Codegraph @

mysql-test/suite/perfschema/t/table_binary_log_transaction_compression_stats_basic.test

raw
1 #
2 # WL#3549: binlog compression
3 #
4 # This test file contains basic tests for
5 # performance_schema.binary_log_transaction_compression_stats
6 #
7 #
8 --source include/have_binlog_format_row.inc
9
10 --let $show_rpl_debug_info = 0
11
12 --disable_query_log
13 --disable_result_log
14
15 # setup
16 --let $saved_binlog_transaction_compression_session_master = `SELECT @@SESSION.binlog_transaction_compression`
17 --let $saved_binlog_transaction_compression_global_master = `SELECT @@GLOBAL.binlog_transaction_compression`
18 --let $trx_size_bytes = 1000000
19 --let $ntrx = 3
20 --let $pfs_table = performance_schema.binary_log_transaction_compression_stats
21 RESET MASTER;
22 --eval TRUNCATE $pfs_table
23
24 --let $i = 1
25 while($i < 3)
26 {
27 --let $cbytes_last = 0
28 --let $ubytes_last = 0
29
30 # compression
31 if ($i == 1)
32 {
33 #
34 # Test 1: compression, check pfs table entries
35 #
36 SET SESSION binlog_transaction_compression = ON;
37 --let $compression_type = ZSTD
38 }
39
40 # no compression
41 if ($i == 2)
42 {
43 #
44 # Test 2: no compression, check pfs table entries
45 #
46
47 SET SESSION binlog_transaction_compression = OFF;
48 --let $compression_type = NONE
49 }
50
51 --let $j=1
52 while($j < 5)
53 {
54 if ($j == 1)
55 {
56 --echo *** TRANSACTION: CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY, c2 LONGTEXT)
57 CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY, c2 LONGTEXT);
58
59 # DDLs are not compressed, since they replicate as statements
60
61 if (`SELECT '$compression_type' = 'NONE'`)
62 {
63 --let $nrows_log_type = 1
64 --let $nrows_trx_compression_type = 1
65 --let $nrows_expected = 1
66 }
67 if (`SELECT '$compression_type' <> 'NONE'`)
68 {
69 --let $nrows_log_type = 1
70 --let $nrows_trx_compression_type = 0
71 --let $nrows_expected = 1
72 }
73 }
74
75 if ($j == 2)
76 {
77 --echo *** TRANSACTION: INSERT INTO t1 VALUES (2, REPEAT('b', $trx_size_bytes))
78 --eval INSERT INTO t1 VALUES (2, REPEAT('b', $trx_size_bytes))
79
80 if (`SELECT '$compression_type' <> 'NONE'`)
81 {
82 --let $nrows_log_type = 2
83 --let $nrows_trx_compression_type = 1
84 --let $nrows_expected = 2
85 }
86 }
87
88 if ($j == 3)
89 {
90 --echo *** TRANSACTION: UPDATE t1 SET c2 = 'a' WHERE c1 = 2
91 UPDATE t1 SET c2 = 'a' WHERE c1 = 2;
92
93 # same settings as the second statement, nothing to update
94 }
95
96 if ($j == 4)
97 {
98 --echo *** TRANSACTION: DROP TABLE t1
99 DROP TABLE t1;
100
101 # same settings as the second statement, nothing to update
102 # DDLs are not compressed, since they replicate as statements
103 }
104
105 # assertions
106
107 --let $nrows = `SELECT COUNT(*) FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
108 --let $assert_cond = $nrows = $nrows_trx_compression_type
109 --let $assert_text = Number of rows in $pfs_table (BINARY, $compression_type) = $nrows_trx_compression_type
110 --source include/assert.inc
111
112 --let $nrows = `SELECT COUNT(*) FROM $pfs_table WHERE log_type = 'BINARY'`
113 --let $assert_cond = $nrows = $nrows_log_type
114 --let $assert_text = Number of rows in $pfs_table (BINARY) = $nrows_log_type
115 --source include/assert.inc
116
117 --let $nrows = `SELECT COUNT(*) FROM $pfs_table`
118 --let $assert_cond = $nrows = $nrows_expected
119 --let $assert_text = Number of rows in $pfs_table = $nrows_expected
120 --source include/assert.inc
121
122 --let $ctrxs = `SELECT SUM(transaction_counter) FROM $pfs_table`
123 --let $assert_cond = $ctrxs = $j
124 --let $assert_text = The number of transactions reported is $ctrxs
125 --source include/assert.inc
126
127 if (`SELECT $j IN (2, 3) OR '$compression_type' = 'NONE' `)
128 {
129
130 --let $cbytes = `SELECT compressed_bytes_counter FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
131 --let $assert_cond = $cbytes > $cbytes_last
132 --let $assert_text = Compressed bytes is larger than last reported value
133 --source include/assert.inc
134
135 --let $ubytes = `SELECT uncompressed_bytes_counter FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
136 --let $assert_cond = $ubytes > $ubytes_last
137 --let $assert_text = Uncompressed bytes is larger than last reported value
138 --source include/assert.inc
139
140 --let $cbytes_last_trx = `SELECT last_transaction_compressed_bytes FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
141 --let $assert_cond = $cbytes_last_trx = ($cbytes - $cbytes_last)
142 --let $assert_text = Compressed bytes is larger than last reported value
143 --source include/assert.inc
144
145 --let $ubytes_last_trx = `SELECT last_transaction_uncompressed_bytes FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
146 --let $assert_cond = $ubytes_last_trx = ($ubytes - $ubytes_last)
147 --let $assert_text = Uncompressed bytes is larger than last reported value
148 --source include/assert.inc
149
150 --let $cperc_reported = `SELECT compression_percentage FROM $pfs_table WHERE log_type = 'BINARY' AND compression_type = '$compression_type'`
151 --let $cperc_calculated = `SELECT ROUND((1.0 - ($cbytes / $ubytes)) * 100)`
152 --let $assert_cond = $cperc_reported = $cperc_calculated
153 --let $assert_text = Compression percentage is reported correctly.
154 --source include/assert.inc
155
156 --let $ubytes_last = $ubytes
157 --let $cbytes_last = $cbytes
158
159 }
160 --inc $j
161 }
162
163 # Test 3: Assert that TRUNCATE deletes all rows from the table
164 --eval TRUNCATE $pfs_table
165
166 --let $nrows = `SELECT COUNT(*) FROM $pfs_table`
167 --let $assert_cond = $nrows = 0
168 --let $assert_text = Number of rows in $pfs_table = 0
169 --source include/assert.inc
170
171 RESET MASTER;
172 --eval SET SESSION binlog_transaction_compression = $saved_binlog_transaction_compression_session_master
173
174 --inc $i
175 }
176
177 #
178 # Test 4: DML on the performace_schema.binary_log_transaction_compression_stats
179 #
180 --error ER_TABLEACCESS_DENIED_ERROR
181 --eval DELETE FROM $pfs_table
182
183 --error ER_TABLEACCESS_DENIED_ERROR
184 --eval INSERT INTO $pfs_table VALUES ('BINARY', 'ZSTD', 1, 1, 1.0, "", 1, 1, NULL)
185
186 --error ER_TABLEACCESS_DENIED_ERROR
187 --eval UPDATE $pfs_table SET log_type = 'BINARY' WHERE log_type = 'RELAY'
188
189 # clean up
190
191 --eval SET SESSION binlog_transaction_compression = $saved_binlog_transaction_compression_session_master
192 --eval SET GLOBAL binlog_transaction_compression = $saved_binlog_transaction_compression_global_master
193
194 --enable_result_log
195 --enable_query_log