File: rpl_generated_invisible_primary_key.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (230 lines) | stat: -rw-r--r-- 11,943 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
####################################################################################
# WL#13784 - Create auto_increment PK on table creation when no PK is specified    #
#                                                                                  #
# Test cases in this file verifies feature requirements,                           #
#   a) In GIPK mode if primary key is generated for a non-PK table then            #
#      query string CREATE TABLE must be re-written to include generated           #
#      primary key definition in the binlog event to replicate table               #
#      correctly.                                                                  #
#                                                                                  #
#   b) DML operation on table for which primary key is generated at source only,   #
#      should be replicated correctly.                                             #
#                                                                                  #
# Case 1: Verify replication of a table with generated invisible primary key.      #
#         Source: @sql_generate_invisible_primary_key = ON.                        #
#                 Create table t1 without explicit primary key and Insert rows.    #
#         Replica: Verify that table t1 has same table structure and column values.#
#                                                                                  #
#                                                                                  #
# Case 2: Verify replication of a table with generated invisible primary key when  #
#         system variable show_gipk_in_create_table_and_information_schema = OFF.  #
#         Source: @sql_generate_invisible_primary_key = ON.                        #
#                 @show_gipk_in_create_table_and_information_schema = OFF          #
#                 Create table t1 without explicit primary key and Insert rows.    #
#         Replica: Verify that table t1 has same table structure and column values.#
#                  show_gipk_in_create_table_and_information_schema should not     #
#                  query re-writing to log an event.                               #
#                                                                                  #
#                                                                                  #
# Case 3: Verify replication of a tables created using stored procedure and        #
#         prepared statement.                                                      #
#         Source:  @sql_generate_invisible_primary_key = ON.                       #
#                  Create table t1 without explicit primary key using stored       #
#                  procedure and insert a row.                                     #
#                  Create table t2 without explicit primary key using prepared     #
#                  statement and insert a row.                                     #
#         Verify that table t1 and t2 has generated invisible primary key and same #
#         column values in source and replica.                                     #
#         Source:  DROP TABLE t1 and t2.                                           #
#                  Create table t1 without explicit primary key using stored       #
#                  procedure and insert a row.                                     #
#                  Create table t2 without explicit primary key using prepared     #
#                  statement and insert a row.                                     #
#         Verify that table t1 and t2 has generated invisible primary key and same #
#         column values in source and replica.                                     #
#                                                                                  #
#                                                                                  #
# Case 4: Verify replication of CREATE TABLE ... SELECT with an explicitly         #
#         specified primary key similar to generated invisible primary key.        #
#         Source: @sql_generate_invisible_primary_key = ON.                        #
#                 Create table t2 using CREATE TABLE ... SELECT with explicit      #
#                 primary key having same attributes as generated invisible primary#
#                 key.                                                             #
#         Replica: Verify that table t2 is created.                                #
#                                                                                  #
#                                                                                  #
# Case 5: Verify replication of CREATE TABLE ... SELECT using temporary source     #
#         table with GIPK.                                                         #
#         Source: @sql_generate_invisible_primary_key=ON.                          #
#                 Create temporary table t3 without explicit primary key.          #
#                 Create table t4 using CREATE TABLE ... SELECT my_row_id, t3.*    #
#                 from t3 with explicit primary key without auto_increment         #
#                 attributes                                                       #
#         Replica: Verify that table t4 is replicated and has same column values   #
#                  as table in source.                                             #
####################################################################################
--source include/not_have_privilege_checks_user.inc
--source include/master-slave.inc

CALL mtr.add_suppression('Unsafe statement written to the binary log using statement format');

SET @saved_session_sql_generate_invisible_primary_key = @@session.sql_generate_invisible_primary_key;
SET SESSION sql_generate_invisible_primary_key = ON;

--echo # Case 1: Test case to verify replication of a table with generated
--echo #         invisible primary key.
CREATE TABLE t1(f1 INT, f2 INT);
INSERT INTO t1 VALUES (1, 10), (2, 20);

--echo # Check that t1 exists and has generated invisible primary key definition in
--echo # source and replica.
--let $rpl_diff_statement= SHOW CREATE TABLE t1;
--source include/rpl_diff.inc

--echo # Check that t1 has same column values in source and replica.
--let $rpl_diff_statement= SELECT my_row_id, t1.* FROM t1
--source include/rpl_diff.inc

--source include/rpl_connection_master.inc
DROP TABLE t1;
--source include/sync_slave_sql_with_master.inc


--echo # Case 2: Test case to verify replication of a table with generated
--echo #         invisible primary key when susyem variable 
--echo #         show_gipk_in_create_table_and_information_schema = OFF.
--source include/rpl_connection_master.inc
SET @saved_session_show_gipk_in_create_table_and_information_schema =
       @@session.show_gipk_in_create_table_and_information_schema;
SET SESSION show_gipk_in_create_table_and_information_schema = OFF;

CREATE TABLE t1(f1 INT, f2 INT);
INSERT INTO t1 VALUES (1, 10), (2, 20);

--echo # Check that t1 exists and has generated invisible primary key definition in
--echo # source and replica.
--let $rpl_diff_statement= SHOW CREATE TABLE t1;
--source include/rpl_diff.inc
--echo # Check that t1 has same column values in source and replica.
--let $rpl_diff_statement= SELECT my_row_id, t1.* FROM t1
--source include/rpl_diff.inc

--source include/rpl_connection_master.inc
DROP TABLE t1;
SET SESSION show_gipk_in_create_table_and_information_schema =
              @saved_session_show_gipk_in_create_table_and_information_schema;
--source include/sync_slave_sql_with_master.inc


--echo # Case 3: Test case to verify replication of a table created with
--echo #         generated invisible primary key using stored procedure and
--echo #         prepared statement.
--source include/rpl_connection_master.inc
DELIMITER $;
CREATE PROCEDURE p1() BEGIN
  CREATE TABLE t1(f1 INT, f2 INT);
  INSERT INTO t1 VALUES(1, 3);
end
$
DELIMITER ;$
PREPARE stmt1 FROM 'CREATE TABLE t2(f1 INT, f2 INT)';

CALL p1();
EXECUTE stmt1;
INSERT INTO t2 VALUES(8, 4);

--echo # Check that t1 exists and has generated invisible primary key definition
--echo # in source and replica.
--let $rpl_diff_statement= SHOW CREATE TABLE t1;
--source include/rpl_diff.inc
--echo # Check that t1 hase same column values in source and replica.
--let $rpl_diff_statement= SELECT my_row_id, t1.* FROM t1
--source include/rpl_diff.inc

--echo # Check that t2 exists and has generated invisible primary key definition
--echo # in source and replica.
--let $rpl_diff_statement= SHOW CREATE TABLE t2;
--source include/rpl_diff.inc
--echo # Check that t2 hase same column values in source and replica.
--let $rpl_diff_statement= SELECT my_row_id, t2.* FROM t2
--source include/rpl_diff.inc

--source include/rpl_connection_master.inc
DROP TABLE t1, t2;
--source include/sync_slave_sql_with_master.inc
--source include/rpl_connection_master.inc
CALL p1();
EXECUTE stmt1;
INSERT INTO t2 VALUES(8, 4);

--echo # Check that t1 exists and has generated invisible primary key definition
--echo # in source and replica.
--let $rpl_diff_statement= SHOW CREATE TABLE t1;
--source include/rpl_diff.inc

--echo # Check that t1 hase same column values in source and replica.
--let $rpl_diff_statement= SELECT my_row_id, t1.* FROM t1
--source include/rpl_diff.inc

--echo # Check that t2 exists and has generated invisible primary key definition
--echo # in source and replica.
--let $rpl_diff_statement= SHOW CREATE TABLE t2;
--source include/rpl_diff.inc

--echo # Check that t2 hase same column values in source and replica.
--let $rpl_diff_statement= SELECT my_row_id, t2.* FROM t2
--source include/rpl_diff.inc

--source include/rpl_connection_master.inc
DROP TABLE t1, t2;
DROP PROCEDURE p1;
DROP PREPARE stmt1;
--source include/sync_slave_sql_with_master.inc


--echo # Case 4: Verify replication of CREATE TABLE ... SELECT with explicitly
--echo # specified primary key similar to generated invisible primary key.
--echo # Table t2 is created as primary key is explicitly specified.
--source include/rpl_connection_master.inc
CREATE TABLE t1(f1 INT, f2 INT);
INSERT INTO t1 VALUES (1, 10), (2, 20);
# Following statement is marked as unsafe statement when BINLOG_FORMAT = STATEMENT.
# So when BINLOG_FORMAT = STATEMENT, additional warnings are reported. But no warnings
# reported in other BINLOG_FORMAT types. Hence disable printing warnings here so that
# test works with all BINLOG_FORMAT types.
--disable_warnings
CREATE TABLE t2 (my_row_id BIGINT UNSIGNED INVISIBLE AUTO_INCREMENT PRIMARY KEY)
             AS SELECT t1.my_row_id, t1.* FROM t1;
--enable_warnings

--echo # check that t2 exists in source and replica.
--let $rpl_diff_statement= SHOW CREATE TABLE t2;
--source include/rpl_diff.inc


--echo # Case 5: Verify replication of CREATE TABLE ... SELECT using temporary source
--echo # table with GIPK.
CREATE TEMPORARY TABLE t3 (f1 INT);
INSERT INTO t3 VALUES (1),(3),(7),(8),(4);
# Following statement is marked as unsafe statement when BINLOG_FORMAT = STATEMENT.
# So when BINLOG_FORMAT = STATEMENT, additional warnings are reported. But no warnings
# reported in other BINLOG_FORMAT types. Hence disable printing warnings here so that
# test works with all BINLOG_FORMAT types.
--disable_warnings
CREATE TABLE t4(my_row_id BIGINT UNSIGNED INVISIBLE AUTO_INCREMENT PRIMARY KEY)
             AS SELECT my_row_id, f1 FROM t3;
--enable_warnings

--echo # check that t4 exists in source and replica.
--source include/sync_slave_sql_with_master.inc
--let $rpl_diff_statement= SHOW CREATE TABLE t4
--source include/rpl_diff.inc
--let $rpl_diff_statement= SELECT * FROM t4;
--source include/rpl_diff.inc

--source include/rpl_connection_master.inc
DROP TABLE t1, t2, t3, t4;

SET SESSION sql_generate_invisible_primary_key =
              @saved_session_sql_generate_invisible_primary_key;
--source include/rpl_end.inc