File: gr_generated_column.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 (247 lines) | stat: -rw-r--r-- 8,198 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
###############################################################################
# This test checks the behaviour of Generated Columns with GR
#
# Test
# 0. This test requires 2 servers.(M1 and M2)
# 1. Check the behaviour of GR with Stored Columns.
#	1.1 Create table st1 and execute DMLs on M1.Test if data is replicated
#	    properly by verifying data on both the servers.
#		st1: stored column genarated on primary key
#	1.2 Create table st2 and execute DMLs on M2.Test if data is replicated
#	    properly by verifying data on both the servers.
#		st2: stored column as primary key
#	1.3 Create table st3 and execute DMLs on M1.Test if data is replicated
#	    properly by verifying data on both the servers.
#		st3: stored column as unique
#	1.4 Create table st4 and execute DMLs on M2.Test if data is replicated
#	    properly by verifying data on both the servers.
#		st4: Stored column as foreign key
# 2. Check the behaviour of GR with Virtual Columns.
#	2.1 Create table vt1 and execute DMLs on M1.Test if data is replicated
#	    properly by verifying data on both the servers.
#		vt1: virtual column genarated on primary key
#	2.2 Create table vt2 and execute DMLs on M2.Test if data is replicated
#	    properly by verifying data on both the servers.
#		vt2: virtual column as unique key
#	2.3 Create table vt3 and execute DMLs on M1.Test if data is replicated
#	    properly by verifying data on both the servers.
#		vt3: Index on virtual column and foreign key constraints
# 3. Check the behaviour of GR with Generated Columns
#	3.1 Create table gt1 and execute DMLs on M2.Test if data is replicated
#	    properly by verifying data on both the servers.
#		gt1: both stored and virtual columns.
# 4. Clean up.
###############################################################################

--source include/have_group_replication_plugin.inc
--source include/group_replication.inc

# Scenario 1.1 :

--echo # Table st1: stored column genarated on primary key

CREATE TABLE st1 (c1 INT PRIMARY KEY);
ALTER TABLE st1 ADD COLUMN (c2 INT GENERATED ALWAYS AS (c1+1) STORED,INDEX(c2));

# Perform some basic DML on st1
INSERT INTO st1(c1) VALUES(1);
INSERT INTO st1(c1) VALUES(2);
UPDATE st1 SET c1=3 WHERE c2=3;
UPDATE st1 SET c1=4 WHERE c1=3;
DELETE FROM st1 WHERE c2=5;

--source include/rpl_sync.inc
--echo # check that st1 exists and has same values in both servers
--let $diff_tables=server1:st1, server2:st1
--source include/diff_tables.inc

# Scenario 1.2 :

--echo # Table st2: stored column as primary key
--let $rpl_connection_name= server2
--source include/rpl_connection.inc

CREATE TABLE st2 (c1 VARCHAR(10),c2 CHAR(2) GENERATED ALWAYS AS (SUBSTRING(c1, 1, 2)) STORED PRIMARY KEY);

# Perform some basic DML on st2
INSERT INTO st2(c1) VALUES("abcd");
INSERT INTO st2(c1) VALUES("efgh");
UPDATE st2 SET c1="abgh" WHERE c1='abcd';
UPDATE st2 SET c1="cdgh" WHERE c2='ef';
DELETE FROM st2 WHERE c2='cd';

--source include/rpl_sync.inc
--echo # check that st2 exists and has same values in both servers
--let $diff_tables=server1:st2, server2:st2
--source include/diff_tables.inc

# Scenario 1.3 :

--echo Table st3: stored column as unique
--let $rpl_connection_name= server1
--source include/rpl_connection.inc

CREATE TABLE st3 (
	c1 INT AUTO_INCREMENT PRIMARY KEY,
	c2 VARCHAR(10) NOT NULL,
	c3 VARCHAR(10) NOT NULL,
	c4 VARCHAR(21) AS (CONCAT(c2,c3)) STORED UNIQUE
);

# Perform some basic DML on st3
INSERT INTO st3(c2,c3) VALUES('first','insert');
INSERT INTO st3(c2,c3) VALUES('second','insert');

# Error for duplicate entry
--error ER_DUP_ENTRY
INSERT INTO st3 (c2,c3) VALUES('first','insert');

UPDATE st3 SET c3='update' WHERE c2='first';
UPDATE st3 SET c3='update' WHERE c2='second';
DELETE FROM st3 WHERE c2='first';
DELETE FROM st3 WHERE c3='update';

--source include/rpl_sync.inc
--echo # check that st3 exists and has same values in both servers
--let $diff_tables=server1:st3, server2:st3
--source include/diff_tables.inc

# Scenario 1.4 :

--echo Table st4: Stored column as foreign key
--let $rpl_connection_name= server2
--source include/rpl_connection.inc

# Parent table
CREATE TABLE t1 (a INT,b INT GENERATED ALWAYS AS (a-10)STORED, PRIMARY KEY(b));
CREATE TABLE st4 (c1 INT PRIMARY KEY,c2 INT GENERATED ALWAYS AS (c1%10)STORED,FOREIGN KEY(c2) REFERENCES t1(b));

# Insert on parent table
INSERT INTO t1(a) VALUES(11);
INSERT INTO t1(a) VALUES(12);

# Perform some basic DML on st4
INSERT INTO st4(c1) VALUES(31);
INSERT INTO st4(c1) VALUES(32);
UPDATE st4 SET c1=21 WHERE c2=1;
DELETE FROM st4 WHERE c2=2;
DELETE FROM st4 WHERE c1=21;

--source include/rpl_sync.inc
--echo # check that st4 exists and has same values in both servers
--let $diff_tables=server1:st4, server2:st4
--source include/diff_tables.inc

# Scenario 2.1 :

--echo Table vt1: virtual column genarated on primary key
--let $rpl_connection_name= server1
--source include/rpl_connection.inc

CREATE TABLE vt1 (c1 DATE PRIMARY KEY,c2 INT AS (year(c1)) VIRTUAL);

# Perform some basic DML on vt1
INSERT INTO vt1(c1) VALUES('2008-09-02');
INSERT INTO vt1(c1) VALUES('1998-06-17');
UPDATE vt1 SET c1='2009-09-02' WHERE c2=2008;
UPDATE vt1 SET c1='1999-06-17' WHERE c1='1998-06-17';
DELETE FROM vt1 WHERE c1='2009-09-02';
DELETE FROM vt1 WHERE c2=1999;

--source include/rpl_sync.inc
--echo # check that vt1 exists and has same values in both servers
--let $diff_tables=server1:vt1, server2:vt1
--source include/diff_tables.inc

# Scenario 2.2 :

--echo Table  vt2: virtual column as unique key
--let $rpl_connection_name= server2
--source include/rpl_connection.inc

CREATE TABLE vt2 (c1 TEXT,PRIMARY KEY(c1(20)),c2 TEXT GENERATED ALWAYS AS (SUBSTRING(c1, 1, 2)) VIRTUAL ,UNIQUE(c2(2)));

# Perform some basic DML on vt2
INSERT INTO vt2(c1) VALUES('first insert');
INSERT INTO vt2(c1) VALUES('second insert');
UPDATE vt2 SET c1='first update' WHERE c1='first insert';
UPDATE vt2 SET c1='second update' WHERE c2='se';
DELETE FROM vt2 WHERE c1='first update';
DELETE FROM vt2 WHERE c2='se';

--source include/rpl_sync.inc
--echo # check that vt2 exists and has same values in both servers
--let $diff_tables=server1:vt2, server2:vt2
--source include/diff_tables.inc

# Scenario 2.3 :

--echo Table vt3: Virtual Column with foreign keys
--let $rpl_connection_name= server1
--source include/rpl_connection.inc

#Parent table
CREATE TABLE t2(a INT PRIMARY KEY,b INT GENERATED ALWAYS AS (a+1) VIRTUAL,INDEX(b));
CREATE TABLE vt3(a INT PRIMARY KEY,b INT,FOREIGN KEY(b) REFERENCES t2(a) ON UPDATE RESTRICT ON DELETE RESTRICT,c INT AS (a*b)VIRTUAL);

# Insert on Parent table
INSERT INTO t2(a) VALUES(1);
INSERT INTO t2(a) VALUES(3);

# Perform some basic DML on vt3
INSERT INTO vt3(a,b) VALUES(100,1),(200,3);
UPDATE vt3 SET b=NULL WHERE b=3;
UPDATE t2 SET a=2 WHERE b=4;
UPDATE vt3 SET b=2 WHERE b IS NULL;
UPDATE t2,vt3 SET vt3.a=t2.a WHERE t2.b=vt3.b;

# Error due to foreign key constraint
--error ER_ROW_IS_REFERENCED_2
DELETE FROM t2 WHERE a=2;

DELETE FROM vt3 WHERE a=1;
DELETE FROM vt3 WHERE c=100;

--source include/rpl_sync.inc
--echo # check that vt3 exists and has same values in both servers
--let $diff_tables=server1:vt3, server2:vt3
--source include/diff_tables.inc

# Scenario 3.1 :

--echo Table gt1: gt1: both stored and virtual columns
--let $rpl_connection_name= server2
--source include/rpl_connection.inc

CREATE TABLE gt1 (a INT, b INT AS (a+1)STORED PRIMARY KEY);
ALTER TABLE gt1 ADD COLUMN c INT GENERATED ALWAYS AS (b+1)VIRTUAL;
ALTER TABLE gt1 ADD COLUMN d INT GENERATED  ALWAYS AS (c+10) STORED;

# Perform some basic DML on gt1
--let $i=5
while ($i>0){
  --eval INSERT INTO gt1(a) VALUES($i)
  --dec $i
}
UPDATE gt1 SET a=21 WHERE b=2;
UPDATE gt1 SET a=22 WHERE c=4;
UPDATE gt1 SET a=23 WHERE d=15;
UPDATE gt1 SET a=24 WHERE a=4;
DELETE FROM gt1 WHERE a=5;
DELETE FROM gt1 WHERE b=24;
DELETE FROM gt1 WHERE c=24;
DELETE FROM gt1 WHERE d=33;

--source include/rpl_sync.inc
--echo # check that gt1 exists and has same values in both servers
--let $diff_tables=server1:gt1, server2:gt1
--source include/diff_tables.inc

--echo # Clean Up

DROP TABLE st1,st2,st3,st4;
DROP TABLE vt1,vt2,vt3;
DROP TABLE gt1;
DROP TABLE t1,t2;

--source include/group_replication_end.inc