2
# Test of fulltext index
6
drop table if exists t1,t2,t3;
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');
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");
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);
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);
35
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN BOOLEAN MODE WITH QUERY EXPANSION);
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%';
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;
64
select * from t1 where MATCH a,b AGAINST ("+call* +coll*" IN BOOLEAN MODE);
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);
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);
79
# bug#2708, bug#3870 crash
81
select * from t1 where MATCH a,b AGAINST('"space model' IN BOOLEAN MODE);
85
select * from t1 where MATCH a AGAINST ("search" IN BOOLEAN MODE);
86
select * from t1 where MATCH b AGAINST ("sear*" IN BOOLEAN MODE);
89
select * from t1 where MATCH(a,b) AGAINST ("collections") UNION ALL select * from t1 where MATCH(a,b) AGAINST ("indexes");
91
#update/delete with fulltext index
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");
100
# why to scan strings for trunc*
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);
113
# Check bug reported by Matthias Urlichs
122
INSERT INTO t1 VALUES (2,3),(1,2);
128
fulltext index tix (inhalt)
130
INSERT INTO t2 VALUES (1,'foo'),(2,'bar'),(3,'foobar');
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');
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');
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');
147
# Check that we get 'fulltext' index in SHOW CREATE
150
show create table t2;
152
# check for bug reported by Stephan Skusa
154
select * from t2 where MATCH inhalt AGAINST (NULL);
156
# MATCH in HAVING (pretty useless, but still it should work)
158
select * from t2 where MATCH inhalt AGAINST ('foobar');
159
select * from t2 having MATCH inhalt AGAINST ('foobar');
162
# check of fulltext errors
166
CREATE TABLE t3 (t int(11),i text,fulltext tix (t,i));
168
CREATE TABLE t3 (t int(11),i text,
169
j varchar(200) CHARACTER SET latin2,
176
fulltext index tix (inhalt)
180
select * from t2 where MATCH inhalt AGAINST (t2.inhalt);
182
select * from t2 where MATCH ticket AGAINST ('foobar');
184
select * from t2,t3 where MATCH (t2.inhalt,t3.inhalt) AGAINST ('foobar');
189
# three more bugtests
193
id int(11) auto_increment,
194
title varchar(100) default '',
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;
204
update t1 set title='this test once revealed a bug' where id=1;
206
update t1 set title=NULL where id=1;
210
# one more bug - const_table related
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');
216
insert into t1 values (2,"fullaaa fullzzz");
217
select * from t1 where match b against ('full*' in boolean mode);
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');
226
# Check bug reported by Julian Ladisch
227
# ERROR 1030: Got error 127 from table handler
230
create table t1 (a text, fulltext key (a));
231
insert into t1 values ('aaaa');
233
select * from t1 where match (a) against ('aaaa');
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
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);
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);
262
# Bug #7858: bug with many short (< ft_min_word_len) words in boolean search
264
select * from t2 where match name against ('*a*b*c*d*e*f*' in boolean mode);
268
# bug with repair-by-sort and incorrect records estimation
271
create table t1 (a text, fulltext key (a));
272
insert into t1 select "xxxx yyyy zzzz";
279
CREATE TABLE t1 (t text character set utf8 not null, fulltext(t));
280
INSERT t1 VALUES ('Mit freundlichem Gr��'), ('aus Osnabr�ck');
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');
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');
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);
309
# icc -ip bug (ip = interprocedural optimization)
312
CREATE TABLE t1 (h text, FULLTEXT (h));
313
INSERT INTO t1 VALUES ('Jesses Hasse Ling and his syncopators of Swing');
315
select count(*) from t1;
319
# testing out of bounds memory access in ft_nlq_find_relevance()
320
# (bug#8522); visible in valgrind.
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;
328
# mi_flush_bulk_insert (on dup key error in mi_write)
329
# was mangling info->dupp_key_pos
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;
342
CREATE TABLE t1 (t VARCHAR(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci, FULLTEXT (t));
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);
349
# BUG#11684 - repair crashes mysql when table has fulltext index
352
CREATE TABLE t1 (a VARCHAR(30), FULLTEXT(a));
353
INSERT INTO t1 VALUES('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb');
354
SET myisam_repair_threads=2;
356
SET myisam_repair_threads=@@global.myisam_repair_threads;
359
# BUG#5686 - #1034 - Incorrect key file for table - only utf8
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);
366
# BUG#14194: Problem with fulltext boolean search and apostrophe
368
INSERT INTO t1 VALUES('test\'s');
369
SELECT a FROM t1 WHERE MATCH a AGAINST('test' IN BOOLEAN MODE);
373
# BUG#13835: max key length is 1000 bytes when trying to create
376
CREATE TABLE t1 (a VARCHAR(10000), FULLTEXT(a));
377
SHOW CREATE TABLE t1;
381
# BUG#14496: Crash or strange results with prepared statement,
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')";
389
DEALLOCATE PREPARE stmt;
393
# BUG#25951 - ignore/use index does not work with fulltext
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;
399
SELECT * FROM t1 WHERE MATCH(a) AGAINST('test');
403
# BUG#11392 - fulltext search bug
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);
411
# BUG#29445 - match ... against () never returns
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);