mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
f8f714a2fb
BitKeeper/etc/logging_ok: auto-union BitKeeper/deleted/.del-errmsg.txt~11edc4db89248c16: Auto merged BitKeeper/deleted/.del-errmsg.txt~184eb1f09242dc72: Auto merged BitKeeper/deleted/.del-errmsg.txt~2cdeb8d6f80eba72: Auto merged BitKeeper/deleted/.del-errmsg.txt~4617575065d612b9: Auto merged BitKeeper/deleted/.del-errmsg.txt~587903f9311db2d1: Auto merged BitKeeper/deleted/.del-errmsg.txt~606dfaeb9e81aa4e: Auto merged BitKeeper/deleted/.del-errmsg.txt~6bbd9eac7f0e6b89: Auto merged BitKeeper/deleted/.del-errmsg.txt~7397c423c52c6d2c: Auto merged BitKeeper/deleted/.del-errmsg.txt~898865062c970766: Auto merged BitKeeper/deleted/.del-errmsg.txt~8ed1999cbd481dc4: Auto merged BitKeeper/deleted/.del-errmsg.txt~94a93cc742fca24d: Auto merged BitKeeper/deleted/.del-errmsg.txt~9dab24f7fb11b1e1: Auto merged BitKeeper/deleted/.del-errmsg.txt~b44a85a177954da0: Auto merged BitKeeper/deleted/.del-errmsg.txt~b6181e29d8282b06: Auto merged BitKeeper/deleted/.del-errmsg.txt~ba132dc9bc936c8a: Auto merged BitKeeper/deleted/.del-errmsg.txt~e2609fdf7870795: Auto merged BitKeeper/deleted/.del-errmsg.txt~e3183b99fbba0a9c: Auto merged BitKeeper/deleted/.del-errmsg.txt~eeb2c47537ed9c23: Auto merged BitKeeper/deleted/.del-errmsg.txt~ef28b592c7591b7: Auto merged BitKeeper/deleted/.del-errmsg.txt~ef53c33ac0ff8a84: Auto merged BitKeeper/deleted/.del-errmsg.txt~f19bfd5d4c918964: Auto merged BitKeeper/deleted/.del-errmsg.txt~f96b7055cac394e: Auto merged libmysql/libmysql.c: Auto merged myisam/mi_key.c: Auto merged mysql-test/r/alter_table.result: Auto merged mysql-test/r/auto_increment.result: Auto merged mysql-test/r/innodb.result: Auto merged mysql-test/r/select.result: Auto merged mysql-test/t/alter_table.test: Auto merged mysql-test/t/innodb.test: Auto merged mysql-test/t/select.test: Auto merged sql/handler.h: Auto merged sql/item_func.cc: Auto merged sql/sql_yacc.yy: Auto merged mysql-test/r/insert_update.result: Auto merged strings/ctype-ucs2.c: Auto merged sql/sql_table.cc: merge sql/unireg.cc: merge
189 lines
4.1 KiB
Text
189 lines
4.1 KiB
Text
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (a INT, b INT, c INT, UNIQUE (A), UNIQUE(B));
|
|
INSERT t1 VALUES (1,2,10), (3,4,20);
|
|
INSERT t1 VALUES (5,6,30) ON DUPLICATE KEY UPDATE c=c+100;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 20
|
|
5 6 30
|
|
INSERT t1 VALUES (5,7,40) ON DUPLICATE KEY UPDATE c=c+100;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 20
|
|
5 6 130
|
|
INSERT t1 VALUES (8,4,50) ON DUPLICATE KEY UPDATE c=c+1000;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 1020
|
|
5 6 130
|
|
INSERT t1 VALUES (1,4,60) ON DUPLICATE KEY UPDATE c=c+10000;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10010
|
|
3 4 1020
|
|
5 6 130
|
|
INSERT t1 VALUES (1,9,70) ON DUPLICATE KEY UPDATE c=c+100000, b=4;
|
|
ERROR 23000: Duplicate entry '4' for key 2
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10010
|
|
3 4 1020
|
|
5 6 130
|
|
TRUNCATE TABLE t1;
|
|
INSERT t1 VALUES (1,2,10), (3,4,20);
|
|
INSERT t1 VALUES (5,6,30), (7,4,40), (8,9,60) ON DUPLICATE KEY UPDATE c=c+100;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 120
|
|
5 6 30
|
|
8 9 60
|
|
INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 120
|
|
5 0 30
|
|
8 9 60
|
|
INSERT t1 VALUES (2,1,11), (7,4,40) ON DUPLICATE KEY UPDATE c=c+VALUES(a);
|
|
SELECT *, VALUES(a) FROM t1;
|
|
a b c VALUES(a)
|
|
1 2 10 NULL
|
|
3 4 127 NULL
|
|
5 0 30 NULL
|
|
8 9 60 NULL
|
|
2 1 11 NULL
|
|
explain extended SELECT *, VALUES(a) FROM t1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 5
|
|
Warnings:
|
|
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,values(`test`.`t1`.`a`) AS `VALUES(a)` from `test`.`t1`
|
|
explain extended select * from t1 where values(a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
|
|
Warnings:
|
|
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1`
|
|
DROP TABLE t1;
|
|
create table t1(a int primary key, b int);
|
|
insert into t1 values(1,1),(2,2),(3,3),(4,4),(5,5);
|
|
select * from t1;
|
|
a b
|
|
1 1
|
|
2 2
|
|
3 3
|
|
4 4
|
|
5 5
|
|
insert into t1 values(4,14),(5,15),(6,16),(7,17),(8,18)
|
|
on duplicate key update b=b+10;
|
|
affected rows: 7
|
|
info: Records: 5 Duplicates: 2 Warnings: 0
|
|
select * from t1;
|
|
a b
|
|
1 1
|
|
2 2
|
|
3 3
|
|
4 14
|
|
5 15
|
|
6 16
|
|
7 17
|
|
8 18
|
|
replace into t1 values(5,25),(6,26),(7,27),(8,28),(9,29);
|
|
affected rows: 9
|
|
info: Records: 5 Duplicates: 4 Warnings: 0
|
|
select * from t1;
|
|
a b
|
|
1 1
|
|
2 2
|
|
3 3
|
|
4 14
|
|
5 25
|
|
6 26
|
|
7 27
|
|
8 28
|
|
9 29
|
|
drop table t1;
|
|
CREATE TABLE t1 (a INT, b INT, c INT, UNIQUE (A), UNIQUE(B));
|
|
INSERT t1 VALUES (1,2,10), (3,4,20);
|
|
INSERT t1 SELECT 5,6,30 FROM DUAL ON DUPLICATE KEY UPDATE c=c+100;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 20
|
|
5 6 30
|
|
INSERT t1 SELECT 5,7,40 FROM DUAL ON DUPLICATE KEY UPDATE c=c+100;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 20
|
|
5 6 130
|
|
INSERT t1 SELECT 8,4,50 FROM DUAL ON DUPLICATE KEY UPDATE c=c+1000;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 1020
|
|
5 6 130
|
|
INSERT t1 SELECT 1,4,60 FROM DUAL ON DUPLICATE KEY UPDATE c=c+10000;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10010
|
|
3 4 1020
|
|
5 6 130
|
|
INSERT t1 SELECT 1,9,70 FROM DUAL ON DUPLICATE KEY UPDATE c=c+100000, b=4;
|
|
ERROR 23000: Duplicate entry '4' for key 2
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10010
|
|
3 4 1020
|
|
5 6 130
|
|
TRUNCATE TABLE t1;
|
|
INSERT t1 VALUES (1,2,10), (3,4,20);
|
|
CREATE TABLE t2 (a INT, b INT, c INT, d INT);
|
|
INSERT t2 VALUES (5,6,30,1), (7,4,40,1), (8,9,60,1);
|
|
INSERT t2 VALUES (2,1,11,2), (7,4,40,2);
|
|
INSERT t1 SELECT a,b,c FROM t2 WHERE d=1 ON DUPLICATE KEY UPDATE c=c+100;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 120
|
|
5 6 30
|
|
8 9 60
|
|
INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0;
|
|
SELECT * FROM t1;
|
|
a b c
|
|
1 2 10
|
|
3 4 120
|
|
5 0 30
|
|
8 9 60
|
|
INSERT t1 SELECT a,b,c FROM t2 WHERE d=2 ON DUPLICATE KEY UPDATE c=c+VALUES(a);
|
|
SELECT *, VALUES(a) FROM t1;
|
|
a b c VALUES(a)
|
|
1 2 10 NULL
|
|
3 4 127 NULL
|
|
5 0 30 NULL
|
|
8 9 60 NULL
|
|
2 1 11 NULL
|
|
DROP TABLE t1;
|
|
DROP TABLE t2;
|
|
create table t1 (a int not null unique) engine=myisam;
|
|
insert into t1 values (1),(2);
|
|
insert ignore into t1 select 1 on duplicate key update a=2;
|
|
select * from t1;
|
|
a
|
|
1
|
|
2
|
|
insert ignore into t1 select a from t1 on duplicate key update a=a+1 ;
|
|
select * from t1;
|
|
a
|
|
1
|
|
3
|
|
insert into t1 select 1 on duplicate key update a=2;
|
|
select * from t1;
|
|
a
|
|
2
|
|
3
|
|
insert into t1 select a from t1 on duplicate key update a=a+1 ;
|
|
ERROR 23000: Duplicate entry '3' for key 1
|
|
drop table t1;
|