~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
-- source include/have_innodb.inc
2
3
--disable_warnings
4
drop table if exists t1,t2,t3;
5
--enable_warnings
6
7
#
8
# key field overflow test
9
#
10
CREATE TABLE t1
11
(
1217 by Brian Aker
Removed bits of charset support from the parser.
12
FOLDERID VARCHAR(32) NOT NULL
13
, FOLDERNAME VARCHAR(255) NOT NULL
14
, CREATOR VARCHAR(255)
1 by brian
clean slate
15
, CREATED TIMESTAMP NOT NULL
1217 by Brian Aker
Removed bits of charset support from the parser.
16
, DESCRIPTION VARCHAR(255)
1 by brian
clean slate
17
, FOLDERTYPE INTEGER NOT NULL
18
, MODIFIED TIMESTAMP
1217 by Brian Aker
Removed bits of charset support from the parser.
19
, MODIFIER VARCHAR(255)
1 by brian
clean slate
20
, FOLDERSIZE INTEGER NOT NULL
1217 by Brian Aker
Removed bits of charset support from the parser.
21
, PARENTID VARCHAR(32)
22
, REPID VARCHAR(32)
1 by brian
clean slate
23
, ORIGINATOR INTEGER
24
, PRIMARY KEY ( FOLDERID )
25
) ENGINE=InnoDB;
26
CREATE INDEX FFOLDERID_IDX ON t1 (FOLDERID);
27
CREATE INDEX CMFLDRPARNT_IDX ON t1 (PARENTID);
28
INSERT INTO t1 VALUES("0c9aab05b15048c59bc35c8461507deb", "System", "System", "2003-06-05 16:30:00", "The system content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "9c9aab05b15048c59bc35c8461507deb", "1");
29
INSERT INTO t1 VALUES("2f6161e879db43c1a5b82c21ddc49089", "Default", "System", "2003-06-09 10:52:02", "The default content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "03eea05112b845949f3fd03278b5fe43", "1");
30
INSERT INTO t1 VALUES("c373e9f5ad0791724315444553544200", "AddDocumentTest", "admin", "2003-06-09 10:51:25", "Movie Reviews", "0", "2003-06-09 10:51:25", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL);
31
SELECT 'c373e9f5ad0791a0dab5444553544200' IN(SELECT t1.FOLDERID FROM t1 WHERE t1.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t1.FOLDERNAME = 'Level1');
32
drop table t1;
33
34
#
35
# UNION unlocking test
36
#
37
create table t1 (a int) engine=innodb;
38
create table t2 (a int) engine=innodb;
39
create table t3 (a int) engine=innodb;
40
insert into t1 values (1),(2),(3),(4);
41
insert into t2 values (10),(20),(30),(40);
42
insert into t3 values (1),(2),(10),(50);
43
select a from t3 where t3.a in (select a from t1 where a <= 3 union select * from t2 where a <= 30);
44
drop table t1,t2,t3;
45
46
47
CREATE TABLE t1 (
48
   processor_id INTEGER NOT NULL,
49
   PRIMARY KEY (processor_id)
50
) ENGINE=InnoDB;
51
CREATE TABLE t3 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
52
   yod_id BIGINT AUTO_INCREMENT NOT NULL,
53
   login_processor INTEGER ,
1 by brian
clean slate
54
   PRIMARY KEY (yod_id)
55
) ENGINE=InnoDB;
56
CREATE TABLE t2 (
57
   processor_id INTEGER NOT NULL,
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
58
   yod_id BIGINT NOT NULL,
1 by brian
clean slate
59
   PRIMARY KEY (processor_id, yod_id),
60
   INDEX (processor_id),
61
   INDEX (yod_id),
62
   FOREIGN KEY (processor_id) REFERENCES t1(processor_id),
63
   FOREIGN KEY (yod_id) REFERENCES t3(yod_id) 
64
) ENGINE=InnoDB;
65
INSERT INTO t1 VALUES (1),(2),(3);
66
INSERT INTO t3 VALUES (1,1),(2,2),(3,3);
67
INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
68
SELECT distinct p1.processor_id, (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.processor_id and p2.processor_id = y.processor_id) FROM t1 p1;
69
drop table t2,t1,t3;
70
71
#
72
# innodb locking
73
#
74
CREATE TABLE t1 (
223 by Brian Aker
Cleanup int() work.
75
  id int NOT NULL default '0',
76
  b int default NULL,
1 by brian
clean slate
77
  c char(3) default NULL,
78
  PRIMARY KEY  (id),
79
  KEY t2i1 (b)
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
80
) ENGINE=innodb;
1 by brian
clean slate
81
INSERT INTO t1 VALUES (0,0,'GPL'),(1,0,'GPL'),(2,1,'GPL'),(3,2,'GPL');
82
CREATE TABLE t2 (
223 by Brian Aker
Cleanup int() work.
83
  id int NOT NULL default '0',
84
  b int default NULL,
1 by brian
clean slate
85
  c char(3) default NULL,
86
  PRIMARY KEY  (id),
87
  KEY t2i (b)
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
88
) ENGINE=innodb;
1 by brian
clean slate
89
INSERT INTO t2 VALUES (0,0,'GPL'),(1,0,'GPL'),(2,1,'GPL'),(3,2,'GPL');
90
select (select max(id) from t2 where b=1 group by b) as x,b from t1 where b=1;
91
drop table t1,t2;
92
93
#
94
# reiniting innodb tables
95
#
96
create table t1 (id int not null, value char(255), primary key(id)) engine=innodb;
97
create table t2 (id int not null, value char(255)) engine=innodb;
98
insert into t1 values (1,'a'),(2,'b');
99
insert into t2 values (1,'z'),(2,'x');
100
select t2.id,t2.value,(select t1.value from t1 where t1.id=t2.id) from t2;
101
select t2.id,t2.value,(select t1.value from t1 where t1.id=t2.id) from t2;
102
drop table t1,t2;
103
104
#
105
# unlocking tables with subqueries in HAVING
106
#
107
create table t1 (a int, b int) engine=innodb;
108
insert into t1 values (1,2), (1,3), (2,3), (2,4), (2,5), (3,4), (4,5), (4,100);
109
create table t2 (a int) engine=innodb;
110
insert into t2 values (1),(2),(3),(4);
111
select a, sum(b) as b from t1 group by a having b > (select max(a) from t2);
112
drop table t1, t2;
113
114
#
115
# bug #5220 test suite
116
#
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
117
CREATE TABLE `t1` ( `unit` varchar(50) NOT NULL default '', `ingredient` varchar(50) NOT NULL default '') ENGINE=InnoDB;
1 by brian
clean slate
118
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
119
CREATE TABLE `t2` ( `ingredient` varchar(50) NOT NULL default '', `unit` varchar(50) NOT NULL default '', PRIMARY KEY (ingredient, unit)) ENGINE=InnoDB;
1 by brian
clean slate
120
121
INSERT INTO `t1` VALUES ('xx','yy');
122
INSERT INTO `t2` VALUES ('yy','xx');
123
124
SELECT R.unit, R.ingredient FROM t1 R WHERE R.ingredient IN (SELECT N.ingredient FROM t2 N WHERE N.unit = R.unit);
125
126
drop table t1, t2;
127
128
#
129
# possible early unlock
130
#
131
CREATE TABLE t1 (
132
  id INT NOT NULL auto_increment,
133
  date1 DATE, coworkerid INT,
134
  description VARCHAR(255),
135
  sum_used DOUBLE,
136
  sum_remaining DOUBLE,
137
  comments VARCHAR(255),
138
  PRIMARY KEY(id)
139
) engine=innodb;
140
insert into t1 values (NULL, '1999-01-01', 1,'test', 22, 33, 'comment'), (NULL, '1999-01-01', 1,'test', 22, 33, 'comment'), (NULL, '1999-01-01', 1,'test', 22, 33, 'comment'), (NULL, '1998-01-01', 1,'test', 22, 33, 'comment'), (NULL, '1998-01-01', 1,'test', 22, 33, 'comment'), (NULL, '2004-01-01', 1,'test', 22, 33, 'comment'), (NULL, '2004-01-01', 1,'test', 22, 33, 'comment');
141
SELECT DISTINCT
142
 (SELECT sum(sum_used) FROM t1 WHERE sum_used > 0 AND year(date1) <= '2004') as somallontvangsten,
143
 (SELECT sum(sum_used) FROM t1 WHERE sum_used < 0 AND year(date1) <= '2004') as somalluitgaven
144
 FROM t1;
145
select * from t1;
146
drop table t1;
147
148
# End of 4.1 tests
149
150
CREATE TABLE t1 (
151
  school_name varchar(45) NOT NULL,
152
  country varchar(45) NOT NULL,    
153
  funds_requested float NOT NULL,
154
  schooltype varchar(45) NOT NULL
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
155
) ENGINE=InnoDB;
1 by brian
clean slate
156
157
insert into t1 values ("the school", "USA", 1200, "Human");
158
159
select count(country) as countrycount, sum(funds_requested) as smcnt,
160
       country, (select sum(funds_requested) from t1) as total_funds
161
from t1
162
group by country;
163
164
select count(country) as countrycount, sum(funds_requested) as smcnt,
165
       country, (select sum(funds_requested) from t1) as total_funds
166
from t1
167
group by country;
168
169
drop table t1;
170
171
#
172
# BUG#14342: wrong placement of subquery internals in complex queries
173
#
174
CREATE TABLE `t1` (
175
  `t3_id` int NOT NULL,
176
  `t1_id` int NOT NULL,
177
  PRIMARY KEY  (`t1_id`)
178
);
179
CREATE TABLE `t2` (
180
  `t2_id` int NOT NULL,
181
  `t1_id` int NOT NULL,
182
  `b` int NOT NULL,
183
  PRIMARY KEY  (`t2_id`),
184
  UNIQUE KEY `idx_t2_t1_b` (`t1_id`,`b`)
185
) ENGINE=InnoDB;
186
CREATE TABLE `t3` (
187
  `t3_id` int NOT NULL
188
);
189
INSERT INTO `t3` VALUES (3);
190
select
191
  (SELECT rs.t2_id
192
   FROM t2 rs
193
   WHERE rs.t1_id=
194
     (SELECT lt.t1_id
195
      FROM t1 lt
196
      WHERE lt.t3_id=a.t3_id)
197
   ORDER BY b DESC LIMIT 1)
198
from t3 AS a;
1119.4.10 by Stewart Smith
make subselect_innodb test not leave tables behind
199
200
DROP TABLE t1,t2,t3;