ALTER DATABASE test CHARACTER SET latin1 COLLATE latin1_swedish_ci;
drop table if exists t1,t2;
create table t1 (a int auto_increment , primary key (a));
insert 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);
update t1 set a=a+10 where a > 34;
update t1 set a=a+100 where a > 0;
update t1 set a=a+100 where a=1and a=2;
update t1 set a=b+100 where a=1and a=2; ERROR42S22: Unknown column 'b' in 'SELECT'
update t1 set a=b+100 where c=1and a=2; ERROR42S22: Unknown column 'c' in 'WHERE'
update t1 set d=a+100 where a=1; ERROR42S22: Unknown column 'd' in 'SET'
select * from t1;
a 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 145 146
drop table t1;
CREATE TABLE t1
(
place_id int (10) unsigned NOT NULL,
shows int(10) unsigned DEFAULT '0'NOT NULL,
ishows int(10) unsigned DEFAULT '0'NOT NULL,
ushows int(10) unsigned DEFAULT '0'NOT NULL,
clicks int(10) unsigned DEFAULT '0'NOT NULL,
iclicks int(10) unsigned DEFAULT '0'NOT NULL,
uclicks int(10) unsigned DEFAULT '0'NOT NULL,
ts timestamp,
PRIMARY KEY (place_id,ts)
);
INSERT INTO t1 (place_id,shows,ishows,ushows,clicks,iclicks,uclicks,ts)
VALUES (1,0,0,0,0,0,0,20000928174434);
UPDATE t1 SET shows=shows+1,ishows=ishows+1,ushows=ushows+1,clicks=clicks+1,iclicks=iclicks+1,uclicks=uclicks+1 WHERE place_id=1AND ts>="2000-09-28 00:00:00";
select place_id,shows from t1;
place_id shows 11
drop table t1;
CREATE TABLE t1 (
lfdnr int(10) unsigned NOT NULL default '0',
ticket int(10) unsigned NOT NULL default '0',
client varchar(255) NOT NULL default '',
replyto varchar(255) NOT NULL default '',
subject varchar(100) NOT NULL default '',
timestamp int(10) unsigned NOT NULL default '0',
tstamp timestamp NOT NULL,
status int(3) NOT NULL default '0',
type varchar(15) NOT NULL default '',
assignment int(10) unsigned NOT NULL default '0',
fupcount int(4) unsigned NOT NULL default '0',
parent int(10) unsigned NOT NULL default '0',
activity int(10) unsigned NOT NULL default '0',
priority tinyint(1) unsigned NOT NULL default '1',
cc varchar(255) NOT NULL default '',
bcc varchar(255) NOT NULL default '',
body text NOT NULL,
comment text,
header text,
PRIMARY KEY (lfdnr),
KEY k1 (timestamp),
KEY k2 (type),
KEY k3 (parent),
KEY k4 (assignment),
KEY ticket (ticket)
) ENGINE=MyISAM;
INSERT INTO t1 VALUES (773,773,'','','',980257344,20010318180652,0,'Open',10,0,0,0,1,'','','','','');
alter table t1 change lfdnr lfdnr int(10) unsigned not null auto_increment;
update t1 set status=1 where type='Open';
select status from t1;
status 1
drop table t1;
create table t1 (a int not null, b int not null, key (a));
insert 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); SET @tmp=0;
update t1 set b=(@tmp:=@tmp+1) order by a;
update t1 set b=99 where a=1 order by b asc limit 1;
select * from t1 order by a,b;
a b 12 13 199 24 25 26 37 38 39 310 311 312
update t1 set b=100 where a=1 order by b desc limit 2;
update t1 set a=a+10+b where a=1 order by b;
select * from t1 order by a,b;
a b 24 25 26 37 38 39 310 311 312 132 111100 111100
create table t2 (a int not null, b int not null);
insert into t2 values (1,1),(1,2),(1,3);
update t1 set b=(select distinct 1 from (select * from t2) a);
drop table t1,t2;
CREATE TABLE t1 (
`id_param` smallint(3) unsigned NOT NULL default '0',
`nom_option` char(40) NOT NULL default '',
`valid` tinyint(1) NOT NULL default '0',
KEY `id_param` (`id_param`,`nom_option`)
) ENGINE=MyISAM;
INSERT INTO t1 (id_param,nom_option,valid) VALUES (185,'600x1200',1);
UPDATE t1 SET nom_option='test' WHERE id_param=185AND nom_option='600x1200'AND valid=1 LIMIT 1;
select * from t1;
id_param nom_option valid 185 test 1
drop table t1;
create table t1 (F1 VARCHAR(30), F2 VARCHAR(30), F3 VARCHAR(30), cnt int, groupid int, KEY groupid_index (groupid));
insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6),
('0','1','2',1,5), ('0','2','0',1,3), ('1','0','1',1,2),
('1','2','1',1,1), ('1','2','2',1,1), ('2','0','1',2,4),
('2','2','0',1,7);
delete 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);
select * from t1;
F1 F2 F3 cnt groupid 00016 01215 02013 10112 12111 20124 22017
drop table t1;
CREATE TABLE t1 (
`colA` int(10) unsigned NOT NULL auto_increment,
`colB` int(11) NOT NULL default '0',
PRIMARY KEY (`colA`)
);
INSERT INTO t1 VALUES (4433,5424);
CREATE TABLE t2 (
`colC` int(10) unsigned NOT NULL default '0',
`colA` int(10) unsigned NOT NULL default '0',
`colD` int(10) unsigned NOT NULL default '0',
`colE` int(10) unsigned NOT NULL default '0',
`colF` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`colC`,`colA`,`colD`,`colE`)
);
INSERT INTO t2 VALUES (3,4433,10005,495,500);
INSERT INTO t2 VALUES (3,4433,10005,496,500);
INSERT INTO t2 VALUES (3,4433,10009,494,500);
INSERT INTO t2 VALUES (3,4433,10011,494,500);
INSERT INTO t2 VALUES (3,4433,10005,497,500);
INSERT INTO t2 VALUES (3,4433,10013,489,500);
INSERT INTO t2 VALUES (3,4433,10005,494,500);
INSERT INTO t2 VALUES (3,4433,10005,493,500);
INSERT INTO t2 VALUES (3,4433,10005,492,500);
UPDATE IGNORE t2,t1 set t2.colE = t2.colE + 1,colF=0 WHERE t1.colA = t2.colA AND (t1.colB & 4096) > 0AND (colE + 1) < colF;
SELECT * FROM t2;
colC colA colD colE colF 3443310005495500 3443310005496500 34433100094950 34433100114950 34433100054980 34433100134900 3443310005494500 3443310005493500 3443310005492500
DROP TABLE t1;
DROP TABLE t2;
create table t1 (c1 int, c2 char(6), c3 int);
create table t2 (c1 int, c2 char(6));
insert into t1 values (1, "t1c2-1", 10), (2, "t1c2-2", 20);
update t1 left join t2 on t1.c1 = t2.c1 set t2.c2 = "t2c2-1";
update t1 left join t2 on t1.c1 = t2.c1 set t2.c2 = "t2c2-1" where t1.c3 = 10;
drop table t1, t2;
create table t1 (id int not null auto_increment primary key, id_str varchar(32));
insert into t1 (id_str) values ("test");
update t1 set id_str = concat(id_str, id) where id = last_insert_id();
select * from t1;
id id_str 1 test1
drop table t1;
create table t1 (a int, b char(255), key(a, b(20)));
insert into t1 values (0, '1');
update t1 set b = b + 1 where a = 0;
select * from t1;
a b 02
drop table t1;
create table t1 (a int, b varchar(10), key b(b(5))) engine=myisam;
create table t2 (a int, b varchar(10)) engine=myisam;
insert into t1 values ( 1, 'abcd1e');
insert into t1 values ( 2, 'abcd2e');
insert into t2 values ( 1, 'abcd1e');
insert into t2 values ( 2, 'abcd2e');
analyze table t1,t2;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK
update t1, t2 set t1.a = t2.a where t2.b = t1.b;
show warnings;
Level Code Message
drop table t1, t2;
create table t1(f1 int, f2 int);
create table t2(f3 int, f4 int);
create index idx on t2(f3);
insert into t1 values(1,0),(2,0);
insert into t2 values(1,1),(2,2);
UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
select * from t1;
f1 f2 11 22
drop table t1,t2;
create table t1(f1 int);
select DATABASE();
DATABASE()
test
update t1 set f1=1 where count(*)=1; ERROR HY000: Invalid use of group function
select DATABASE();
DATABASE()
test
delete from t1 where count(*)=1; ERROR HY000: Invalid use of group function
drop table t1;
create table t1 ( a int, b int default 0, index (a) );
insert into t1 (a) values (0),(0),(0),(0),(0),(0),(0),(0);
flush status;
select a from t1 order by a limit 1;
a 0
show status like 'handler_read%';
Variable_name Value
Handler_read_first 1
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
update t1 set a=9999 order by a limit 1;
update t1 set b=9999 order by a limit 1;
show status like 'handler_read%';
Variable_name Value
Handler_read_first 2
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 2
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
delete from t1 order by a limit 1;
show status like 'handler_read%';
Variable_name Value
Handler_read_first 1
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
delete from t1 order by a desc limit 1;
show status like 'handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 0
Handler_read_last 1
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
alter table t1 disable keys;
flush status;
delete from t1 order by a limit 1;
show status like 'handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 4
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 1
Handler_read_rnd_deleted 2
Handler_read_rnd_next 7
select * from t1;
a b 00 00 00 00 00
update t1 set a=a+10,b=1 order by a limit 3;
update t1 set a=a+11,b=2 order by a limit 3;
update t1 set a=a+12,b=3 order by a limit 3;
select * from t1 order by a;
a b 112 212 223 223 233
drop table t1;
create table t1 (f1 date not null);
insert into t1 values('2000-01-01'),('0000-00-00');
update t1 set f1='2002-02-02' where f1 is null;
select * from t1;
f1 2000-01-01 2002-02-02
drop table t1;
create table t1 (f1 int);
create table t2 (f2 int);
insert into t1 values(1),(2);
insert into t2 values(1),(1);
update t1,t2 set f1=3,f2=3 where f1=f2 and f1=1;
affected rows: 3
info: Rows matched: 3 Changed: 3 Warnings: 0
update t2 set f2=1;
update t1 set f1=1 where f1=3;
update t2,t1 set f1=3,f2=3 where f1=f2 and f1=1;
affected rows: 3
info: Rows matched: 3 Changed: 3 Warnings: 0
drop table t1,t2;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, filler1 char(200), filler2 char(200), key(a));
insert into t2 select A.a + 10*B.a, 'filler','filler' from t1 A, t1 B;
flush status;
update t2 set a=3 where a=2;
show status like 'handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 1
Handler_read_last 0
Handler_read_next 1
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 1
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
drop table t1, t2;
create table t1(f1 int, `*f2` int);
insert into t1 values (1,1);
update t1 set `*f2`=1;
drop table t1;
create table t1(f1 int);
update t1 set f2=1 order by f2; ERROR42S22: Unknown column 'f2' in 'SET'
drop table t1;
CREATE TABLE t1 (
request_id int unsigned NOT NULL auto_increment,
user_id varchar(12) default NULL,
time_stamp datetime NOT NULL default '0000-00-00 00:00:00',
ip_address varchar(15) default NULL,
PRIMARY KEY (request_id),
KEY user_id_2 (user_id,time_stamp)
);
INSERT INTO t1 (user_id) VALUES ('user1');
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
INSERT INTO t1(user_id) SELECT user_id FROM t1;
flush status;
SELECT user_id FROM t1 WHERE request_id=9999999999999;
user_id
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 1
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT user_id FROM t1 WHERE request_id=999999999999999999999999999999;
user_id
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
UPDATE t1 SET user_id=null WHERE request_id=9999999999999;
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
UPDATE t1 SET user_id=null WHERE request_id=999999999999999999999999999999;
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
DROP TABLE t1;
CREATE TABLE t1 (
a INT(11),
quux decimal( 31, 30 ),
UNIQUE KEY bar (a),
KEY quux (quux)
);
INSERT INTO
t1 ( a, quux )
VALUES
( 1, 1 ),
( 2, 0.1 );
INSERT INTO t1( a )
SELECT @newA := 1 + a FROM t1 WHERE quux <= 0.1;
SELECT * FROM t1;
a quux 11.000000000000000000000000000000 20.100000000000000000000000000000 3 NULL
DROP TABLE t1;
connect con1,localhost,root,,test;
connection con1; set tmp_table_size=2048;
Warnings:
Warning 1292 Truncated incorrect tmp_table_size value: '2048'
create table t1 (id int, a int, key idx(a));
create table t2 (id int unsigned not null auto_increment primary key, a int);
insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
insert into t2(a) select a from t2;
insert into t2(a) select a from t2;
insert into t2(a) select a from t2;
update t2 set a=id;
insert into t1 select * from t2;
select count(*) from t1 join t2 on (t1.a=t2.a);
count(*) 64
update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id;
affected rows: 0
info: Rows matched: 64 Changed: 0 Warnings: 0
insert into t2(a) select a from t2;
update t2 set a=id;
truncate t1;
insert into t1 select * from t2;
select count(*) from t1 join t2 on (t1.a=t2.a);
count(*) 128
update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id;
affected rows: 0
info: Rows matched: 128 Changed: 0 Warnings: 0
update t1 set a=1;
update t2 set a=1;
select count(*) from t1 join t2 on (t1.a=t2.a);
count(*) 16384
update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id;
affected rows: 127
info: Rows matched: 128 Changed: 127 Warnings: 0
drop table t1,t2;
connection default;
disconnect con1;
DROP TABLE IF EXISTS t1;
DROP FUNCTION IF EXISTS f1;
CREATE FUNCTION f1() RETURNS INT RETURN f1();
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1);
UPDATE t1 SET i = 3 WHERE f1(); ERROR HY000: Recursive stored functions and triggers are not allowed
UPDATE t1 SET i = f1(); ERROR HY000: Recursive stored functions and triggers are not allowed
DROP TABLE t1;
DROP FUNCTION f1;
End of 5.0 tests
#
# Bug #47919assert in open_table during ALTER temporary table
#
CREATE TABLE t1 (f1 INTEGER AUTO_INCREMENT, PRIMARY KEY (f1));
CREATE TEMPORARY TABLE t2 LIKE t1;
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (1);
ALTER TABLE t2 COMMENT = 'ABC';
UPDATE t2, t1 SET t2.f1 = 2, t1.f1 = 9;
ALTER TABLE t2 COMMENT = 'DEF';
DROP TABLE t1, t2;
#
# Bug#50545: Single table UPDATE IGNORE crashes on join view in
# sql_safe_updates mode.
#
CREATE TABLE t1 ( a INT, KEY( a ) );
INSERT INTO t1 VALUES (0), (1);
CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12; SET SESSION sql_safe_updates = 1;
UPDATE IGNORE v1 SET a = 1; ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column SET SESSION sql_safe_updates = DEFAULT;
DROP TABLE t1;
DROP VIEW v1;
#
# Bug#54734assert in Diagnostics_area::set_ok_status
#
DROP TABLE IF EXISTS t1, not_exists;
DROP FUNCTION IF EXISTS f1;
DROP VIEW IF EXISTS v1;
CREATE TABLE t1 (PRIMARY KEY(pk)) AS SELECT 1 AS pk;
CREATE FUNCTION f1() RETURNS INTEGER RETURN (SELECT 1 FROM not_exists);
CREATE VIEW v1 AS SELECT pk FROM t1 WHERE f1() = 13;
UPDATE v1 SET pk = 7 WHERE pk > 0; ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
DROP VIEW v1;
DROP FUNCTION f1;
DROP TABLE t1;
# Bug #21143080: UPDATE ON VARCHAR AND TEXT COLUMNS PRODUCE INCORRECT
# RESULTS
CREATE TABLE t1 (a VARCHAR(50), b TEXT, c CHAR(50)) ENGINE=INNODB;
INSERT INTO t1 (a, b, c) VALUES ('start trail', '', 'even longer string');
UPDATE t1 SET b = a, a = 'inject';
SELECT a, b FROM t1;
a b
inject start trail
UPDATE t1 SET b = c, c = 'inject';
SELECT c, b FROM t1;
c b
inject even longer string
DROP TABLE t1;
#
# MDEV-3948 Assertion `records_are_comparable(table)' fails in compare_record(const TABLE*) on UPDATE with simple AND condition, index_merge+index_merge_intersection, InnoDB
#
# Verify that UPDATE does the same number of handler_update
# operations, no matter if there is ORDER BY ornot.
#
CREATE TABLE t1 (i INT) ENGINE=INNODB;
INSERT INTO t1 VALUES (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);
CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2),
INDEX idx (a,b(1),c)) ENGINE=INNODB;
INSERT INTO t2 SELECT i, i, i, i FROM t1;
FLUSH STATUS;
START TRANSACTION;
UPDATE t2 SET d = 10 WHERE b = 10 LIMIT 5;
SHOW STATUS LIKE 'HANDLER_UPDATE';
Variable_name Value
Handler_update 1
ROLLBACK;
FLUSH STATUS;
START TRANSACTION;
UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
SHOW STATUS LIKE 'HANDLER_UPDATE';
Variable_name Value
Handler_update 1
ROLLBACK;
Same test with a different UPDATE.
ALTER TABLE t2 DROP INDEX idx, ADD INDEX idx2 (a, b);
FLUSH STATUS;
START TRANSACTION;
UPDATE t2 SET c = 10 LIMIT 5;
SHOW STATUS LIKE 'HANDLER_UPDATE';
Variable_name Value
Handler_update 5
ROLLBACK;
FLUSH STATUS;
START TRANSACTION;
UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
SHOW STATUS LIKE 'HANDLER_UPDATE';
Variable_name Value
Handler_update 5
ROLLBACK;
DROP TABLE t1, t2;
#
# MDEV-8938: Server Crash on Update with joins
#
CREATE TABLE `t1` (
`name` varchar(255) NOT NULL,
`value` varchar(4095) DEFAULT NULL,
PRIMARY KEY (`name`)
);
UPDATE `t1` SET value = CONCAT("*.",(SELECT `temptable`.`value` FROM (SELECT * FROM `t1` WHERE `name`="consoleproxy.url.domain") AS `temptable` WHERE `temptable`.`name`="consoleproxy.url.domain")) WHERE `name`="consoleproxy.url.domain";
drop table t1;
CREATE TABLE `t1` (
`name` varchar(255) NOT NULL,
`value` varchar(4095) DEFAULT NULL,
PRIMARY KEY (`name`)
);
create table t2 (
`name` varchar(255) NOT NULL,
`value` varchar(4095) DEFAULT NULL,
PRIMARY KEY (`name`)
);
UPDATE t1 SET value = (SELECT value FROM t2 WHERE `name`= t1.name)
WHERE value is null ;
drop table t1,t2;
#
#MDEV-8701: Crash on derived query
#
CREATE TABLE t1 (
data_exit_entry_id int(11) NOT NULL,
data_entry_id int(11) NOT NULL,
data_entry_exit_id int(11) NOT NULL,
data_exit_entry_quantity double NOT NULL
) DEFAULT CHARSET=utf8;
CREATE TABLE t2 (
data_entry_id int(11) NOT NULL,
data_entry_cost double NOT NULL,
data_entry_quantity double NOT NULL
) DEFAULT CHARSET=utf8;
create algorithm=temptable view v1 as SELECT data_entry_exit_id, data_exit_entry_quantity, data_entry_cost
FROM t1 INNER JOIN t2 as dt ON dt.data_entry_id = t1.data_entry_id;
UPDATE t2 SET data_entry_cost
= ( ( SELECT SUM(data_exit_entry_quantity * data_entry_cost)
FROM
v1 AS query
WHERE data_entry_exit_id = t2.data_entry_id
)
);
UPDATE t2 SET data_entry_cost
= ( ( SELECT SUM(data_exit_entry_quantity * data_entry_cost)
FROM
( SELECT data_entry_exit_id, data_exit_entry_quantity, data_entry_cost
FROM t1 INNER JOIN t2 as dt ON dt.data_entry_id = t1.data_entry_id) AS query
WHERE data_entry_exit_id = t2.data_entry_id
)
);
drop view v1;
drop table t1, t2;
#
# MDEV-4410: update does not want to use a covering index, but select uses it.
#
create table t2(a int);
insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (key1 int, col1 int, key(key1));
insert into t1
select A.a + 10 * B.a + 100 * C.a, 1234 from t2 A, t2 B, t2 C;
# This must not have "Using filesort":
explain
update t1 set key1=key1+1 where key1 between 10and110 order by key1 limit 2;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range key1 key1 5 NULL 2 Using where; Using buffer
flush status;
update t1 set key1=key1+1 where key1 between 10and110 order by key1 limit 2;
show status like 'Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 1
Handler_read_last 0
Handler_read_next 1
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 2
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
drop table t1, t2;
# End of MariaDB 10.0 tests
#
# MDEV-18945: multi-table update with constant table and
# comparison of date field with integer field
#
CREATE TABLE t1 (i1 int, d1 date , i2 int , d2 date) engine=myisam;
INSERT INTO t1 VALUES (19,'0000-00-00',73,'2008-05-21');
CREATE TABLE t2 (d1 date , i1 int, i2 int , d2 date) engine=myisam;
INSERT INTO t2 VALUES
('2006-01-12',-102,45,'2023-11-25'),('2034-12-19',-102,45,'2001-11-20');
UPDATE t1,t2 SET t1.i1 = -39 WHERE t2.d1 <> t1.i1 AND t2.d1 = t1.d2; ERROR22007: Incorrect datetime value: '19' for column `test`.`t1`.`i1` at row 1
DROP TABLE t1,t2;
# End of MariaDB 10.2 tests
#
# MDEV-20773: UPDATE with LIKE predicate over non-indexed column
# of VARCHAR type
#
create table t1 (a1 varchar(30), a2 varchar(30) collate utf8_bin);
insert into t1 values
('aa','zzz'), ('b','xxaa'), ('ccc','yyy'), ('ddd','xxb');
analyze table t1 persistent for all;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
explain extended
update t1 set a1 = 'u'
where a2 like 'xx%'and exists(select 1 from t1 where t1.a1 < 'c');
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 450.00 Using where 2 SUBQUERY t1 ALL NULL NULL NULL NULL 450.00 Using where
Warnings:
Note 1003/* select#1 */ update `test`.`t1` set `test`.`t1`.`a1` = 'u' where `test`.`t1`.`a2` like 'xx%'
update t1 set a1 = 'u'
where a2 like 'xx%'and exists(select 1 from t1 where t1.a1 < 'c');
select * from t1;
a1 a2
aa zzz
u xxaa
ccc yyy
u xxb
drop table t1;
# End of MariaDB 10.4 tests
#
# MDEV-35955 Wrong result for UPDATE ... ORDER BY LIMIT which uses tmp.table
#
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
insert into t1 (id, v) values (2,3),(1,4);
insert into t2 (id, v) values (5,5),(6,6);
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 2;
id v id v 1455 1466
UPDATE t1, t2 SET t1.v=-1, t2.v=-1 ORDER BY t1.id, t2.id LIMIT 2;
select * from t1;
id v 23 1 -1
select * from t2;
id v 5 -1 6 -1
drop table t1, t2;
create table t1 (id int primary key, v text) engine=myisam;
create table t2 (id int primary key, v text) engine=myisam;
insert into t1 (id, v) values (1,'b'),(2,'fo'),(3,'bar'),(4,'barr'),(5,'bazzz');
insert into t2 (id, v) values (6,'quxqux'),(7,'foofoof'),(8,'barbarba'),(9,'quxquxqux'),(10,'bazbazbazb');
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 2;
id v id v 1 b 6 quxqux 1 b 7 foofoof
update t1, t2 set t1.v='DELETED', t2.v='DELETED' order by t1.id, t2.id limit 2;
select * from t1;
id v 1 DELETED 2 fo 3 bar 4 barr 5 bazzz
select * from t2;
id v 6 DELETED 7 DELETED 8 barbarba 9 quxquxqux 10 bazbazbazb
drop table t1, t2;
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
create table t3 (id int primary key, v int);
insert into t1 (id, v) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000);
insert into t2 (id, v) values (10, 100), (20, 200), (30, 300), (40, 400), (50, 500);
insert into t3 (id, v) values (11, 111), (22, 222), (33, 333), (44, 444), (55, 555);
select t1.*, t2.*, t3.* from t1, t2, t3 order by t1.id, t2.id, t3.id limit 3;
id v id v id v 110001010011111 110001010022222 110001010033333
UPDATE t1, t2, t3 SET t1.v=-1, t2.v=-2, t3.v=-3 ORDER BY t1.id, t2.id, t3.id LIMIT 3;
select * from t1;
id v 1 -1 22000 33000 44000 55000
select * from t2;
id v 10 -2 20200 30300 40400 50500
select * from t3;
id v 11 -3 22 -3 33 -3 44444 55555
drop table t1, t2, t3;
# End of MariaDB 10.11 tests
#
# MDEV-29189: Second execution of SF using UPDATE?DELETE
# after reported error by the first execution
#
CREATE TABLE t1 (c int);
CREATE FUNCTION f1() RETURNS int
BEGIN
UPDATE t1 SET c=c+1; RETURN1;
END;//
CREATE FUNCTION f2() RETURNS int
BEGIN
DELETE FROM t1 WHERE c < 7; RETURN1;
END;//
INSERT INTO t1 VALUES (3), (7), (1);
SELECT * FROM t1 WHERE f1() = 1; ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
SELECT f1();
f1() 1
SELECT * FROM t1;
c 4 8 2
SELECT * FROM t1 WHERE f2() = 1; ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
SELECT f2();
f2() 1
SELECT * FROM t1;
c 8
DROP FUNCTION f1;
DROP FUNCTION f2;
DROP TABLE t1;
# End of MariaDB 11.1 tests
#
# MDEV-25008: Delete query gets stuck on mariadb, same query works
# on MySQL 8.0.21
#
CREATE TABLE t1 (
id int NOT NULL PRIMARY KEY,
item_id varchar(100),
seller_name varchar(400),
variant varchar(400),
FULLTEXT KEY t1_serial_IDX (item_id,seller_name,variant)
)engine=innodb;
insert into t1 select seq,seq,seq,seq from seq_1_to_10000;
explain
UPDATE t1 SET item_id="foo" WHERE id NOT IN
(SELECT m FROM (SELECT max(id) m FROM t1 GROUP BY item_id, seller_name, variant) AS innertable);
id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using where 2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL # 3 DERIVED t1 ALL NULL NULL NULL NULL # Using temporary; Using filesort
drop table t1;
create table t1 (a int primary key, b int, c int, key(b));
insert into t1 select seq, seq, seq from seq_1_to_20000;
create table t2 as select * from t1;
explain update t1 set c = 5 where b <= 2and a not in (select b from t2);
id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 range b b 5 NULL 2 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 20000 Using where
explain update t1 set c = 5 where b <= 3and a not in (select b from t2);
id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 range b b 5 NULL 3 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 20000
drop table t1, t2;
#
# MDEV-35662 Assertion failure in diagnostics area upon EXPLAIN UPDATE
#
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (b INET6);
INSERT INTO t2 VALUES ('::'),('::');
EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT b FROM t2) ORDER BY a LIMIT 1; ERROR HY000: Illegal parameter data types int and inet6 for operation '='
DROP TABLE t1, t2;
# End of 11.7 tests
ALTER DATABASE test CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;
# MDEV-35955 Wrong result for UPDATE ... ORDER BY LIMIT which uses tmp.table
#
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
insert into t1 (id, v) values (2,3),(1,4);
insert into t2 (id, v) values (5,5),(6,6);
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 2;
id v id v 1455 1466
UPDATE t1, t2 SET t1.v=-1, t2.v=-1 ORDER BY t1.id, t2.id LIMIT 2;
select * from t1;
id v 23 1 -1
select * from t2;
id v 5 -1 6 -1
drop table t1, t2;
create table t1 (id int primary key, v text) engine=myisam;
create table t2 (id int primary key, v text) engine=myisam;
insert into t1 (id, v) values (1,'b'),(2,'fo'),(3,'bar'),(4,'barr'),(5,'bazzz');
insert into t2 (id, v) values (6,'quxqux'),(7,'foofoof'),(8,'barbarba'),(9,'quxquxqux'),(10,'bazbazbazb');
select t1.*, t2.* from t1, t2 order by t1.id, t2.id limit 2;
id v id v 1 b 6 quxqux 1 b 7 foofoof
update t1, t2 set t1.v='DELETED', t2.v='DELETED' order by t1.id, t2.id limit 2;
select * from t1;
id v 1 DELETED 2 fo 3 bar 4 barr 5 bazzz
select * from t2;
id v 6 DELETED 7 DELETED 8 barbarba 9 quxquxqux 10 bazbazbazb
drop table t1, t2;
create table t1 (id int primary key, v int);
create table t2 (id int primary key, v int);
create table t3 (id int primary key, v int);
insert into t1 (id, v) values (1, 1000), (2, 2000), (3, 3000), (4, 4000), (5, 5000);
insert into t2 (id, v) values (10, 100), (20, 200), (30, 300), (40, 400), (50, 500);
insert into t3 (id, v) values (11, 111), (22, 222), (33, 333), (44, 444), (55, 555);
select t1.*, t2.*, t3.* from t1, t2, t3 order by t1.id, t2.id, t3.id limit 3;
id v id v id v 110001010011111 110001010022222 110001010033333
UPDATE t1, t2, t3 SET t1.v=-1, t2.v=-2, t3.v=-3 ORDER BY t1.id, t2.id, t3.id LIMIT 3;
select * from t1;
id v 1 -1 22000 33000 44000 55000
select * from t2;
id v 10 -2 20200 30300 40400 50500
select * from t3;
id v 11 -3 22 -3 33 -3 44444 55555
drop table t1, t2, t3;
# End of MariaDB 11.8 tests
# Beginning of 13.0 test
#
# MDEV-5092: Implement UPDATE with result set (UPDATE ... RETURNING)
#
CREATE TABLE t1(
id INT PRIMARY KEY,
a INT,
b VARCHAR(5)
);
CREATE TABLE t2(
id INT PRIMARY KEY,
a INT
);
INSERT INTO t1 VALUES (1, 10, 'x'), (2, 20, 'y'), (3, 30, 'z');
INSERT INTO t2 VALUES (1, 100), (2, 200);
CREATE VIEW v1 AS SELECT id, a, b FROM t1;
CREATE FUNCTION f(x INT) RETURNS INT
BEGIN RETURN x*2;
END|
UPDATE t1 SET a = a + 1
RETURNING id AS new_id, OLD_VALUE(id) AS old_id,
a AS new_a, OLD_VALUE(a) as old_a,
b AS new_b, OLD_VALUE(b) as old_b;
new_id old_id new_a old_a new_b old_b 111110 x x 222120 y y 333130 z z
UPDATE v1 SET a = a + 5 WHERE id = 3
RETURNING id AS new_id, OLD_VALUE(id) AS old_id,
a AS new_a, OLD_VALUE(a) AS old_a,
b AS new_b, OLD_VALUE(b) AS old_b;
new_id old_id new_a old_a new_b old_b 333631 z z
CREATE TRIGGER trg BEFORE UPDATE ON t1 FOR EACH ROW SET NEW.a = NEW.a + 100;
UPDATE t1 SET a = 1 WHERE id = 1
RETURNING id AS new_id, OLD_VALUE(id) AS old_id,
a AS new_a, OLD_VALUE(a) AS old_a,
b AS new_b, OLD_VALUE(b) AS old_b;
new_id old_id new_a old_a new_b old_b 1110111 x x
DROP TRIGGER trg;
PREPARE s FROM "UPDATE t1 SET a = a + 10 WHERE id = 2
RETURNING id AS new_id, OLD_VALUE(id) AS old_id,
a AS new_a, OLD_VALUE(a) AS old_a,
b AS new_b, OLD_VALUE(b) AS old_b";
EXECUTE s;
new_id old_id new_a old_a new_b old_b 223121 y y
EXECUTE s;
new_id old_id new_a old_a new_b old_b 224131 y y
DEALLOCATE PREPARE s;
UPDATE t1 JOIN t2 ON t1.id=t2.id SET t1.a=t2.a
RETURNING id AS new_id, OLD_VALUE(id) AS old_id,
a AS new_a, OLD_VALUE(a) AS old_a,
b AS new_b, OLD_VALUE(b) AS old_b; ERROR42000: This version of MariaDB doesn't yet support 'RETURNING for multi-table UPDATE'
SELECT OLD_VALUE(a) FROM t1; ERROR HY000: Incorrect usage of OLD_VALUE and non-UPDATE
UPDATE t1 SET a=1 WHERE id=1
RETURNING OLD_VALUE(nonexistent); ERROR42S22: Unknown column 'nonexistent' in 'RETURNING'
EXPLAIN UPDATE t1 SET a = a + 1
RETURNING id AS new_id, OLD_VALUE(id) AS old_id,
a AS new_a, OLD_VALUE(a) AS old_a,
b AS new_b, OLD_VALUE(b) AS old_b;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
EXPLAIN EXTENDED UPDATE t1 SET a = a + 1
RETURNING id AS new_id, OLD_VALUE(id) AS old_id,
a AS new_a, OLD_VALUE(a) AS old_a,
b AS new_b, OLD_VALUE(b) AS old_b;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3100.00
Warnings:
Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1
SHOW WARNINGS;
Level Code Message
Note 1003 update `test`.`t1` set `test`.`t1`.`a` = `test`.`t1`.`a` + 1
ANALYZE FORMAT=JSON UPDATE t1 SET a = a + 1
RETURNING id AS new_id, OLD_VALUE(id) AS old_id,
a AS new_a, OLD_VALUE(a) AS old_a,
b AS new_b, OLD_VALUE(b) AS old_b;
ANALYZE
{ "query_optimization": { "r_total_time_ms": "REPLACED"
}, "query_block": { "select_id": 1, "r_total_time_ms": "REPLACED", "table": { "update": 1, "table_name": "t1", "access_type": "ALL", "rows": 3, "r_rows": 3, "r_total_filtered": 100, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "r_engine_stats": REPLACED, "r_filtered": 100
}
}
}
DROP VIEW v1;
DROP FUNCTION f;
DROP TABLE t1;
DROP TABLE t2;
#
# MDEV-39127: UBSAN : downcast of address X which does not point to an object of type
# 'multi_update' in sql/sql_update.cc | Sql_cmd_update::update_single_table
#
#
CREATE ORREPLACE TABLE t3(a INT);
INSERT INTO t3 VALUES (1);
UPDATE t3 SET a = 10 RETURNING a;
a 10
DROP TABLE t3;
#
# MDEV-39119: Improve error handling when using OLD_VALUE as alias name
#
CREATE ORREPLACE TABLE t3(a INT);
INSERT INTO t3 VALUES (1);
UPDATE t3 SET a = 10 RETURNING OLD_VALUE(a) AS old_value;
old_value 1
DROP TABLE t3;
#
# MDEV-39179: Incorrect NULL handling in UPDATE ... RETURNING result
#
CREATE ORREPLACE TABLE t1(a VARCHAR(10));
INSERT INTO t1 VALUES('') RETURNING *;
a
UPDATE t1 SET a=NULL RETURNING OLD_VALUE(a) AS old, a AS new;
old new
NULL
DROP TABLE t1;
#
# MDEV-40125: OLD_VALUE crashes on a view with an expression
#
CREATE TABLE t ( id INT PRIMARY KEY, a INT );
INSERT INTO t VALUES (1, 1), (3, 3), (5, 5);
CREATE VIEW v AS SELECT id, a, a*2 AS a2 FROM t;
SELECT * FROM v;
id a a2 112 336 5510
UPDATE v SET a = a+1 WHERE id = 1 RETURNING OLD_VALUE(id) as old_id, id,
OLD_VALUE(a) as old_a, a,
OLD_VALUE(a2)as old_a2, a2;
old_id id old_a a old_a2 a2 111224
SELECT * FROM v;
id a a2 124 336 5510
UPDATE v SET a = a+1 WHERE id = 20 RETURNING OLD_VALUE(id) as old_id, id,
OLD_VALUE(a) as old_a, a,
OLD_VALUE(a2)as old_a2, a2;
old_id id old_a a old_a2 a2
DROP TABLE t;
DROP VIEW v;
# End of 13.0 test
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.6 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.