提交 71a4906c 编写于 作者: S shangyanwen 提交者: mergify[bot]

test(mtr):add insert_selet.test,insert_update.test..(#497)

上级 db45bef0
#
# DELETE FROM TABLE_NAME WHERE ...
#
use test;
CREATE TABLE `column_type_test` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) DEFAULT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) DEFAULT NULL COMMENT 'bigint',
`c_float` float DEFAULT NULL COMMENT 'float',
`c_double` double DEFAULT NULL COMMENT 'double',
`c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal',
`c_date` date DEFAULT NULL COMMENT 'date',
`c_datetime` datetime DEFAULT NULL COMMENT 'datetime',
`c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp',
`c_time` time DEFAULT NULL COMMENT 'time',
`c_char` char(10) DEFAULT NULL COMMENT 'char',
`c_varchar` varchar(10) DEFAULT NULL COMMENT 'varchar',
`c_blob` blob COMMENT 'blob',
`c_text` text COMMENT 'text',
`c_longblob` longblob COMMENT 'longblob'
) ENGINE=TIANMU;
#
# DELETE FROM TABLE_NAME WHERE ...for Large amount of data
#
load data infile '../../std_data/tianmu/bigdata4load' into table column_type_test fields terminated by '|';
select count(*) from column_type_test;
count(*)
100000
select max(c_int) from column_type_test;
max(c_int)
104
select min(c_int) from column_type_test;
min(c_int)
100
select avg(c_int) from column_type_test;
avg(c_int)
102.0000
select sum(c_int) from column_type_test;
sum(c_int)
10200000
show create table column_type_test;
Table Create Table
column_type_test CREATE TABLE `column_type_test` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) DEFAULT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) DEFAULT NULL COMMENT 'bigint',
`c_float` float DEFAULT NULL COMMENT 'float',
`c_double` double DEFAULT NULL COMMENT 'double',
`c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal',
`c_date` date DEFAULT NULL COMMENT 'date',
`c_datetime` datetime DEFAULT NULL COMMENT 'datetime',
`c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp',
`c_time` time DEFAULT NULL COMMENT 'time',
`c_char` char(10) DEFAULT NULL COMMENT 'char',
`c_varchar` varchar(10) DEFAULT NULL COMMENT 'varchar',
`c_blob` blob COMMENT 'blob',
`c_text` text COMMENT 'text',
`c_longblob` longblob COMMENT 'longblob'
) ENGINE=TIANMU DEFAULT CHARSET=latin1
select count(*) from column_type_test;
count(*)
100000
select max(c_int) from column_type_test;
max(c_int)
104
select min(c_int) from column_type_test;
min(c_int)
100
select avg(c_int) from column_type_test;
avg(c_int)
102.0000
select sum(c_int) from column_type_test;
sum(c_int)
10200000
drop table column_type_test;
drop table if exists t1,t2,t3,t11,t12;
CREATE TABLE t1 (a tinyint(3), b tinyint(5));
INSERT INTO t1 VALUES (1,1);
INSERT LOW_PRIORITY INTO t1 VALUES (1,2);
INSERT INTO t1 VALUES (1,3);
DELETE from t1 where a=1 limit 1;
DELETE LOW_PRIORITY from t1 where a=1;
INSERT INTO t1 VALUES (1,1);
DELETE from t1;
LOCK TABLE t1 write;
INSERT INTO t1 VALUES (1,2);
DELETE from t1;
UNLOCK TABLES;
INSERT INTO t1 VALUES (1,2);
SET AUTOCOMMIT=0;
DELETE from t1;
SET AUTOCOMMIT=1;
drop table t1;
create table t1 (
a bigint not null,
b bigint not null default 0,
c bigint not null default 0,
d bigint not null default 0,
e bigint not null default 0,
f bigint not null default 0,
g bigint not null default 0,
h bigint not null default 0,
i bigint not null default 0,
j bigint not null default 0,
primary key (a,b,c,d,e,f,g,h,i,j));
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23);
delete from t1 where a=26;
drop table t1;
create table t1 (
a bigint not null,
b bigint not null default 0,
c bigint not null default 0,
d bigint not null default 0,
e bigint not null default 0,
f bigint not null default 0,
g bigint not null default 0,
h bigint not null default 0,
i bigint not null default 0,
j bigint not null default 0,
primary key (a,b,c,d,e,f,g,h,i,j));
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23),(27);
delete from t1 where a=27;
drop table t1;
CREATE TABLE `t1` (
`i` int(10) NOT NULL default '0',
`i2` int(10) NOT NULL default '0',
PRIMARY KEY (`i`)
);
DELETE FROM t1 USING t1 WHERE post='1';
ERROR 42S22: Unknown column 'post' in 'where clause'
drop table t1;
CREATE TABLE t1 (
bool char(0) default NULL,
not_null varchar(20) binary NOT NULL default '',
misc integer not null,
PRIMARY KEY (not_null)
);
INSERT INTO t1 VALUES (NULL,'a',4), (NULL,'b',5), (NULL,'c',6), (NULL,'d',7);
select * from t1 where misc > 5 and bool is null;
bool not_null misc
NULL c 6
NULL d 7
delete from t1 where misc > 5 and bool is null;
select * from t1 where misc > 5 and bool is null;
bool not_null misc
select count(*) from t1;
count(*)
2
delete from t1 where 1 > 2;
select count(*) from t1;
count(*)
2
delete from t1 where 3 > 2;
select count(*) from t1;
count(*)
0
drop table t1;
create table t11 (a int NOT NULL, b int, primary key (a));
create table t12 (a int NOT NULL, b int, primary key (a));
create table t2 (a int NOT NULL, b int, primary key (a));
insert into t11 values (0, 10),(1, 11),(2, 12);
insert into t12 values (33, 10),(0, 11),(2, 12);
insert into t2 values (1, 21),(2, 12),(3, 23);
select * from t11;
a b
0 10
1 11
2 12
select * from t12;
a b
0 11
2 12
33 10
select * from t2;
a b
1 21
2 12
3 23
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
ERROR 21000: Subquery returns more than 1 row
select * from t11;
a b
0 10
1 11
2 12
select * from t12;
a b
0 11
2 12
33 10
delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
Warnings:
Warning 1242 Subquery returns more than 1 row
select * from t11;
a b
0 10
1 11
select * from t12;
a b
0 11
33 10
insert into t11 values (2, 12);
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
ERROR 21000: Subquery returns more than 1 row
select * from t11;
a b
0 10
1 11
2 12
delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
Warnings:
Warning 1242 Subquery returns more than 1 row
Warning 1242 Subquery returns more than 1 row
select * from t11;
a b
0 10
1 11
drop table t11, t12, t2;
# sql_safe_updates mode with multi-table DELETE
CREATE TABLE t1(a INTEGER PRIMARY KEY);
INSERT INTO t1 VALUES(10),(20);
CREATE TABLE t2(b INTEGER);
INSERT INTO t2 VALUES(10),(20);
SET SESSION sql_safe_updates=1;
EXPLAIN DELETE t2 FROM t1 JOIN t2 WHERE t1.a = 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL const PRIMARY PRIMARY 4 const 1 100.00 Using index
1 DELETE t2 NULL ALL NULL NULL NULL NULL 2 100.00 NULL
DELETE t2 FROM t1 JOIN t2 WHERE t1.a = 10;
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, t2;
create table t1 (a int, b int, unique key (a), key (b));
insert into t1 values (3, 3), (7, 7);
delete t1 from t1 where a = 3;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1;
a b
7 7
drop table t1;
CREATE TABLE t1 ( a int PRIMARY KEY );
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
INSERT INTO t1 VALUES (0),(1),(2);
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a LIMIT 1;
SELECT * FROM t1;
a
0
2
DROP TABLE t1;
CREATE TABLE t1 (a int not null,b int not null);
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b));
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b));
insert into t1 values (1,1),(2,1),(1,3);
insert into t2 values (1,1),(2,2),(3,3);
insert into t3 values (1,1),(2,1),(1,3);
select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
a b a b a b
1 1 1 1 1 1
2 1 2 2 2 1
1 3 1 1 1 3
explain select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 NULL
1 SIMPLE t2 NULL ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
1 SIMPLE t3 NULL eq_ref PRIMARY PRIMARY 8 test.t2.b,test.t1.b 1 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`a` = `test`.`t2`.`b`) and (`test`.`t2`.`a` = `test`.`t1`.`a`))
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
select * from t3;
a b
drop table t1,t2,t3;
create table t1(a date not null);
insert ignore into t1 values (0);
Warnings:
Warning 1264 Out of range value for column 'a' at row 1
select * from t1 where a is null;
a
0000-00-00
delete from t1 where a is null;
select count(*) from t1;
count(*)
0
drop table t1;
#
# Adds some test cases for unicode. such as insert unicode chars, in values, table name, or etc.
#
CREATE TABLE `abc def` (i int)engine=tianmu;
INSERT INTO `abc def` VALUES (1);
delete from `abc def` where i=1;
drop table `abc def`;
CREATE TABLE t1 (`abc def1` int, `abc def2` int);
INSERT INTO t1 VALUES (1,1);
DELETE from t1 where `abc def1` = 1;
LOCK TABLE t1 write;
INSERT INTO t1 VALUES (1,2);
DELETE from t1 where `abc def1` = 1;
UNLOCK TABLES;
INSERT INTO t1 VALUES (1,2);
SET AUTOCOMMIT=0;
DELETE from t1 where `abc def2` = 2;
SET AUTOCOMMIT=1;
drop table t1;
#
# deleting rows from a temporary tables
#
CREATE TABLE t1 (c int not null, d char (10) not null);
insert into t1 values(1,""),(2,"a"),(3,"b");
CREATE TEMPORARY TABLE t1 (a int not null, b char (10) not null);
insert into t1 values(4,"e"),(5,"f"),(6,"g");
alter table t1 rename t2;
select * from t1;
c d
1
2 a
3 b
select * from t2;
a b
4 e
5 f
6 g
delete from t1;
drop table t1 , t2;
#
# Multi engine
#
drop table if exists tbIn,t1;
Warnings:
Note 1051 Unknown table 'test.tbIn'
Note 1051 Unknown table 'test.t1'
create table tbIn(c1 int,c2 varchar(255))engine=InnoDB;
insert into tbIn values(3,'hhhb');
insert into tbIn values(2,'hhhb');
insert into tbIn values(1,'hhhb');
create table t1(c1 int,c2 varchar(255))engine=tianmu;
insert into t1 values(3,'hhhb');
insert into t1 values(2,'hhhb');
insert into t1 values(1,'hhhb');
delete tbIn,t1 from tbIn,t1 where tbIn.c1=t1.c1 and tbIn.c1=1;
drop table tbIn,t1;
#
# DELETE FROM TABLE_NAME
#
use test;
CREATE TABLE `column_type_test` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) DEFAULT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) DEFAULT NULL COMMENT 'bigint',
`c_float` float DEFAULT NULL COMMENT 'float',
`c_double` double DEFAULT NULL COMMENT 'double',
`c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal',
`c_date` date DEFAULT NULL COMMENT 'date',
`c_datetime` datetime DEFAULT NULL COMMENT 'datetime',
`c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp',
`c_time` time DEFAULT NULL COMMENT 'time',
`c_char` char(10) DEFAULT NULL COMMENT 'char',
`c_varchar` varchar(10) DEFAULT NULL COMMENT 'varchar',
`c_blob` blob COMMENT 'blob',
`c_text` text COMMENT 'text',
`c_longblob` longblob COMMENT 'longblob'
) ENGINE=TIANMU;
#
# DELETE FROM TABLE_NAME for Large amount of data
#
load data infile '../../std_data/tianmu/bigdata4load' into table column_type_test fields terminated by '|';
select count(*) from column_type_test;
count(*)
100000
select max(c_int) from column_type_test;
max(c_int)
104
select min(c_int) from column_type_test;
min(c_int)
100
select avg(c_int) from column_type_test;
avg(c_int)
102.0000
select sum(c_int) from column_type_test;
sum(c_int)
10200000
delete from column_type_test;
show create table column_type_test;
Table Create Table
column_type_test CREATE TABLE `column_type_test` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) DEFAULT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) DEFAULT NULL COMMENT 'bigint',
`c_float` float DEFAULT NULL COMMENT 'float',
`c_double` double DEFAULT NULL COMMENT 'double',
`c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal',
`c_date` date DEFAULT NULL COMMENT 'date',
`c_datetime` datetime DEFAULT NULL COMMENT 'datetime',
`c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp',
`c_time` time DEFAULT NULL COMMENT 'time',
`c_char` char(10) DEFAULT NULL COMMENT 'char',
`c_varchar` varchar(10) DEFAULT NULL COMMENT 'varchar',
`c_blob` blob COMMENT 'blob',
`c_text` text COMMENT 'text',
`c_longblob` longblob COMMENT 'longblob'
) ENGINE=TIANMU DEFAULT CHARSET=latin1
select count(*) from column_type_test;
count(*)
0
select max(c_int) from column_type_test;
max(c_int)
NULL
select min(c_int) from column_type_test;
min(c_int)
NULL
select avg(c_int) from column_type_test;
avg(c_int)
NULL
select sum(c_int) from column_type_test;
sum(c_int)
NULL
#
# DELETE FROM TABLE_NAME for select/insert/Aggregate query
#
insert into column_type_test(c_tinyint,c_smallint,c_mediumint,c_int,c_bigint,c_float,c_double,c_decimal,c_date,c_datetime,c_timestamp,c_time,c_char,c_varchar,c_text)
values(105,105,105,105,105,5.2,10.88,105.083,'2016-02-25','2016-02-25 10:20:01','2016-02-25 05:20:01','10:20:01','stoneatom','hello','bcdefghijklmn');
select * from column_type_test;
c_tinyint c_smallint c_mediumint c_int c_bigint c_float c_double c_decimal c_date c_datetime c_timestamp c_time c_char c_varchar c_blob c_text c_longblob
105 105 105 105 105 5.2 10.88 105.08300 2016-02-25 2016-02-25 10:20:01 2016-02-25 05:20:01 10:20:01 stoneatom hello NULL bcdefghijklmn NULL
select count(*) from column_type_test;
count(*)
1
select max(c_int) from column_type_test;
max(c_int)
105
select min(c_int) from column_type_test;
min(c_int)
105
select avg(c_int) from column_type_test;
avg(c_int)
105.0000
select sum(c_int) from column_type_test;
sum(c_int)
105
delete from column_type_test;
delete from column_type_test;
select * from column_type_test;
c_tinyint c_smallint c_mediumint c_int c_bigint c_float c_double c_decimal c_date c_datetime c_timestamp c_time c_char c_varchar c_blob c_text c_longblob
select count(*) from column_type_test;
count(*)
0
select max(c_int) from column_type_test;
max(c_int)
NULL
select min(c_int) from column_type_test;
min(c_int)
NULL
select avg(c_int) from column_type_test;
avg(c_int)
NULL
select sum(c_int) from column_type_test;
sum(c_int)
NULL
drop table column_type_test;
#
# DELETE FROM TABLE_NAME for primary key
#
CREATE TABLE t1(c1 int,c2 varchar(255),primary key(c1))ENGINE=TIANMU;
insert into t1 values(1,'test1');
insert into t1 values(2,'test2');
delete from t1;
select * from t1;
c1 c2
insert into t1 values(1,'test1');
insert into t1 values(2,'test2');
select * from t1;
c1 c2
1 test1
2 test2
delete from t1;
drop table t1;
CREATE TABLE t1 (a tinyint(3), b tinyint(5));
INSERT INTO t1 VALUES (1,1);
INSERT LOW_PRIORITY INTO t1 VALUES (1,2);
INSERT INTO t1 VALUES (1,3);
DELETE from t1 where a=1 limit 1;
DELETE LOW_PRIORITY from t1 where a=1;
INSERT INTO t1 VALUES (1,1);
DELETE from t1;
LOCK TABLE t1 write;
INSERT INTO t1 VALUES (1,2);
DELETE from t1;
UNLOCK TABLES;
INSERT INTO t1 VALUES (1,2);
SET AUTOCOMMIT=0;
DELETE from t1;
SET AUTOCOMMIT=1;
drop table t1;
#
# Adds some test cases for unicode. such as insert unicode chars, in values, table name, or etc.
#
CREATE TABLE `abc def` (i int)engine=tianmu;
INSERT INTO `abc def` VALUES (1);
delete from `abc def`;
drop table `abc def`;
CREATE TABLE t1 (`abc def1` tinyint(3), `abc def2` tinyint(5));
INSERT INTO t1 VALUES (1,1);
DELETE from t1;
LOCK TABLE t1 write;
INSERT INTO t1 VALUES (1,2);
DELETE from t1;
UNLOCK TABLES;
INSERT INTO t1 VALUES (1,2);
SET AUTOCOMMIT=0;
DELETE from t1;
SET AUTOCOMMIT=1;
drop table t1;
......@@ -63,7 +63,8 @@ drop table t1;
#
# Test of duplicate key values with packed keys
#
create table t1 (id int not null auto_increment primary key, username varchar(32) not null, unique (username));
create table t1 (id int not null auto_increment primary key, username varchar(32) not null,
unique (username));
insert into t1 values (0,"mysql");
insert into t1 values (0,"mysql ab");
insert into t1 values (0,"mysql a");
......@@ -73,7 +74,10 @@ drop table t1;
#
# Test insert syntax
#
create table t1 (a int not null auto_increment, primary key (a), t timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, c char(10) default "hello", i int)engine=tianmu;
create table t1 (a int not null auto_increment,
primary key (a),
t timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
c char(10) default "hello", i int)engine=tianmu;
insert into t1 values (default,default,default,default), (default,default,default,default), (4,0,"a",5),(default,default,default,default);
select a,t>0,c,i from t1;
a t>0 c i
......@@ -96,26 +100,6 @@ a t>0 c i
6 1 hello NULL
drop table t1;
#
# Test problem with bulk insert and auto_increment on second part keys
#
create table t1 (sid char(20), id int(2) NOT NULL auto_increment, key(sid, id)) engine=myisam;
insert into t1 values ('skr',NULL),('skr',NULL),('test',NULL);
select * from t1;
sid id
skr 1
skr 2
test 1
insert into t1 values ('rts',NULL),('rts',NULL),('test',NULL);
select * from t1;
sid id
rts 1
rts 2
skr 1
skr 2
test 1
test 2
drop table t1;
#
#Test of behaviour with INSERT VALUES (NULL)
#
create table t1 (id int NOT NULL DEFAULT 8);
......@@ -143,7 +127,17 @@ use test;
#
# Test of wrong values for float data
#
create table t1(number int auto_increment primary key, original_value varchar(50), f_double double, f_float float, f_double_7_2 double(7,2), f_float_4_3 float (4,3), f_double_u double, f_float_u float, f_double_15_1_u double(15,1), f_float_3_1_u float (3,1));
create table t1(
number int auto_increment primary key,
original_value varchar(50),
f_double double,
f_float float,
f_double_7_2 double(7,2),
f_float_4_3 float (4,3),
f_double_u double,
f_float_u float,
f_double_15_1_u double(15,1),
f_float_3_1_u float (3,1));
set @value= "aa";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
Warnings:
......@@ -156,16 +150,6 @@ Warning 1265 Data truncated for column 'f_float_u' at row 1
Warning 1265 Data truncated for column 'f_double_15_1_u' at row 1
Warning 1265 Data truncated for column 'f_float_3_1_u' at row 1
select * from t1 where number =last_insert_id();
number 1
original_value aa
f_double 0
f_float 0
f_double_7_2 0.00
f_float_4_3 0.000
f_double_u 0
f_float_u 0
f_double_15_1_u 0.0
f_float_3_1_u 0.0
set @value= "1aa";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
Warnings:
......@@ -178,16 +162,6 @@ Warning 1265 Data truncated for column 'f_float_u' at row 1
Warning 1265 Data truncated for column 'f_double_15_1_u' at row 1
Warning 1265 Data truncated for column 'f_float_3_1_u' at row 1
select * from t1 where number =last_insert_id();
number 2
original_value 1aa
f_double 1
f_float 1
f_double_7_2 1.00
f_float_4_3 1.000
f_double_u 1
f_float_u 1
f_double_15_1_u 1.0
f_float_3_1_u 1.0
set @value= "aa1";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
Warnings:
......@@ -200,16 +174,6 @@ Warning 1265 Data truncated for column 'f_float_u' at row 1
Warning 1265 Data truncated for column 'f_double_15_1_u' at row 1
Warning 1265 Data truncated for column 'f_float_3_1_u' at row 1
select * from t1 where number =last_insert_id();
number 3
original_value aa1
f_double 0
f_float 0
f_double_7_2 0.00
f_float_4_3 0.000
f_double_u 0
f_float_u 0
f_double_15_1_u 0.0
f_float_3_1_u 0.0
set @value= "1e+1111111111a";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
Warnings:
......@@ -228,16 +192,6 @@ Warning 1264 Out of range value for column 'f_double_15_1_u' at row 1
Warning 1264 Out of range value for column 'f_float_3_1_u' at row 1
Warning 1264 Out of range value for column 'f_float_3_1_u' at row 1
select * from t1 where number =last_insert_id();
number 4
original_value 1e+1111111111a
f_double 1.7976931348623157e308
f_float 3.40282e38
f_double_7_2 99999.99
f_float_4_3 9.999
f_double_u 1.7976931348623157e308
f_float_u 3.40282e38
f_double_15_1_u 99999999999999.9
f_float_3_1_u 99.9
set @value= "-1e+1111111111a";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
Warnings:
......@@ -256,16 +210,6 @@ Warning 1264 Out of range value for column 'f_double_15_1_u' at row 1
Warning 1264 Out of range value for column 'f_float_3_1_u' at row 1
Warning 1264 Out of range value for column 'f_float_3_1_u' at row 1
select * from t1 where number =last_insert_id();
number 5
original_value -1e+1111111111a
f_double -1.7976931348623157e308
f_float -3.40282e38
f_double_7_2 -99999.99
f_float_4_3 -9.999
f_double_u -1.7976931348623157e308
f_float_u -3.40282e38
f_double_15_1_u -99999999999999.9
f_float_3_1_u -99.9
set @value= 1e+1111111111;
ERROR 22007: Illegal double '1e+1111111111' value found during parsing
set @value= -1e+1111111111;
......@@ -280,16 +224,6 @@ Warning 1264 Out of range value for column 'f_float_u' at row 1
Warning 1264 Out of range value for column 'f_double_15_1_u' at row 1
Warning 1264 Out of range value for column 'f_float_3_1_u' at row 1
select * from t1 where number =last_insert_id();
number 6
original_value 1e111
f_double 1e111
f_float 3.40282e38
f_double_7_2 99999.99
f_float_4_3 9.999
f_double_u 1e111
f_float_u 3.40282e38
f_double_15_1_u 99999999999999.9
f_float_3_1_u 99.9
set @value= -1e+111;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
Warnings:
......@@ -300,42 +234,12 @@ Warning 1264 Out of range value for column 'f_float_u' at row 1
Warning 1264 Out of range value for column 'f_double_15_1_u' at row 1
Warning 1264 Out of range value for column 'f_float_3_1_u' at row 1
select * from t1 where number =last_insert_id();
number 7
original_value -1e111
f_double -1e111
f_float -3.40282e38
f_double_7_2 -99999.99
f_float_4_3 -9.999
f_double_u -1e111
f_float_u -3.40282e38
f_double_15_1_u -99999999999999.9
f_float_3_1_u -99.9
set @value= 1;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
select * from t1 where number =last_insert_id();
number 8
original_value 1
f_double 1
f_float 1
f_double_7_2 1.00
f_float_4_3 1.000
f_double_u 1
f_float_u 1
f_double_15_1_u 1.0
f_float_3_1_u 1.0
set @value= -1;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
select * from t1 where number =last_insert_id();
number 9
original_value -1
f_double -1
f_float -1
f_double_7_2 -1.00
f_float_4_3 -1.000
f_double_u -1
f_float_u -1
f_double_15_1_u -1.0
f_float_3_1_u -1.0
drop table t1;
#
# Test automatic result buffering with INSERT INTO t1 ... SELECT ... FROM t1
......@@ -349,7 +253,7 @@ count(*)
insert into t2 select t1.* from t1, t2 t, t3 where t1.id1 = t.id2 and t.id2 = t3.id3;
select count(*) from t2;
count(*)
25500
500
drop table t1,t2,t3;
#
# Test different cases of duplicate fields
......@@ -390,14 +294,6 @@ Warning 1062 Duplicate entry '1' for key 'PRIMARY'
select row_count();
row_count()
-1
replace into t1 values (1, 11);
select row_count();
row_count()
2
replace into t1 values (4, 4);
select row_count();
row_count()
1
insert into t1 values (2, 2) on duplicate key update data= data + 10;
select row_count();
row_count()
......@@ -614,7 +510,8 @@ INSERT IGNORE t1 (a, a) SELECT 1,1 UNION SELECT 2,2;
ERROR 42000: Column 'a' specified twice
DROP TABLE t1;
#
# ASSERTION `TRANSL->ITEM->FIXED' FAILED IN SELECT_LEX::DELETE_UNUSED_MERGED_COLUMN
# ASSERTION `TRANSL->ITEM->FIXED' FAILED
# IN SELECT_LEX::DELETE_UNUSED_MERGED_COLUMN
#
CREATE TABLE t1 ( pk INT, PRIMARY KEY (pk))engine=tianmu;
CREATE TABLE t2 LIKE t1;
......
#
# Problem with INSERT ... SELECT
#
drop table if exists t1,t2,t3;
SET sql_mode = 'NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER';
create table t1 (bandID MEDIUMINT NOT NULL PRIMARY KEY, payoutID SMALLINT NOT NULL);
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
create table t2 (payoutID SMALLINT NOT NULL PRIMARY KEY);
insert into t2 (payoutID) SELECT DISTINCT payoutID FROM t1;
insert into t2 (payoutID) SELECT payoutID+10 FROM t1;
ERROR 23000: Duplicate entry '16' for key 'PRIMARY'
insert ignore into t2 (payoutID) SELECT payoutID+10 FROM t1;
Warnings:
Warning 1062 Duplicate entry '16' for key 'PRIMARY'
Warning 1062 Duplicate entry '22' for key 'PRIMARY'
select * from t2;
payoutID
6
4
9
10
1
12
16
14
19
20
11
22
drop table t1,t2;
#
# Test of insert ... select from same table
#
create table t1 (a int not null);
create table t2 (a int not null);
insert into t1 values (1);
insert into t1 values (a+2);
insert into t1 values (a+3);
insert into t1 values (4),(a+5);
insert into t1 select * from t1;
select * from t1;
a
1
1
2
2
3
3
4
4
5
5
insert into t1 select * from t1 as t2;
select * from t1;
a
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4
5
5
5
5
insert into t2 select * from t1 as t2;
select * from t1;
a
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4
5
5
5
5
insert into t1 select t2.a from t1,t2;
select * from t1;
a
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
insert into t1 select * from t1,t1;
ERROR 42000: Not unique table/alias: 't1'
drop table t1,t2;
#
# Item_func_isnull::update_used_tables() did not update
# const_item_cache
create table t1(f1 varchar(5) key);
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
select * from t1;
f1
2000
2001
2002
drop table t1;
#
# values() fails with 'ambiguous' or returns NULL
# with ON DUPLICATE and SELECT
create table t1(x int, y int);
create table t2(x int, z int);
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(x);
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(z);
ERROR 42S22: Unknown column 'z' in 'field list'
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x);
ERROR 42S22: Unknown column 't2.x' in 'field list'
drop table t1,t2;
#
# INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big tables
#
CREATE TABLE t1 (a int PRIMARY KEY);
INSERT INTO t1 values (1), (2);
flush status;
INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1;
show status like 'Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 1
DROP TABLE t1;
#
# INSERT INTO SELECT inserts values even if
# SELECT statement itself returns empty
#
CREATE TABLE t1 (
f1 int(10) NOT NULL auto_increment PRIMARY KEY,
f2 varchar(100) NOT NULL default ''
);
CREATE TABLE t2 (
f1 varchar(10) NOT NULL default '',
f2 char(3) NOT NULL default '',
PRIMARY KEY (`f1`),
KEY `k1` (`f2`, `f1`)
);
INSERT INTO t1 values(NULL, '');
INSERT INTO `t2` VALUES ('486878','WDT'),('486910','WDT');
SELECT COUNT(*) FROM t1;
COUNT(*)
1
SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;
min(t2.f1)
SELECT COUNT(*) FROM t1;
COUNT(*)
1
SELECT * FROM t1;
f1 f2
1
DROP TABLE t1, t2;
#
# INSERT ... SELECT ... JOIN results in ambiguous field list error
#
CREATE TABLE t1 (x int, y int);
CREATE TABLE t2 (z int, y int);
CREATE TABLE t3 (a int, b int);
INSERT INTO t3 (SELECT x, y FROM t1 JOIN t2 USING (y) WHERE z = 1);
DROP TABLE IF EXISTS t1,t2,t3;
#
# Column count doesn't match value count at row x
#
CREATE DATABASE bug21774_1;
CREATE DATABASE bug21774_2;
CREATE TABLE bug21774_1.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
CREATE TABLE bug21774_2.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
CREATE TABLE bug21774_1.t2(id VARCHAR(10) NOT NULL,label VARCHAR(255));
INSERT INTO bug21774_2.t1 SELECT t1.* FROM bug21774_1.t1;
use bug21774_1;
INSERT INTO bug21774_2.t1 SELECT t1.* FROM t1;
DROP DATABASE bug21774_1;
DROP DATABASE bug21774_2;
USE test;
#
# wrong result, when INSERT t1 SELECT ... FROM t1 ON DUPLICATE
#
CREATE TABLE t1 (f1 INT, f2 INT );
CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT);
INSERT INTO t1 VALUES (1,1),(2,2),(10,10);
INSERT INTO t2 (f1, f2) SELECT f1, f2 FROM t1;
INSERT INTO t2 (f1, f2)
SELECT f1, f1 FROM t2 src WHERE f1 < 2
ON DUPLICATE KEY UPDATE f1 = 100 + src.f1;
SELECT * FROM t2;
f1 f2
101 1
2 2
10 10
DROP TABLE t1, t2;
#
# Assertion fail on duplicate key
# error in 'INSERT ... SELECT' statements
#
CREATE TABLE t1 ( a INT KEY, b INT );
INSERT INTO t1 VALUES ( 0, 1 );
INSERT INTO t1 ( b ) SELECT MAX( b ) FROM t1 WHERE b = 2;
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
DROP TABLE t1;
#
#incorrect pushing of LIMIT into
# the temporary table ignoring ORDER BY clause
#
CREATE TABLE t1 (
id INT AUTO_INCREMENT PRIMARY KEY,
prev_id INT,
join_id INT DEFAULT 0);
INSERT INTO t1 (prev_id) VALUES (NULL), (1), (2);
SELECT * FROM t1;
id prev_id join_id
1 NULL 0
2 1 0
3 2 0
CREATE TABLE t2 (join_id INT);
INSERT INTO t2 (join_id) VALUES (0);
INSERT INTO t1 (prev_id) SELECT id
FROM t2 LEFT JOIN t1 ON t1.join_id = t2.join_id
ORDER BY id DESC LIMIT 1;
SELECT * FROM t1;
id prev_id join_id
1 NULL 0
2 1 0
3 2 0
4 3 0
DROP TABLE t1,t2;
#
#DASH '-' IS NOT RECOGNIZED IN CHARSET ARMSCII8 ON SELECT WHERE QUERY
#
CREATE TABLE t1 (
id INT AUTO_INCREMENT PRIMARY KEY,
a VARCHAR(100) CHARACTER SET ARMSCII8
);
INSERT INTO t1 (a) VALUES('abc-def');
INSERT INTO t1 (a) VALUES(x'616263AC646566');
INSERT INTO t1 (a) VALUES('\'(),-.');
INSERT INTO t1 (a) VALUES(x'FFA5A4ABACA9');
SELECT *, HEX(a) FROM t1;
id a HEX(a)
1 abc-def 6162632D646566
2 abc-def 616263AC646566
3 '(),-. 2728292C2D2E
4 '(),-. FFA5A4ABACA9
SELECT *, HEX(a) FROM t1 WHERE a = 'abc-def';
id a HEX(a)
1 abc-def 6162632D646566
SELECT *, HEX(a) FROM t1 WHERE a = '\'(),-.';
id a HEX(a)
3 '(),-. 2728292C2D2E
DROP TABLE t1;
#
#duplicate key update
#
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
drop table t1;
#
# incorrect behavior with INSERT ... ON DUPL KEY UPDATE and VALUES
#
CREATE TABLE t1
(
a BIGINT,
b BIGINT,
PRIMARY KEY (a)
);
INSERT INTO t1 VALUES (45, 1) ON DUPLICATE KEY UPDATE b =
IF(VALUES(b) > t1.b, VALUES(b), t1.b);
SELECT * FROM t1;
a b
45 1
INSERT INTO t1 VALUES (45, 2) ON DUPLICATE KEY UPDATE b =
IF(VALUES(b) > t1.b, VALUES(b), t1.b);
SELECT * FROM t1;
a b
45 2
INSERT INTO t1 VALUES (45, 1) ON DUPLICATE KEY UPDATE b =
IF(VALUES(b) > t1.b, VALUES(b), t1.b);
SELECT * FROM t1;
a b
45 2
DROP TABLE t1;
#
# Deficiencies in INSERT ... SELECT ... field name resolving.
#
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
INSERT INTO t1 SELECT 1, j;
ERROR 42S22: Unknown column 'j' in 'field list'
DROP TABLE t1;
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
CREATE TABLE t2 (a INT, b INT);
CREATE TABLE t3 (a INT, c INT);
INSERT INTO t1 SELECT 1, a FROM t2 NATURAL JOIN t3
ON DUPLICATE KEY UPDATE j= a;
DROP TABLE t1,t2,t3;
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
CREATE TABLE t2 (a INT);
INSERT INTO t1 VALUES (1, 1);
INSERT INTO t2 VALUES (1), (3);
INSERT INTO t1 SELECT 1, COUNT(*) FROM t2 ON DUPLICATE KEY UPDATE j= a;
ERROR 42S22: Unknown column 'a' in 'field list'
DROP TABLE t1,t2;
#
# Missing default value isn't noticed in insert ... on duplicate key update
#
SET SQL_MODE = 'TRADITIONAL';
CREATE TABLE t1 (a INT PRIMARY KEY, b INT NOT NULL);
INSERT INTO t1 (a) VALUES (1);
ERROR HY000: Field 'b' doesn't have a default value
INSERT INTO t1 (a) VALUES (1) ON DUPLICATE KEY UPDATE a = b;
ERROR HY000: Field 'b' doesn't have a default value
INSERT INTO t1 (a) VALUES (1) ON DUPLICATE KEY UPDATE b = b;
ERROR HY000: Field 'b' doesn't have a default value
SELECT * FROM t1;
a b
DROP TABLE t1;
#
# INSERT .. ON DUPLICATE was silently
# updating rows when it shouldn't.
#
create table t1(f1 int primary key,
f2 timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP);
insert into t1(f1) values(1);
select @stamp1:=f2 from t1;
@stamp1:=f2
#
insert into t1(f1) values(1) on duplicate key update f1=1;
select @stamp2:=f2 from t1;
@stamp2:=f2
#
select if( @stamp1 = @stamp2, "correct", "wrong");
if( @stamp1 = @stamp2, "correct", "wrong")
correct
drop table t1;
#
# update...set....where
#
CREATE TABLE t_latin1(
a CHAR(20) CHARACTER SET latin1,
b VARCHAR(20) CHARACTER SET latin1,
c TEXT(20) CHARACTER SET latin1
)engine=tianmu;
CREATE TABLE t_gb2312(
a CHAR(20) CHARACTER SET gb2312,
b VARCHAR(20) CHARACTER SET gb2312,
c TEXT(20) CHARACTER SET gb2312
)engine=tianmu;
CREATE TABLE t_utf8(
a CHAR(20) CHARACTER SET utf8,
b VARCHAR(20) CHARACTER SET utf8,
c TEXT(20) CHARACTER SET utf8
)engine=tianmu;
SET SQL_MODE="STRICT_TRANS_TABLES";
Warnings:
Warning 3135 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
INSERT INTO t_latin1 values(x'f242', x'f242', x'f242');
UPDATE t_latin1 SET a=x'f343' where a=x'f242';
INSERT INTO t_gb2312 values(x'e5ac', x'e5ac', x'e5ac');
UPDATE t_gb2312 SET a=x'e6af' where a=x'e5ac';
INSERT INTO t_utf8 values(x'e4b8ad', x'e4b8ad', x'e4b8ad');
INSERT INTO t_utf8 values(x'f4b8ad', x'f4b8ad', x'f4b8ad');
ERROR HY000: Incorrect string value: '\xF4\xB8\xAD' for column 'a' at row 1
UPDATE t_utf8 SET a=x'e69687' where a=x'e4b8ad';
UPDATE t_utf8 SET a=x'f69687' where a=x'e69687';
select * from t_utf8;
a b c
? ? ?
#
# test of updating of keys
#
drop table if exists t1,t2;
create table t1 (a int auto_increment , primary key (a))engine=tianmu;
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=1 and a=2;
update t1 set a=b+100 where a=1 and a=2;
ERROR 42S22: Unknown column 'b' in 'field list'
update t1 set a=b+100 where c=1 and a=2;
ERROR 42S22: Unknown column 'c' in 'where clause'
update t1 set d=a+100 where a=1;
ERROR 42S22: Unknown column 'd' in 'field list'
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) NOT NULL,
shows int(10) DEFAULT '0' NOT NULL,
ishows int(10) DEFAULT '0' NOT NULL,
ushows int(10) DEFAULT '0' NOT NULL,
clicks int(10) DEFAULT '0' NOT NULL,
iclicks int(10) DEFAULT '0' NOT NULL,
uclicks int(10) 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=1 AND ts>="2000-09-28 00:00:00";
select place_id,shows from t1;
place_id shows
1 1
drop table t1;
#
# Test bug with update reported by Jan Legenhausen
#
CREATE TABLE t1 (
lfdnr int(10) NOT NULL default '0',
ticket int(10) 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) NOT NULL default '0',
tstamp timestamp NOT NULL,
status int(3) NOT NULL default '0',
type varchar(15) NOT NULL default '',
assignment int(10) NOT NULL default '0',
fupcount int(4) NOT NULL default '0',
parent int(10) NOT NULL default '0',
activity int(10) NOT NULL default '0',
priority tinyint(1) 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=tianmu;
INSERT INTO t1 VALUES (773,773,'','','',980257344,20010318180652,0,'Open',10,0,0,0,1,'','','','','');
update t1 set status=1 where type='Open';
select status from t1;
status
1
drop table t1;
#
# Test with limit (Bug #393)
#
CREATE TABLE t1 (
`id_param` smallint(3) 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=tianmu;
INSERT INTO t1 (id_param,nom_option,valid) VALUES (185,'600x1200',1);
UPDATE t1 SET nom_option='test' WHERE id_param=185 AND nom_option='600x1200' AND valid=1 LIMIT 1;
select * from t1;
id_param nom_option valid
185 test 1
drop table t1;
#
# update..left join...set
#
create table t1 (c1 int, c2 char(6), c3 int)engine=tianmu;
create table t2 (c1 int, c2 char(6))engine=tianmu;
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;
select * from t1;
c1 c2 c3
1 t1c2-1 10
2 t1c2-2 20
select * from t2;
c1 c2
drop table t1, t2;
#
# update...set..where
#
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 test
drop table t1;
#
# a problem with update and partial key part
#
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
0 2
drop table t1;
#
# Update with subquery with ref built with a key from the updated table crashes server
#
create table t1(f1 int, f2 int);
create table t2(f3 int, f4 int);
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
1 1
2 2
drop table t1,t2;
#
# sometimes server accepts sum func in update/delete where condition
#
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;
#
# select datefield is null not updated
#
create table t1 (f1 date not null) engine=tianmu;
insert into t1 values('2000-01-01'),('2001-01-01');
update t1 set f1='2002-02-02' where f1 is null;
select * from t1;
f1
2000-01-01
2001-01-01
drop table t1;
#
# Updating field named like '*name'
#
create table t1(f1 int, `*f2` int)engine=tianmu;
insert into t1 values (1,1);
update t1 set `*f2`=1;
select * from t1;
f1 *f2
1 1
drop table t1;
#
#INSERT INTO ... on unique constraint with data
#
CREATE TABLE t1 (
a INT(11),
quux decimal(17, 10),
UNIQUE KEY bar (a),
KEY quux (quux)
)engine=tianmu;
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
1 1.0000000000
2 0.1000000000
3 NULL
DROP TABLE t1;
#
#UPDATE ON VARCHAR AND TEXT COLUMNS
#
CREATE TABLE t1 (a VARCHAR(50), b TEXT, c CHAR(50)) ENGINE=tianmu;
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;
#
#UPDATE DOES NOT USE INDEX
#
CREATE TABLE t1(
id INTEGER NOT NULL AUTO_INCREMENT,
token VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id),
KEY token (token)
)engine=tianmu;
INSERT INTO t1 VALUES (1, "abc"), (2, "def");
SELECT * FROM t1;
id token
1 abc
2 def
UPDATE t1 SET token = X'ad';
SELECT * FROM t1;
id token
1
2
UPDATE t1 SET token = NULL WHERE token = X'ad';
SELECT * FROM t1;
id token
1
2
DROP TABLE t1;
--source include/have_tianmu.inc
--echo #
--echo # Test of alter table
--echo #
create table t1 (bandID MEDIUMINT NOT NULL PRIMARY KEY, payoutID SMALLINT NOT NULL);
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
alter table t1 add column new_col int, order by payoutid,bandid;
select * from t1;
alter table t1 order by bandid,payoutid;
select * from t1;
drop table t1;
--echo #
--echo # Test of ALTER TABLE ... ORDER BY
--echo #
create table t1 (n int);
insert into t1 values(9),(3),(12),(10);
alter table t1 order by n;
select * from t1;
drop table t1;
--echo #
--echo # Drop and add an auto_increment column
--echo #
create table t1 (i int not null auto_increment primary key);
insert into t1 values (null),(null),(null),(null);
#alter table t1 drop i,add i int unsigned not null auto_increment, drop primary key, add primary key (i);
select * from t1;
drop table t1;
--echo #
--echo # 'alter table t1 rename mysqltest.t1' silently drops mysqltest.t1
--echo # if it exists
--echo #
create table t1 (name char(15));
insert into t1 (name) values ("current");
create database mysqltest;
create table mysqltest.t1 (name char(15));
insert into mysqltest.t1 (name) values ("mysqltest");
select * from t1;
select * from mysqltest.t1;
--error ER_TABLE_EXISTS_ERROR
alter table t1 rename mysqltest.t1;
select * from t1;
select * from mysqltest.t1;
drop table t1;
drop database mysqltest;
--echo #
--echo # ALTER TABLE ... ENABLE/DISABLE KEYS
--echo #
create table t1 (n1 int not null, n2 int, n3 int, n4 float,
unique(n1),
key (n1, n2, n3, n4),
key (n2, n3, n4, n1),
key (n3, n4, n1, n2),
key (n4, n1, n2, n3))engine=tianmu;
alter table t1 disable keys;
show keys from t1;
insert into t1 values(RAND()*100,RAND()*100,RAND()*10,RAND()*10);
alter table t1 enable keys;
show keys from t1;
drop table t1;
--echo #
--echo # Alter table and rename
--echo #
create table t1 (i int not null auto_increment primary key)engine=tianmu;
alter table t1 rename t2;
show columns from t2;
drop table t2;
--echo #
--echo # check for valid table names
--echo #
create table t1 (a int);
--error ER_WRONG_TABLE_NAME
alter table t1 rename to ``;
--error ER_WRONG_TABLE_NAME
rename table t1 to ``;
drop table t1;
--source include/have_tianmu.inc
--echo #
--echo # DELETE FROM TABLE_NAME
--echo #
use test;
CREATE TABLE `column_type_test` (
`c_tinyint` tinyint(4) DEFAULT NULL COMMENT 'tinyint',
`c_smallint` smallint(6) DEFAULT NULL COMMENT 'smallint',
`c_mediumint` mediumint(9) DEFAULT NULL COMMENT 'mediumint',
`c_int` int(11) DEFAULT NULL COMMENT 'int',
`c_bigint` bigint(20) DEFAULT NULL COMMENT 'bigint',
`c_float` float DEFAULT NULL COMMENT 'float',
`c_double` double DEFAULT NULL COMMENT 'double',
`c_decimal` decimal(10,5) DEFAULT NULL COMMENT 'decimal',
`c_date` date DEFAULT NULL COMMENT 'date',
`c_datetime` datetime DEFAULT NULL COMMENT 'datetime',
`c_timestamp` timestamp NULL DEFAULT NULL COMMENT 'timestamp',
`c_time` time DEFAULT NULL COMMENT 'time',
`c_char` char(10) DEFAULT NULL COMMENT 'char',
`c_varchar` varchar(10) DEFAULT NULL COMMENT 'varchar',
`c_blob` blob COMMENT 'blob',
`c_text` text COMMENT 'text',
`c_longblob` longblob COMMENT 'longblob'
) ENGINE=TIANMU;
--echo #
--echo # DELETE FROM TABLE_NAME for Large amount of data
--echo #
load data infile '../../std_data/tianmu/bigdata4load' into table column_type_test fields terminated by '|';
select count(*) from column_type_test;
select max(c_int) from column_type_test;
select min(c_int) from column_type_test;
select avg(c_int) from column_type_test;
select sum(c_int) from column_type_test;
delete from column_type_test;
show create table column_type_test;
select count(*) from column_type_test;
select max(c_int) from column_type_test;
select min(c_int) from column_type_test;
select avg(c_int) from column_type_test;
select sum(c_int) from column_type_test;
--echo #
--echo # DELETE FROM TABLE_NAME for select/insert/Aggregate query
--echo #
insert into column_type_test(c_tinyint,c_smallint,c_mediumint,c_int,c_bigint,c_float,c_double,c_decimal,c_date,c_datetime,c_timestamp,c_time,c_char,c_varchar,c_text)
values(105,105,105,105,105,5.2,10.88,105.083,'2016-02-25','2016-02-25 10:20:01','2016-02-25 05:20:01','10:20:01','stoneatom','hello','bcdefghijklmn');
select * from column_type_test;
select count(*) from column_type_test;
select max(c_int) from column_type_test;
select min(c_int) from column_type_test;
select avg(c_int) from column_type_test;
select sum(c_int) from column_type_test;
delete from column_type_test;
delete from column_type_test;
select * from column_type_test;
select count(*) from column_type_test;
select max(c_int) from column_type_test;
select min(c_int) from column_type_test;
select avg(c_int) from column_type_test;
select sum(c_int) from column_type_test;
drop table column_type_test;
--echo #
--echo # DELETE FROM TABLE_NAME for primary key
--echo #
CREATE TABLE t1(c1 int,c2 varchar(255),primary key(c1))ENGINE=TIANMU;
insert into t1 values(1,'test1');
insert into t1 values(2,'test2');
delete from t1;
select * from t1;
insert into t1 values(1,'test1');
insert into t1 values(2,'test2');
select * from t1;
delete from t1;
drop table t1;
--enable_warnings
CREATE TABLE t1 (a tinyint(3), b tinyint(5));
INSERT INTO t1 VALUES (1,1);
INSERT LOW_PRIORITY INTO t1 VALUES (1,2);
INSERT INTO t1 VALUES (1,3);
DELETE from t1 where a=1 limit 1;
DELETE LOW_PRIORITY from t1 where a=1;
INSERT INTO t1 VALUES (1,1);
DELETE from t1;
LOCK TABLE t1 write;
INSERT INTO t1 VALUES (1,2);
DELETE from t1;
UNLOCK TABLES;
INSERT INTO t1 VALUES (1,2);
SET AUTOCOMMIT=0;
DELETE from t1;
SET AUTOCOMMIT=1;
drop table t1;
--echo #
--echo # Adds some test cases for unicode. such as insert unicode chars, in values, table name, or etc.
--echo #
CREATE TABLE `abc def` (i int)engine=tianmu;
INSERT INTO `abc def` VALUES (1);
delete from `abc def`;
drop table `abc def`;
CREATE TABLE t1 (`abc def1` tinyint(3), `abc def2` tinyint(5));
INSERT INTO t1 VALUES (1,1);
DELETE from t1;
LOCK TABLE t1 write;
INSERT INTO t1 VALUES (1,2);
DELETE from t1;
UNLOCK TABLES;
INSERT INTO t1 VALUES (1,2);
SET AUTOCOMMIT=0;
DELETE from t1;
SET AUTOCOMMIT=1;
drop table t1;
\ No newline at end of file
......@@ -59,7 +59,8 @@ drop table t1;
--echo # Test of duplicate key values with packed keys
--echo #
create table t1 (id int not null auto_increment primary key, username varchar(32) not null, unique (username));
create table t1 (id int not null auto_increment primary key, username varchar(32) not null,
unique (username));
insert into t1 values (0,"mysql");
insert into t1 values (0,"mysql ab");
insert into t1 values (0,"mysql a");
......@@ -71,7 +72,10 @@ drop table t1;
--echo # Test insert syntax
--echo #
create table t1 (a int not null auto_increment, primary key (a), t timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, c char(10) default "hello", i int)engine=tianmu;
create table t1 (a int not null auto_increment,
primary key (a),
t timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
c char(10) default "hello", i int)engine=tianmu;
insert into t1 values (default,default,default,default), (default,default,default,default), (4,0,"a",5),(default,default,default,default);
select a,t>0,c,i from t1;
......@@ -84,17 +88,6 @@ insert into t1 set a=default,t=default,c=default,i=default;
select a,t>0,c,i from t1;
drop table t1;
--echo #
--echo # Test problem with bulk insert and auto_increment on second part keys
--echo #
create table t1 (sid char(20), id int(2) NOT NULL auto_increment, key(sid, id)) engine=myisam;
insert into t1 values ('skr',NULL),('skr',NULL),('test',NULL);
select * from t1;
insert into t1 values ('rts',NULL),('rts',NULL),('test',NULL);
select * from t1;
drop table t1;
--echo #
--echo #Test of behaviour with INSERT VALUES (NULL)
--echo #
......@@ -127,7 +120,17 @@ use test;
# PS gives sligthly different numbers for max-float/max-double
--disable_ps_protocol
create table t1(number int auto_increment primary key, original_value varchar(50), f_double double, f_float float, f_double_7_2 double(7,2), f_float_4_3 float (4,3), f_double_u double, f_float_u float, f_double_15_1_u double(15,1), f_float_3_1_u float (3,1));
create table t1(
number int auto_increment primary key,
original_value varchar(50),
f_double double,
f_float float,
f_double_7_2 double(7,2),
f_float_4_3 float (4,3),
f_double_u double,
f_float_u float,
f_double_15_1_u double(15,1),
f_float_3_1_u float (3,1));
set @value= "aa";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
......@@ -244,11 +247,6 @@ insert ignore into t1 values (1, 1);
#insert ignore gives warnings which resets the row_count.
#'select row_count()' will not show the row_count from above statement.
select row_count();
# Reports that 2 rows are affected (1 deleted + 1 inserted)
replace into t1 values (1, 11);
select row_count();
replace into t1 values (4, 4);
select row_count();
# Reports that 2 rows are affected. This conforms to documentation.
# (Useful for differentiating inserts from updates).
insert into t1 values (2, 2) on duplicate key update data= data + 10;
......@@ -260,6 +258,7 @@ drop table t1;
--echo #
--echo # ON DUPLICATE KEY clause allows fields not from the insert table
--echo #
create table t1 (f1 int unique, f2 int);
create table t2 (f3 int, f4 int);
create view v1 as select * from t1, t2 where f1= f3;
......@@ -421,7 +420,8 @@ INSERT IGNORE t1 (a, a) SELECT 1,1 UNION SELECT 2,2;
DROP TABLE t1;
--echo #
--echo # ASSERTION `TRANSL->ITEM->FIXED' FAILED IN SELECT_LEX::DELETE_UNUSED_MERGED_COLUMN
--echo # ASSERTION `TRANSL->ITEM->FIXED' FAILED
--echo # IN SELECT_LEX::DELETE_UNUSED_MERGED_COLUMN
--echo #
CREATE TABLE t1 ( pk INT, PRIMARY KEY (pk))engine=tianmu;
......
--source include/no_valgrind_without_big.inc
--echo #
--echo # Problem with INSERT ... SELECT
--echo #
--disable_warnings
drop table if exists t1,t2,t3;
--enable_warnings
SET sql_mode = 'NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER';
create table t1 (bandID MEDIUMINT NOT NULL PRIMARY KEY, payoutID SMALLINT NOT NULL);
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
create table t2 (payoutID SMALLINT NOT NULL PRIMARY KEY);
insert into t2 (payoutID) SELECT DISTINCT payoutID FROM t1;
--error ER_DUP_ENTRY
insert into t2 (payoutID) SELECT payoutID+10 FROM t1;
insert ignore into t2 (payoutID) SELECT payoutID+10 FROM t1;
select * from t2;
drop table t1,t2;
--echo #
--echo # Test of insert ... select from same table
--echo #
create table t1 (a int not null);
create table t2 (a int not null);
insert into t1 values (1);
insert into t1 values (a+2);
insert into t1 values (a+3);
insert into t1 values (4),(a+5);
insert into t1 select * from t1;
--sorted_result
select * from t1;
insert into t1 select * from t1 as t2;
--sorted_result
select * from t1;
insert into t2 select * from t1 as t2;
--sorted_result
select * from t1;
insert into t1 select t2.a from t1,t2;
--sorted_result
select * from t1;
--error 1066
insert into t1 select * from t1,t1;
drop table t1,t2;
--echo #
--echo # Item_func_isnull::update_used_tables() did not update
--echo # const_item_cache
create table t1(f1 varchar(5) key);
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
select * from t1;
drop table t1;
--echo #
--echo # values() fails with 'ambiguous' or returns NULL
--echo # with ON DUPLICATE and SELECT
create table t1(x int, y int);
create table t2(x int, z int);
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(x);
--error 1054
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(z);
--error 1054
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x);
drop table t1,t2;
--echo #
--echo # INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big tables
--echo #
#Note: not an exsaustive test : just a check of the code path.
CREATE TABLE t1 (a int PRIMARY KEY);
INSERT INTO t1 values (1), (2);
flush status;
INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1;
show status like 'Handler_read%';
DROP TABLE t1;
--echo #
--echo # INSERT INTO SELECT inserts values even if
--echo # SELECT statement itself returns empty
--echo #
CREATE TABLE t1 (
f1 int(10) NOT NULL auto_increment PRIMARY KEY,
f2 varchar(100) NOT NULL default ''
);
CREATE TABLE t2 (
f1 varchar(10) NOT NULL default '',
f2 char(3) NOT NULL default '',
PRIMARY KEY (`f1`),
KEY `k1` (`f2`, `f1`)
);
INSERT INTO t1 values(NULL, '');
INSERT INTO `t2` VALUES ('486878','WDT'),('486910','WDT');
SELECT COUNT(*) FROM t1;
SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;
SELECT COUNT(*) FROM t1;
SELECT * FROM t1;
DROP TABLE t1, t2;
--echo #
--echo # INSERT ... SELECT ... JOIN results in ambiguous field list error
--echo #
CREATE TABLE t1 (x int, y int);
CREATE TABLE t2 (z int, y int);
CREATE TABLE t3 (a int, b int);
INSERT INTO t3 (SELECT x, y FROM t1 JOIN t2 USING (y) WHERE z = 1);
DROP TABLE IF EXISTS t1,t2,t3;
--echo #
--echo # Column count doesn't match value count at row x
--echo #
CREATE DATABASE bug21774_1;
CREATE DATABASE bug21774_2;
CREATE TABLE bug21774_1.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
CREATE TABLE bug21774_2.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
CREATE TABLE bug21774_1.t2(id VARCHAR(10) NOT NULL,label VARCHAR(255));
INSERT INTO bug21774_2.t1 SELECT t1.* FROM bug21774_1.t1;
use bug21774_1;
INSERT INTO bug21774_2.t1 SELECT t1.* FROM t1;
DROP DATABASE bug21774_1;
DROP DATABASE bug21774_2;
USE test;
--echo #
--echo # wrong result, when INSERT t1 SELECT ... FROM t1 ON DUPLICATE
--echo #
CREATE TABLE t1 (f1 INT, f2 INT );
CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT);
INSERT INTO t1 VALUES (1,1),(2,2),(10,10);
INSERT INTO t2 (f1, f2) SELECT f1, f2 FROM t1;
INSERT INTO t2 (f1, f2)
SELECT f1, f1 FROM t2 src WHERE f1 < 2
ON DUPLICATE KEY UPDATE f1 = 100 + src.f1;
SELECT * FROM t2;
DROP TABLE t1, t2;
--echo #
--echo # Assertion fail on duplicate key
--echo # error in 'INSERT ... SELECT' statements
--echo #
CREATE TABLE t1 ( a INT KEY, b INT );
INSERT INTO t1 VALUES ( 0, 1 );
--error ER_DUP_ENTRY
INSERT INTO t1 ( b ) SELECT MAX( b ) FROM t1 WHERE b = 2;
DROP TABLE t1;
--echo #
--echo #incorrect pushing of LIMIT into
--echo # the temporary table ignoring ORDER BY clause
--echo #
CREATE TABLE t1 (
id INT AUTO_INCREMENT PRIMARY KEY,
prev_id INT,
join_id INT DEFAULT 0);
INSERT INTO t1 (prev_id) VALUES (NULL), (1), (2);
SELECT * FROM t1;
CREATE TABLE t2 (join_id INT);
INSERT INTO t2 (join_id) VALUES (0);
INSERT INTO t1 (prev_id) SELECT id
FROM t2 LEFT JOIN t1 ON t1.join_id = t2.join_id
ORDER BY id DESC LIMIT 1;
SELECT * FROM t1;
DROP TABLE t1,t2;
--echo #
--echo #DASH '-' IS NOT RECOGNIZED IN CHARSET ARMSCII8 ON SELECT WHERE QUERY
--echo #
CREATE TABLE t1 (
id INT AUTO_INCREMENT PRIMARY KEY,
a VARCHAR(100) CHARACTER SET ARMSCII8
);
INSERT INTO t1 (a) VALUES('abc-def');
INSERT INTO t1 (a) VALUES(x'616263AC646566');
INSERT INTO t1 (a) VALUES('\'(),-.');
INSERT INTO t1 (a) VALUES(x'FFA5A4ABACA9');
SELECT *, HEX(a) FROM t1;
SELECT *, HEX(a) FROM t1 WHERE a = 'abc-def';
SELECT *, HEX(a) FROM t1 WHERE a = '\'(),-.';
DROP TABLE t1;
--source include/have_tianmu.inc
--echo #
--echo #duplicate key update
--echo #
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;
--enable_info
insert into t1 values(4,14),(5,15),(6,16),(7,17),(8,18)
on duplicate key update b=b+10;
--disable_info
select * from t1;
drop table t1;
--echo #
--echo # incorrect behavior with INSERT ... ON DUPL KEY UPDATE and VALUES
--echo #
CREATE TABLE t1
(
a BIGINT,
b BIGINT,
PRIMARY KEY (a)
);
INSERT INTO t1 VALUES (45, 1) ON DUPLICATE KEY UPDATE b =
IF(VALUES(b) > t1.b, VALUES(b), t1.b);
SELECT * FROM t1;
INSERT INTO t1 VALUES (45, 2) ON DUPLICATE KEY UPDATE b =
IF(VALUES(b) > t1.b, VALUES(b), t1.b);
SELECT * FROM t1;
INSERT INTO t1 VALUES (45, 1) ON DUPLICATE KEY UPDATE b =
IF(VALUES(b) > t1.b, VALUES(b), t1.b);
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Deficiencies in INSERT ... SELECT ... field name resolving.
--echo #
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
--error 1054
INSERT INTO t1 SELECT 1, j;
DROP TABLE t1;
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
CREATE TABLE t2 (a INT, b INT);
CREATE TABLE t3 (a INT, c INT);
INSERT INTO t1 SELECT 1, a FROM t2 NATURAL JOIN t3
ON DUPLICATE KEY UPDATE j= a;
DROP TABLE t1,t2,t3;
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
CREATE TABLE t2 (a INT);
INSERT INTO t1 VALUES (1, 1);
INSERT INTO t2 VALUES (1), (3);
--error 1054
INSERT INTO t1 SELECT 1, COUNT(*) FROM t2 ON DUPLICATE KEY UPDATE j= a;
DROP TABLE t1,t2;
--echo #
--echo # Missing default value isn't noticed in insert ... on duplicate key update
--echo #
SET SQL_MODE = 'TRADITIONAL';
CREATE TABLE t1 (a INT PRIMARY KEY, b INT NOT NULL);
--error ER_NO_DEFAULT_FOR_FIELD
INSERT INTO t1 (a) VALUES (1);
--error ER_NO_DEFAULT_FOR_FIELD
INSERT INTO t1 (a) VALUES (1) ON DUPLICATE KEY UPDATE a = b;
--error ER_NO_DEFAULT_FOR_FIELD
INSERT INTO t1 (a) VALUES (1) ON DUPLICATE KEY UPDATE b = b;
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # INSERT .. ON DUPLICATE was silently
--echo # updating rows when it shouldn't.
--echo #
create table t1(f1 int primary key,
f2 timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP);
insert into t1(f1) values(1);
--replace_column 1 #
select @stamp1:=f2 from t1;
--sleep 2
insert into t1(f1) values(1) on duplicate key update f1=1;
--replace_column 1 #
select @stamp2:=f2 from t1;
select if( @stamp1 = @stamp2, "correct", "wrong");
drop table t1;
--echo #
--echo # update...set....where
--echo #
CREATE TABLE t_latin1(
a CHAR(20) CHARACTER SET latin1,
b VARCHAR(20) CHARACTER SET latin1,
c TEXT(20) CHARACTER SET latin1
)engine=tianmu;
CREATE TABLE t_gb2312(
a CHAR(20) CHARACTER SET gb2312,
b VARCHAR(20) CHARACTER SET gb2312,
c TEXT(20) CHARACTER SET gb2312
)engine=tianmu;
CREATE TABLE t_utf8(
a CHAR(20) CHARACTER SET utf8,
b VARCHAR(20) CHARACTER SET utf8,
c TEXT(20) CHARACTER SET utf8
)engine=tianmu;
SET SQL_MODE="STRICT_TRANS_TABLES";
INSERT INTO t_latin1 values(x'f242', x'f242', x'f242');
UPDATE t_latin1 SET a=x'f343' where a=x'f242';
INSERT INTO t_gb2312 values(x'e5ac', x'e5ac', x'e5ac');
UPDATE t_gb2312 SET a=x'e6af' where a=x'e5ac';
INSERT INTO t_utf8 values(x'e4b8ad', x'e4b8ad', x'e4b8ad');
--disable_abort_on_error
INSERT INTO t_utf8 values(x'f4b8ad', x'f4b8ad', x'f4b8ad');
--enable_abort_on_error
UPDATE t_utf8 SET a=x'e69687' where a=x'e4b8ad';
UPDATE t_utf8 SET a=x'f69687' where a=x'e69687';
select * from t_utf8;
--echo #
--echo # test of updating of keys
--echo #
--disable_warnings
drop table if exists t1,t2;
--enable_warnings
create table t1 (a int auto_increment , primary key (a))engine=tianmu;
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;
# Some strange updates to test some otherwise unused code
update t1 set a=a+100 where a=1 and a=2;
--error 1054
update t1 set a=b+100 where a=1 and a=2;
--error 1054
update t1 set a=b+100 where c=1 and a=2;
--error 1054
update t1 set d=a+100 where a=1;
select * from t1;
drop table t1;
CREATE TABLE t1
(
place_id int (10) NOT NULL,
shows int(10) DEFAULT '0' NOT NULL,
ishows int(10) DEFAULT '0' NOT NULL,
ushows int(10) DEFAULT '0' NOT NULL,
clicks int(10) DEFAULT '0' NOT NULL,
iclicks int(10) DEFAULT '0' NOT NULL,
uclicks int(10) 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=1 AND ts>="2000-09-28 00:00:00";
select place_id,shows from t1;
drop table t1;
--echo #
--echo # Test bug with update reported by Jan Legenhausen
--echo #
CREATE TABLE t1 (
lfdnr int(10) NOT NULL default '0',
ticket int(10) 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) NOT NULL default '0',
tstamp timestamp NOT NULL,
status int(3) NOT NULL default '0',
type varchar(15) NOT NULL default '',
assignment int(10) NOT NULL default '0',
fupcount int(4) NOT NULL default '0',
parent int(10) NOT NULL default '0',
activity int(10) NOT NULL default '0',
priority tinyint(1) 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=tianmu;
INSERT INTO t1 VALUES (773,773,'','','',980257344,20010318180652,0,'Open',10,0,0,0,1,'','','','','');
#alter table t1 change lfdnr lfdnr int(10) not null auto_increment;
update t1 set status=1 where type='Open';
select status from t1;
drop table t1;
--echo #
--echo # Test with limit (Bug #393)
--echo #
CREATE TABLE t1 (
`id_param` smallint(3) 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=tianmu;
INSERT INTO t1 (id_param,nom_option,valid) VALUES (185,'600x1200',1);
UPDATE t1 SET nom_option='test' WHERE id_param=185 AND nom_option='600x1200' AND valid=1 LIMIT 1;
select * from t1;
drop table t1;
--echo #
--echo # update..left join...set
--echo #
create table t1 (c1 int, c2 char(6), c3 int)engine=tianmu;
create table t2 (c1 int, c2 char(6))engine=tianmu;
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;
select * from t1;
select * from t2;
drop table t1, t2;
--echo #
--echo # update...set..where
--echo #
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;
drop table t1;
--echo #
--echo # a problem with update and partial key part
--echo #
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;
drop table t1;
--echo #
--echo # Update with subquery with ref built with a key from the updated table crashes server
--echo #
create table t1(f1 int, f2 int);
create table t2(f3 int, f4 int);
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;
drop table t1,t2;
--echo #
--echo # sometimes server accepts sum func in update/delete where condition
--echo #
create table t1(f1 int);
select DATABASE();
--error 1111
update t1 set f1=1 where count(*)=1;
select DATABASE();
--error 1111
delete from t1 where count(*)=1;
drop table t1;
--echo #
--echo # select datefield is null not updated
--echo #
create table t1 (f1 date not null) engine=tianmu;
insert into t1 values('2000-01-01'),('2001-01-01');
update t1 set f1='2002-02-02' where f1 is null;
select * from t1;
drop table t1;
--echo #
--echo # Updating field named like '*name'
--echo #
create table t1(f1 int, `*f2` int)engine=tianmu;
insert into t1 values (1,1);
update t1 set `*f2`=1;
select * from t1;
drop table t1;
--echo #
--echo #INSERT INTO ... on unique constraint with data
--echo #
CREATE TABLE t1 (
a INT(11),
quux decimal(17, 10),
UNIQUE KEY bar (a),
KEY quux (quux)
)engine=tianmu;
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;
DROP TABLE t1;
--echo #
--echo #UPDATE ON VARCHAR AND TEXT COLUMNS
--echo #
CREATE TABLE t1 (a VARCHAR(50), b TEXT, c CHAR(50)) ENGINE=tianmu;
INSERT INTO t1 (a, b, c) VALUES ('start trail', '', 'even longer string');
UPDATE t1 SET b = a, a = 'inject';
SELECT a, b FROM t1;
UPDATE t1 SET b = c, c = 'inject';
SELECT c, b FROM t1;
DROP TABLE t1;
--echo #
--echo #UPDATE DOES NOT USE INDEX
--echo #
CREATE TABLE t1(
id INTEGER NOT NULL AUTO_INCREMENT,
token VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id),
KEY token (token)
)engine=tianmu;
INSERT INTO t1 VALUES (1, "abc"), (2, "def");
SELECT * FROM t1;
UPDATE t1 SET token = X'ad';
SELECT * FROM t1;
UPDATE t1 SET token = NULL WHERE token = X'ad';
SELECT * FROM t1;
DROP TABLE t1;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册