oceanbase
887 строк · 34.2 Кб
1# owner: yuchen.wyc
2#tags: pl, optimizer
3# owner group: SQL1
4# description: foobar
5# tags: dml
6# case_transfer:
7# (1) update ignore语法不支持;
8# (2)update 多表操作不支持;
9# (3)create table t1 (a int, b char(255), key(a, b(20))); 不支持key为列的部分长度
10# (4)alter table t1 disable keys; 不支持;
11# (5)flush status;不支持
12# (6)系统变量%Handler_read% 不支持;
13# (7)set tmp_table_size=1024; 不支持
14# (8)系统变量不支持;SET SESSION sql_safe_updates = DEFAULT;
15# (9)HANDLER_UPDATE 系统变量不支持
16#
17# test of updating of keys
18#
19--source mysql_test/include/backup_spm_var.inc
20--disable_query_log
21set @@session.explicit_defaults_for_timestamp=off;
22connect (conn_admin, $OBMYSQL_MS0,admin,$OBMYSQL_PWD,test,$OBMYSQL_PORT);
23connection conn_admin;
24alter system set_tp tp_no = 509, error_code = 4016, frequency = 1;
25connection default;
26--enable_query_log
27
28--disable_warnings
29drop table if exists t1,t2;
30--enable_warnings
31--explain_protocol 1
32--result_format 4
33
34alter system set ob_enable_batched_multi_statement=true;
35--real_sleep 1
36create table t1 (a int auto_increment , primary key (a));
37insert into t1 values (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
38update t1 set a=a+10 where a > 34;
39update t1 set a=a+100 where a > 0;
40
41# Some strange updates to test some otherwise unused code
42update t1 set a=a+100 where a=1 and a=2;
43--error 1054
44update t1 set a=b+100 where a=1 and a=2;
45--error 1054
46update t1 set a=b+100 where c=1 and a=2;
47--error 1054
48update t1 set d=a+100 where a=1;
49select * from t1;
50drop table t1;
51
52create table t1(a int primary key, b int) partition by hash(a) partitions 3;
53insert into t1 values(1, 1), (2, 2);
54update t1 set b=b+1 where a>0;
55select * from t1;
56drop table t1;
57
58create table t1(a int primary key, b int) partition by hash(a) partitions 3;
59insert into t1 values(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
60update t1 set b=b+1 where a>0;
61select * from t1;
62drop table t1;
63
64create table t1(a int primary key, b int) partition by hash(a) partitions 3;
65create index gkey on t1(b) global;
66insert into t1 values(1, 1), (2, 2);
67update t1 set b=b+1 where a>0;
68select * from t1;
69drop table t1;
70
71create table t1(a int primary key, b int) partition by hash(a) partitions 3;
72create index gkey on t1(b) global;
73insert into t1 values(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
74update t1 set b=b+1 where a>0;
75select * from t1;
76drop table t1;
77
78create table t1(a int primary key, b int);
79create index gkey on t1(b) partition by hash(b) partitions 2;
80insert into t1 values(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
81update /*+index(t1 gkey)*/ t1 set b=b+1 where b>0 and b<5;
82select /*+index(t1 primary)*/ * from t1 order by a;
83drop table t1;
84
85create table t1(a int primary key, b int) partition by hash(a) partitions 3;
86create table t2(a int primary key, b int) partition by hash(a) partitions 3;
87insert into t1 values(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
88update /*+use_nl(t1, t2), leading(t1)*/ t1 set b=b+1 where a in (select a from t2);
89select * from t1;
90drop table t1, t2;
91
92CREATE TABLE t1
93(
94place_id int (10) unsigned NOT NULL,
95shows int(10) unsigned DEFAULT '0' NOT NULL,
96ishows int(10) unsigned DEFAULT '0' NOT NULL,
97ushows int(10) unsigned DEFAULT '0' NOT NULL,
98clicks int(10) unsigned DEFAULT '0' NOT NULL,
99iclicks int(10) unsigned DEFAULT '0' NOT NULL,
100uclicks int(10) unsigned DEFAULT '0' NOT NULL,
101ts timestamp,
102PRIMARY KEY (place_id,ts)
103);
104
105INSERT INTO t1 (place_id,shows,ishows,ushows,clicks,iclicks,uclicks,ts)
106VALUES (1,0,0,0,0,0,0,20000928174434);
107UPDATE t1 SET shows=shows+1,ishows=ishows+1,ushows=ushows+1,clicks=clicks+1,iclicks=iclicks+1,uclicks=uclicks+1 WHERE place_id=1 AND ts>="2000-09-28 00:00:00";
108select place_id,shows from t1;
109drop table t1;
110
111#
112# Test bug with update reported by Jan Legenhausen
113#
114
115CREATE TABLE t1 (
116lfdnr int(10) unsigned NOT NULL default '0',
117ticket int(10) unsigned NOT NULL default '0',
118client varchar(255) NOT NULL default '',
119replyto varchar(255) NOT NULL default '',
120subject varchar(100) NOT NULL default '',
121timestamp int(10) unsigned NOT NULL default '0',
122tstamp timestamp NOT NULL,
123status int(3) NOT NULL default '0',
124type varchar(15) NOT NULL default '',
125assignment int(10) unsigned NOT NULL default '0',
126fupcount int(4) unsigned NOT NULL default '0',
127parent int(10) unsigned NOT NULL default '0',
128activity int(10) unsigned NOT NULL default '0',
129priority tinyint(1) unsigned NOT NULL default '1',
130cc varchar(255) NOT NULL default '',
131bcc varchar(255) NOT NULL default '',
132body varchar(255) NOT NULL,
133comment varchar(255),
134header varchar(255),
135PRIMARY KEY (lfdnr),
136KEY k1 (timestamp),
137KEY k2 (type),
138KEY k3 (parent),
139KEY k4 (assignment),
140KEY ticket (ticket)
141) ;
142
143INSERT INTO t1 VALUES (773,773,'','','',980257344,20010318180652,0,'Open',10,0,0,0,1,'','','','','');
144
145alter table t1 change lfdnr lfdnr int(10) unsigned not null auto_increment;
146update t1 set status=1 where type='Open';
147select status from t1;
148drop table t1;
149
150#
151# Test of ORDER BY
152#
153
154create table t1 (a int not null, b int not null, key (a));
155insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3);
156SET @tmp=0;
157update t1 set b=(@tmp:=@tmp+1) order by a;
158update /*+index(t1 a)*/ t1 set b=99 where a=1 order by b asc limit 1;
159select * from t1 order by a,b;
160update t1 set b=100 where a=1 order by b desc limit 2;
161update t1 set a=a+10+b where a=1 order by b;
162select * from t1 order by a,b;
163create table t2 (a int not null, b int not null);
164insert into t2 values (1,1),(1,2),(1,3);
165update t1 set b=(select distinct 1 from (select * from t2) a);
166drop table t1,t2;
167
168#
169# Test with limit (Bug #393)
170#
171
172CREATE TABLE t1 (
173`id_param` smallint(3) unsigned NOT NULL default '0',
174`nom_option` char(40) NOT NULL default '',
175`valid` tinyint(1) NOT NULL default '0',
176KEY `id_param` (`id_param`,`nom_option`)
177);
178
179INSERT INTO t1 (id_param,nom_option,valid) VALUES (185,'600x1200',1);
180
181UPDATE t1 SET nom_option='test' WHERE id_param=185 AND nom_option='600x1200' AND valid=1 LIMIT 1;
182select * from t1;
183drop table t1;
184
185#
186# Multi table update test from bugs
187#
188
189create table t1 (F1 VARCHAR(30), F2 VARCHAR(30), F3 VARCHAR(30), cnt int, groupid int, KEY groupid_index (groupid));
190
191insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6),
192('0','1','2',1,5), ('0','2','0',1,3), ('1','0','1',1,2),
193('1','2','1',1,1), ('1','2','2',1,1), ('2','0','1',2,4),
194('2','2','0',1,7);
195delete from m1 using t1 m1,t1 m2 where m1.groupid=m2.groupid and (m1.cnt < m2.cnt or m1.cnt=m2.cnt and m1.F3>m2.F3);
196select * from t1;
197drop table t1;
198
199
200# Bug#5553 - Multi table UPDATE IGNORE fails on duplicate keys
201
202
203CREATE TABLE t1 (
204`colA` int(10) unsigned NOT NULL auto_increment,
205`colB` int(11) NOT NULL default '0',
206PRIMARY KEY (`colA`)
207);
208INSERT INTO t1 VALUES (4433,5424);
209CREATE TABLE t2 (
210`colC` int(10) unsigned NOT NULL default '0',
211`colA` int(10) unsigned NOT NULL default '0',
212`colD` int(10) unsigned NOT NULL default '0',
213`colE` int(10) unsigned NOT NULL default '0',
214`colF` int(10) unsigned NOT NULL default '0',
215PRIMARY KEY (`colC`,`colA`,`colD`,`colE`)
216);
217INSERT INTO t2 VALUES (3,4433,10005,495,500);
218INSERT INTO t2 VALUES (3,4433,10005,496,500);
219INSERT INTO t2 VALUES (3,4433,10009,494,500);
220INSERT INTO t2 VALUES (3,4433,10011,494,500);
221INSERT INTO t2 VALUES (3,4433,10005,497,500);
222INSERT INTO t2 VALUES (3,4433,10013,489,500);
223INSERT INTO t2 VALUES (3,4433,10005,494,500);
224INSERT INTO t2 VALUES (3,4433,10005,493,500);
225INSERT INTO t2 VALUES (3,4433,10005,492,500);
226#UPDATE IGNORE t2,t1 set t2.colE = t2.colE + 1,colF=0 WHERE t1.colA = t2.colA AND (t1.colB & 4096) > 0 AND (colE + 1) < colF;
227--error 1062
228UPDATE t2,t1 set t2.colE = t2.colE + 1,colF=0 WHERE t1.colA = t2.colA AND (t1.colB & 4096) > 0 AND (colE + 1) < colF;
229
230SELECT * FROM t2;
231DROP TABLE t1;
232DROP TABLE t2;
233
234#
235# Bug #6054
236#
237create table t1 (c1 int, c2 char(6), c3 int);
238create table t2 (c1 int, c2 char(6));
239insert into t1 values (1, "t1c2-1", 10), (2, "t1c2-2", 20);
240update t1 left join t2 on t1.c1 = t2.c1 set t2.c2 = "t2c2-1";
241update t1 left join t2 on t1.c1 = t2.c1 set t2.c2 = "t2c2-1" where t1.c3 = 10;
242drop table t1, t2;
243
244#
245# Bug #8057
246#
247create table t1 (id int not null auto_increment primary key, id_str varchar(32));
248insert into t1 (id_str) values ("test");
249update t1 set id_str = concat(id_str, id) where id = last_insert_id();
250select * from t1;
251drop table t1;
252
253#
254# Bug #8942: a problem with update and partial key part
255#
256
257create table t1 (a int, b char(255), key(a, b(20)));
258insert into t1 values (0, '1');
259update /*+index(t1 a)*/ t1 set b = b + 1 where a = 0;
260select * from t1;
261drop table t1;
262
263# BUG#9103 "Erroneous data truncation warnings on multi-table updates"
264create table t1 (a int, b varchar(10), key b(b(5)));
265create table t2 (a int, b varchar(10));
266
267insert into t1 values ( 1, 'abcd1e');
268insert into t1 values ( 2, 'abcd2e');
269insert into t2 values ( 1, 'abcd1e');
270insert into t2 values ( 2, 'abcd2e');
271update t1, t2 set t1.a = t2.a where t2.b = t1.b;
272show warnings;
273select * from t1;
274select * from t2;
275drop table t1, t2;
276
277#
278# Bug #11868 Update with subquery with ref built with a key from the updated
279# table crashes server
280#
281create table t1(f1 int, f2 int);
282create table t2(f3 int, f4 int);
283create index idx on t2(f3);
284insert into t1 values(1,0),(2,0);
285insert into t2 values(1,1),(2,2);
286UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
287select * from t1;
288drop table t1,t2;
289
290#
291# Bug #13180 sometimes server accepts sum func in update/delete where condition
292#
293create table t1(f1 int);
294select DATABASE();
295--error 1111
296update t1 set f1=1 where count(*)=1;
297select DATABASE();
298--error 1111
299delete from t1 where count(*)=1;
300drop table t1;
301
302# BUG#12915: Optimize "DELETE|UPDATE ... ORDER BY ... LIMIT n" to use an index
303create table t1 ( a int, b int default 0, index (a) );
304insert into t1 (a) values (0),(0),(0),(0),(0),(0),(0),(0);
305
306#flush status;
307select a from t1 order by a limit 1;
308#show status like 'handler_read%';
309
310#flush status;
311update t1 set a=9999 order by a limit 1;
312update t1 set b=9999 order by a limit 1;
313#show status like 'handler_read%';
314
315#flush status;
316delete from t1 order by a limit 1;
317#show status like 'handler_read%';
318
319#flush status;
320delete from t1 order by a desc limit 1;
321#show status like 'handler_read%';
322
323#alter table t1 disable keys;
324
325#flush status;
326delete from t1 order by a limit 1;
327#show status like 'handler_read%';
328
329select * from t1;
330update t1 set a=a+10,b=1 order by a limit 3;
331update t1 set a=a+11,b=2 order by a limit 3;
332update t1 set a=a+12,b=3 order by a limit 3;
333select * from t1 order by a;
334
335drop table t1;
336
337#
338# Bug#14186 select datefield is null not updated
339#
340create table t1 (f1 date not null);
341insert into t1 values('2000-01-01'),('0000-00-00');
342update t1 set f1='2002-02-02' where f1 is null;
343select * from t1;
344drop table t1;
345
346#
347# Bug#15028 Multitable update returns different numbers of matched rows
348# depending on table order
349create table t1 (f1 int);
350create table t2 (f2 int);
351insert into t1 values(1),(2);
352insert into t2 values(1),(1);
353#--enable_info
354#update t1,t2 set f1=3,f2=3 where f1=f2 and f1=1;
355#--disable_info
356update t2 set f2=1;
357update t1 set f1=1 where f1=3;
358#--enable_info
359#update t2,t1 set f1=3,f2=3 where f1=f2 and f1=1;
360#--disable_info
361drop table t1,t2;
362
363
364# BUG#15935
365#create table t1 (a int);
366#insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
367#create table t2 (a int, filler1 char(200), filler2 char(200), key(a));
368#insert into t2 select A.a + 10*B.a, 'filler','filler' from t1 A, t1 B;
369#flush status;
370#update t2 set a=3 where a=2;
371#show status like 'handler_read%';
372#drop table t1, t2;
373
374#
375# Bug #16510 Updating field named like '*name' caused server crash
376#
377create table t1(f1 int, `*f2` int);
378insert into t1 values (1,1);
379update t1 set `*f2`=1;
380drop table t1;
381
382#
383# Bug#25126: Wrongly resolved field leads to a crash
384#
385create table t1(f1 int);
386--error 1054
387update t1 set f2=1 order by f2;
388drop table t1;
389# End of 4.1 tests
390
391#
392# Bug #24035: performance degradation with condition int_field=big_decimal
393#
394
395CREATE TABLE t1 (
396request_id int unsigned NOT NULL auto_increment,
397user_id varchar(12) default NULL,
398time_stamp datetime NOT NULL default '0000-00-00 00:00:00',
399ip_address varchar(15) default NULL,
400PRIMARY KEY (request_id),
401KEY user_id_2 (user_id,time_stamp)
402);
403
404INSERT INTO t1 (user_id) VALUES ('user1');
405INSERT INTO t1 (user_id) VALUES ('user1');
406INSERT INTO t1 (user_id) VALUES ('user1');
407INSERT INTO t1 (user_id) VALUES ('user1');
408INSERT INTO t1 (user_id) VALUES ('user1');
409#INSERT INTO t1(user_id) SELECT user_id FROM t1;
410#INSERT INTO t1(user_id) SELECT user_id FROM t1;
411#INSERT INTO t1(user_id) SELECT user_id FROM t1;
412#INSERT INTO t1(user_id) SELECT user_id FROM t1;
413#INSERT INTO t1(user_id) SELECT user_id FROM t1;
414#INSERT INTO t1(user_id) SELECT user_id FROM t1;
415#INSERT INTO t1(user_id) SELECT user_id FROM t1;
416#INSERT INTO t1(user_id) SELECT user_id FROM t1;
417#
418#flush status;
419SELECT user_id FROM t1 WHERE request_id=9999999999999;
420#show status like '%Handler_read%';
421SELECT user_id FROM t1 WHERE request_id=999999999999999999999999999999;
422#show status like '%Handler_read%';
423UPDATE t1 SET user_id=null WHERE request_id=9999999999999;
424#show status like '%Handler_read%';
425UPDATE t1 SET user_id=null WHERE request_id=999999999999999999999999999999;
426#show status like '%Handler_read%';
427
428DROP TABLE t1;
429
430#
431# Bug #24010: INSERT INTO ... SELECT fails on unique constraint with data it
432# doesn't select
433#
434CREATE TABLE t1 (
435
436a INT(11),
437quux decimal( 31, 30 ),
438
439UNIQUE KEY bar (a),
440KEY quux (quux)
441);
442
443INSERT INTO
444t1 ( a, quux )
445VALUES
446( 1, 1 ),
447( 2, 0.1 );
448
449#INSERT INTO t1( a )
450# SELECT @newA := 1 + a FROM t1 WHERE quux <= 0.1;
451
452SELECT * FROM t1;
453
454DROP TABLE t1;
455
456#
457# Bug #22364: Inconsistent "matched rows" when executing UPDATE
458#
459
460#connect (con1,localhost,root,,test);
461#connection con1;
462#
463#set tmp_table_size=1024;
464#
465## Create the test tables
466#create table t1 (id int, a int, key idx(a));
467#create table t2 (id int unsigned not null auto_increment primary key, a int);
468#insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
469##insert into t2(a) select a from t2;
470##insert into t2(a) select a from t2;
471##insert into t2(a) select a from t2;
472#insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
473#insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
474#insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
475#insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
476#insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
477#update t2 set a=id;
478#insert into t1 select * from t2;
479#
480## Check that the number of matched rows is correct when the temporary
481## table is small enough to not be converted to MyISAM
482#select count(*) from t1 join t2 on (t1.a=t2.a);
483##--enable_info
484##update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id;
485##--disable_info
486#
487## Increase table sizes
488##insert into t2(a) select a from t2;
489#update t2 set a=id;
490#truncate t1;
491##insert into t1 select * from t2;
492#
493## Check that the number of matched rows is correct when the temporary
494## table has to be converted to MyISAM
495#select count(*) from t1 join t2 on (t1.a=t2.a);
496#--enable_info
497#update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id;
498#--disable_info
499#
500## Check that the number of matched rows is correct when there are duplicate
501## key errors
502#update t1 set a=1;
503#update t2 set a=1;
504#select count(*) from t1 join t2 on (t1.a=t2.a);
505#--enable_info
506#update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id;
507#--disable_info
508#
509#drop table t1,t2;
510#
511#connection default;
512#disconnect con1;
513
514#
515# Bug #40745: Error during WHERE clause calculation in UPDATE
516# leads to an assertion failure
517#
518#--disable_warnings
519#DROP TABLE IF EXISTS t1;
520#DROP FUNCTION IF EXISTS f1;
521#--enable_warnings
522#
523#CREATE FUNCTION f1() RETURNS INT RETURN f1();
524#CREATE TABLE t1 (i INT);
525#INSERT INTO t1 VALUES (1);
526#
527#--error ER_SP_NO_RECURSION
528#UPDATE t1 SET i = 3 WHERE f1();
529#--error ER_SP_NO_RECURSION
530#UPDATE t1 SET i = f1();
531#
532#DROP TABLE t1;
533#DROP FUNCTION f1;
534#
535#--echo End of 5.0 tests
536#
537#--echo #
538#--echo # Bug #47919 assert in open_table during ALTER temporary table
539#--echo #
540#
541CREATE TABLE t1 (f1 INTEGER AUTO_INCREMENT, PRIMARY KEY (f1));
542#CREATE TEMPORARY TABLE t2 LIKE t1;
543CREATE TABLE t2(f1 INTEGER AUTO_INCREMENT, PRIMARY KEY (f1));
544INSERT INTO t1 VALUES (1);
545INSERT INTO t2 VALUES (1);
546
547ALTER TABLE t2 COMMENT = 'ABC';
548#UPDATE t2, t1 SET t2.f1 = 2, t1.f1 = 9;
549ALTER TABLE t2 COMMENT = 'DEF';
550
551DROP TABLE t1, t2;
552
553--echo #
554--echo # Bug#50545: Single table UPDATE IGNORE crashes on join view in
555--echo # sql_safe_updates mode.
556--echo #
557CREATE TABLE t1 ( a INT, KEY( a ) );
558INSERT INTO t1 VALUES (0), (1);
559CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
560#SET SESSION sql_safe_updates = 1;
561
562#--error ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE
563#UPDATE IGNORE v1 SET a = 1;
564
565#SET SESSION sql_safe_updates = DEFAULT;
566DROP TABLE t1;
567DROP VIEW v1;
568
569--echo #
570--echo # Bug#54734 assert in Diagnostics_area::set_ok_status
571--echo #
572
573#--disable_warnings
574#DROP TABLE IF EXISTS t1, not_exists;
575#DROP FUNCTION IF EXISTS f1;
576#DROP VIEW IF EXISTS v1;
577#--enable_warnings
578#
579#CREATE TABLE t1 (PRIMARY KEY(pk)) AS SELECT 1 AS pk;
580#CREATE FUNCTION f1() RETURNS INTEGER RETURN (SELECT 1 FROM not_exists);
581#CREATE VIEW v1 AS SELECT pk FROM t1 WHERE f1() = 13;
582#--error ER_VIEW_INVALID
583#UPDATE v1 SET pk = 7 WHERE pk > 0;
584#
585#DROP VIEW v1;
586#DROP FUNCTION f1;
587#DROP TABLE t1;
588
589--echo #
590--echo # Verify that UPDATE does the same number of handler_update
591--echo # operations, no matter if there is ORDER BY or not.
592--echo #
593
594CREATE TABLE t1 (i INT);
595INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
596(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
597(30),(31),(32),(33),(34),(35);
598#CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2),
599# INDEX idx (a,b(1),c));
600CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2),
601INDEX idx (a,b,c));
602
603INSERT INTO t2 VALUES (10,10,10,10),(11,11,11,11),(12,12,12,12),(13,13,13,13),(14,14,14,14),(15,15,15,15),(16,16,16,16),(17,17,17,17),(18,18,18,18),(19,19,19,19);
604
605#INSERT INTO t2 SELECT i, i, i, i FROM t1;
606#FLUSH STATUS; # FLUSH is autocommit, so we put it outside of transaction
607START TRANSACTION;
608UPDATE t2 SET d = 10 WHERE b = 10 LIMIT 5;
609#SHOW STATUS LIKE 'HANDLER_UPDATE';
610ROLLBACK;
611#FLUSH STATUS;
612START TRANSACTION;
613UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
614#SHOW STATUS LIKE 'HANDLER_UPDATE';
615ROLLBACK;
616
617--echo Same test with a different UPDATE.
618
619ALTER TABLE t2 DROP INDEX idx;
620alter table t2 ADD INDEX idx2 (a, b);
621#FLUSH STATUS;
622START TRANSACTION;
623UPDATE t2 SET c = 10 LIMIT 5;
624#SHOW STATUS LIKE 'HANDLER_UPDATE';
625ROLLBACK;
626#FLUSH STATUS;
627START TRANSACTION;
628UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
629#SHOW STATUS LIKE 'HANDLER_UPDATE';
630ROLLBACK;
631DROP TABLE t1, t2;
632
633--disable_warnings
634drop table if exists table10_bigint;
635--enable_warnings
636
637CREATE TABLE table10_bigint (col_char_34_key char(34),col_char_24 char(24),col_char_48_unique_index char(48),col_char_26_unique_index char(26),col_char_36 char(36),col_char_26 char(26),col_char_20 char(20),col_char_37 char(37),col_char_29_key char(29),pk bigint,col_char_20_unique_index char(20),col_char_39 char(39),col_char_23 char(23),col_char_28_key char(28),col_char_45 char(45),col_char_40_unique_index char(40),col_char_43_unique_index char(43),col_char_21_key char(21),col_char_29 char(29),col_char_25_key char(25),col_timestamp_6 timestamp(6) NULL DEFAULT NULL,col_char_32_key char(32),col_char_22 char(22),col_char_45_key char(45),col_char_20_key char(20),col_char_35_key char(35),col_char_22_unique_index char(22),col_char_46_unique_index char(46),col_char_28_unique_index char(28),col_char_25 char(25),col_char_42_unique_index char(42),col_char_30_key char(30),col_char_33_unique_index char(33),col_char_42 char(42),col_char_23_key char(23),col_char_36_key char(36),col_timestamp_6_unique_index timestamp(6) NULL DEFAULT NULL,col_char_37_unique_index char(37),col_char_46_key char(46),col_char_32_unique_index char(32),col_char_34_unique_index char(34),col_char_28 char(28),col_char_25_unique_index char(25),col_char_39_unique_index char(39),col_char_30 char(30),col_char_36_unique_index char(36),col_char_47_key char(47),col_char_41_unique_index char(41),col_char_42_key char(42),col_char_48 char(48),col_char_46 char(46),col_char_48_key char(48),col_char_22_key char(22),col_bigint_unique_index bigint,col_char_38 char(38),col_char_21 char(21),col_char_43 char(43),col_char_27 char(27),col_char_40_key char(40),col_char_40 char(40),col_char_47_unique_index char(47),col_char_21_unique_index char(21),col_char_33 char(33),col_char_27_unique_index char(27),col_char_44_key char(44),col_char_35_unique_index char(35),col_char_26_key char(26),col_bigint bigint,col_char_30_unique_index char(30),col_char_45_unique_index char(45),col_char_32 char(32),col_char_41 char(41),col_char_24_unique_index char(24),col_char_31_unique_index char(31),col_char_33_key char(33),col_char_39_key char(39),col_char_35 char(35),col_timestamp_6_key timestamp(6) NULL DEFAULT NULL,col_char_44 char(44),col_char_31 char(31),col_char_43_key char(43),col_char_29_unique_index char(29),col_char_37_key char(37),col_char_23_unique_index char(23),col_char_41_key char(41),col_char_38_unique_index char(38),col_char_44_unique_index char(44),col_bigint_key bigint,col_char_24_key char(24),col_char_27_key char(27),col_char_38_key char(38),col_char_47 char(47),col_char_31_key char(31),col_char_34 char(34),key idx46(col_char_34_key ),key idx31(col_char_29_key ),primary key (pk)) ;
638insert into table10_bigint values('a', 'b','c','d','e', 'f', 'h','i','j',1,'a', 'b','c','d','e', 'f', 'h','i','j','k','2001-03-04 10:10:10', 'a', 'b','c','d','e', 'f', 'h','i','j','k','j','i','o','p','u','2001-03-04 10:10:10','a', 'b','c','d','e', 'f', 'h','i','j','k','j','i','o','p','u','y',2,'a', 'b','c','d','e', 'f','h','i','j','k','j','i','o',3,'a', 'b','c','d','e', 'f', 'h','i','j','2001-03-04 10:10:10','a', 'b','c','d','e', 'f', 'h','i','j',4,'a', 'b','c','d','e', 'f');
639UPDATE table10_bigint SET col_char_20 = 'a' ;
640delete from table10_bigint;
641alter system set ob_enable_batched_multi_statement=false;
642DROP TABLE /*! IF EXISTS*/ table10_bigint;
643
644--disable_warnings
645drop table if exists t1,t2;
646drop view if exists update_view, update_view1;
647--enable_warnings
648create table t1 (c1 int, c2 int, c3 int);
649create table t2 (c1 int, c2 int, c3 int);
650create view update_view (c1,c2) as select t1.c2 as c1, t2.c2 as c2 from t1, t2 where t1.c1 = t2.c1;
651create view update_view1 (c1,c2) as select t1.c2 as c1, t2.c2 as c2 from t1 join t2 on t1.c1 = t2.c1;
652--error 5868
653update t1, t2 set t1.c2 = t2.c2 where t1.c1 = t2.c1 order by t2.c2;
654--error 5868
655update t1 join t2 on t1.c1 = t2.c1 set t1.c2 = t2.c2 order by t2.c2;
656--error 5868
657update t1 left join t2 on t1.c1 = t2.c1 set t1.c2 = t2.c2 order by t2.c2;
658--error 5868
659update update_view set c1 = c2 order by c2;
660--error 5868
661update update_view1 set c1 = c2 order by c2;
662--error 5869
663update t1, t2 set t1.c2 = t2.c2 where t1.c1 = t2.c1 limit 10;
664--error 5869
665update t1 join t2 on t1.c1 = t2.c1 set t1.c2 = t2.c2 limit 10;
666--error 5869
667update t1 left join t2 on t1.c1 = t2.c1 set t1.c2 = t2.c2 limit 10;
668--error 5869
669update update_view set c1 = c2 limit 10;
670--error 5869
671update update_view1 set c1 = c2 limit 10;
672drop view update_view;
673drop view update_view1;
674drop table t1;
675drop table t2;
676
677--disable_warnings
678drop table if exists gf_ar_mthly_bill;
679--enable_warnings
680
681set binlog_row_image='MINIMAL';
682CREATE TABLE `gf_ar_mthly_bill` (
683`tnt_inst_id` varchar(8) COLLATE utf8mb4_bin NOT NULL COMMENT '租户机构id',
684`bill_no` varchar(64) COLLATE utf8mb4_bin NOT NULL COMMENT '账单号',
685`ip_id` varchar(32) COLLATE utf8mb4_bin NOT NULL COMMENT '结算对象ipid',
686`ip_role_id` varchar(32) COLLATE utf8mb4_bin NOT NULL COMMENT '结算对象pid',
687`inst_id` varchar(32) COLLATE utf8mb4_bin NOT NULL COMMENT '分支机构',
688`pd_code` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '产品码',
689`ar_no` varchar(34) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '合约号',
690`bill_tp` varchar(2) COLLATE utf8mb4_bin NOT NULL COMMENT '账单类型',
691`setl_tp` varchar(2) COLLATE utf8mb4_bin NOT NULL COMMENT '结算方式',
692`bill_st` varchar(2) COLLATE utf8mb4_bin NOT NULL COMMENT '核销状态',
693`bill_strt_dt` varchar(8) COLLATE utf8mb4_bin NOT NULL COMMENT '账单开始日期',
694`bill_end_dt` varchar(8) COLLATE utf8mb4_bin NOT NULL COMMENT '账单结束日期',
695`bill_mth` varchar(6) COLLATE utf8mb4_bin NOT NULL COMMENT '账单月份',
696`acrd_dt` varchar(8) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '应收日期',
697`gmt_pay` timestamp(6) NULL DEFAULT NULL COMMENT '付款时间',
698`payee_ac` varchar(34) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '收款方账号',
699`payer_ac` varchar(34) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '付款方账号',
700`pay_way` varchar(2) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '支付方式',
701`pay_orig` varchar(2) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '支付来源',
702`clcn_bsc_amt` decimal(25,4) DEFAULT NULL COMMENT '计算交易量',
703`clcn_bsc_tp` varchar(2) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '计算依据',
704`clcn_mthd` varchar(2) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '计算方法',
705`chrg_itm_code` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '收费项编码',
706`ccy` varchar(3) COLLATE utf8mb4_bin NOT NULL COMMENT '币种',
707`bill_amt` bigint(20) NOT NULL COMMENT '账单金额',
708`adj_amt` bigint(20) NOT NULL COMMENT '调整金额',
709`rcvd_amt` bigint(20) NOT NULL COMMENT '已收金额',
710`tax_tp` varchar(16) COLLATE utf8mb4_bin NOT NULL COMMENT '税种 01:增值税 02:营业税',
711`tax_rate` decimal(10,8) NOT NULL COMMENT '税率',
712`tax_amt` bigint(20) NOT NULL COMMENT '税额',
713`exn_inf` varchar(4000) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '扩展信息',
714`anl_dmsn1` varchar(1000) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '分析维度1',
715`anl_dmsn2` varchar(1000) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '分析维度2',
716`anl_dmsn3` varchar(1000) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '分析维度3',
717`anl_dmsn4` varchar(1000) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '分析维度4',
718`wrtof_dtl_cnt` bigint(20) DEFAULT NULL COMMENT '已核销明细数量',
719`to_wrtof_dtl_cnt` bigint(20) DEFAULT NULL COMMENT '待核销明细数量',
720`rcrd_id` varchar(64) COLLATE utf8mb4_bin NOT NULL COMMENT '数据唯一ID',
721`last_moder` varchar(32) COLLATE utf8mb4_bin NOT NULL COMMENT '最近修改人',
722`gmt_create` timestamp(6) NOT NULL COMMENT '创建时间',
723`gmt_modified` timestamp(6) NOT NULL COMMENT '修改时间',
724`charge_tp` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '计收费环境类型 01 主站云计收费 02 主站离线计收费 03 主站老计收费',
725`stl_ip_role_id` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '结算对象',
726`svc_amt` bigint(20) DEFAULT NULL COMMENT '交易金额',
727`inved_amt` bigint(20) DEFAULT NULL COMMENT '已开票金额',
728`chk_st` varchar(2) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '出账状态 01 初始化 02 待确认出账 03 已出账 04 客户已对账 05 对账差异',
729`acnt_day` varchar(14) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '出账日',
730`inv_amt` bigint(20) DEFAULT NULL COMMENT '可开票金额',
731`rel_inv_amt` bigint(20) DEFAULT NULL COMMENT '已关联发票金额',
732`tp` varchar(2) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '应收1 返点2',
733`payer_ip_role_id` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '扣款对象pid',
734`sgn_ip_id` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '签约对象ipid',
735`sgn_ip_role_id` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '签约对象pid',
736`chking_amt` bigint(20) DEFAULT '0' COMMENT '出账中金额',
737`frz_amt` bigint(20) DEFAULT '0' COMMENT '冻结金额(用于控制流程上互斥的业务)',
738`chked_amt` bigint(20) DEFAULT '0' COMMENT '已出账金额',
739`writingoff_amt` bigint(20) DEFAULT '0' COMMENT '核销中金额',
740`svc_bill_amt` bigint(20) DEFAULT NULL COMMENT '账单计费金额,计收费计费时生成的中间金额',
741`svc_ccy` varchar(3) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '账单计费币种',
742`env_source` varchar(16) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '环境标识',
743`metadata_source` varchar(1024) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '元数据来源标识,包括(用户、商户、产品、合约、计费)来源',
744`setl_time_zone` varchar(12) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '账单结算时区',
745`actg_time_zone` varchar(12) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '账单核算时区',
746`inter_trade_flag` varchar(1) COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'Y: 是关联交易 N: 不是关联交易',
747`actg_bill_mth` varchar(6) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '核算时区账单月份',
748`auto_writeoff_group_no` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '自动核销关联组号',
749`partition_id` varchar(4) COLLATE utf8mb4_bin GENERATED ALWAYS AS (substr(`bill_no`,23,2)) VIRTUAL,
750PRIMARY KEY (`tnt_inst_id`, `bill_no`),
751UNIQUE KEY `uk_tnt_inst_id_rcrd_id` (`tnt_inst_id`, `rcrd_id`) GLOBAL BLOCK_SIZE 16384,
752KEY `idx_tnt_inst_id_acnt_day_chk_st_gmt_create` (`tnt_inst_id`, `acnt_day`, `chk_st`, `gmt_create`) GLOBAL BLOCK_SIZE 16384,
753KEY `idx_tnt_inst_id_acnt_day_chk_st` (`tnt_inst_id`, `acnt_day`, `chk_st`) GLOBAL BLOCK_SIZE 16384,
754KEY `idx_tnt_inst_id_ip_role_id` (`tnt_inst_id`, `ip_role_id`) LOCAL BLOCK_SIZE 16384,
755KEY `idx_tnt_inst_id_setl_tp_bill_st` (`tnt_inst_id`, `setl_tp`, `bill_st`) GLOBAL BLOCK_SIZE 16384,
756KEY `idx_tnt_inst_id_ar_no` (`tnt_inst_id`, `ar_no`) GLOBAL BLOCK_SIZE 16384,
757KEY `idx_tnt_inst_id_bill_mth` (`tnt_inst_id`, `bill_mth`) GLOBAL BLOCK_SIZE 16384,
758KEY `idx_ip_role_id_bill_mth` (`tnt_inst_id`, `ip_role_id`, `bill_mth`) LOCAL BLOCK_SIZE 16384,
759KEY `idx_tnt_inst_id_ip_id` (`tnt_inst_id`, `ip_id`, `bill_mth`, `setl_tp`) GLOBAL BLOCK_SIZE 16384,
760KEY `idx_acrd_dt_setl_tp_bill_st` (`tnt_inst_id`, `acrd_dt`, `setl_tp`, `bill_st`) GLOBAL BLOCK_SIZE 16384,
761KEY `idx_tnt_inst_id_ip_role_id_bill_mth_setl_tp` (`tnt_inst_id`, `ip_role_id`, `bill_mth`, `setl_tp`) LOCAL BLOCK_SIZE 16384,
762KEY `idx_bill_mth` (`bill_mth`, `tnt_inst_id`) GLOBAL BLOCK_SIZE 16384,
763KEY `idx_payer_ip_role_id_bill_mth` (`tnt_inst_id`, `payer_ip_role_id`, `bill_mth`) GLOBAL BLOCK_SIZE 16384,
764KEY `idx_ip_id_bill_mth` (`tnt_inst_id`, `ip_id`, `bill_mth`) GLOBAL BLOCK_SIZE 16384,
765KEY `idx_policy_id_bill_mth_inst_id_type` (`tnt_inst_id`, `inst_id`, `bill_mth`, `tp`, `anl_dmsn2`) GLOBAL,
766KEY `idx_tnt_inst_id_inst_id_tp_anl_dmsn_1_bill_mth` (`tnt_inst_id`, `inst_id`, `tp`, `anl_dmsn1`, `bill_mth`) GLOBAL,
767KEY `idx_tnt_inst_id_inst_id_tp_anl_dmsn_3_bill_mth` (`tnt_inst_id`, `inst_id`, `tp`, `anl_dmsn3`, `bill_mth`) GLOBAL,
768KEY `idx_tnt_inst_id_inst_id_tp_anl_dmsn_4_bill_mth` (`tnt_inst_id`, `inst_id`, `tp`, `anl_dmsn4`, `bill_mth`) GLOBAL,
769KEY `idx_tnt_inst_id_inst_id_tp_anl_dmsn_2_bill_mth` (`tnt_inst_id`, `inst_id`, `tp`, `anl_dmsn2`, `bill_mth`) GLOBAL
770) partition by list columns(partition_id)
771(partition p0 values in ('00'),
772partition p80 values in ('80'),
773partition p81 values in ('81'),
774partition p82 values in ('82'),
775partition p95 values in ('95'),
776partition p96 values in ('96'),
777partition p97 values in ('97'),
778partition p98 values in ('98'),
779partition p99 values in ('99'));
780
781insert into gf_ar_mthly_bill(tnt_inst_id, bill_no, ip_id, ip_role_id, inst_id,
782bill_tp, setl_tp, bill_st, bill_strt_dt, bill_end_dt, bill_mth, ccy, bill_amt,
783adj_amt, rcvd_amt, tax_tp, tax_rate, tax_amt, rcrd_id, last_moder, gmt_create, gmt_modified)
784values('ylctest', '2018090310122000040400820033834415',
7851, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, '2021-05-17 12:09:34', '2021-05-17 12:09:34');
786begin;
787update gf_ar_mthly_bill
788set bill_st='01',
789gmt_pay='2021-05-17 12:09:35',
790clcn_bsc_amt='123.12',
791bill_amt=1,
792rcvd_amt=2,
793tax_amt=3,
794exn_inf='123456',
795anl_dmsn1='123456',
796anl_dmsn2='234567',
797anl_dmsn3='345678',
798anl_dmsn4='456789',
799last_moder='ylc',
800adj_amt=4,
801svc_amt = 5,
802chk_st = '06',
803inv_amt = 6,
804writingoff_amt = 7,
805wrtof_dtl_cnt = 9 ,
806to_wrtof_dtl_cnt = 8,
807chking_amt=10,
808chked_amt=11,
809frz_amt=12,
810svc_bill_amt=13,
811gmt_modified='2021-05-17 12:09:34'
812where
813tnt_inst_id='ylctest' and bill_no='2018090310122000040400820033834415';
814
815select * from gf_ar_mthly_bill;
816rollback;
817connect (obsys,$OBMYSQL_MS0,admin,$OBMYSQL_PWD,test,$OBMYSQL_PORT);
818connection obsys;
819--sleep 3
820connection default;
821set binlog_row_image='MINIMAL';
822update gf_ar_mthly_bill
823set bill_st='01',
824gmt_pay='2021-05-17 12:09:35',
825clcn_bsc_amt='123.12',
826bill_amt=1,
827rcvd_amt=2,
828tax_amt=3,
829exn_inf='123456',
830anl_dmsn1='123456',
831anl_dmsn2='234567',
832anl_dmsn3='345678',
833anl_dmsn4='456789',
834last_moder='ylc',
835adj_amt=4,
836svc_amt = 5,
837chk_st = '06',
838inv_amt = 6,
839writingoff_amt = 7,
840wrtof_dtl_cnt = 9 ,
841to_wrtof_dtl_cnt = 8,
842chking_amt=10,
843chked_amt=11,
844frz_amt=12,
845svc_bill_amt=13,
846gmt_modified='2021-05-17 12:09:34'
847where
848tnt_inst_id='ylctest' and bill_no='2018090310122000040400820033834415';
849
850select * from gf_ar_mthly_bill;
851drop table gf_ar_mthly_bill;
852set binlog_row_image='FULL';
853connection obsys;
854connection default;
855
856#bug fix:
857drop table if exists TBFUNDSALESTAT;
858CREATE TABLE TBFUNDSALESTAT (
859PRD_CODE VARCHAR(32) DEFAULT ' ',
860SELLER_CODE VARCHAR(9) DEFAULT ' ',
861HOLD_AMT NUMBER(18,2) DEFAULT 0
862);
863
864connection obsys;
865connection default;
866
867UPDATE tbfundsalestat a
868SET a.hold_amt = (SELECT /*+merge*/Sum(c.hold_amt)
869FROM tbfundsalestat c
870WHERE c.prd_code = a.prd_code)
871WHERE a.seller_code = (SELECT /*+unnest*/Max(b.seller_code)
872FROM tbfundsalestat b
873WHERE a.prd_code = b.prd_code);
874
875connection obsys;
876connection default;
877
878UPDATE tbfundsalestat a
879SET a.hold_amt = (SELECT /*+merge*/Sum(c.hold_amt)
880FROM tbfundsalestat c
881WHERE c.prd_code = a.prd_code)
882WHERE a.seller_code = (SELECT /*+unnest*/Max(b.seller_code)
883FROM tbfundsalestat b
884WHERE a.prd_code = b.prd_code);
885
886drop table if exists TBFUNDSALESTAT;
887--source mysql_test/include/recover_spm_var.inc
888