~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/t/heap_hash.test

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Test of MEMORY tables.
3
 
#
4
 
 
5
 
--disable_warnings
6
 
drop table if exists t1,t2;
7
 
--enable_warnings
8
 
 
9
 
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
10
 
insert into t1 values(1,1),(2,2),(3,3),(4,4);
11
 
delete from t1 where a=1 or a=0;
12
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
13
 
show table status like "t1";
14
 
show keys from t1;
15
 
select * from t1;
16
 
select * from t1 where a=4;
17
 
update t1 set b=5 where a=4;
18
 
update t1 set b=b+1 where a>=3;
19
 
replace t1 values (3,3);
20
 
select * from t1;
21
 
alter table t1 add c int not null, add key using HASH (c,a);
22
 
drop table t1;
23
 
 
24
 
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
25
 
insert into t1 values(1,1),(2,2),(3,3),(4,4);
26
 
delete from t1 where a > 0;
27
 
select * from t1;
28
 
drop table t1;
29
 
 
30
 
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
31
 
insert into t1 values(1,1),(2,2),(3,3),(4,4);
32
 
alter table t1 modify a int not null auto_increment, engine=innodb, comment="new innodb table";
33
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
34
 
show table status like "t1";
35
 
select * from t1;
36
 
drop table t1;
37
 
 
38
 
create temporary table t1 (a int not null) engine=MEMORY;
39
 
insert into t1 values (869751),(736494),(226312),(802616),(728912);
40
 
select * from t1 where a > 736494;
41
 
alter table t1 add unique uniq_id using HASH (a);
42
 
select * from t1 where a > 736494;
43
 
select * from t1 where a = 736494;
44
 
select * from t1 where a=869751 or a=736494;
45
 
select * from t1 where a in (869751,736494,226312,802616);
46
 
alter table t1 engine=innodb;
47
 
explain select * from t1 where a in (869751,736494,226312,802616);
48
 
drop table t1;
49
 
 
50
 
create temporary table t1 (x int not null, y int not null, key x  using HASH (x), unique y  using HASH (y))
51
 
engine=MEMORY;
52
 
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
53
 
select * from t1 where x=1;
54
 
select * from t1,t1 as t2 where t1.x=t2.y;
55
 
explain select * from t1,t1 as t2 where t1.x=t2.y;
56
 
drop table t1;
57
 
 
58
 
create temporary table t1 (a int) engine=MEMORY;
59
 
insert into t1 values(1);
60
 
select max(a) from t1;
61
 
drop table t1;
62
 
 
63
 
CREATE TEMPORARY TABLE t1 ( a int not null default 0, b int not null default 0,  key  using HASH (a),  key  using HASH (b)  ) ENGINE=MEMORY;
64
 
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
65
 
select * from t1 where a=1; 
66
 
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
67
 
select * from t1 where a=1;
68
 
drop table t1;
69
 
 
70
 
create temporary table t1 (id int not null, primary key  using HASH (id)) engine=MEMORY;
71
 
insert into t1 values(1);
72
 
select max(id) from t1; 
73
 
insert into t1 values(2);
74
 
select max(id) from t1; 
75
 
replace into t1 values(1);
76
 
drop table t1;
77
 
 
78
 
create temporary table t1 (n int) engine=MEMORY;
79
 
drop table t1;
80
 
 
81
 
create temporary table t1 (n int) engine=MEMORY;
82
 
drop table if exists t1;
83
 
 
84
 
# Test of non unique index
85
 
 
86
 
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not 
87
 
null,index(f2)) engine=MEMORY;
88
 
INSERT into t1 set f1=12,f2="bill";
89
 
INSERT into t1 set f1=13,f2="bill";
90
 
INSERT into t1 set f1=14,f2="bill";
91
 
INSERT into t1 set f1=15,f2="bill";
92
 
INSERT into t1 set f1=16,f2="ted";
93
 
INSERT into t1 set f1=12,f2="ted";
94
 
INSERT into t1 set f1=12,f2="ted";
95
 
INSERT into t1 set f1=12,f2="ted";
96
 
INSERT into t1 set f1=12,f2="ted";
97
 
delete from t1 where f2="bill";
98
 
select * from t1;
99
 
drop table t1;
100
 
 
101
 
#
102
 
# Test when using part key searches
103
 
#
104
 
 
105
 
create temporary table t1 (btn char(10) not null, key using HASH (btn)) engine=MEMORY;
106
 
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
107
 
explain select * from t1 where btn like "q%";
108
 
select * from t1 where btn like "q%";
109
 
alter table t1 add column new_col char(1) not null, add key using HASH (btn,new_col), drop key btn;
110
 
update t1 set new_col=left(btn,1);
111
 
explain select * from t1 where btn="a";
112
 
explain select * from t1 where btn="a" and new_col="a";
113
 
drop table t1;
114
 
 
115
 
#
116
 
# Test of NULL keys
117
 
#
118
 
 
119
 
CREATE TEMPORARY TABLE t1 (
120
 
  a int default NULL,
121
 
  b int default NULL,
122
 
  KEY a using HASH (a),
123
 
  UNIQUE b using HASH (b)
124
 
) engine=MEMORY;
125
 
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
126
 
SELECT * FROM t1 WHERE a=NULL;
127
 
explain SELECT * FROM t1 WHERE a IS NULL;
128
 
SELECT * FROM t1 WHERE a<=>NULL;
129
 
SELECT * FROM t1 WHERE b=NULL;
130
 
explain SELECT * FROM t1 WHERE b IS NULL;
131
 
SELECT * FROM t1 WHERE b<=>NULL;
132
 
 
133
 
--error ER_DUP_ENTRY
134
 
INSERT INTO t1 VALUES (1,3);
135
 
DROP TABLE t1;
136
 
 
137
 
#
138
 
# Test when deleting all rows
139
 
#
140
 
 
141
 
CREATE TEMPORARY TABLE t1 (a int not null, primary key using HASH (a)) engine=MEMORY;
142
 
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
143
 
DELETE from t1 where a < 100;
144
 
SELECT * from t1;
145
 
DROP TABLE t1;
146
 
 
147
 
 
148
 
#
149
 
# Hash index # records estimate test
150
 
#
151
 
create temporary table t1
152
 
(
153
 
  a char(8) not null,
154
 
  b char(20) not null,
155
 
  c int not null,
156
 
  key (a)
157
 
) engine=MEMORY;
158
 
 
159
 
insert into t1 values ('aaaa', 'prefill-hash=5',0);
160
 
insert into t1 values ('aaab', 'prefill-hash=0',0);
161
 
insert into t1 values ('aaac', 'prefill-hash=7',0);
162
 
insert into t1 values ('aaad', 'prefill-hash=2',0);
163
 
insert into t1 values ('aaae', 'prefill-hash=1',0);
164
 
insert into t1 values ('aaaf', 'prefill-hash=4',0);
165
 
insert into t1 values ('aaag', 'prefill-hash=3',0);
166
 
insert into t1 values ('aaah', 'prefill-hash=6',0);
167
 
 
168
 
explain select * from t1 where a='aaaa';
169
 
explain select * from t1 where a='aaab';
170
 
explain select * from t1 where a='aaac';
171
 
explain select * from t1 where a='aaad';
172
 
insert into t1 select * from t1;
173
 
 
174
 
# avoid statistics differences between normal and ps-protocol tests
175
 
flush tables;
176
 
explain select * from t1 where a='aaaa';
177
 
explain select * from t1 where a='aaab';
178
 
explain select * from t1 where a='aaac';
179
 
explain select * from t1 where a='aaad';
180
 
 
181
 
# a known effect: table reload causes statistics to be updated:
182
 
flush tables;
183
 
explain select * from t1 where a='aaaa';
184
 
explain select * from t1 where a='aaab';
185
 
explain select * from t1 where a='aaac';
186
 
explain select * from t1 where a='aaad';
187
 
 
188
 
# Check if delete_all_rows() updates #hash_buckets
189
 
create temporary table t2 as select * from t1;
190
 
delete from t1;
191
 
insert into t1 select * from t2;
192
 
explain select * from t1 where a='aaaa';
193
 
explain select * from t1 where a='aaab';
194
 
explain select * from t1 where a='aaac';
195
 
explain select * from t1 where a='aaad';
196
 
drop table t1, t2;
197
 
 
198
 
 
199
 
# Btree and hash index use costs. 
200
 
create temporary table t1 (
201
 
  id int not null primary key auto_increment, 
202
 
  name varchar(20) not null,
203
 
  index heap_idx(name),
204
 
  index btree_idx using btree(name)
205
 
) engine=MEMORY;
206
 
 
207
 
create temporary table t2 (
208
 
  id int not null primary key auto_increment, 
209
 
  name varchar(20) not null,
210
 
  index btree_idx using btree(name),
211
 
  index heap_idx(name)
212
 
) engine=MEMORY;
213
 
 
214
 
insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'), 
215
 
  ('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'), 
216
 
  ('Emily'), ('Mike');
217
 
insert into t2 select * from t1;
218
 
explain select * from t1 where name='matt';
219
 
explain select * from t2 where name='matt';
220
 
 
221
 
explain select * from t1 where name='Lilu';
222
 
explain select * from t2 where name='Lilu';
223
 
 
224
 
explain select * from t1 where name='Phil';
225
 
explain select * from t2 where name='Phil';
226
 
 
227
 
explain select * from t1 where name='Lilu';
228
 
explain select * from t2 where name='Lilu';
229
 
 
230
 
insert into t1 (name) select name from t2;
231
 
insert into t1 (name) select name from t2;
232
 
insert into t1 (name) select name from t2;
233
 
insert into t1 (name) select name from t2;
234
 
insert into t1 (name) select name from t2;
235
 
insert into t1 (name) select name from t2;
236
 
flush tables;
237
 
select count(*) from t1 where name='Matt';
238
 
explain select * from t1 ignore index (btree_idx) where name='matt';
239
 
show index from t1;
240
 
 
241
 
show index from t1;
242
 
 
243
 
create temporary table t3
244
 
(
245
 
  a varchar(20) not null,
246
 
  b varchar(20) not null,
247
 
  key (a,b)
248
 
) engine=MEMORY;
249
 
insert into t3 select name, name from t1;
250
 
show index from t3;
251
 
show index from t3;
252
 
 
253
 
# test rec_per_key use for joins.
254
 
explain select * from t1 ignore key(btree_idx), t3 where t1.name='matt' and t3.a = concat('',t1.name) and t3.b=t1.name;
255
 
 
256
 
drop table t1, t2, t3;
257
 
 
258
 
# Fix for BUG#8371: wrong rec_per_key value for hash index on temporary table
259
 
create temporary table t1 ( a int, index (a) ) engine=memory;
260
 
insert into t1 values (1),(2),(3),(4),(5);
261
 
select a from t1 where a in (1,3);
262
 
explain select a from t1 where a in (1,3);
263
 
drop table t1;
264
 
 
265
 
--echo End of 4.1 tests
266
 
 
267
 
#
268
 
# Bug #27643: query failed : 1114 (The table '' is full)
269
 
#
270
 
# Check that HASH indexes disregard trailing spaces when comparing 
271
 
# strings with binary collations
272
 
 
273
 
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
274
 
                col2 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
275
 
                UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
276
 
INSERT INTO t1 VALUES('A', 'A');
277
 
--error ER_DUP_ENTRY
278
 
INSERT INTO t1 VALUES('A ', 'A ');
279
 
DROP TABLE t1;
280
 
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
281
 
                col2 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
282
 
                UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
283
 
INSERT INTO t1 VALUES('A', 'A');
284
 
--error ER_DUP_ENTRY
285
 
INSERT INTO t1 VALUES('A ', 'A ');
286
 
DROP TABLE t1;
287
 
 
288
 
--echo End of 5.0 tests