mirror of
https://github.com/MariaDB/server.git
synced 2025-02-01 03:21:53 +01:00
568 lines
11 KiB
Text
568 lines
11 KiB
Text
drop table if exists t1, t2, t3;
|
||
create table `t1` (`id` int( 11 ) not null ,primary key ( `id` )) engine = pbxt;
|
||
insert into `t1`values ( 1 ) ;
|
||
create table `t2` (`id` int( 11 ) not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = pbxt;
|
||
insert into `t2`values ( 1 ) ;
|
||
create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = pbxt;
|
||
insert into `t3`values ( 1 ) ;
|
||
select * from t1;
|
||
id
|
||
1
|
||
select * from t2;
|
||
id
|
||
1
|
||
select * from t3;
|
||
id
|
||
1
|
||
update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
|
||
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (Constraint: `t1_id_fk`)
|
||
select * from t1;
|
||
id
|
||
1
|
||
select * from t2;
|
||
id
|
||
1
|
||
select * from t3;
|
||
id
|
||
1
|
||
delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
|
||
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (Constraint: `t1_id_fk`)
|
||
select * from t1;
|
||
id
|
||
1
|
||
select * from t2;
|
||
id
|
||
1
|
||
select * from t3;
|
||
id
|
||
1
|
||
drop table if exists t3, t2, t1;
|
||
create table t1 (id int primary key) engine = pbxt;
|
||
create table t2 (id int) engine = pbxt;
|
||
insert into t1 values ( 1 ) ;
|
||
insert into t1 values ( 2 ) ;
|
||
insert into t2 values ( 1 ) ;
|
||
insert into t2 values ( 2 ) ;
|
||
select * from t1;
|
||
id
|
||
1
|
||
2
|
||
select * from t2;
|
||
id
|
||
1
|
||
2
|
||
update t1 set t1.id=1 where t1.id=2;
|
||
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
|
||
select * from t1;
|
||
id
|
||
1
|
||
2
|
||
select * from t2;
|
||
id
|
||
1
|
||
2
|
||
update t1,t2 set t1.id=3, t2.id=3 where t1.id=2 and t2.id = t1.id;
|
||
select * from t1;
|
||
id
|
||
1
|
||
3
|
||
select * from t2;
|
||
id
|
||
1
|
||
3
|
||
update t1,t2 set t1.id=1, t2.id=1 where t1.id=3 and t2.id = t1.id;
|
||
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
|
||
select * from t1;
|
||
id
|
||
1
|
||
3
|
||
select * from t2;
|
||
id
|
||
1
|
||
3
|
||
update t1 set t1.id=1 where t1.id=3;
|
||
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
|
||
select * from t1;
|
||
id
|
||
1
|
||
3
|
||
select * from t2;
|
||
id
|
||
1
|
||
3
|
||
drop table if exists t1, t2, t3;
|
||
create table t1 (c1 int);
|
||
insert t1 values (1);
|
||
select * from t1;
|
||
c1
|
||
1
|
||
rename table t1 to t2;
|
||
create table t1 (a text character set utf8, b text character set latin1);
|
||
insert t1 values (0x4F736E616272C3BC636B, 0x4BF66C6E);
|
||
select * from t1;
|
||
a b
|
||
Osnabr<EFBFBD>ck K<>ln
|
||
test.t1: Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
|
||
select * from t1 for update;
|
||
a b
|
||
Osnabr<EFBFBD>ck K<>ln
|
||
drop table if exists t1,t3;
|
||
create table t1 (
|
||
id char(16) not null default '',
|
||
data int not null
|
||
);
|
||
insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|
|
||
create table t3 (
|
||
v char(16) not null primary key,
|
||
c int unsigned not null
|
||
)|
|
||
create function getcount(s char(16)) returns int
|
||
begin
|
||
declare x int;
|
||
select count(*) into x from t3 where v = s;
|
||
if x = 0 then
|
||
insert into t3 values (s, 1);
|
||
else
|
||
update t3 set c = c+1 where v = s;
|
||
end if;
|
||
return x;
|
||
end|
|
||
select * from t1|
|
||
id data
|
||
foo 3
|
||
bar 2
|
||
zip 5
|
||
zap 1
|
||
select * from t3|
|
||
v c
|
||
select * from t1 where data = getcount("bar")|
|
||
id data
|
||
zap 1
|
||
select * from t1|
|
||
id data
|
||
foo 3
|
||
bar 2
|
||
zip 5
|
||
zap 1
|
||
select * from t3|
|
||
v c
|
||
bar 4
|
||
drop table t1,t3|
|
||
drop function getcount;
|
||
drop tables if exists t1;
|
||
Warnings:
|
||
Note 1051 Unknown table 't1'
|
||
create table t1 (id int);
|
||
lock tables t1 write;
|
||
insert t1 values (1);
|
||
insert t1 values (2);
|
||
select id from t1;
|
||
id
|
||
1
|
||
2
|
||
unlock tables;
|
||
select id from t1;
|
||
id
|
||
1
|
||
2
|
||
DROP TABLE if exists t1;
|
||
create table t1 (id int primary key);
|
||
insert t1 values (100);
|
||
LOCK TABLES t1 WRITE;
|
||
insert t1 values (98);
|
||
insert into t1 values (99),(100);
|
||
ERROR 23000: Duplicate entry '100' for key 'PRIMARY'
|
||
select id from t1;
|
||
id
|
||
98
|
||
100
|
||
UNLOCK TABLES;
|
||
select id from t1;
|
||
id
|
||
98
|
||
100
|
||
DROP TABLE if exists t1;
|
||
create table t1 (id int primary key);
|
||
insert t1 values (100);
|
||
begin;
|
||
insert t1 values (98);
|
||
insert into t1 values (99),(100);
|
||
ERROR 23000: Duplicate entry '100' for key 'PRIMARY'
|
||
select id from t1;
|
||
id
|
||
98
|
||
99
|
||
100
|
||
rollback;
|
||
select id from t1;
|
||
id
|
||
100
|
||
DROP TABLE if exists t1;
|
||
create table t1 (id int primary key);
|
||
insert t1 values (100);
|
||
insert t1 values (98);
|
||
insert into t1 values (99),(100);
|
||
ERROR 23000: Duplicate entry '100' for key 'PRIMARY'
|
||
select id from t1;
|
||
id
|
||
98
|
||
100
|
||
DROP TABLE if exists t1, t2;
|
||
create table t1 (id int primary key);
|
||
insert t1 values (100);
|
||
create table t2 (id int primary key);
|
||
insert t2 values (100);
|
||
LOCK TABLES t1 WRITE, t2 READ;
|
||
insert t1 values (98);
|
||
select * from t1, t2 where t1.id = t2.id;
|
||
id id
|
||
100 100
|
||
insert t1 values (97);
|
||
insert into t1 values (99),(100);
|
||
ERROR 23000: Duplicate entry '100' for key 'PRIMARY'
|
||
select id from t1;
|
||
id
|
||
97
|
||
98
|
||
100
|
||
UNLOCK TABLES;
|
||
select id from t1;
|
||
id
|
||
97
|
||
98
|
||
100
|
||
DROP TABLE t1;
|
||
drop table if exists t1, t2, t3;
|
||
create table t1 (a int, b int);
|
||
insert into t1 values (1, 2), (2, 3), (3, 4);
|
||
create table t2 (a int);
|
||
insert into t2 values (10), (20), (30);
|
||
create view v1 as select a as b, a/10 as a from t2;
|
||
lock table t1 write;
|
||
alter table t1 add column c int default 100 after a;
|
||
update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a;
|
||
unlock tables;
|
||
select * from t1;
|
||
a c b
|
||
1 100 13
|
||
2 100 25
|
||
3 100 37
|
||
select * from t2;
|
||
a
|
||
10
|
||
20
|
||
30
|
||
drop view v1;
|
||
drop table t1, t2;
|
||
drop table if exists t1, t4;
|
||
create table t1 (
|
||
a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
|
||
) engine=pbxt;
|
||
insert t1 values ("a1", "a2", "b", "c", "d", "dummy");
|
||
create table t4 (
|
||
pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
|
||
) engine=pbxt;
|
||
insert into t4 (a1, a2, b, c, d, dummy) select * from t1;
|
||
create index idx12672_0 on t4 (a1);
|
||
create index idx12672_1 on t4 (a1,a2,b,c);
|
||
create index idx12672_2 on t4 (a1,a2,b);
|
||
analyze table t1;
|
||
Table Op Msg_type Msg_text
|
||
test.t1 analyze status OK
|
||
use test;
|
||
drop table if exists t1;
|
||
drop database if exists mysqltest;
|
||
create database mysqltest;
|
||
use mysqltest;
|
||
create table t1 (id int);
|
||
create trigger t1_bi before insert on t1 for each row set @a:=new.id;
|
||
insert into t1 values (101);
|
||
alter table t1 rename to test.t1, add column val int default 0;
|
||
Got one of the listed errors
|
||
drop database mysqltest;
|
||
use test;
|
||
create table t9 (id int primary key auto_increment, fk int, index (fk)) engine=pbxt;
|
||
insert into t9 (id) values (null),(null),(null),(null),(null);
|
||
update t9 set fk=69 where fk is null order by id limit 1;
|
||
SELECT * from t9;
|
||
id fk
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
1 69
|
||
drop table t9;
|
||
create table t9 (id int primary key auto_increment, fk int, index (fk)) engine=pbxt;
|
||
lock tables t9 write;
|
||
insert into t9 (id) values (null),(null),(null),(null),(null);
|
||
update t9 set fk=69 where fk is null order by id limit 1;
|
||
SELECT * from t9 order by id;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
unlock tables;
|
||
SELECT * from t9 order by id;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
drop table t9;
|
||
create table t9 (id int primary key auto_increment, fk int, index (fk)) engine=pbxt;
|
||
create procedure auto_test()
|
||
begin
|
||
insert into t9 (id) values (null),(null),(null),(null),(null);
|
||
update t9 set fk=69 where fk is null order by id limit 1;
|
||
SELECT * from t9;
|
||
end|
|
||
call auto_test();
|
||
id fk
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
1 69
|
||
SELECT * from t9;
|
||
id fk
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
1 69
|
||
drop procedure auto_test;
|
||
drop table t9;
|
||
SET AUTOCOMMIT=0;
|
||
create table t9 (id int primary key auto_increment, fk int, index (fk)) engine=pbxt;
|
||
insert into t9 (id) values (null),(null),(null),(null),(null);
|
||
update t9 set fk=69 where fk is null order by id limit 1;
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
drop table t9;
|
||
create table t9 (id int primary key auto_increment, fk int, index (fk)) engine=pbxt;
|
||
lock tables t9 write;
|
||
insert into t9 (id) values (null),(null),(null),(null),(null);
|
||
update t9 set fk=69 where fk is null order by id limit 1;
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
unlock tables;
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
drop table t9;
|
||
create table t9 (id int primary key auto_increment, fk int, index (fk)) engine=pbxt;
|
||
create procedure auto_test()
|
||
begin
|
||
insert into t9 (id) values (null),(null),(null),(null),(null);
|
||
update t9 set fk=69 where fk is null order by id limit 1;
|
||
SELECT * from t9;
|
||
end|
|
||
call auto_test();
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
drop procedure auto_test;
|
||
drop table t9;
|
||
SET AUTOCOMMIT=1;
|
||
SET AUTOCOMMIT=0;
|
||
create table t9 (id int primary key auto_increment, fk int, index (fk)) engine=pbxt;
|
||
insert into t9 (id) values (null),(null),(null),(null),(null);
|
||
update t9 set fk=69 where fk is null order by id limit 1;
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
commit;
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
drop table t9;
|
||
create table t9 (id int primary key auto_increment, fk int, index (fk)) engine=pbxt;
|
||
lock tables t9 write;
|
||
insert into t9 (id) values (null),(null),(null),(null),(null);
|
||
update t9 set fk=69 where fk is null order by id limit 1;
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
unlock tables;
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
commit;
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
drop table t9;
|
||
create table t9 (id int primary key auto_increment, fk int, index (fk)) engine=pbxt;
|
||
create procedure auto_test()
|
||
begin
|
||
insert into t9 (id) values (null),(null),(null),(null),(null);
|
||
update t9 set fk=69 where fk is null order by id limit 1;
|
||
SELECT * from t9;
|
||
end|
|
||
call auto_test();
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
commit;
|
||
SELECT * from t9;
|
||
id fk
|
||
1 69
|
||
2 NULL
|
||
3 NULL
|
||
4 NULL
|
||
5 NULL
|
||
drop procedure auto_test;
|
||
drop table t9;
|
||
SET AUTOCOMMIT=1;
|
||
drop table if exists t1,t3|
|
||
create table t1 (
|
||
id char(16) not null default '',
|
||
data int not null
|
||
)|
|
||
insert t1 value ("one", 1), ("two", 2)|
|
||
drop function if exists bug12472|
|
||
create function bug12472() returns int
|
||
begin
|
||
declare a int;
|
||
declare b int;
|
||
set a = (select count(*) from t1);
|
||
set b = (select count(*) from t1);
|
||
return (a + b);
|
||
end|
|
||
create table t3 as select bug12472() as i|
|
||
show create table t3|
|
||
Table Create Table
|
||
t3 CREATE TABLE `t3` (
|
||
`i` int(11) DEFAULT NULL
|
||
) ENGINE=PBXT DEFAULT CHARSET=latin1
|
||
select * from t3|
|
||
i
|
||
4
|
||
drop table t3|
|
||
create view v1 as select bug12472() as j|
|
||
create table t3 as select * from v1|
|
||
show create table t3|
|
||
Table Create Table
|
||
t3 CREATE TABLE `t3` (
|
||
`j` int(11) DEFAULT NULL
|
||
) ENGINE=PBXT DEFAULT CHARSET=latin1
|
||
select * from t3|
|
||
j
|
||
4
|
||
drop table t3|
|
||
drop view v1|
|
||
drop function bug12472|
|
||
drop table t1|
|
||
drop table if exists t1, t3|
|
||
drop procedure if exists t3_update|
|
||
drop function if exists t3_update|
|
||
create table t3 (a smallint primary key) engine=pbxt|
|
||
insert into t3 (a) values (1)|
|
||
create procedure t3_update()
|
||
deterministic
|
||
begin
|
||
declare continue handler for 1062 -- ER_DUP_ENTRY
|
||
select 'Outer (bad)' as 't3_update';
|
||
begin
|
||
declare continue handler for 1062 -- ER_DUP_ENTRY
|
||
select 'Inner (good)' as 't3_update';
|
||
insert into t3 values (1);
|
||
end;
|
||
end|
|
||
call t3_update()|
|
||
t3_update
|
||
Inner (good)
|
||
Warnings:
|
||
Error 1062 Duplicate entry '1' for key 'PRIMARY'
|
||
begin|
|
||
call t3_update()|
|
||
t3_update
|
||
Inner (good)
|
||
Warnings:
|
||
Error 1062 Duplicate entry '1' for key 'PRIMARY'
|
||
commit|
|
||
drop table if exists t3|
|
||
drop procedure if exists t3_update|
|
||
drop function if exists t3_update|
|
||
create table t3 (a smallint primary key) engine=pbxt|
|
||
insert into t3 (a) values (40)|
|
||
insert into t3 (a) values (50)|
|
||
create function t3_update() returns int
|
||
begin
|
||
insert into t3 values (10);
|
||
insert into t3 values (40);
|
||
insert into t3 values (500);
|
||
return 100;
|
||
end|
|
||
select * from t3|
|
||
a
|
||
40
|
||
50
|
||
begin|
|
||
insert into t3 values (10)|
|
||
select t3_update()|
|
||
rollback|
|
||
ERROR 23000: Duplicate entry '40' for key 'PRIMARY'
|
||
select * from t3|
|
||
a
|
||
40
|
||
50
|
||
drop function t3_update|
|
||
drop table if exists t1, t2, t3, t4|
|