~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/t/information_schema_inno.test

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- source include/testdb_only.inc
 
2
-- source include/have_innodb.inc
 
3
--disable_warnings
 
4
DROP TABLE IF EXISTS t1,t2,t3;
 
5
--enable_warnings
 
6
 
 
7
#
 
8
# Test for KEY_COLUMN_USAGE & TABLE_CONSTRAINTS tables
 
9
#
 
10
 
 
11
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
 
12
CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id, id),
 
13
FOREIGN KEY (t1_id) REFERENCES t1(id)  ON DELETE CASCADE,
 
14
FOREIGN KEY (t1_id) REFERENCES t1(id)  ON UPDATE CASCADE) ENGINE=INNODB;
 
15
 
 
16
CREATE TABLE t3 (id INT PRIMARY KEY, t2_id INT, INDEX par_ind (t2_id),
 
17
FOREIGN KEY (id, t2_id) REFERENCES t2(t1_id, id)  ON DELETE CASCADE) ENGINE=INNODB;
 
18
 
 
19
select * from information_schema.TABLE_CONSTRAINTS where
 
20
TABLE_SCHEMA= "test";
 
21
select * from information_schema.KEY_COLUMN_USAGE where
 
22
TABLE_SCHEMA= "test";
 
23
 
 
24
drop table t3, t2, t1;
 
25
 
 
26
#
 
27
# Test for REFERENTIAL_CONSTRAINTS table
 
28
#
 
29
CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL,
 
30
                PRIMARY KEY(a1, a2)) ENGINE=INNODB;
 
31
CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2),
 
32
                CONSTRAINT A1
 
33
                FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2)
 
34
                ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB;
 
35
CREATE TABLE t3(b1 INT, b2 INT, INDEX t3_indx (b1, b2),
 
36
                CONSTRAINT A2
 
37
                FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2)
 
38
                ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB;
 
39
CREATE TABLE t4(b1 INT, b2 INT, UNIQUE KEY t4_ukey (b1, b2),
 
40
                CONSTRAINT A3
 
41
                FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2)
 
42
                ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB;
 
43
CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2),
 
44
                CONSTRAINT A4
 
45
                FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2)
 
46
                ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB;
 
47
                
 
48
select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE,
 
49
       b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME,
 
50
       MATCH_OPTION, UPDATE_RULE, DELETE_RULE, b.REFERENCED_TABLE_NAME
 
51
from information_schema.TABLE_CONSTRAINTS a,
 
52
     information_schema.REFERENTIAL_CONSTRAINTS b
 
53
where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
 
54
a.CONSTRAINT_NAME = b.CONSTRAINT_NAME;
 
55
drop tables t5, t4, t3, t2, t1;
 
56
 
 
57
#
 
58
# Bug#25026  `information_schema.KEY_COLUMN_USAGE`.`REFERENCED_TABLE_NAME` returns garbage
 
59
#
 
60
create database `db-1`;
 
61
use `db-1`;
 
62
create table `t-2` (
 
63
  id int(10) unsigned not null auto_increment,
 
64
  primary key (id)
 
65
) engine=innodb;
 
66
 
 
67
create table `t-1` (
 
68
  id int(10) unsigned not null auto_increment,
 
69
  idtype int(10) unsigned not null,
 
70
  primary key (id),
 
71
  key fk_t1_1 (idtype),
 
72
  constraint fk_t1_1 foreign key (idtype) references `t-2` (id)
 
73
) engine=innodb;
 
74
use test;
 
75
select referenced_table_schema, referenced_table_name 
 
76
from information_schema.key_column_usage
 
77
where constraint_schema = 'db-1';
 
78
drop database `db-1`;
 
79
 
 
80
#
 
81
# Bug#35108 SELECT FROM REFERENTIAL_CONSTRAINTS crashes
 
82
#
 
83
create table t1(id int primary key) engine = Innodb;
 
84
create table t2(pid int, foreign key (pid) references t1(id)) engine = Innodb;
 
85
set foreign_key_checks = 0;
 
86
drop table t1;
 
87
select UNIQUE_CONSTRAINT_NAME
 
88
from information_schema.referential_constraints
 
89
where constraint_schema = schema();
 
90
drop table t2;
 
91
set foreign_key_checks = 1;