~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/t/fulltext.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
#
 
2
# Test of fulltext index
 
3
#
 
4
 
 
5
--disable_warnings
 
6
drop table if exists t1,t2,t3;
 
7
--enable_warnings
 
8
 
 
9
CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b));
 
10
INSERT INTO t1 VALUES('MySQL has now support', 'for full-text search'),
 
11
                       ('Full-text indexes', 'are called collections'),
 
12
                          ('Only MyISAM tables','support collections'),
 
13
             ('Function MATCH ... AGAINST()','is used to do a search'),
 
14
        ('Full-text search in MySQL', 'implements vector space model');
 
15
SHOW INDEX FROM t1;
 
16
 
 
17
# nl search
 
18
 
 
19
select * from t1 where MATCH(a,b) AGAINST ("collections");
 
20
explain extended select * from t1 where MATCH(a,b) AGAINST ("collections");
 
21
select * from t1 where MATCH(a,b) AGAINST ("indexes");
 
22
select * from t1 where MATCH(a,b) AGAINST ("indexes collections");
 
23
select * from t1 where MATCH(a,b) AGAINST ("only");
 
24
 
 
25
# query expansion
 
26
 
 
27
select * from t1 where MATCH(a,b) AGAINST ("collections" WITH QUERY EXPANSION);
 
28
select * from t1 where MATCH(a,b) AGAINST ("indexes" WITH QUERY EXPANSION);
 
29
select * from t1 where MATCH(a,b) AGAINST ("indexes collections" WITH QUERY EXPANSION);
 
30
 
 
31
# IN NATURAL LANGUAGE MODE
 
32
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN NATURAL LANGUAGE MODE);
 
33
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION);
 
34
--error 1064
 
35
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN BOOLEAN MODE WITH QUERY EXPANSION);
 
36
 
 
37
# add_ft_keys() tests
 
38
 
 
39
explain select * from t1 where MATCH(a,b) AGAINST ("collections");
 
40
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>0;
 
41
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>1;
 
42
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>=0;
 
43
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>=1;
 
44
explain select * from t1 where 0<MATCH(a,b) AGAINST ("collections");
 
45
explain select * from t1 where 1<MATCH(a,b) AGAINST ("collections");
 
46
explain select * from t1 where 0<=MATCH(a,b) AGAINST ("collections");
 
47
explain select * from t1 where 1<=MATCH(a,b) AGAINST ("collections");
 
48
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>0 and a like '%ll%';
 
49
 
 
50
# boolean search
 
51
 
 
52
select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE);
 
53
explain extended select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE);
 
54
select * from t1 where MATCH(a,b) AGAINST("support  collections" IN BOOLEAN MODE);
 
55
select * from t1 where MATCH(a,b) AGAINST("support +collections" IN BOOLEAN MODE);
 
56
select * from t1 where MATCH(a,b) AGAINST("sear*" IN BOOLEAN MODE);
 
57
select * from t1 where MATCH(a,b) AGAINST("+support +collections" IN BOOLEAN MODE);
 
58
select * from t1 where MATCH(a,b) AGAINST("+search" IN BOOLEAN MODE);
 
59
select * from t1 where MATCH(a,b) AGAINST("+search +(support vector)" IN BOOLEAN MODE);
 
60
select * from t1 where MATCH(a,b) AGAINST("+search -(support vector)" IN BOOLEAN MODE);
 
61
select *, MATCH(a,b) AGAINST("support collections" IN BOOLEAN MODE) as x from t1;
 
62
select *, MATCH(a,b) AGAINST("collections support" IN BOOLEAN MODE) as x from t1;
 
63
 
 
64
select * from t1 where MATCH a,b AGAINST ("+call* +coll*" IN BOOLEAN MODE);
 
65
 
 
66
select * from t1 where MATCH a,b AGAINST ('"support now"' IN BOOLEAN MODE);
 
67
select * from t1 where MATCH a,b AGAINST ('"Now sUPPort"' IN BOOLEAN MODE);
 
68
select * from t1 where MATCH a,b AGAINST ('"now   support"' IN BOOLEAN MODE);
 
69
select * from t1 where MATCH a,b AGAINST ('"text search"  "now support"' IN BOOLEAN MODE);
 
70
select * from t1 where MATCH a,b AGAINST ('"text search" -"now support"' IN BOOLEAN MODE);
 
71
select * from t1 where MATCH a,b AGAINST ('"text search" +"now support"' IN BOOLEAN MODE);
 
72
select * from t1 where MATCH a,b AGAINST ('"text i"' IN BOOLEAN MODE);
 
73
select * from t1 where MATCH a,b AGAINST ('"xt indexes"' IN BOOLEAN MODE);
 
74
 
 
75
select * from t1 where MATCH a,b AGAINST ('+(support collections) +foobar*' IN BOOLEAN MODE);
 
76
select * from t1 where MATCH a,b AGAINST ('+(+(support collections)) +foobar*' IN BOOLEAN MODE);
 
77
select * from t1 where MATCH a,b AGAINST ('+collections -supp* -foobar*' IN BOOLEAN MODE);
 
78
 
 
79
# bug#2708, bug#3870 crash
 
80
 
 
81
select * from t1 where MATCH a,b AGAINST('"space model' IN BOOLEAN MODE);
 
82
 
 
83
# boolean w/o index:
 
84
 
 
85
select * from t1 where MATCH a AGAINST ("search" IN BOOLEAN MODE);
 
86
select * from t1 where MATCH b AGAINST ("sear*" IN BOOLEAN MODE);
 
87
 
 
88
# UNION of fulltext's
 
89
select * from t1 where MATCH(a,b) AGAINST ("collections") UNION ALL select * from t1 where MATCH(a,b) AGAINST ("indexes");
 
90
 
 
91
#update/delete with fulltext index
 
92
 
 
93
delete from t1 where a like "MySQL%";
 
94
update t1 set a='some test foobar' where MATCH a,b AGAINST ('model');
 
95
delete from t1 where MATCH(a,b) AGAINST ("indexes");
 
96
select * from t1;
 
97
drop table t1;
 
98
 
 
99
#
 
100
# why to scan strings for trunc*
 
101
#
 
102
create table t1 (a varchar(200) not null, fulltext (a));
 
103
insert t1 values ("aaa10 bbb20"), ("aaa20 bbb15"), ("aaa30 bbb10");
 
104
select * from t1 where match a against ("+aaa* +bbb*" in boolean mode);
 
105
select * from t1 where match a against ("+aaa* +bbb1*" in boolean mode);
 
106
select * from t1 where match a against ("+aaa* +ccc*" in boolean mode);
 
107
select * from t1 where match a against ("+aaa10 +(bbb*)" in boolean mode);
 
108
select * from t1 where match a against ("+(+aaa* +bbb1*)" in boolean mode);
 
109
select * from t1 where match a against ("(+aaa* +bbb1*)" in boolean mode);
 
110
drop table t1;
 
111
 
 
112
#
 
113
# Check bug reported by Matthias Urlichs
 
114
#
 
115
 
 
116
CREATE TABLE t1 (
 
117
  id int(11),
 
118
  ticket int(11),
 
119
  KEY ti (id),
 
120
  KEY tit (ticket)
 
121
);
 
122
INSERT INTO t1 VALUES (2,3),(1,2);
 
123
 
 
124
CREATE TABLE t2 (
 
125
  ticket int(11),
 
126
  inhalt text,
 
127
  KEY tig (ticket),
 
128
  fulltext index tix (inhalt)
 
129
);
 
130
INSERT INTO t2 VALUES (1,'foo'),(2,'bar'),(3,'foobar');
 
131
 
 
132
select t1.id FROM t2 as ttxt,t1,t1 as ticket2
 
133
WHERE ticket2.id = ttxt.ticket AND t1.id = ticket2.ticket and
 
134
match(ttxt.inhalt) against ('foobar');
 
135
 
 
136
# In the following query MySQL didn't use the fulltext index
 
137
select ticket2.id FROM t2 as ttxt,t2 INNER JOIN t1 as ticket2 ON
 
138
ticket2.id = t2.ticket
 
139
WHERE ticket2.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar');
 
140
 
 
141
INSERT INTO t1 VALUES (3,3);
 
142
select ticket2.id FROM t2 as ttxt,t2
 
143
INNER JOIN t1 as ticket2 ON ticket2.id = t2.ticket
 
144
WHERE ticket2.id = ticket2.ticket and
 
145
      match(ttxt.inhalt) against ('foobar');
 
146
 
 
147
# Check that we get 'fulltext' index in SHOW CREATE
 
148
 
 
149
show keys from t2;
 
150
show create table t2;
 
151
 
 
152
# check for bug reported by Stephan Skusa
 
153
 
 
154
select * from t2 where MATCH inhalt AGAINST (NULL);
 
155
 
 
156
# MATCH in HAVING (pretty useless, but still it should work)
 
157
 
 
158
select * from t2 where  MATCH inhalt AGAINST ('foobar');
 
159
select * from t2 having MATCH inhalt AGAINST ('foobar');
 
160
 
 
161
#
 
162
# check of fulltext errors
 
163
#
 
164
 
 
165
--error 1283
 
166
CREATE TABLE t3 (t int(11),i text,fulltext tix (t,i));
 
167
--error 1283
 
168
CREATE TABLE t3 (t int(11),i text,
 
169
                 j varchar(200) CHARACTER SET latin2,
 
170
                 fulltext tix (i,j));
 
171
 
 
172
CREATE TABLE t3 (
 
173
  ticket int(11),
 
174
  inhalt text,
 
175
  KEY tig (ticket),
 
176
  fulltext index tix (inhalt)
 
177
);
 
178
 
 
179
--error 1210
 
180
select * from t2 where MATCH inhalt AGAINST (t2.inhalt);
 
181
--error 1191
 
182
select * from t2 where MATCH ticket AGAINST ('foobar');
 
183
--error 1210
 
184
select * from t2,t3 where MATCH (t2.inhalt,t3.inhalt) AGAINST ('foobar');
 
185
 
 
186
drop table t1,t2,t3;
 
187
 
 
188
#
 
189
# three more bugtests
 
190
#
 
191
 
 
192
CREATE TABLE t1 (
 
193
  id int(11)  auto_increment,
 
194
  title varchar(100)  default '',
 
195
  PRIMARY KEY  (id),
 
196
  KEY ind5 (title)
 
197
) ENGINE=MyISAM;
 
198
 
 
199
CREATE FULLTEXT INDEX ft1 ON t1(title);
 
200
insert into t1 (title) values ('this is a test');
 
201
select * from t1 where match title against ('test' in boolean mode);
 
202
update t1 set title='this is A test' where id=1;
 
203
check table t1;
 
204
update t1 set title='this test once revealed a bug' where id=1;
 
205
select * from t1;
 
206
update t1 set title=NULL where id=1;
 
207
 
 
208
drop table t1;
 
209
 
 
210
# one more bug - const_table related
 
211
 
 
212
CREATE TABLE t1 (a int(11), b text, FULLTEXT KEY (b)) ENGINE=MyISAM;
 
213
insert into t1 values (1,"I wonder why the fulltext index doesnt work?");
 
214
SELECT * from t1 where MATCH (b) AGAINST ('apples');
 
215
 
 
216
insert into t1 values (2,"fullaaa fullzzz");
 
217
select * from t1 where match b against ('full*' in boolean mode);
 
218
 
 
219
drop table t1;
 
220
CREATE TABLE t1 ( id int(11) NOT NULL auto_increment primary key, mytext text NOT NULL, FULLTEXT KEY mytext (mytext)) ENGINE=MyISAM;
 
221
INSERT INTO t1 VALUES (1,'my small mouse'),(2,'la-la-la'),(3,'It is so funny'),(4,'MySQL Tutorial');
 
222
select 8 from t1;
 
223
drop table t1;
 
224
 
 
225
#
 
226
# Check bug reported by Julian Ladisch
 
227
# ERROR 1030: Got error 127 from table handler
 
228
#
 
229
 
 
230
create table t1 (a text, fulltext key (a));
 
231
insert into t1 values ('aaaa');
 
232
repair table t1;
 
233
select * from t1 where match (a) against ('aaaa');
 
234
drop table t1;
 
235
 
 
236
#
 
237
# bug #283 by jocelyn fournier <joc@presence-pc.com>
 
238
# FULLTEXT index on a TEXT filed converted to a CHAR field doesn't work anymore
 
239
 
240
 
 
241
create table t1 ( ref_mag text not null, fulltext (ref_mag));
 
242
insert into t1 values ('test');
 
243
select ref_mag from t1 where match ref_mag against ('+test' in boolean mode);
 
244
alter table t1 change ref_mag ref_mag char (255) not null;
 
245
select ref_mag from t1 where match ref_mag against ('+test' in boolean mode);
 
246
drop table t1;
 
247
 
 
248
#
 
249
# bug #942: JOIN
 
250
#
 
251
 
 
252
create table t1 (t1_id int(11) primary key, name varchar(32));
 
253
insert into t1 values (1, 'data1');
 
254
insert into t1 values (2, 'data2');
 
255
create table t2 (t2_id int(11) primary key, t1_id int(11), name varchar(32));
 
256
insert into t2 values (1, 1, 'xxfoo');
 
257
insert into t2 values (2, 1, 'xxbar');
 
258
insert into t2 values (3, 1, 'xxbuz');
 
259
select * from t1 join t2 using(`t1_id`) where match (t1.name, t2.name) against('xxfoo' in boolean mode);
 
260
 
 
261
#
 
262
# Bug #7858: bug with many short (< ft_min_word_len) words in boolean search
 
263
#
 
264
select * from t2 where match name against ('*a*b*c*d*e*f*' in boolean mode);
 
265
drop table t1,t2;
 
266
 
 
267
#
 
268
# bug with repair-by-sort and incorrect records estimation
 
269
#
 
270
 
 
271
create table t1 (a text, fulltext key (a));
 
272
insert into t1 select "xxxx yyyy zzzz";
 
273
drop table t1;
 
274
 
 
275
#
 
276
# UTF8
 
277
#
 
278
SET NAMES latin1;
 
279
CREATE TABLE t1 (t text character set utf8 not null, fulltext(t));
 
280
INSERT t1 VALUES ('Mit freundlichem Gr��'), ('aus Osnabr�ck');
 
281
SET NAMES koi8r;
 
282
INSERT t1 VALUES ("��� �� - ������"),("������, �����!"),
 
283
                ("�� ������, �����!"),("� ����� ����!");
 
284
SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('������');
 
285
SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('���*' IN BOOLEAN MODE);
 
286
SELECT * FROM t1 WHERE MATCH t AGAINST ('���' IN BOOLEAN MODE);
 
287
SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabr�ck');
 
288
SET NAMES latin1;
 
289
SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabr�ck');
 
290
SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabrueck');
 
291
SELECT t, collation(t),FORMAT(MATCH t AGAINST ('Osnabruck'),6) FROM t1 WHERE MATCH t AGAINST ('Osnabruck');
 
292
#alter table t1 modify t text character set latin1 collate latin1_german2_ci not null;
 
293
alter table t1 modify t varchar(200) collate latin1_german2_ci not null;
 
294
SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabr�ck');
 
295
SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabrueck');
 
296
DROP TABLE t1;
 
297
 
 
298
#
 
299
# bug#3964
 
300
#
 
301
 
 
302
CREATE TABLE t1 (s varchar(255), FULLTEXT (s)) DEFAULT CHARSET=utf8;
 
303
insert into t1 (s) values ('p�ra para para'),('para para para');
 
304
select * from t1 where match(s) against('para' in boolean mode);
 
305
select * from t1 where match(s) against('par*' in boolean mode);
 
306
DROP TABLE t1;
 
307
 
 
308
#
 
309
# icc -ip bug (ip = interprocedural optimization)
 
310
# bug#5528
 
311
#
 
312
CREATE TABLE t1 (h text, FULLTEXT (h));
 
313
INSERT INTO t1 VALUES ('Jesses Hasse Ling and his syncopators of Swing');
 
314
REPAIR TABLE t1;
 
315
select count(*) from t1;
 
316
drop table t1;
 
317
 
 
318
#
 
319
# testing out of bounds memory access in ft_nlq_find_relevance()
 
320
# (bug#8522); visible in valgrind.
 
321
#
 
322
CREATE TABLE t1 ( a TEXT, FULLTEXT (a) );
 
323
INSERT INTO t1 VALUES ('testing ft_nlq_find_relevance');
 
324
SELECT MATCH(a) AGAINST ('nosuchword') FROM t1;
 
325
DROP TABLE t1;
 
326
#
 
327
# bug#6784
 
328
# mi_flush_bulk_insert (on dup key error in mi_write)
 
329
# was mangling info->dupp_key_pos
 
330
#
 
331
 
 
332
create table t1 (a int primary key, b text, fulltext(b));
 
333
create table t2 (a int, b text);
 
334
insert t1 values (1, "aaaa"), (2, "bbbb");
 
335
insert t2 values (10, "aaaa"), (2, "cccc");
 
336
replace t1 select * from t2;
 
337
drop table t1, t2;
 
338
 
 
339
#
 
340
# bug#8351
 
341
#
 
342
CREATE TABLE t1 (t VARCHAR(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci, FULLTEXT (t));
 
343
SET NAMES latin1;
 
344
INSERT INTO t1 VALUES('Mit freundlichem Gr�� aus Osnabr�ck');
 
345
SELECT COUNT(*) FROM t1 WHERE MATCH(t) AGAINST ('"osnabr�ck"' IN BOOLEAN MODE);
 
346
DROP TABLE t1;
 
347
 
 
348
#
 
349
# BUG#11684 - repair crashes mysql when table has fulltext index
 
350
#
 
351
 
 
352
CREATE TABLE t1 (a VARCHAR(30), FULLTEXT(a));
 
353
INSERT INTO t1 VALUES('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb');
 
354
SET myisam_repair_threads=2;
 
355
REPAIR TABLE t1;
 
356
SET myisam_repair_threads=@@global.myisam_repair_threads;
 
357
 
 
358
#
 
359
# BUG#5686 - #1034 - Incorrect key file for table - only utf8
 
360
#
 
361
INSERT INTO t1 VALUES('testword\'\'');
 
362
SELECT a FROM t1 WHERE MATCH a AGAINST('testword' IN BOOLEAN MODE);
 
363
SELECT a FROM t1 WHERE MATCH a AGAINST('testword\'\'' IN BOOLEAN MODE);
 
364
 
 
365
#
 
366
# BUG#14194: Problem with fulltext boolean search and apostrophe
 
367
#
 
368
INSERT INTO t1 VALUES('test\'s');
 
369
SELECT a FROM t1 WHERE MATCH a AGAINST('test' IN BOOLEAN MODE);
 
370
DROP TABLE t1;
 
371
 
 
372
#
 
373
# BUG#13835: max key length is 1000 bytes when trying to create
 
374
#            a fulltext index
 
375
#
 
376
CREATE TABLE t1 (a VARCHAR(10000), FULLTEXT(a));
 
377
SHOW CREATE TABLE t1;
 
378
DROP TABLE t1;
 
379
 
 
380
#
 
381
# BUG#14496: Crash or strange results with prepared statement,
 
382
#            MATCH and FULLTEXT
 
383
#
 
384
CREATE TABLE t1 (a TEXT, FULLTEXT KEY(a));
 
385
INSERT INTO t1 VALUES('test'),('test1'),('test');
 
386
PREPARE stmt from "SELECT a, FORMAT(MATCH(a) AGAINST('test1 test'),6) FROM t1 WHERE MATCH(a) AGAINST('test1 test')";
 
387
EXECUTE stmt;
 
388
EXECUTE stmt;
 
389
DEALLOCATE PREPARE stmt;
 
390
DROP TABLE t1;
 
391
 
 
392
#
 
393
# BUG#25951 - ignore/use index does not work with fulltext
 
394
#
 
395
CREATE TABLE t1 (a VARCHAR(255), FULLTEXT(a));
 
396
SELECT * FROM t1 IGNORE INDEX(a) WHERE MATCH(a) AGAINST('test');
 
397
ALTER TABLE t1 DISABLE KEYS;
 
398
--error 1191
 
399
SELECT * FROM t1 WHERE MATCH(a) AGAINST('test');
 
400
DROP TABLE t1;
 
401
 
 
402
#
 
403
# BUG#11392 - fulltext search bug
 
404
#
 
405
CREATE TABLE t1(a TEXT);
 
406
INSERT INTO t1 VALUES(' aaaaa aaaa');
 
407
SELECT * FROM t1 WHERE MATCH(a) AGAINST ('"aaaa"' IN BOOLEAN MODE);
 
408
DROP TABLE t1;
 
409
 
 
410
#
 
411
# BUG#29445 - match ... against () never returns
 
412
#
 
413
CREATE TABLE t1(a VARCHAR(20), FULLTEXT(a));
 
414
INSERT INTO t1 VALUES('Offside'),('City Of God');
 
415
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city of*' IN BOOLEAN MODE);
 
416
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city (of*)' IN BOOLEAN MODE);
 
417
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city* of*' IN BOOLEAN MODE);
 
418
DROP TABLE t1;
 
419
 
 
420
# End of 4.1 tests