mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / extra / rpl_tests / rpl_multi_update3.test
blob6c7a980aecb4dd57f2ebe53973a55f0ed6e5e1a8
1 ##############################################################################
3 # Let's verify that multi-update with a subselect does not cause the slave to crash
4 # (BUG#10442)
6 --disable_query_log
7 SELECT '-------- Test for BUG#9361 --------' as "";
8 --enable_query_log
10 eval CREATE TABLE t1 (
11  a int unsigned not null auto_increment primary key,
12  b int unsigned
13 ) ENGINE=$engine_type;
15 eval CREATE TABLE t2 (
16  a int unsigned not null auto_increment primary key,
17  b int unsigned
18 ) ENGINE=$engine_type;
20 INSERT INTO t1 VALUES (NULL, 0);
21 INSERT INTO t1 SELECT NULL, 0 FROM t1;
23 INSERT INTO t2 VALUES (NULL, 0), (NULL,1);
25 SELECT * FROM t1 ORDER BY a;
26 SELECT * FROM t2 ORDER BY a;
28 UPDATE t2, (SELECT a FROM t1 ORDER BY a) AS t SET t2.b = t.a+5 ;
29 SELECT * FROM t1 ORDER BY a;
30 SELECT * FROM t2 ORDER BY a;
32 sync_slave_with_master;
33 connection slave;
34 SELECT * FROM t1 ORDER BY a;
35 SELECT * FROM t2 ORDER BY a;
37 connection master;
38 drop table t1,t2;
40 ##############################################################################
42 #  Test for BUG#9361: 
43 #  Subselects should work inside multi-updates
45 --disable_query_log
46 SELECT '-------- Test 1 for BUG#9361 --------' as "";
47 --enable_query_log
49 connection master;
51 --disable_warnings
52 DROP TABLE IF EXISTS t1;
53 DROP TABLE IF EXISTS t2;
54 --enable_warnings
56 CREATE TABLE t1 (
57   a1  char(30),
58   a2  int,
59   a3  int,
60   a4  char(30),
61   a5  char(30)
64 CREATE TABLE t2 (
65   b1  int,
66   b2  char(30)
69 # Insert one row per table
70 INSERT INTO t1 VALUES ('Yes', 1, NULL, 'foo', 'bar');
71 INSERT INTO t2 VALUES (1, 'baz');
73 # This should update the row in t1
74 UPDATE t1 a, t2 
75   SET    a.a1 = 'No' 
76   WHERE  a.a2 = 
77     (SELECT  b1 
78      FROM    t2 
79      WHERE   b2 = 'baz') 
80   AND a.a3 IS NULL 
81   AND a.a4 = 'foo' 
82   AND a.a5 = 'bar';
84 sync_slave_with_master;
85 connection slave;
86 SELECT * FROM t1;
87 SELECT * FROM t2;
89 connection master;
90 DROP TABLE t1, t2;
92 ##############################################################################
94 # Second test for BUG#9361
97 --disable_query_log
98 SELECT '-------- Test 2 for BUG#9361 --------' as "";
99 --enable_query_log
101 connection master;
103 --disable_warnings
104 DROP TABLE IF EXISTS t1;
105 DROP TABLE IF EXISTS t2;
106 DROP TABLE IF EXISTS t3;
107 --enable_warnings
109 CREATE TABLE t1 (
110   i   INT,
111   j   INT,
112   x   INT,
113   y   INT,
114   z   INT
117 CREATE TABLE t2 (
118   i   INT,
119   k   INT,
120   x   INT,
121   y   INT,
122   z   INT
125 CREATE TABLE t3 (
126   j   INT,
127   k   INT,
128   x   INT,
129   y   INT,
130   z   INT
133 INSERT INTO t1 VALUES ( 1, 2,13,14,15);
134 INSERT INTO t2 VALUES ( 1, 3,23,24,25);
135 INSERT INTO t3 VALUES ( 2, 3, 1,34,35), ( 2, 3, 1,34,36);
137 UPDATE      t1 AS a  
138 INNER JOIN  t2 AS b 
139               ON a.i = b.i
140 INNER JOIN  t3 AS c 
141               ON a.j = c.j  AND  b.k = c.k
142 SET         a.x = b.x, 
143             a.y = b.y, 
144             a.z = (
145               SELECT  sum(z) 
146               FROM    t3
147               WHERE   y = 34 
148             ) 
149 WHERE       b.x = 23;
151 sync_slave_with_master;
152 connection slave;
154 SELECT * FROM t1;
156 connection master;
157 DROP TABLE t1, t2, t3;
159 ##############################################################################
161 # BUG#12618
163 # TEST: Replication of a statement containing a join in a multi-update.
165 DROP TABLE IF EXISTS t1;
166 DROP TABLE IF EXISTS t2;
168 CREATE TABLE t1 (
169   idp int(11) NOT NULL default '0',
170   idpro int(11) default NULL,
171   price decimal(19,4) default NULL,
172   PRIMARY KEY (idp)
175 CREATE TABLE t2 (
176   idpro int(11) NOT NULL default '0',
177   price decimal(19,4) default NULL,
178   nbprice int(11) default NULL,
179   PRIMARY KEY (idpro)
182 INSERT INTO t1 VALUES 
183   (1,1,'3.0000'),
184   (2,2,'1.0000'),
185   (3,1,'1.0000'),
186   (4,1,'4.0000'),
187   (5,3,'2.0000'),
188   (6,2,'4.0000');
190 INSERT INTO t2 VALUES 
191   (1,'0.0000',0),
192   (2,'0.0000',0),
193   (3,'0.0000',0);
195 # This update sets t2 to the minimal prices for each product
196 update 
197   t2
198     join 
199   ( select    idpro, min(price) as min_price, count(*) as nbr_price
200     from      t1 
201     where     idpro>0 and price>0 
202     group by  idpro
203   ) as table_price
204 on   t2.idpro = table_price.idpro 
205 set  t2.price = table_price.min_price, 
206      t2.nbprice = table_price.nbr_price;
208 select "-- MASTER AFTER JOIN --" as "";
209 select * from t1;
210 select * from t2;
212 sync_slave_with_master;
214 select "-- SLAVE AFTER JOIN --" as "";
215 select * from t1;
216 select * from t2;
218 connection master;
219 DROP TABLE t1, t2;
220 # End of 4.1 tests