~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to mysql-test/extra/rpl_tests/rpl_multi_update3.test

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Let's verify that multi-update with a subselect does not cause the slave to crash
 
4
# (BUG#10442)
 
5
#
 
6
--disable_query_log
 
7
SELECT '-------- Test for BUG#9361 --------' as "";
 
8
--enable_query_log
 
9
 
 
10
eval CREATE TABLE t1 (
 
11
 a int unsigned not null auto_increment primary key,
 
12
 b int unsigned
 
13
) ENGINE=$engine_type;
 
14
 
 
15
eval CREATE TABLE t2 (
 
16
 a int unsigned not null auto_increment primary key,
 
17
 b int unsigned
 
18
) ENGINE=$engine_type;
 
19
 
 
20
INSERT INTO t1 VALUES (NULL, 0);
 
21
INSERT INTO t1 SELECT NULL, 0 FROM t1;
 
22
 
 
23
INSERT INTO t2 VALUES (NULL, 0), (NULL,1);
 
24
 
 
25
SELECT * FROM t1 ORDER BY a;
 
26
SELECT * FROM t2 ORDER BY a;
 
27
 
 
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;
 
31
 
 
32
sync_slave_with_master;
 
33
connection slave;
 
34
SELECT * FROM t1 ORDER BY a;
 
35
SELECT * FROM t2 ORDER BY a;
 
36
 
 
37
connection master;
 
38
drop table t1,t2;
 
39
 
 
40
##############################################################################
 
41
#
 
42
#  Test for BUG#9361: 
 
43
#  Subselects should work inside multi-updates
 
44
#
 
45
--disable_query_log
 
46
SELECT '-------- Test 1 for BUG#9361 --------' as "";
 
47
--enable_query_log
 
48
 
 
49
connection master;
 
50
 
 
51
--disable_warnings
 
52
DROP TABLE IF EXISTS t1;
 
53
DROP TABLE IF EXISTS t2;
 
54
--enable_warnings
 
55
 
 
56
CREATE TABLE t1 (
 
57
  a1  char(30),
 
58
  a2  int,
 
59
  a3  int,
 
60
  a4  char(30),
 
61
  a5  char(30)
 
62
);
 
63
 
 
64
CREATE TABLE t2 (
 
65
  b1  int,
 
66
  b2  char(30)
 
67
);
 
68
 
 
69
# Insert one row per table
 
70
INSERT INTO t1 VALUES ('Yes', 1, NULL, 'foo', 'bar');
 
71
INSERT INTO t2 VALUES (1, 'baz');
 
72
 
 
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';
 
83
 
 
84
sync_slave_with_master;
 
85
connection slave;
 
86
SELECT * FROM t1;
 
87
SELECT * FROM t2;
 
88
 
 
89
connection master;
 
90
DROP TABLE t1, t2;
 
91
 
 
92
##############################################################################
 
93
#
 
94
# Second test for BUG#9361
 
95
#
 
96
 
 
97
--disable_query_log
 
98
SELECT '-------- Test 2 for BUG#9361 --------' as "";
 
99
--enable_query_log
 
100
 
 
101
connection master;
 
102
 
 
103
--disable_warnings
 
104
DROP TABLE IF EXISTS t1;
 
105
DROP TABLE IF EXISTS t2;
 
106
DROP TABLE IF EXISTS t3;
 
107
--enable_warnings
 
108
 
 
109
CREATE TABLE t1 (
 
110
  i   INT,
 
111
  j   INT,
 
112
  x   INT,
 
113
  y   INT,
 
114
  z   INT
 
115
);
 
116
 
 
117
CREATE TABLE t2 (
 
118
  i   INT,
 
119
  k   INT,
 
120
  x   INT,
 
121
  y   INT,
 
122
  z   INT
 
123
);
 
124
 
 
125
CREATE TABLE t3 (
 
126
  j   INT,
 
127
  k   INT,
 
128
  x   INT,
 
129
  y   INT,
 
130
  z   INT
 
131
);
 
132
 
 
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);
 
136
 
 
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;
 
150
 
 
151
sync_slave_with_master;
 
152
connection slave;
 
153
 
 
154
SELECT * FROM t1;
 
155
 
 
156
connection master;
 
157
DROP TABLE t1, t2, t3;
 
158
 
 
159
##############################################################################
 
160
#
 
161
# BUG#12618
 
162
#
 
163
# TEST: Replication of a statement containing a join in a multi-update.
 
164
 
 
165
DROP TABLE IF EXISTS t1;
 
166
DROP TABLE IF EXISTS t2;
 
167
 
 
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)
 
173
);
 
174
 
 
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)
 
180
);
 
181
 
 
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');
 
189
 
 
190
INSERT INTO t2 VALUES 
 
191
  (1,'0.0000',0),
 
192
  (2,'0.0000',0),
 
193
  (3,'0.0000',0);
 
194
 
 
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;
 
207
 
 
208
select "-- MASTER AFTER JOIN --" as "";
 
209
select * from t1;
 
210
select * from t2;
 
211
 
 
212
sync_slave_with_master;
 
213
 
 
214
select "-- SLAVE AFTER JOIN --" as "";
 
215
select * from t1;
 
216
select * from t2;
 
217
 
 
218
connection master;
 
219
DROP TABLE t1, t2;
 
220
# End of 4.1 tests