Innodb full text search tests.

This commit is contained in:
unknown 2013-09-24 16:47:33 +03:00
parent 192bafe526
commit 4a38b9db9a
48 changed files with 14274 additions and 0 deletions

View File

@ -173,6 +173,7 @@ my $DEFAULT_SUITES= join(',', map { "$_-" } qw(
handler
heap
innodb
innodb_fts
maria
multi_source
optimizer_unfixed_bugs

View File

@ -0,0 +1,642 @@
drop table if exists t1,t2,t3;
CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('MySQL has now support', 'for full-text search'),
('Full-text indexes', 'are called collections'),
('Only MyISAM tables','support collections'),
('Function MATCH ... AGAINST()','is used to do a search'),
('Full-text search in MySQL', 'implements vector space model');
ANALYZE TABLE t1;
SHOW INDEX FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 a 1 a NULL 5 NULL NULL YES FULLTEXT
t1 1 a 2 b NULL 5 NULL NULL YES FULLTEXT
select * from t1 where MATCH(a,b) AGAINST ("collections");
a b
Full-text indexes are called collections
Only MyISAM tables support collections
explain extended select * from t1 where MATCH(a,b) AGAINST ("collections");
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 fulltext a a 0 1 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (match `test`.`t1`.`a`,`test`.`t1`.`b` against ('collections'))
select * from t1 where MATCH(a,b) AGAINST ("indexes");
a b
Full-text indexes are called collections
select * from t1 where MATCH(a,b) AGAINST ("indexes collections");
a b
Full-text indexes are called collections
Only MyISAM tables support collections
select * from t1 where MATCH(a,b) AGAINST ("only");
a b
Only MyISAM tables support collections
select * from t1 where MATCH(a,b) AGAINST ("collections" WITH QUERY EXPANSION);
a b
Only MyISAM tables support collections
Full-text indexes are called collections
MySQL has now support for full-text search
Full-text search in MySQL implements vector space model
select * from t1 where MATCH(a,b) AGAINST ("indexes" WITH QUERY EXPANSION);
a b
Full-text indexes are called collections
Only MyISAM tables support collections
MySQL has now support for full-text search
Full-text search in MySQL implements vector space model
select * from t1 where MATCH(a,b) AGAINST ("indexes collections" WITH QUERY EXPANSION);
a b
Only MyISAM tables support collections
Full-text indexes are called collections
MySQL has now support for full-text search
Full-text search in MySQL implements vector space model
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN NATURAL LANGUAGE MODE);
a b
Full-text indexes are called collections
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION);
a b
Full-text indexes are called collections
Only MyISAM tables support collections
MySQL has now support for full-text search
Full-text search in MySQL implements vector space model
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN BOOLEAN MODE WITH QUERY EXPANSION);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'QUERY EXPANSION)' at line 1
explain select * from t1 where MATCH(a,b) AGAINST ("collections");
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>=0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
explain select * from t1 where 0<MATCH(a,b) AGAINST ("collections");
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
explain select * from t1 where 1<MATCH(a,b) AGAINST ("collections");
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
explain select * from t1 where 0<=MATCH(a,b) AGAINST ("collections");
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where
explain select * from t1 where 1<=MATCH(a,b) AGAINST ("collections");
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>0 and a like '%ll%';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE);
a b
MySQL has now support for full-text search
explain extended select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 fulltext a a 0 1 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (match `test`.`t1`.`a`,`test`.`t1`.`b` against ('support -collections' in boolean mode))
select * from t1 where MATCH(a,b) AGAINST("support collections" IN BOOLEAN MODE);
a b
Only MyISAM tables support collections
MySQL has now support for full-text search
Full-text indexes are called collections
select * from t1 where MATCH(a,b) AGAINST("support +collections" IN BOOLEAN MODE);
a b
Only MyISAM tables support collections
Full-text indexes are called collections
select * from t1 where MATCH(a,b) AGAINST("sear*" IN BOOLEAN MODE);
a b
MySQL has now support for full-text search
Function MATCH ... AGAINST() is used to do a search
Full-text search in MySQL implements vector space model
select * from t1 where MATCH(a,b) AGAINST("+support +collections" IN BOOLEAN MODE);
a b
Only MyISAM tables support collections
select * from t1 where MATCH(a,b) AGAINST("+search" IN BOOLEAN MODE);
a b
MySQL has now support for full-text search
Function MATCH ... AGAINST() is used to do a search
Full-text search in MySQL implements vector space model
select * from t1 where MATCH(a,b) AGAINST("+search +(support vector)" IN BOOLEAN MODE);
a b
MySQL has now support for full-text search
Full-text search in MySQL implements vector space model
select * from t1 where MATCH(a,b) AGAINST("+search -(support vector)" IN BOOLEAN MODE);
a b
Function MATCH ... AGAINST() is used to do a search
select *, MATCH(a,b) AGAINST("support collections" IN BOOLEAN MODE) as x from t1;
a b x
MySQL has now support for full-text search 0.15835624933242798
Full-text indexes are called collections 0.15835624933242798
Only MyISAM tables support collections 0.31671249866485596
Function MATCH ... AGAINST() is used to do a search 0
Full-text search in MySQL implements vector space model 0
select *, MATCH(a,b) AGAINST("collections support" IN BOOLEAN MODE) as x from t1;
a b x
MySQL has now support for full-text search 0.15835624933242798
Full-text indexes are called collections 0.15835624933242798
Only MyISAM tables support collections 0.31671249866485596
Function MATCH ... AGAINST() is used to do a search 0
Full-text search in MySQL implements vector space model 0
select * from t1 where MATCH a,b AGAINST ("+call* +coll*" IN BOOLEAN MODE);
a b
Full-text indexes are called collections
select * from t1 where MATCH a,b AGAINST ('"support now"' IN BOOLEAN MODE);
a b
select * from t1 where MATCH a,b AGAINST ('"Now sUPPort"' IN BOOLEAN MODE);
a b
MySQL has now support for full-text search
select * from t1 where MATCH a,b AGAINST ('"now support"' IN BOOLEAN MODE);
a b
MySQL has now support for full-text search
select * from t1 where MATCH a,b AGAINST ('"text search" "now support"' IN BOOLEAN MODE);
a b
MySQL has now support for full-text search
Full-text search in MySQL implements vector space model
select * from t1 where MATCH a,b AGAINST ('"text search" -"now support"' IN BOOLEAN MODE);
a b
Full-text search in MySQL implements vector space model
select * from t1 where MATCH a,b AGAINST ('"text search" +"now support"' IN BOOLEAN MODE);
a b
MySQL has now support for full-text search
select * from t1 where MATCH a,b AGAINST ('"text i"' IN BOOLEAN MODE);
a b
select * from t1 where MATCH a,b AGAINST ('"xt indexes"' IN BOOLEAN MODE);
a b
select * from t1 where MATCH a,b AGAINST ('+(support collections) +foobar*' IN BOOLEAN MODE);
a b
select * from t1 where MATCH a,b AGAINST ('+(+(support collections)) +foobar*' IN BOOLEAN MODE);
a b
select * from t1 where MATCH a,b AGAINST ('+collections -supp* -foobar*' IN BOOLEAN MODE);
a b
Full-text indexes are called collections
select * from t1 where MATCH a,b AGAINST('"space model' IN BOOLEAN MODE);
a b
Full-text search in MySQL implements vector space model
delete from t1 where a like "MySQL%";
update t1 set a='some test foobar' where MATCH a,b AGAINST ('model');
delete from t1 where MATCH(a,b) AGAINST ("indexes");
select * from t1;
a b
Only MyISAM tables support collections
Function MATCH ... AGAINST() is used to do a search
some test foobar implements vector space model
drop table t1;
create table t1 (a varchar(200) not null, fulltext (a)) engine = innodb;
insert t1 values ("aaa10 bbb20"), ("aaa20 bbb15"), ("aaa30 bbb10");
select * from t1 where match a against ("+aaa* +bbb*" in boolean mode);
a
aaa10 bbb20
aaa20 bbb15
aaa30 bbb10
select * from t1 where match a against ("+aaa* +bbb1*" in boolean mode);
a
aaa20 bbb15
aaa30 bbb10
select * from t1 where match a against ("+aaa* +ccc*" in boolean mode);
a
select * from t1 where match a against ("+aaa10 +(bbb*)" in boolean mode);
a
aaa10 bbb20
select * from t1 where match a against ("+(+aaa* +bbb1*)" in boolean mode);
a
select * from t1 where match a against ("(+aaa* +bbb1*)" in boolean mode);
a
aaa20 bbb15
aaa30 bbb10
drop table t1;
CREATE TABLE t1 (
id int(11),
ticket int(11),
KEY ti (id),
KEY tit (ticket)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES (2,3),(1,2);
CREATE TABLE t2 (
ticket int(11),
inhalt text,
KEY tig (ticket),
fulltext index tix (inhalt)
) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1,'foo'),(2,'bar'),(3,'foobar');
INSERT INTO t1 VALUES (3,3);
ANALYZE TABLE t1;
ANALYZE TABLE t2;
select ticket2.id FROM t2 as ttxt,t2
INNER JOIN t1 as ticket2 ON ticket2.id = t2.ticket
WHERE ticket2.id = ticket2.ticket and
match(ttxt.inhalt) against ('foobar');
id
3
show keys from t2;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t2 1 tig 1 ticket A 3 NULL NULL YES BTREE
t2 1 tix 1 inhalt NULL 3 NULL NULL YES FULLTEXT
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`ticket` int(11) DEFAULT NULL,
`inhalt` text,
KEY `tig` (`ticket`),
FULLTEXT KEY `tix` (`inhalt`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
select * from t2 where MATCH inhalt AGAINST (NULL);
ticket inhalt
select * from t2 where MATCH inhalt AGAINST ('foobar');
ticket inhalt
3 foobar
select * from t2 having MATCH inhalt AGAINST ('foobar');
ticket inhalt
3 foobar
CREATE TABLE t3 (t int(11),i text,fulltext tix (t,i));
ERROR HY000: Column 't' cannot be part of FULLTEXT index
CREATE TABLE t3 (t int(11),i text,
j varchar(200) CHARACTER SET latin2,
fulltext tix (i,j));
ERROR HY000: Column 'j' cannot be part of FULLTEXT index
CREATE TABLE t3 (
ticket int(11),
inhalt text,
KEY tig (ticket),
fulltext index tix (inhalt)
) ENGINE = InnoDB;
select * from t2 where MATCH inhalt AGAINST (t2.inhalt);
ERROR HY000: Incorrect arguments to AGAINST
select * from t2 where MATCH ticket AGAINST ('foobar');
ERROR HY000: Can't find FULLTEXT index matching the column list
select * from t2,t3 where MATCH (t2.inhalt,t3.inhalt) AGAINST ('foobar');
ERROR HY000: Incorrect arguments to MATCH
drop table t1,t2,t3;
CREATE TABLE t1 (
id int(11) auto_increment,
title varchar(100) default '',
PRIMARY KEY (id),
KEY ind5 (title)
) ENGINE = InnoDB;
CREATE FULLTEXT INDEX ft1 ON t1(title);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
insert into t1 (title) values ('this is a test');
select * from t1 where match title against ('test' in boolean mode);
id title
1 this is a test
update t1 set title='this is A test' where id=1;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
update t1 set title='this test once revealed a bug' where id=1;
select * from t1;
id title
1 this test once revealed a bug
update t1 set title=NULL where id=1;
drop table t1;
CREATE TABLE t1 (a int(11), b text, FULLTEXT KEY (b)) ENGINE = InnoDB;
insert into t1 values (1,"I wonder why the fulltext index doesnt work?");
SELECT * from t1 where MATCH (b) AGAINST ('apples');
a b
insert into t1 values (2,"fullaaa fullzzz");
select * from t1 where match b against ('full*' in boolean mode);
a b
1 I wonder why the fulltext index doesnt work?
2 fullaaa fullzzz
drop table t1;
CREATE TABLE t1 ( id int(11) NOT NULL auto_increment primary key, mytext text NOT NULL, FULLTEXT KEY mytext (mytext)) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1,'my small mouse'),(2,'la-la-la'),(3,'It is so funny'),(4,'MySQL Tutorial');
select 8 from t1;
8
8
8
8
8
drop table t1;
create table t1 (a text, fulltext key (a)) ENGINE = InnoDB;
insert into t1 values ('aaaa');
select * from t1 where match (a) against ('aaaa');
a
aaaa
drop table t1;
create table t1 ( ref_mag text not null, fulltext (ref_mag)) ENGINE = InnoDB;
insert into t1 values ('test');
select ref_mag from t1 where match ref_mag against ('+test' in boolean mode);
ref_mag
test
alter table t1 change ref_mag ref_mag char (255) not null;
select ref_mag from t1 where match ref_mag against ('+test' in boolean mode);
ref_mag
test
drop table t1;
create table t1 (t1_id int(11) primary key, name varchar(32)) ENGINE = InnoDB;
insert into t1 values (1, 'data1');
insert into t1 values (2, 'data2');
create table t2 (t2_id int(11) primary key, t1_id int(11), name varchar(32)) ENGINE = InnoDB;
insert into t2 values (1, 1, 'xxfoo');
insert into t2 values (2, 1, 'xxbar');
insert into t2 values (3, 1, 'xxbuz');
select * from t1 join t2 using(`t1_id`) where match (t1.name, t2.name) against('xxfoo' in boolean mode);
ERROR HY000: The table does not have FULLTEXT index to support this query
select * from t2 where match name against ('*a*b*c*d*e*f*' in boolean mode);
ERROR HY000: The table does not have FULLTEXT index to support this query
drop table t1,t2;
create table t1 (a text, fulltext key (a)) ENGINE = InnoDB;
insert into t1 select "xxxx yyyy zzzz";
drop table t1;
SET NAMES latin1;
CREATE TABLE t1 (t text character set utf8 not null, fulltext(t)) ENGINE = InnoDB;
INSERT t1 VALUES ('Mit freundlichem Grüß'), ('aus Osnabrück');
SET NAMES koi8r;
INSERT t1 VALUES ("üÔÏ ÍÙ - ÏÐÉÌËÉ"),("ïÔÌÅÚØ, ÇÎÉÄÁ!"),
("îÅ ×ÌÅÚÁÊ, ÕÂØÅÔ!"),("É ÂÕÄÅÔ ÐÒÁ×!");
SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('ïðéìëé');
t collation(t)
üÔÏ ÍÙ - ÏÐÉÌËÉ utf8_general_ci
DROP TABLE t1;
CREATE TABLE t1 (s varchar(255), FULLTEXT (s)) ENGINE = InnoDB DEFAULT CHARSET=utf8;
insert into t1 (s) values ('pära para para'),('para para para');
select * from t1 where match(s) against('para' in boolean mode);
s
para para para
pära para para
select * from t1 where match(s) against('par*' in boolean mode);
s
para para para
pära para para
DROP TABLE t1;
CREATE TABLE t1 (h text, FULLTEXT (h)) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('Jesses Hasse Ling and his syncopators of Swing');
select count(*) from t1;
count(*)
1
drop table t1;
CREATE TABLE t1 ( a TEXT, FULLTEXT (a) ) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('testing ft_nlq_find_relevance');
SELECT MATCH(a) AGAINST ('nosuchword') FROM t1;
MATCH(a) AGAINST ('nosuchword')
0
DROP TABLE t1;
create table t1 (a int primary key, b text, fulltext(b)) ENGINE = InnoDB;
create table t2 (a int, b text) ENGINE = InnoDB;
insert t1 values (1, "aaaa"), (2, "bbbb");
insert t2 values (10, "aaaa"), (2, "cccc");
replace t1 select * from t2;
drop table t1, t2;
CREATE TABLE t1 (t VARCHAR(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci, FULLTEXT (t)) ENGINE = InnoDB;
SET NAMES latin1;
INSERT INTO t1 VALUES('Mit freundlichem Grüß aus Osnabrück');
SELECT COUNT(*) FROM t1 WHERE MATCH(t) AGAINST ('"osnabrück"' IN BOOLEAN MODE);
COUNT(*)
1
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(30), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb');
INSERT INTO t1 VALUES('testword\'\'');
SELECT a FROM t1 WHERE MATCH a AGAINST('testword' IN BOOLEAN MODE);
a
testword''
SELECT a FROM t1 WHERE MATCH a AGAINST('testword\'\'' IN BOOLEAN MODE);
a
INSERT INTO t1 VALUES('test\'s');
SELECT a FROM t1 WHERE MATCH a AGAINST('test' IN BOOLEAN MODE);
a
test's
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(10000), FULLTEXT(a)) ENGINE = InnoDB;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varchar(10000) DEFAULT NULL,
FULLTEXT KEY `a` (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
DROP TABLE t1;
CREATE TABLE t1 (a TEXT, FULLTEXT KEY(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('test'),('test1'),('test');
ANALYZE TABLE t1;
PREPARE stmt from "SELECT a, FORMAT(MATCH(a) AGAINST('test1 test'),6) FROM t1 WHERE MATCH(a) AGAINST('test1 test')";
EXECUTE stmt;
a FORMAT(MATCH(a) AGAINST('test1 test'),6)
test1 0.227645
test 0.031008
test 0.031008
EXECUTE stmt;
a FORMAT(MATCH(a) AGAINST('test1 test'),6)
test1 0.227645
test 0.031008
test 0.031008
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(255), FULLTEXT(a)) ENGINE = InnoDB;
SELECT * FROM t1 IGNORE INDEX(a) WHERE MATCH(a) AGAINST('test');
a
SELECT * FROM t1 WHERE MATCH(a) AGAINST('test');
a
DROP TABLE t1;
CREATE TABLE t1(a TEXT, fulltext(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES(' aaaaa aaaa');
SELECT * FROM t1 WHERE MATCH(a) AGAINST ('"aaaa"' IN BOOLEAN MODE);
a
aaaaa aaaa
DROP TABLE t1;
CREATE TABLE t1(a VARCHAR(20), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('Offside'),('City Of God');
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city of*' IN BOOLEAN MODE);
a
Offside
City Of God
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city (of*)' IN BOOLEAN MODE);
a
Offside
City Of God
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city* of*' IN BOOLEAN MODE);
a
Offside
City Of God
DROP TABLE t1;
create table t1(a text,b date,fulltext index(a)) ENGINE = InnoDB;
insert into t1 set a='water',b='2008-08-04';
select 1 from t1 where match(a) against ('water' in boolean mode) and b>='2008-08-01';
1
1
drop table t1;
show warnings;
Level Code Message
CREATE TABLE t1 (a VARCHAR(255), b INT, FULLTEXT(a), KEY(b)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('test', 1),('test', 1),('test', 1),('test', 1),
('test', 1),('test', 2),('test', 3),('test', 4);
ANALYZE TABLE t1;
EXPLAIN SELECT * FROM t1
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext b,a a 0 1 Using where
EXPLAIN SELECT * FROM t1 USE INDEX(a)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
EXPLAIN SELECT * FROM t1 FORCE INDEX(a)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where
EXPLAIN SELECT * FROM t1 IGNORE INDEX(a)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL b NULL NULL NULL 8 Using where
EXPLAIN SELECT * FROM t1 USE INDEX(b)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL b NULL NULL NULL 8 Using where
EXPLAIN SELECT * FROM t1 FORCE INDEX(b)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref b b 5 const 5 Using where
DROP TABLE t1;
CREATE TABLE t1(a CHAR(10), fulltext(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('aaa15');
SELECT MATCH(a) AGAINST('aaa1* aaa14 aaa16' IN BOOLEAN MODE) FROM t1;
MATCH(a) AGAINST('aaa1* aaa14 aaa16' IN BOOLEAN MODE)
0.000000001885928302414186
SELECT MATCH(a) AGAINST('aaa1* aaa14 aaa15 aaa16' IN BOOLEAN MODE) FROM t1;
MATCH(a) AGAINST('aaa1* aaa14 aaa15 aaa16' IN BOOLEAN MODE)
0.000000003771856604828372
DROP TABLE t1;
CREATE TABLE t1(a TEXT) ENGINE = InnoDB;
SELECT GROUP_CONCAT(a) AS st FROM t1 HAVING MATCH(st) AGAINST('test' IN BOOLEAN MODE);
ERROR HY000: Incorrect arguments to AGAINST
DROP TABLE t1;
CREATE TABLE t1(a VARCHAR(64), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('awrd bwrd cwrd'),('awrd bwrd cwrd'),('awrd bwrd cwrd');
SELECT * FROM t1 WHERE MATCH(a) AGAINST('+awrd bwrd* +cwrd*' IN BOOLEAN MODE);
a
awrd bwrd cwrd
awrd bwrd cwrd
awrd bwrd cwrd
DROP TABLE t1;
CREATE TABLE t1 (col text, FULLTEXT KEY full_text (col)) ENGINE = InnoDB;
PREPARE s FROM
"SELECT MATCH (col) AGAINST('findme') FROM t1 ORDER BY MATCH (col) AGAINST('findme')"
;
EXECUTE s;
MATCH (col) AGAINST('findme')
DEALLOCATE PREPARE s;
DROP TABLE t1;
#
# Bug #49250 : spatial btree index corruption and crash
# Part two : fulltext syntax check
#
CREATE TABLE t1(col1 TEXT,
FULLTEXT INDEX USING BTREE (col1));
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USING BTREE (col1))' at line 2
CREATE TABLE t2(col1 TEXT) ENGINE = InnoDB;
CREATE FULLTEXT INDEX USING BTREE ON t2(col);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USING BTREE ON t2(col)' at line 1
ALTER TABLE t2 ADD FULLTEXT INDEX USING BTREE (col1);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USING BTREE (col1)' at line 1
DROP TABLE t2;
End of 5.0 tests
#
# Bug #47930: MATCH IN BOOLEAN MODE returns too many results
# inside subquery
#
CREATE TABLE t1 (a int) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1), (2);
CREATE TABLE t2 (a int, b2 char(10), FULLTEXT KEY b2 (b2)) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1,'Scargill');
CREATE TABLE t3 (a int, b int) ENGINE = InnoDB;
INSERT INTO t3 VALUES (1,1), (2,1);
# t2 should use full text index
EXPLAIN
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2, t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t2 fulltext b2 b2 0 1 Using where
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where
# should return 0
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2, t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);
count(*)
1
# should return 0
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2 IGNORE INDEX (b2), t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);
count(*)
0
DROP TABLE t1,t2,t3;
CREATE TABLE t1 (a VARCHAR(4), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('awrd'),('cwrd'),
('awrd');
SELECT COUNT(*) FROM t1 WHERE MATCH(a) AGAINST("+awrd bwrd* +cwrd*" IN BOOLEAN MODE);
COUNT(*)
0
DROP TABLE t1;
#
# Bug #49445: Assertion failed: 0, file .\item_row.cc, line 55 with
# fulltext search and row op
#
CREATE TABLE t1(a CHAR(1),FULLTEXT(a)) ENGINE = InnoDB;
SELECT 1 FROM t1 WHERE MATCH(a) AGAINST ('') AND ROW(a,a) > ROW(1,1);
1
DROP TABLE t1;
#
# BUG#51866 - crash with repair by sort and fulltext keys
#
CREATE TABLE t1(a CHAR(4), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('aaaa');
DROP TABLE t1;
#
# Bug#54484 explain + prepared statement: crash and Got error -1 from storage engine
#
CREATE TABLE t1(f1 VARCHAR(6) NOT NULL, FULLTEXT KEY(f1), UNIQUE(f1)) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('test');
SELECT 1 FROM t1 WHERE 1 >
ALL((SELECT 1 FROM t1 JOIN t1 a
ON (MATCH(t1.f1) against (""))
WHERE t1.f1 GROUP BY t1.f1)) xor f1;
1
1
PREPARE stmt FROM
'SELECT 1 FROM t1 WHERE 1 >
ALL((SELECT 1 FROM t1 RIGHT OUTER JOIN t1 a
ON (MATCH(t1.f1) against (""))
WHERE t1.f1 GROUP BY t1.f1)) xor f1';
EXECUTE stmt;
1
1
EXECUTE stmt;
1
1
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM
'SELECT 1 FROM t1 WHERE 1 >
ALL((SELECT 1 FROM t1 JOIN t1 a
ON (MATCH(t1.f1) against (""))
WHERE t1.f1 GROUP BY t1.f1))';
EXECUTE stmt;
1
1
EXECUTE stmt;
1
1
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
End of 5.1 tests

View File

@ -0,0 +1,243 @@
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
i int(10) unsigned not null auto_increment primary key,
a varchar(255) not null,
FULLTEXT KEY (a)
) ENGINE = INNODB;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
select count(*) from t1 where match a against ('aaaxxx');
count(*)
260
select count(*) from t1 where match a against ('aaayyy');
count(*)
250
select count(*) from t1 where match a against ('aaazzz');
count(*)
255
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
count(*)
260
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
count(*)
250
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
count(*)
255
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz');
count(*)
765
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz' in boolean mode);
count(*)
765
select count(*) from t1 where match a against ('aaax*' in boolean mode);
count(*)
260
select count(*) from t1 where match a against ('aaay*' in boolean mode);
count(*)
250
select count(*) from t1 where match a against ('aaa*' in boolean mode);
count(*)
765
insert t1 (a) values ('aaaxxx'),('aaayyy');
insert t1 (a) values ('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz');
select count(*) from t1 where match a against ('aaaxxx');
count(*)
261
select count(*) from t1 where match a against ('aaayyy');
count(*)
251
select count(*) from t1 where match a against ('aaazzz');
count(*)
260
insert t1 (a) values ('aaaxxx 000000');
select count(*) from t1 where match a against ('000000');
count(*)
1
delete from t1 where match a against ('000000');
select count(*) from t1 where match a against ('000000');
count(*)
0
select count(*) from t1 where match a against ('aaaxxx');
count(*)
261
delete from t1 where match a against ('aaazzz');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
count(*)
261
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
count(*)
251
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
count(*)
0
select count(*) from t1 where a = 'aaaxxx';
count(*)
261
select count(*) from t1 where a = 'aaayyy';
count(*)
251
select count(*) from t1 where a = 'aaazzz';
count(*)
0
insert t1 (a) values ('aaaxxx 000000');
select count(*) from t1 where match a against ('000000');
count(*)
1
update t1 set a='aaazzz' where match a against ('000000');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
count(*)
261
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
count(*)
1
update t1 set a='aaazzz' where a = 'aaaxxx';
update t1 set a='aaaxxx' where a = 'aaayyy';
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
count(*)
251
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
count(*)
0
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
count(*)
262
drop table t1;
CREATE TABLE t1 (
i int(10) unsigned not null auto_increment primary key,
a varchar(255) not null,
FULLTEXT KEY (a)
) ENGINE = INNODB;
select count(*) from t1 where match a against ('aaaxxx');
count(*)
260
select count(*) from t1 where match a against ('aaayyy');
count(*)
250
select count(*) from t1 where match a against ('aaazzz');
count(*)
255
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
count(*)
260
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
count(*)
250
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
count(*)
255
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz');
count(*)
765
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz' in boolean mode);
count(*)
765
select count(*) from t1 where match a against ('aaax*' in boolean mode);
count(*)
260
select count(*) from t1 where match a against ('aaay*' in boolean mode);
count(*)
250
select count(*) from t1 where match a against ('aaa*' in boolean mode);
count(*)
765
insert t1 (a) values ('aaaxxx'),('aaayyy');
insert t1 (a) values ('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz');
select count(*) from t1 where match a against ('aaaxxx');
count(*)
261
select count(*) from t1 where match a against ('aaayyy');
count(*)
251
select count(*) from t1 where match a against ('aaazzz');
count(*)
260
insert t1 (a) values ('aaaxxx 000000');
select count(*) from t1 where match a against ('000000');
count(*)
1
delete from t1 where match a against ('000000');
select count(*) from t1 where match a against ('000000');
count(*)
0
select count(*) from t1 where match a against ('aaaxxx');
count(*)
261
delete from t1 where match a against ('aaazzz');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
count(*)
261
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
count(*)
251
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
count(*)
0
select count(*) from t1 where a = 'aaaxxx';
count(*)
261
select count(*) from t1 where a = 'aaayyy';
count(*)
251
select count(*) from t1 where a = 'aaazzz';
count(*)
0
insert t1 (a) values ('aaaxxx 000000');
select count(*) from t1 where match a against ('000000');
count(*)
1
update t1 set a='aaazzz' where match a against ('000000');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
count(*)
261
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
count(*)
1
update t1 set a='aaazzz' where a = 'aaaxxx';
update t1 set a='aaaxxx' where a = 'aaayyy';
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
count(*)
251
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
count(*)
0
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
count(*)
262
drop table t1;
set names utf8;
create table t1(a text,fulltext(a)) ENGINE = INNODB collate=utf8_swedish_ci;
insert into t1 values('test test '),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test');
delete from t1 limit 1;
truncate table t1;
insert into t1 values('ab c d');
update t1 set a='ab c d';
select * from t1 where match a against('ab c' in boolean mode);
a
select * from t1 where match a against('ab c' in boolean mode);
a
drop table t1;
set names latin1;
SET NAMES utf8;
CREATE TABLE t1(a VARCHAR(255), FULLTEXT(a)) ENGINE = INNODB DEFAULT CHARSET=utf8;
INSERT INTO t1 VALUES('„MySQL“');
SELECT a FROM t1 WHERE MATCH a AGAINST('“MySQL„' IN BOOLEAN MODE);
a
DROP TABLE t1;
SET NAMES latin1;

View File

@ -0,0 +1,9 @@
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a VARCHAR(255) CHARACTER SET gbk, FULLTEXT(a)) ENGINE = InnoDB;
SET NAMES utf8;
DELETE FROM t1 LIMIT 1;
SET NAMES latin1;
DROP TABLE t1;
CREATE TABLE t1(a VARCHAR(2) CHARACTER SET big5 COLLATE big5_chinese_ci,
FULLTEXT(a)) ENGINE=<default_engine>;
DROP TABLE t1;

View File

@ -0,0 +1,70 @@
drop table if exists t1, t2;
CREATE TABLE t1 (
id int(10) unsigned NOT NULL auto_increment,
q varchar(255) default NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1,'aaaaaaaaa dsaass de');
INSERT INTO t1 VALUES (2,'ssde df s fsda sad er');
CREATE TABLE t2 (
id int(10) unsigned NOT NULL auto_increment,
id2 int(10) unsigned default NULL,
item varchar(255) default NULL,
PRIMARY KEY (id),
FULLTEXT KEY item(item)
) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1,1,'sushi');
INSERT INTO t2 VALUES (2,1,'Bolo de Chocolate');
INSERT INTO t2 VALUES (3,1,'Feijoada');
INSERT INTO t2 VALUES (4,1,'Mousse de Chocolate');
INSERT INTO t2 VALUES (5,2,'um copo de Vodka');
INSERT INTO t2 VALUES (6,2,'um chocolate Snickers');
INSERT INTO t2 VALUES (7,1,'Bife');
INSERT INTO t2 VALUES (8,1,'Pizza de Salmao');
ANALYZE TABLE t1;
ANALYZE TABLE t2;
SELECT t1.q, t2.item, t2.id, round(MATCH t2.item AGAINST ('sushi'),6)
as x FROM t1, t2 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
q item id x
aaaaaaaaa dsaass de sushi 1 0.815572
aaaaaaaaa dsaass de Bolo de Chocolate 2 0.000000
aaaaaaaaa dsaass de Feijoada 3 0.000000
aaaaaaaaa dsaass de Mousse de Chocolate 4 0.000000
ssde df s fsda sad er um copo de Vodka 5 0.000000
ssde df s fsda sad er um chocolate Snickers 6 0.000000
aaaaaaaaa dsaass de Bife 7 0.000000
aaaaaaaaa dsaass de Pizza de Salmao 8 0.000000
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi' IN BOOLEAN MODE)
as x FROM t1, t2 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
q item id x
aaaaaaaaa dsaass de sushi 1 0.8155715465545654
aaaaaaaaa dsaass de Bolo de Chocolate 2 0
aaaaaaaaa dsaass de Feijoada 3 0
aaaaaaaaa dsaass de Mousse de Chocolate 4 0
ssde df s fsda sad er um copo de Vodka 5 0
ssde df s fsda sad er um chocolate Snickers 6 0
aaaaaaaaa dsaass de Bife 7 0
aaaaaaaaa dsaass de Pizza de Salmao 8 0
SELECT t1.q, t2.item, t2.id, round(MATCH t2.item AGAINST ('sushi'),6)
as x FROM t2, t1 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
q item id x
aaaaaaaaa dsaass de sushi 1 0.815572
aaaaaaaaa dsaass de Bolo de Chocolate 2 0.000000
aaaaaaaaa dsaass de Feijoada 3 0.000000
aaaaaaaaa dsaass de Mousse de Chocolate 4 0.000000
ssde df s fsda sad er um copo de Vodka 5 0.000000
ssde df s fsda sad er um chocolate Snickers 6 0.000000
aaaaaaaaa dsaass de Bife 7 0.000000
aaaaaaaaa dsaass de Pizza de Salmao 8 0.000000
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi' IN BOOLEAN MODE)
as x FROM t2, t1 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
q item id x
aaaaaaaaa dsaass de sushi 1 0.8155715465545654
aaaaaaaaa dsaass de Bolo de Chocolate 2 0
aaaaaaaaa dsaass de Feijoada 3 0
aaaaaaaaa dsaass de Mousse de Chocolate 4 0
ssde df s fsda sad er um copo de Vodka 5 0
ssde df s fsda sad er um chocolate Snickers 6 0
aaaaaaaaa dsaass de Bife 7 0
aaaaaaaaa dsaass de Pizza de Salmao 8 0
drop table t1, t2;

View File

@ -0,0 +1,45 @@
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (
id mediumint unsigned NOT NULL auto_increment,
tag char(6) NOT NULL default '',
value text NOT NULL default '',
PRIMARY KEY (id),
KEY kt(tag),
KEY kv(value(15)),
FULLTEXT KEY kvf(value)
) ENGINE = InnoDB;
Warnings:
Warning 1101 BLOB/TEXT column 'value' can't have a default value
CREATE TABLE t2 (
id_t2 mediumint unsigned NOT NULL default '0',
id_t1 mediumint unsigned NOT NULL default '0',
field_number tinyint unsigned NOT NULL default '0',
PRIMARY KEY (id_t2,id_t1,field_number),
KEY id_t1(id_t1)
) ENGINE = InnoDB;
INSERT INTO t1 (tag,value) VALUES ('foo123','bar111');
INSERT INTO t1 (tag,value) VALUES ('foo123','bar222');
INSERT INTO t1 (tag,value) VALUES ('bar345','baz333 ar');
INSERT INTO t2 VALUES (2231626,64280,0);
INSERT INTO t2 VALUES (2231626,64281,0);
INSERT INTO t2 VALUES (12346, 3, 1);
SELECT * FROM t1;
id tag value
1 foo123 bar111
2 foo123 bar222
3 bar345 baz333 ar
SELECT * FROM t2;
id_t2 id_t1 field_number
12346 3 1
2231626 64280 0
2231626 64281 0
SELECT DISTINCT t2.id_t2 FROM t2, t1
WHERE MATCH (t1.value) AGAINST ('baz333') AND t1.id = t2.id_t1;
id_t2
12346
SELECT DISTINCT t2.id_t2 FROM t2, t1
WHERE MATCH (t1.value) AGAINST ('baz333' IN BOOLEAN MODE)
AND t1.id = t2.id_t1;
id_t2
12346
DROP TABLE t1, t2;

View File

@ -0,0 +1,104 @@
drop table if exists t1, t2;
CREATE TABLE t1 (
id VARCHAR(255) NOT NULL PRIMARY KEY,
sujet VARCHAR(255),
motsclefs TEXT,
texte MEDIUMTEXT,
FULLTEXT(sujet, motsclefs, texte)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES('123','toto','essai','test');
INSERT INTO t1 VALUES('456','droit','penal','lawyer');
INSERT INTO t1 VALUES('789','aaaaa','bbbbb','cccccc');
CREATE TABLE t2 (
id VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL
) ENGINE = InnoDB;
INSERT INTO t2 VALUES('123', 'moi');
INSERT INTO t2 VALUES('123', 'lui');
INSERT INTO t2 VALUES('456', 'lui');
ANALYZE TABLE t1;
ANALYZE TABLE t2;
select round(match(t1.texte,t1.sujet,t1.motsclefs) against('droit'),5)
from t1 left join t2 on t2.id=t1.id;
round(match(t1.texte,t1.sujet,t1.motsclefs) against('droit'),5)
0.00000
0.00000
0.22764
0.00000
select match(t1.texte,t1.sujet,t1.motsclefs) against('droit' IN BOOLEAN MODE)
from t1 left join t2 on t2.id=t1.id;
match(t1.texte,t1.sujet,t1.motsclefs) against('droit' IN BOOLEAN MODE)
0
0
0.22764469683170319
0
drop table t1, t2;
create table t1 (venue_id int(11) default null, venue_text varchar(255) default null, dt datetime default null) ENGINE = InnoDB;
insert into t1 (venue_id, venue_text, dt) values (1, 'a1', '2003-05-23 19:30:00'),(null, 'a2', '2003-05-23 19:30:00');
create table t2 (name varchar(255) not null default '', entity_id int(11) not null auto_increment, primary key (entity_id), fulltext key name (name)) engine= innodb;
insert into t2 (name, entity_id) values ('aberdeen town hall', 1), ('glasgow royal concert hall', 2), ('queen\'s hall, edinburgh', 3);
ANALYZE TABLE t1;
ANALYZE TABLE t2;
select * from t1 left join t2 on venue_id = entity_id where match(name) against('aberdeen' in boolean mode) and dt = '2003-05-23 19:30:00';
venue_id venue_text dt name entity_id
1 a1 2003-05-23 19:30:00 aberdeen town hall 1
select * from t1 left join t2 on venue_id = entity_id where match(name) against('aberdeen') and dt = '2003-05-23 19:30:00';
venue_id venue_text dt name entity_id
1 a1 2003-05-23 19:30:00 aberdeen town hall 1
select * from t1 left join t2 on (venue_id = entity_id and match(name) against('aberdeen' in boolean mode)) where dt = '2003-05-23 19:30:00';
venue_id venue_text dt name entity_id
1 a1 2003-05-23 19:30:00 aberdeen town hall 1
NULL a2 2003-05-23 19:30:00 NULL NULL
select * from t1 left join t2 on (venue_id = entity_id and match(name) against('aberdeen')) where dt = '2003-05-23 19:30:00';
venue_id venue_text dt name entity_id
1 a1 2003-05-23 19:30:00 aberdeen town hall 1
NULL a2 2003-05-23 19:30:00 NULL NULL
drop table t1,t2;
create table t1 (id int not null primary key, d char(200) not null, e char(200), fulltext (d, e)) ENGINE = InnoDB;
insert into t1 values (1, 'aword', null), (2, 'aword', 'bword'), (3, 'bword', null), (4, 'bword', 'aword'), (5, 'aword and bword', null);
ANALYZE TABLE t1;
select * from t1 where match(d, e) against ('+aword +bword' in boolean mode);
id d e
2 aword bword
4 bword aword
5 aword and bword NULL
create table t2 (m_id int not null, f char(200), key (m_id), fulltext (f)) engine = InnoDB;
insert into t2 values (1, 'bword'), (3, 'aword'), (5, '');
ANALYZE TABLE t2;
select * from t1 left join t2 on m_id = id where match(d, e, f) against ('+aword +bword' in boolean mode);
id d e m_id f
drop table t1,t2;
CREATE TABLE t1 (
id int(10) NOT NULL auto_increment,
link int(10) default NULL,
name mediumtext default NULL,
PRIMARY KEY (id),
FULLTEXT (name)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1, 1, 'string');
INSERT INTO t1 VALUES (2, 0, 'string');
CREATE TABLE t2 (
id int(10) NOT NULL auto_increment,
name mediumtext default NULL,
PRIMARY KEY (id),
FULLTEXT (name)
) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1, 'string');
ANALYZE TABLE t1;
ANALYZE TABLE t2;
SELECT t1.*, MATCH(t1.name) AGAINST('string') AS relevance
FROM t1 LEFT JOIN t2 ON t1.link = t2.id
WHERE MATCH(t1.name, t2.name) AGAINST('string' IN BOOLEAN MODE);
id link name relevance
1 1 string 0.000000001885928302414186
2 0 string 0.000000001885928302414186
DROP TABLE t1,t2;
CREATE TABLE t1 (a INT) ENGINE = InnoDB;
CREATE TABLE t2 (b INT, c TEXT, KEY(b), FULLTEXT(c)) ENGINE = InnoDB;
INSERT INTO t1 VALUES(1);
INSERT INTO t2(b,c) VALUES(2,'castle'),(3,'castle');
ANALYZE TABLE t1;
ANALYZE TABLE t2;
SELECT * FROM t1 LEFT JOIN t2 ON a=b WHERE MATCH(c) AGAINST('+castle' IN BOOLEAN MODE);
a b c
DROP TABLE t1, t2;

View File

@ -0,0 +1,188 @@
drop table if exists t1;
#
# Bug#56814 Explain + subselect + fulltext crashes server
#
CREATE TABLE t1(f1 VARCHAR(6) NOT NULL,FULLTEXT KEY(f1),UNIQUE(f1)) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('test');
EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT 1 FROM t1 JOIN t1 a ON (MATCH(t1.f1) AGAINST (""))
WHERE t1.f1 GROUP BY t1.f1));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL f1_2 8 NULL 1 Using index
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where
2 SUBQUERY a index NULL f1_2 8 NULL 1 Using index
PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT 1 FROM t1 RIGHT OUTER JOIN t1 a
ON (MATCH(t1.f1) AGAINST (""))
WHERE t1.f1 GROUP BY t1.f1))';
EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL f1_2 8 NULL 1 Using index
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where
2 SUBQUERY a index NULL f1_2 8 NULL 1 Using index
EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL f1_2 8 NULL 1 Using index
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where
2 SUBQUERY a index NULL f1_2 8 NULL 1 Using index
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT 1 FROM t1 JOIN t1 a
ON (MATCH(t1.f1) AGAINST (""))
WHERE t1.f1 GROUP BY t1.f1))';
EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL f1_2 8 NULL 1 Using index
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where
2 SUBQUERY a index NULL f1_2 8 NULL 1 Using index
EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL f1_2 8 NULL 1 Using index
2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where
2 SUBQUERY a index NULL f1_2 8 NULL 1 Using index
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
drop table if exists t1;
CREATE TABLE t1 (
kodoboru varchar(10) default NULL,
obor tinytext,
aobor tinytext,
UNIQUE INDEX kodoboru (kodoboru),
FULLTEXT KEY obor (obor),
FULLTEXT KEY aobor (aobor)
) ENGINE = InnoDB;
drop table t1;
CREATE TABLE t1 (
kodoboru varchar(10) default NULL,
obor tinytext,
aobor tinytext,
UNIQUE INDEX kodoboru (kodoboru),
FULLTEXT KEY obor (obor)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('0101000000','aaa','AAA');
INSERT INTO t1 VALUES ('0102000000','bbb','BBB');
INSERT INTO t1 VALUES ('0103000000','ccc','CCC');
INSERT INTO t1 VALUES ('0104000000','xxx','XXX');
select * from t1;
kodoboru obor aobor
0101000000 aaa AAA
0102000000 bbb BBB
0103000000 ccc CCC
0104000000 xxx XXX
drop table t1;
create table t1 (c1 varchar(1), c2 int, c3 int, c4 int, c5 int, c6 int,
c7 int, c8 int, c9 int, fulltext key (`c1`)) ENGINE = InnoDB;
select distinct match (`c1`) against ('z') , c2, c3, c4,c5, c6,c7, c8
from t1 where c9=1 order by c2, c2;
match (`c1`) against ('z') c2 c3 c4 c5 c6 c7 c8
drop table t1;
CREATE TABLE t1 (c1 int not null auto_increment primary key, c2 varchar(20), fulltext(c2)) ENGINE = InnoDB;
insert into t1 (c2) VALUES ('real Beer'),('Water'),('Kossu'),('Coca-Cola'),('Vodka'),('Wine'),('almost real Beer');
select * from t1 WHERE match (c2) against ('Beer');
c1 c2
1 real Beer
7 almost real Beer
CREATE VIEW v1 AS SELECT * from t1 WHERE match (c2) against ('Beer');
select * from v1;
c1 c2
1 real Beer
7 almost real Beer
drop view v1;
drop table t1;
create table t1 (mytext text, FULLTEXT (mytext)) ENGINE = InnoDB;
insert t1 values ('aaabbb');
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
create table t1 (a varchar(10), fulltext key(a)) ENGINE = InnoDB;
insert into t1 values ('a');
select hex(concat(match (a) against ('a'))) from t1;
hex(concat(match (a) against ('a')))
30
create table t2 ENGINE = InnoDB as select concat(match (a) against ('a')) as a from t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` varchar(23) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
drop table t1, t2;
CREATE TABLE t1(a TEXT CHARSET ucs2 COLLATE ucs2_unicode_ci) ENGINE = InnoDB;
INSERT INTO t1 VALUES('abcd');
SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abcd' IN BOOLEAN MODE);
ERROR HY000: The table does not have FULLTEXT index to support this query
DROP TABLE t1;
create table t1 (a varchar(10), key(a), fulltext (a)) ENGINE = InnoDB;
insert into t1 values ("a"),("abc"),("abcd"),("hello"),("test");
select * from t1 where a like "abc%";
a
abc
abcd
select * from t1 where a like "test%";
a
test
select * from t1 where a like "te_t";
a
test
select * from t1 where match a against ("te*" in boolean mode)+0;
a
drop table t1;
#
# Bug #49734: Crash on EXPLAIN EXTENDED UNION ... ORDER BY
# <any non-const-function>
#
CREATE TABLE t1 (a VARCHAR(10), FULLTEXT KEY a (a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1),(2);
# Should not crash
EXPLAIN EXTENDED
SELECT * FROM t1 UNION SELECT * FROM t1 ORDER BY a + 12;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 UNION t1 ALL NULL NULL NULL NULL 2 100.00
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Using filesort
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` union select `test`.`t1`.`a` AS `a` from `test`.`t1` order by (`a` + 12)
# Should not crash
SELECT * FROM t1 UNION SELECT * FROM t1 ORDER BY a + 12;
a
1
2
# Should not crash
EXPLAIN EXTENDED
SELECT * FROM t1 UNION SELECT * FROM t1
ORDER BY MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE);
ERROR 42000: Incorrect usage/placement of 'MATCH()'
# Should not crash
SELECT * FROM t1 UNION SELECT * FROM t1
ORDER BY MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE);
ERROR 42000: Incorrect usage/placement of 'MATCH()'
# Should not crash
EXPLAIN EXTENDED
SELECT * FROM t1 UNION SELECT * FROM t1
ORDER BY (SELECT a FROM t2 WHERE b = 12);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 UNION t1 ALL NULL NULL NULL NULL 2 100.00
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL Using filesort
3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'a' of SELECT #3 was resolved in SELECT #-1
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` union select `test`.`t1`.`a` AS `a` from `test`.`t1` order by (select `a` from `test`.`t2` where (`test`.`t2`.`b` = 12))
# Should not crash
SELECT * FROM t1 UNION SELECT * FROM t1
ORDER BY (SELECT a FROM t2 WHERE b = 12);
# Should not crash
SELECT * FROM t2 UNION SELECT * FROM t2
ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE));
b
1
2
DROP TABLE t1,t2;
End of 5.1 tests

View File

@ -0,0 +1,38 @@
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
a int(11) NOT NULL auto_increment,
b text,
c varchar(254) default NULL,
PRIMARY KEY (a),
FULLTEXT KEY bb(b),
FULLTEXT KEY cc(c),
FULLTEXT KEY a(b,c)
) ENGINE = InnoDB;
drop table t1;
CREATE TABLE t1 (
a int(11) NOT NULL auto_increment,
b text,
c varchar(254) default NULL,
PRIMARY KEY (a),
FULLTEXT KEY a(b,c)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1,'lala lolo lili','oooo aaaa pppp');
INSERT INTO t1 VALUES (2,'asdf fdsa','lkjh fghj');
INSERT INTO t1 VALUES (3,'qpwoei','zmxnvb');
ANALYZE TABLE t1;
SELECT a, round(MATCH b,c AGAINST ('lala lkjh'),5) FROM t1;
a round(MATCH b,c AGAINST ('lala lkjh'),5)
1 0.22764
2 0.22764
3 0.00000
SELECT a, round(MATCH c,c AGAINST ('lala lkjh'),5) FROM t1;
a round(MATCH c,c AGAINST ('lala lkjh'),5)
1 0.22764
2 0.22764
3 0.00000
SELECT a, round(MATCH b,c AGAINST ('lala lkjh'),5) FROM t1;
a round(MATCH b,c AGAINST ('lala lkjh'),5)
1 0.22764
2 0.22764
3 0.00000
drop table t1;

View File

@ -0,0 +1,179 @@
DROP TABLE IF EXISTS t1,t2,t3;
CREATE TABLE t1 (
a INT AUTO_INCREMENT PRIMARY KEY,
message CHAR(20),
FULLTEXT(message)
) ENGINE = InnoDB comment = 'original testcase by sroussey@network54.com';
INSERT INTO t1 (message) VALUES ("Testing"),("table"),("testbug"),
("steve"),("is"),("cool"),("steve is cool");
ANALYZE TABLE t1;
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE MATCH (message) AGAINST ('steve');
a FORMAT(MATCH (message) AGAINST ('steve'),6)
4 0.296010
7 0.296010
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE MATCH (message) AGAINST ('steve');
a MATCH (message) AGAINST ('steve' IN BOOLEAN MODE)
4 0.2960100471973419
7 0.2960100471973419
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE MATCH (message) AGAINST ('steve' IN BOOLEAN MODE);
a FORMAT(MATCH (message) AGAINST ('steve'),6)
4 0.296010
7 0.296010
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE MATCH (message) AGAINST ('steve' IN BOOLEAN MODE);
a MATCH (message) AGAINST ('steve' IN BOOLEAN MODE)
4 0.2960100471973419
7 0.2960100471973419
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY a;
a FORMAT(MATCH (message) AGAINST ('steve'),6)
4 0.296010
7 0.296010
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) ORDER BY a;
a MATCH (message) AGAINST ('steve' IN BOOLEAN MODE)
4 0.2960100471973419
7 0.2960100471973419
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE a in (2,7,4) and MATCH (message) AGAINST ('steve') ORDER BY a DESC;
a FORMAT(MATCH (message) AGAINST ('steve'),6)
7 0.296010
4 0.296010
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE a in (2,7,4) and MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) ORDER BY a DESC;
a MATCH (message) AGAINST ('steve' IN BOOLEAN MODE)
7 0.2960100471973419
4 0.2960100471973419
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE a=7 and MATCH (message) AGAINST ('steve') ORDER BY 1;
a FORMAT(MATCH (message) AGAINST ('steve'),6)
7 0.296010
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE a=7 and MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) ORDER BY 1;
a MATCH (message) AGAINST ('steve' IN BOOLEAN MODE)
7 0.2960100471973419
SELECT if(a in (4,7),2,1), FORMAT(MATCH (message) AGAINST ('steve'),6) as rel FROM t1 ORDER BY rel;
if(a in (4,7),2,1) rel
1 0.000000
1 0.000000
1 0.000000
1 0.000000
1 0.000000
2 0.296010
2 0.296010
SELECT if(a in (4,7),2,1), MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) as rel FROM t1 ORDER BY rel;
if(a in (4,7),2,1) rel
1 0
1 0
1 0
1 0
1 0
2 0.2960100471973419
2 0.2960100471973419
alter table t1 add key m (message);
ANALYZE TABLE t1;
explain SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext message message 0 1 Using where; Using filesort
SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message desc;
message
steve is cool
steve
drop table t1;
CREATE TABLE t1 (
a INT AUTO_INCREMENT PRIMARY KEY,
message CHAR(20),
FULLTEXT(message)
) ENGINE = InnoDB;
INSERT INTO t1 (message) VALUES ("testbug"),("testbug foobar");
ANALYZE TABLE t1;
SELECT a, MATCH (message) AGAINST ('t* f*' IN BOOLEAN MODE) as rel FROM t1;
a rel
1 0.000000001885928302414186
2 0.0906190574169159
SELECT a, MATCH (message) AGAINST ('t* f*' IN BOOLEAN MODE) as rel FROM t1 ORDER BY rel,a;
a rel
1 0.000000001885928302414186
2 0.0906190574169159
drop table t1;
CREATE TABLE t1 (
id int(11) NOT NULL auto_increment,
thread int(11) NOT NULL default '0',
beitrag longtext NOT NULL,
PRIMARY KEY (id),
KEY thread (thread),
FULLTEXT KEY beitrag (beitrag)
) ENGINE =InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7923 ;
CREATE TABLE t2 (
id int(11) NOT NULL auto_increment,
text varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY text (text)
) ENGINE = InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=63 ;
CREATE TABLE t3 (
id int(11) NOT NULL auto_increment,
forum int(11) NOT NULL default '0',
betreff varchar(70) NOT NULL default '',
PRIMARY KEY (id),
KEY forum (forum),
FULLTEXT KEY betreff (betreff)
) ENGINE = InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=996 ;
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(b.betreff) against ('+abc' in boolean mode)
group by a.text, b.id, b.betreff
union
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(c.beitrag) against ('+abc' in boolean mode)
group by
a.text, b.id, b.betreff
order by
match(b.betreff) against ('+abc' in boolean mode) desc;
ERROR 42000: Incorrect usage/placement of 'MATCH()'
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(b.betreff) against ('+abc' in boolean mode)
union
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(c.beitrag) against ('+abc' in boolean mode)
order by
match(b.betreff) against ('+abc' in boolean mode) desc;
ERROR 42000: Incorrect usage/placement of 'MATCH()'
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(b.betreff) against ('+abc' in boolean mode)
union
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(c.beitrag) against ('+abc' in boolean mode)
order by
match(betreff) against ('+abc' in boolean mode) desc;
ERROR 42000: Incorrect usage/placement of 'MATCH()'
(select b.id, b.betreff from t3 b) union
(select b.id, b.betreff from t3 b)
order by match(betreff) against ('+abc' in boolean mode) desc;
id betreff
(select b.id, b.betreff from t3 b) union
(select b.id, b.betreff from t3 b)
order by match(betreff) against ('+abc') desc;
ERROR HY000: Can't find FULLTEXT index matching the column list
select distinct b.id, b.betreff from t3 b
order by match(betreff) against ('+abc' in boolean mode) desc;
id betreff
select b.id, b.betreff from t3 b group by b.id+1
order by match(betreff) against ('+abc' in boolean mode) desc;
id betreff
drop table t1,t2,t3;

View File

@ -0,0 +1,24 @@
drop table if exists test;
CREATE TABLE test (
gnr INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
url VARCHAR(80) DEFAULT '' NOT NULL,
shortdesc VARCHAR(200) DEFAULT '' NOT NULL,
longdesc text DEFAULT '' NOT NULL,
description VARCHAR(80) DEFAULT '' NOT NULL,
name VARCHAR(80) DEFAULT '' NOT NULL,
FULLTEXT(url,description,shortdesc,longdesc),
PRIMARY KEY(gnr)
) ENGINE = InnoDB;
Warnings:
Warning 1101 BLOB/TEXT column 'longdesc' can't have a default value
insert into test (url,shortdesc,longdesc,description,name) VALUES
("http:/test.at", "kurz", "lang","desc", "name");
insert into test (url,shortdesc,longdesc,description,name) VALUES
("http:/test.at", "kurz", "","desc", "name");
update test set url='test', description='ddd', name='nam' where gnr=2;
update test set url='test', shortdesc='ggg', longdesc='mmm',
description='ddd', name='nam' where gnr=2;
check table test;
Table Op Msg_type Msg_text
test.test check status OK
drop table test;

View File

@ -0,0 +1,38 @@
drop table if exists t1;
show variables like "ft\_%";
Variable_name Value
ft_boolean_syntax + -><()~*:""&|
ft_max_word_len 84
ft_min_word_len 4
ft_query_expansion_limit 20
ft_stopword_file (built-in)
create table t1 (b text not null, fulltext(b)) engine = innodb;
insert t1 values ('aaaaaa bbbbbb cccccc');
insert t1 values ('bbbbbb cccccc');
insert t1 values ('aaaaaa cccccc');
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
b
aaaaaa bbbbbb cccccc
bbbbbb cccccc
aaaaaa cccccc
set ft_boolean_syntax=' +-><()~*:""&|';
ERROR HY000: Variable 'ft_boolean_syntax' is a GLOBAL variable and should be set with SET GLOBAL
set global ft_boolean_syntax=' +-><()~*:""&|';
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
b
aaaaaa bbbbbb cccccc
bbbbbb cccccc
aaaaaa cccccc
set global ft_boolean_syntax='@ -><()~*:""&|';
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
b
aaaaaa bbbbbb cccccc
bbbbbb cccccc
aaaaaa cccccc
select * from t1 where match b against ('+aaaaaa @bbbbbb' in boolean mode);
b
set global ft_boolean_syntax='@ -><()~*:""@|';
ERROR 42000: Variable 'ft_boolean_syntax' can't be set to the value of '@ -><()~*:""@|'
set global ft_boolean_syntax='+ -><()~*:""@!|';
ERROR 42000: Variable 'ft_boolean_syntax' can't be set to the value of '+ -><()~*:""@!|'
drop table t1;

View File

@ -0,0 +1,6 @@
CREATE TABLE t (a INT, b TEXT) engine=innodb;
SET debug_dbug='+d,alter_table_rollback_new_index';
ALTER TABLE t ADD FULLTEXT INDEX (b(64));
ERROR HY000: Unknown error
SET debug_dbug='-d,alter_table_rollback_new_index';
DROP TABLE t;

View File

@ -0,0 +1,238 @@
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
ANALYZE TABLE articles;
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
5 MySQL vs. YourSQL In the following database comparison ...
SELECT COUNT(*) FROM articles
WHERE MATCH (title,body)
AGAINST ('database' IN NATURAL LANGUAGE MODE);
COUNT(*)
2
SELECT * FROM articles
WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT COUNT(IF(MATCH (title,body)
AGAINST ('database' IN NATURAL LANGUAGE MODE), 1, NULL))
AS count FROM articles;
count
2
SELECT id, body, MATCH (title,body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE) AS score
FROM articles;
id body score
1 DBMS stands for DataBase ... 0.22764469683170319
2 After you went through a ... 0
3 In this tutorial we will show ... 0
4 1. Never run mysqld as root. 2. ... 0
5 In the following database comparison ... 0.22764469683170319
6 When configured properly, MySQL ... 0
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN NATURAL LANGUAGE MODE);
id title body
6 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);
id title body
6 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('DBMS Security' IN BOOLEAN MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
6 MySQL Security When configured properly, MySQL ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL +YourSQL' IN BOOLEAN MODE);
id title body
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL YourSQL' IN BOOLEAN MODE);
id title body
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL ~YourSQL' IN BOOLEAN MODE);
id title body
6 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('t*' IN BOOLEAN MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('MY*' IN BOOLEAN MODE);
id title body
6 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('ru*' IN BOOLEAN MODE);
id title body
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+ MySQL >Well < stands' IN BOOLEAN MODE);
id title body
2 How To Use MySQL Well After you went through a ...
6 MySQL Security When configured properly, MySQL ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
1 MySQL Tutorial DBMS stands for DataBase ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+ MySQL - (Well stands)' IN BOOLEAN MODE);
id title body
6 MySQL Security When configured properly, MySQL ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+ MySQL + (>Well < stands)' IN BOOLEAN MODE);
id title body
2 How To Use MySQL Well After you went through a ...
1 MySQL Tutorial DBMS stands for DataBase ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('YourSQL + (+MySQL - (Tricks Security))' IN BOOLEAN MODE);
id title body
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('(+MySQL - (Tricks Security)) - YourSQL' IN BOOLEAN MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT COUNT(*) FROM articles
WHERE MATCH (title,body)
AGAINST ('database' WITH QUERY EXPANSION);
COUNT(*)
6
INSERT INTO articles (title,body) VALUES
('test query expansion','for database ...');
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('test' WITH QUERY EXPANSION);
id title body
7 test query expansion for database ...
1 MySQL Tutorial DBMS stands for DataBase ...
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"following comparison"@3' IN BOOLEAN MODE);
id title body
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"following comparison"@2' IN BOOLEAN MODE);
id title body
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"following database"' IN BOOLEAN MODE);
id title body
5 MySQL vs. YourSQL In the following database comparison ...
INSERT INTO articles (title,body) VALUES
('test proximity search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO articles (title,body) VALUES
('test my proximity fts new search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO articles (title,body) VALUES
('test more of proximity fts search, test, more proximity and phrase',
'search, with proximity innodb');
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"proximity search"@3' IN BOOLEAN MODE);
id title body
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test my proximity fts new search, test, proximity and phrase search, with proximity innodb
10 test more of proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"proximity search"@2' IN BOOLEAN MODE);
id title body
8 test proximity search, test, proximity and phrase search, with proximity innodb
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"proximity search"@5' IN BOOLEAN MODE);
id title body
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test my proximity fts new search, test, proximity and phrase search, with proximity innodb
10 test more of proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"test proximity"@5' IN BOOLEAN MODE);
id title body
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test my proximity fts new search, test, proximity and phrase search, with proximity innodb
10 test more of proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"test proximity"@1' IN BOOLEAN MODE);
id title body
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"test proximity"@4' IN BOOLEAN MODE);
id title body
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test my proximity fts new search, test, proximity and phrase search, with proximity innodb
10 test more of proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"test proximity"@3' IN BOOLEAN MODE);
id title body
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test my proximity fts new search, test, proximity and phrase search, with proximity innodb
10 test more of proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"more test proximity"@4' IN BOOLEAN MODE);
id title body
10 test more of proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"more test proximity"@3' IN BOOLEAN MODE);
id title body
10 test more of proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"more test proximity"' IN BOOLEAN MODE);
id title body
drop table articles;

View File

@ -0,0 +1,229 @@
CREATE TABLE fts_test (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
INSERT INTO fts_test (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on fts_test (title, body);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
DROP INDEX idx ON fts_test;
INSERT INTO fts_test (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on fts_test (title, body);
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
7 MySQL Tutorial DBMS stands for DataBase ...
9 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM fts_test WHERE MATCH (title,body)
AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);
id title body
6 MySQL Security When configured properly, MySQL ...
12 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
7 MySQL Tutorial DBMS stands for DataBase ...
8 How To Use MySQL Well After you went through a ...
9 Optimizing MySQL In this tutorial we will show ...
10 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
TRUNCATE TABLE fts_test;
DROP INDEX idx ON fts_test;
INSERT INTO fts_test (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on fts_test (title, body);
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
DROP TABLE fts_test;
CREATE TABLE fts_test (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
create unique index FTS_DOC_ID_INDEX on fts_test(FTS_DOC_ID);
INSERT INTO fts_test (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on fts_test (title, body) LOCK=NONE;
ERROR 0A000: LOCK=NONE is not supported. Reason: Fulltext index creation requires a lock. Try LOCK=SHARED.
CREATE FULLTEXT INDEX idx on fts_test (title, body);
ALTER TABLE fts_test ROW_FORMAT=REDUNDANT, LOCK=NONE;
ERROR 0A000: LOCK=NONE is not supported. Reason: InnoDB presently supports one FULLTEXT index creation at a time. Try LOCK=SHARED.
ALTER TABLE fts_test ROW_FORMAT=REDUNDANT;
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
drop index idx on fts_test;
CREATE FULLTEXT INDEX idx on fts_test (title, body);
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
drop index idx on fts_test;
drop index FTS_DOC_ID_INDEX on fts_test;
CREATE FULLTEXT INDEX idx on fts_test (title, body);
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
drop table fts_test;
CREATE TABLE fts_test (
FTS_DOC_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL DEFAULT '',
text mediumtext NOT NULL,
PRIMARY KEY (FTS_DOC_ID),
UNIQUE KEY FTS_DOC_ID_INDEX (FTS_DOC_ID),
FULLTEXT KEY idx (title,text)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
set @@auto_increment_increment=10;
INSERT INTO fts_test (title, text) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
ANALYZE TABLE fts_test;
set @@auto_increment_increment=1;
select *, match(title, text) AGAINST ('database') as score
from fts_test order by score desc;
FTS_DOC_ID title text score
11 MySQL Tutorial DBMS stands for DataBase ... 0.22764469683170319
51 MySQL vs. YourSQL In the following database comparison ... 0.22764469683170319
21 How To Use MySQL Well After you went through a ... 0
31 Optimizing MySQL In this tutorial we will show ... 0
41 1001 MySQL Tricks 1. Never run mysqld as root. 2. ... 0
61 MySQL Security When configured properly, MySQL ... 0
drop index idx on fts_test;
drop table fts_test;
CREATE TABLE fts_test (
FTS_DOC_ID int(20) unsigned NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL DEFAULT '',
text mediumtext NOT NULL,
PRIMARY KEY (FTS_DOC_ID),
UNIQUE KEY FTS_DOC_ID_INDEX (FTS_DOC_ID),
FULLTEXT KEY idx (title,text)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
ERROR 42000: Incorrect column name 'FTS_DOC_ID'
CREATE TABLE fts_test (
FTS_DOC_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL DEFAULT '',
text mediumtext NOT NULL,
PRIMARY KEY (FTS_DOC_ID),
KEY FTS_DOC_ID_INDEX (FTS_DOC_ID),
FULLTEXT KEY idx (title,text)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
ERROR HY000: Index 'FTS_DOC_ID_INDEX' is of wrong type for an InnoDB FULLTEXT index
CREATE TABLE articles (
FTS_DOC_ID BIGINT UNSIGNED NOT NULL ,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
INSERT INTO articles (FTS_DOC_ID, title, body) VALUES
(9, 'MySQL Tutorial','DBMS stands for DataBase ...'),
(10, 'How To Use MySQL Well','After you went through a ...'),
(12, 'Optimizing MySQL','In this tutorial we will show ...'),
(14,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(19, 'MySQL vs. YourSQL','In the following database comparison ...'),
(20, 'MySQL Security','When configured properly, MySQL ...');
ALTER TABLE articles ADD FULLTEXT INDEX idx3 (title),
ADD FULLTEXT INDEX idx5 (title);
ERROR HY000: InnoDB presently supports one FULLTEXT index creation at a time
CREATE FULLTEXT INDEX idx on articles (title);
ALTER TABLE articles ADD FULLTEXT INDEX idx3 (title);
ALTER TABLE articles ADD INDEX t20 (title(20)), LOCK=NONE;
ALTER TABLE articles DROP INDEX t20;
INSERT INTO articles (FTS_DOC_ID, title, body) VALUES
(29, 'MySQL Tutorial','DBMS stands for DataBase ...'),
(30, 'How To Use MySQL Well','After you went through a ...'),
(32, 'Optimizing MySQL','In this tutorial we will show ...'),
(34,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(39, 'MySQL vs. YourSQL','In the following database comparison ...'),
(40, 'MySQL Security','When configured properly, MySQL ...');
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
9 MySQL Tutorial DBMS stands for DataBase ...
29 MySQL Tutorial DBMS stands for DataBase ...
DROP INDEX idx ON articles;
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
9 MySQL Tutorial DBMS stands for DataBase ...
29 MySQL Tutorial DBMS stands for DataBase ...
CREATE FULLTEXT INDEX idx on articles (title, body);
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
9 MySQL Tutorial DBMS stands for DataBase ...
12 Optimizing MySQL In this tutorial we will show ...
29 MySQL Tutorial DBMS stands for DataBase ...
32 Optimizing MySQL In this tutorial we will show ...
DROP TABLE articles;
create table articles(`FTS_DOC_ID` serial,
`col32` timestamp not null,`col115` text) engine=innodb;
create fulltext index `idx5` on articles(`col115`) ;
alter ignore table articles add primary key (`col32`) ;
drop table articles;
CREATE TABLE articles (
id INT UNSIGNED NOT NULL,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
INSERT INTO articles VALUES
(1, 'MySQL Tutorial','DBMS stands for DataBase ...') ,
(2, 'How To Use MySQL Well','After you went through a ...'),
(3, 'Optimizing MySQL','In this tutorial we will show ...'),
(4, '1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5, 'MySQL vs. YourSQL','In the following database comparison ...'),
(6, 'MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on articles (title, body);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
DROP INDEX idx ON articles;
CREATE UNIQUE INDEX idx2 ON articles(id);
CREATE FULLTEXT INDEX idx on articles (title, body);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
DROP TABLE articles;

View File

@ -0,0 +1,190 @@
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on articles (title, body);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT COUNT(*) FROM articles
WHERE MATCH (title, body)
AGAINST ('database' IN NATURAL LANGUAGE MODE);
COUNT(*)
2
SELECT * FROM articles
WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT COUNT(IF(MATCH (title, body)
AGAINST ('database' IN NATURAL LANGUAGE MODE), 1, NULL))
AS count FROM articles;
count
2
ANALYZE TABLE articles;
Table Op Msg_type Msg_text
test.articles analyze status OK
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);
id title body
6 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('DBMS Security' IN BOOLEAN MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
6 MySQL Security When configured properly, MySQL ...
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL +YourSQL' IN BOOLEAN MODE);
id title body
5 MySQL vs. YourSQL In the following database comparison ...
DROP INDEX idx ON articles;
CREATE FULLTEXT INDEX idx on articles (title, body);
CREATE FULLTEXT INDEX idx1 on articles (title);
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
DROP INDEX idx ON articles;
DROP INDEX idx1 ON articles;
CREATE FULLTEXT INDEX idx1 on articles (title);
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
drop table articles;
CREATE TABLE articles (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
create unique index FTS_DOC_ID_INDEX on articles(FTS_DOC_ID);
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on articles (title, body);
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
drop table articles;
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on articles (title);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
CREATE FULLTEXT INDEX idx2 on articles (body);
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
ERROR HY000: Can't find FULLTEXT index matching the column list
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
SELECT * FROM articles WHERE MATCH (body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
3 Optimizing MySQL In this tutorial we will show ...
drop index idx2 on articles;
SELECT * FROM articles WHERE MATCH (body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
ERROR HY000: Can't find FULLTEXT index matching the column list
CREATE FULLTEXT INDEX idx2 on articles (body);
SELECT * FROM articles WHERE MATCH (body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
3 Optimizing MySQL In this tutorial we will show ...
UPDATE articles set title = 'aaaa'
WHERE MATCH(title) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id title body
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('aaaa' IN NATURAL LANGUAGE MODE);
id title body
1 aaaa DBMS stands for DataBase ...
drop table articles;
CREATE TABLE articles (
FTS_DOC_ID BIGINT UNSIGNED NOT NULL ,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
CREATE FULLTEXT INDEX idx on articles (title);
INSERT INTO articles VALUES (9, 'MySQL Tutorial','DBMS stands for DataBase ...');
UPDATE articles set title = 'bbbb' WHERE MATCH(title) AGAINST ('tutorial' IN NATURAL LANGUAGE MODE);
ERROR HY000: Invalid InnoDB FTS Doc ID
UPDATE articles set title = 'bbbb', FTS_DOC_ID=8 WHERE MATCH(title) AGAINST ('tutorial' IN NATURAL LANGUAGE MODE);
ERROR HY000: Invalid InnoDB FTS Doc ID
UPDATE articles set title = 'bbbb', FTS_DOC_ID=10 WHERE MATCH(title) AGAINST ('tutorial' IN NATURAL LANGUAGE MODE);
SELECT * FROM articles WHERE MATCH (title) AGAINST ('bbbb' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
10 bbbb DBMS stands for DataBase ...
SELECT * FROM articles WHERE MATCH (title) AGAINST ('tutorial' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
CREATE FULLTEXT INDEX idx2 ON articles (body);
SELECT * FROM articles WHERE MATCH (body) AGAINST ('database' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID title body
10 bbbb DBMS stands for DataBase ...
UPDATE articles set body = 'bbbb', FTS_DOC_ID=11 WHERE MATCH(body) AGAINST ('database' IN NATURAL LANGUAGE MODE);
drop table articles;
create table `articles`(`a` varchar(2) not null)engine=innodb;
create fulltext index `FTS_DOC_ID_INDEX` on `articles`(`a`);
ERROR HY000: Index 'FTS_DOC_ID_INDEX' is of wrong type for an InnoDB FULLTEXT index
create unique index `a` on `articles`(`a`);
drop table articles;
CREATE TABLE wp(
FTS_DOC_ID bigint PRIMARY KEY,
title VARCHAR(255) NOT NULL DEFAULT '',
text MEDIUMTEXT NOT NULL ) ENGINE=InnoDB;
INSERT INTO wp (FTS_DOC_ID, title, text) VALUES
(1, 'MySQL Tutorial','DBMS stands for DataBase ...'),
(2, 'How To Use MySQL Well','After you went through a ...');
CREATE FULLTEXT INDEX idx ON wp(title, text);
ERROR HY000: Column 'FTS_DOC_ID' is of wrong type for an InnoDB FULLTEXT index
DROP TABLE wp;
CREATE TABLE wp(
FTS_DOC_ID bigint unsigned PRIMARY KEY,
title VARCHAR(255) NOT NULL DEFAULT '',
text MEDIUMTEXT NOT NULL ) ENGINE=InnoDB;
INSERT INTO wp (FTS_DOC_ID, title, text) VALUES
(1, 'MySQL Tutorial','DBMS stands for DataBase ...'),
(2, 'How To Use MySQL Well','After you went through a ...');
CREATE FULLTEXT INDEX idx ON wp(title, text);
SELECT FTS_DOC_ID, MATCH(title, text) AGAINST ('database')
FROM wp;
FTS_DOC_ID MATCH(title, text) AGAINST ('database')
1 0.0906190574169159
2 0
DROP TABLE wp;

View File

@ -0,0 +1,754 @@
select * from information_schema.innodb_ft_default_stopword;
value
a
about
an
are
as
at
be
by
com
de
en
for
from
how
i
in
is
it
la
of
on
or
that
the
this
to
was
what
when
where
who
will
with
und
the
www
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('the' IN NATURAL LANGUAGE MODE);
id title body
select @@innodb_ft_server_stopword_table;
@@innodb_ft_server_stopword_table
NULL
select @@innodb_ft_enable_stopword;
@@innodb_ft_enable_stopword
1
select @@innodb_ft_user_stopword_table;
@@innodb_ft_user_stopword_table
NULL
set global innodb_ft_server_stopword_table = "not_defined";
ERROR 42000: Variable 'innodb_ft_server_stopword_table' can't be set to the value of 'not_defined'
create table user_stopword(value varchar(30)) engine = innodb;
set global innodb_ft_server_stopword_table = "test/user_stopword";
drop index title on articles;
create fulltext index idx on articles(title, body);
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('the' IN NATURAL LANGUAGE MODE);
id title body
5 MySQL vs. YourSQL In the following database comparison ...
CREATE TABLE articles_2 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles_2 (title, body)
VALUES ('test for stopwords','this is it...');
SELECT * FROM articles_2 WHERE MATCH (title,body)
AGAINST ('this' IN NATURAL LANGUAGE MODE);
id title body
1 test for stopwords this is it...
insert into user_stopword values("this");
CREATE TABLE articles_3 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles_3 (title, body)
VALUES ('test for stopwords','this is it...');
SELECT * FROM articles_3 WHERE MATCH (title,body)
AGAINST ('this' IN NATURAL LANGUAGE MODE);
id title body
create table user_stopword_session(value varchar(30)) engine = innodb;
insert into user_stopword_session values("session");
set session innodb_ft_user_stopword_table="test/user_stopword_session";
CREATE TABLE articles_4 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles_4 (title, body)
VALUES ('test for session stopwords','this should also be excluded...');
SELECT * FROM articles_4 WHERE MATCH (title,body)
AGAINST ('session' IN NATURAL LANGUAGE MODE);
id title body
SELECT * FROM articles_4 WHERE MATCH (title,body)
AGAINST ('this' IN NATURAL LANGUAGE MODE);
id title body
1 test for session stopwords this should also be excluded...
CREATE TABLE articles_5 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles_5 (title, body)
VALUES ('test for session stopwords','this should also be excluded...');
SELECT * FROM articles_5 WHERE MATCH (title,body)
AGAINST ('session' IN NATURAL LANGUAGE MODE);
id title body
1 test for session stopwords this should also be excluded...
drop table articles;
drop table articles_2;
drop table articles_3;
drop table articles_4;
drop table articles_5;
drop table user_stopword;
drop table user_stopword_session;
SET GLOBAL innodb_ft_enable_stopword=1;
SET GLOBAL innodb_ft_server_stopword_table=default;
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT `idx` (title,body)
) ENGINE=InnoDB;
SHOW CREATE TABLE articles;
Table Create Table
articles CREATE TABLE `articles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) DEFAULT NULL,
`body` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `idx` (`title`,`body`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
INSERT INTO articles (title,body) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','In what tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
id title body
INSERT INTO articles(title,body) values ('the record will' , 'not index the , will words');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
id title body
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE id = 7;
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
DELETE FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE id = 7;
id title body
7 update the record to see will is indexed or not
DELETE FROM articles WHERE id = 7;
SET SESSION innodb_ft_enable_stopword = 0;
select @@innodb_ft_enable_stopword;
@@innodb_ft_enable_stopword
0
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
id title body
INSERT INTO articles(title,body) values ('the record will' , 'not index the , will words');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
id title body
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE id = 8;
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
SELECT * FROM articles WHERE id = 8;
id title body
8 update the record to see will is indexed or not
DELETE FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE id = 8;
id title body
8 update the record to see will is indexed or not
DELETE FROM articles WHERE id = 8;
ALTER TABLE articles DROP INDEX idx;
SHOW CREATE TABLE articles;
Table Create Table
articles CREATE TABLE `articles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) DEFAULT NULL,
`body` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
ANALYZE TABLE articles;
Table Op Msg_type Msg_text
test.articles analyze status OK
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
id title body
2 when To Use MySQL Well After that you went through a ...
6 MySQL Security When configured properly, MySQL ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
1 MySQL from Tutorial DBMS stands for DataBase ...
6 MySQL Security When configured properly, MySQL ...
2 when To Use MySQL Well After that you went through a ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
id title body
2 when To Use MySQL Well After that you went through a ...
3 where will Optimizing MySQL In what tutorial we will show ...
6 MySQL Security When configured properly, MySQL ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
id title body
1 MySQL from Tutorial DBMS stands for DataBase ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
INSERT INTO articles(title,body) values ('the record will' , 'not index the , will words');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
id title body
9 the record will not index the , will words
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
id title body
9 the record will not index the , will words
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT COUNT(*),max(id) FROM articles;
COUNT(*) max(id)
7 9
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
id title body
9 update the record to see will is indexed or not
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
9 update the record to see will is indexed or not
DELETE FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE id = 9;
id title body
DROP TABLE articles;
SET SESSION innodb_ft_enable_stopword=1;
SET GLOBAL innodb_ft_server_stopword_table=default;
SET SESSION innodb_ft_user_stopword_table=default;
select @@innodb_ft_server_stopword_table;
@@innodb_ft_server_stopword_table
NULL
select @@innodb_ft_enable_stopword;
@@innodb_ft_enable_stopword
1
select @@innodb_ft_user_stopword_table;
@@innodb_ft_user_stopword_table
NULL
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT `idx` (title,body)
) ENGINE=InnoDB;
INSERT INTO articles (title,body) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','In what tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
create table user_stopword(value varchar(30)) engine = innodb;
set session innodb_ft_user_stopword_table = "test/user_stopword";
create table server_stopword(value varchar(30)) engine = innodb;
set global innodb_ft_server_stopword_table = "test/server_stopword";
insert into user_stopword values("this"),("will"),("the");
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
insert into server_stopword values("what"),("where");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
DELETE FROM user_stopword;
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
insert into user_stopword values("this"),("will"),("the");
ALTER TABLE articles DROP INDEX idx;
SET SESSION innodb_ft_enable_stopword = 0;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SET SESSION innodb_ft_enable_stopword = 1;
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
SET SESSION innodb_ft_enable_stopword = 1;
SET SESSION innodb_ft_user_stopword_table = default;
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
DROP TABLE articles,user_stopword,server_stopword;
SET SESSION innodb_ft_enable_stopword=1;
SET GLOBAL innodb_ft_server_stopword_table=default;
SET SESSION innodb_ft_user_stopword_table=default;
select @@innodb_ft_server_stopword_table;
@@innodb_ft_server_stopword_table
NULL
select @@innodb_ft_enable_stopword;
@@innodb_ft_enable_stopword
1
select @@innodb_ft_user_stopword_table;
@@innodb_ft_user_stopword_table
NULL
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT `idx` (title,body)
) ENGINE=InnoDB;
SHOW CREATE TABLE articles;
Table Create Table
articles CREATE TABLE `articles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) DEFAULT NULL,
`body` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `idx` (`title`,`body`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
INSERT INTO articles (title,body) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','In what tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
create table user_stopword(value varchar(30)) engine = innodb;
set session innodb_ft_user_stopword_table = "test/user_stopword";
insert into user_stopword values("mysqld"),("DBMS");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+DBMS +mysql" IN BOOLEAN MODE);
id title body
1 MySQL from Tutorial DBMS stands for DataBase ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('mysqld');
id title body
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+DBMS +mysql" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('mysqld');
id title body
set session innodb_ft_user_stopword_table = default;
create table server_stopword(value varchar(30)) engine = innodb;
set global innodb_ft_server_stopword_table = "test/server_stopword";
insert into server_stopword values("root"),("properly");
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+root +mysql" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('properly');
id title body
set session innodb_ft_user_stopword_table = "test/user_stopword";
set global innodb_ft_server_stopword_table = "test/server_stopword";
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+root +mysql" IN BOOLEAN MODE);
id title body
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('properly');
id title body
6 MySQL Security When configured properly, MySQL ...
set session innodb_ft_user_stopword_table = "test/user_stopword";
DELETE FROM user_stopword;
set global innodb_ft_server_stopword_table = "test/server_stopword";
DELETE FROM server_stopword;
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+root +mysql" IN BOOLEAN MODE);
id title body
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('properly');
id title body
6 MySQL Security When configured properly, MySQL ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+DBMS +mysql" IN BOOLEAN MODE);
id title body
1 MySQL from Tutorial DBMS stands for DataBase ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('mysqld');
id title body
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
DROP TABLE articles,user_stopword,server_stopword;
SET SESSION innodb_ft_enable_stopword=1;
SET GLOBAL innodb_ft_server_stopword_table=default;
SET SESSION innodb_ft_user_stopword_table=default;
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT `idx` (title,body)
) ENGINE=InnoDB;
SHOW CREATE TABLE articles;
Table Create Table
articles CREATE TABLE `articles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) DEFAULT NULL,
`body` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `idx` (`title`,`body`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
INSERT INTO articles (title,body) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','In what tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
SET SESSION innodb_ft_enable_stopword = 0;
select @@innodb_ft_enable_stopword;
@@innodb_ft_enable_stopword
0
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
"In connection 1"
select @@innodb_ft_enable_stopword;
@@innodb_ft_enable_stopword
1
ANALYZE TABLE articles;
Table Op Msg_type Msg_text
test.articles analyze status OK
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
id title body
2 when To Use MySQL Well After that you went through a ...
6 MySQL Security When configured properly, MySQL ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
1 MySQL from Tutorial DBMS stands for DataBase ...
6 MySQL Security When configured properly, MySQL ...
2 when To Use MySQL Well After that you went through a ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
id title body
2 when To Use MySQL Well After that you went through a ...
3 where will Optimizing MySQL In what tutorial we will show ...
6 MySQL Security When configured properly, MySQL ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
id title body
1 MySQL from Tutorial DBMS stands for DataBase ...
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SET SESSION innodb_ft_enable_stopword = 1;
select @@innodb_ft_enable_stopword;
@@innodb_ft_enable_stopword
1
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
id title body
"In connection default"
select @@innodb_ft_enable_stopword;
@@innodb_ft_enable_stopword
0
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
id title body
INSERT INTO articles(title,body) values ('the record will' , 'not index the , will words');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
id title body
SET SESSION innodb_ft_enable_stopword = 1;
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
id title body
"In connection 1"
SET SESSION innodb_ft_enable_stopword = 1;
create table user_stopword(value varchar(30)) engine = innodb;
set session innodb_ft_user_stopword_table = "test/user_stopword";
insert into user_stopword values("this"),("will"),("the");
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
"In connection default"
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
id title body
select @@innodb_ft_user_stopword_table;
@@innodb_ft_user_stopword_table
NULL
create table user_stopword_1(value varchar(30)) engine = innodb;
set session innodb_ft_user_stopword_table = "test/user_stopword_1";
insert into user_stopword_1 values("when");
SET SESSION innodb_ft_enable_stopword = 1;
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+when" IN BOOLEAN MODE);
id title body
2 when To Use MySQL Well After that you went through a ...
6 MySQL Security When configured properly, MySQL ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('when');
id title body
2 when To Use MySQL Well After that you went through a ...
6 MySQL Security When configured properly, MySQL ...
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+when" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('when');
id title body
"In connection 1"
SET SESSION innodb_ft_enable_stopword = 1;
SET SESSION innodb_ft_user_stopword_table=default;
select @@innodb_ft_user_stopword_table;
@@innodb_ft_user_stopword_table
NULL
select @@innodb_ft_server_stopword_table;
@@innodb_ft_server_stopword_table
NULL
create table server_stopword(value varchar(30)) engine = innodb;
SET GLOBAL innodb_ft_server_stopword_table = "test/server_stopword";
select @@innodb_ft_server_stopword_table;
@@innodb_ft_server_stopword_table
test/server_stopword
insert into server_stopword values("when"),("the");
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+when" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('the');
id title body
"In connection default"
SET SESSION innodb_ft_enable_stopword = 1;
SET SESSION innodb_ft_user_stopword_table=default;
select @@innodb_ft_server_stopword_table;
@@innodb_ft_server_stopword_table
test/server_stopword
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+will +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('where');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
insert into server_stopword values("where"),("will");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+will +where" IN BOOLEAN MODE);
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('where');
id title body
3 where will Optimizing MySQL In what tutorial we will show ...
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+when" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('the');
id title body
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+will +where" IN BOOLEAN MODE);
id title body
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('where');
id title body
DROP TABLE articles,user_stopword,user_stopword_1,server_stopword;
SET SESSION innodb_ft_enable_stopword=1;
SET GLOBAL innodb_ft_server_stopword_table=default;
SET SESSION innodb_ft_user_stopword_table=default;

View File

@ -0,0 +1,305 @@
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT
) ENGINE = InnoDB;
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
"Loading data using LOAD DATA Command , File <MYSQLTEST_VARDIR>/tmp/fts_input_data1.txt"
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT COUNT(*) FROM t1;
COUNT(*)
49
SELECT FTS_DOC_ID FROM t1 WHERE MATCH (a,b)
AGAINST ('row35col2word49' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID
35
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row5col2word49" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row35col2word49 +(row35col1word49 row35col2word40)" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row35col2word49 -(row45col2word49)" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("row5col2word49 row5col2word40" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ("+row5col2word* +row5col1word49*" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ('"row35col2word49"' IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ('"ROW35col2WORD49"' IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST ("row5col2word49" WITH QUERY EXPANSION);
COUNT(*)
1
SELECT FTS_DOC_ID FROM t1
WHERE MATCH (a,b)
AGAINST ('"row5col2word48 row5col2word49"@2' IN BOOLEAN MODE);
FTS_DOC_ID
5
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"row5col2word48 row5col2word49"@1' IN BOOLEAN MODE);
FTS_DOC_ID a b
UPDATE t1 SET a = "using update" , b = "changing fulltext index record", FTS_DOC_ID = FTS_DOC_ID + 10000
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
a b
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("changing fulltext" IN BOOLEAN MODE);
a b
using update changing fulltext index record
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
a b
using update changing fulltext index record
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
a b
DROP TABLE t1;
CREATE TABLE t1 (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT
) ENGINE = InnoDB;
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
"Loading data using LOAD DATA Command , File <MYSQLTEST_VARDIR>/tmp/fts_input_data2.txt"
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT COUNT(*) FROM t1;
COUNT(*)
100
SELECT FTS_DOC_ID from t1 WHERE b like '%row300col2word30%';
FTS_DOC_ID
SELECT FTS_DOC_ID FROM t1 WHERE MATCH (a,b)
AGAINST ('row35col2word49' IN NATURAL LANGUAGE MODE);
FTS_DOC_ID
35
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row5col2word49" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row35col2word49 +(row35col1word49 row35col2word40)" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row35col2word49 -(row45col2word49)" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("row5col2word49 row5col2word40" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ("+row5col2word* +row5col1word49*" IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ('"row35col2word49"' IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ('"ROW35col2WORD49"' IN BOOLEAN MODE);
COUNT(*)
1
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST ("row5col2word49" WITH QUERY EXPANSION);
COUNT(*)
1
SELECT FTS_DOC_ID FROM t1
WHERE MATCH (a,b)
AGAINST ('"row5col2word48 row5col2word49"@2' IN BOOLEAN MODE);
FTS_DOC_ID
5
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"row5col2word48 row5col2word49"@1' IN BOOLEAN MODE);
FTS_DOC_ID a b
UPDATE t1 SET a = "using update" , b = "changing fulltext index record", FTS_DOC_ID = FTS_DOC_ID + 10000
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
SELECT a,b FROM t1
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
a b
SELECT a,b FROM t1
WHERE MATCH(a,b) AGAINST("changing fulltext" IN BOOLEAN MODE);
a b
using update changing fulltext index record
SELECT a,b FROM t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
a b
using update changing fulltext index record
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
a b
ALTER TABLE t1 DROP INDEX idx;
CREATE FULLTEXT INDEX idx on t1 (a,b);
UPDATE t1 SET a = NULL , b = NULL, FTS_DOC_ID= 6000 + FTS_DOC_ID;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
COUNT(*)
99
ALTER TABLE t1 DROP INDEX idx;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
COUNT(*)
99
DROP TABLE t1;
CREATE TABLE t1 (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT
) ENGINE = InnoDB;
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
"Loading data using LOAD DATA Command , File <MYSQLTEST_VARDIR>/tmp/fts_input_data3.txt"
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT COUNT(*) FROM t1;
COUNT(*)
100
SELECT COUNT(*) from t1 WHERE b like '%samerowword%';
COUNT(*)
100
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b)
AGAINST ('samerowword' IN NATURAL LANGUAGE MODE);
COUNT(*)
100
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword +samerowword" IN BOOLEAN MODE);
COUNT(*)
100
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword" IN BOOLEAN MODE);
COUNT(*)
100
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword -(row45col2word49)" IN BOOLEAN MODE);
COUNT(*)
100
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ("+sameroww" IN BOOLEAN MODE);
COUNT(*)
0
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST ("samerowword" WITH QUERY EXPANSION);
COUNT(*)
100
UPDATE t1 SET a = "using update" , b = "changing fulltext index record",
FTS_DOC_ID = FTS_DOC_ID + 10000
WHERE MATCH(a,b) AGAINST("+samerowword +samerowword" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword +samerowword" IN BOOLEAN MODE);
COUNT(*)
0
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword" IN BOOLEAN MODE);
COUNT(*)
0
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("changing fulltext" IN BOOLEAN MODE);
COUNT(*)
100
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
COUNT(*)
100
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
COUNT(*)
0
ALTER TABLE t1 DROP INDEX idx;
CREATE FULLTEXT INDEX idx on t1 (a,b);
UPDATE t1 SET a = NULL , b = NULL ;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
COUNT(*)
0
ALTER TABLE t1 DROP INDEX idx;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
COUNT(*)
0
DROP TABLE t1;
CREATE TABLE t1 (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT
) ENGINE = InnoDB;
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
"Loading data using LOAD DATA Command , File <MYSQLTEST_VARDIR>/tmp/fts_input_data4.txt"
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT COUNT(*) FROM t1;
COUNT(*)
100
SELECT COUNT(*) from t1 WHERE a like '%samerowword%';
COUNT(*)
100
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b)
AGAINST ('samerowword' IN NATURAL LANGUAGE MODE);
COUNT(*)
100
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST("+samerowword +1050" IN BOOLEAN MODE);
COUNT(*)
100
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST("+samerowword" IN BOOLEAN MODE);
COUNT(*)
100
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST("+samerowword -(1050)" IN BOOLEAN MODE);
COUNT(*)
0
SELECT COUNT(*) from t1 WHERE MATCH a,b AGAINST ("+2001" IN BOOLEAN MODE);
COUNT(*)
0
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST ("samerowword" WITH QUERY EXPANSION);
COUNT(*)
100
UPDATE t1 SET a = "using update" , b = "changing fulltext index record",
FTS_DOC_ID = FTS_DOC_ID + 10000
WHERE MATCH(a,b) AGAINST("+samerowword +1050" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword +1050" IN BOOLEAN MODE);
COUNT(*)
0
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword" IN BOOLEAN MODE);
COUNT(*)
0
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("changing fulltext" IN BOOLEAN MODE);
COUNT(*)
100
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
COUNT(*)
100
DELETE FROM t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
COUNT(*)
0
ALTER TABLE t1 DROP INDEX idx;
CREATE FULLTEXT INDEX idx on t1 (a,b);
UPDATE t1 SET a = NULL , b = NULL ;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
COUNT(*)
0
ALTER TABLE t1 DROP INDEX idx;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
COUNT(*)
0
DROP TABLE t1;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,904 @@
drop table if exists t2,t1;
set names utf8;
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) ,
b1 TEXT ,
FULLTEXT KEY (a1,b1), PRIMARY KEY (a1, id1)
) CHARACTER SET = utf8 , ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON UPDATE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...');
INSERT INTO t1 (id1,a1,b1) VALUES
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
INSERT INTO t2 (a2,b2) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE)
DELETE FROM t1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE)
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ;
id1
1
3
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial') ;
id2
1
3
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id1
3
6
2
4
5
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id2
3
6
2
4
5
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial' WITH QUERY EXPANSION) ;
id1
1
3
5
6
2
4
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial' WITH QUERY EXPANSION) ;
id2
1
3
5
6
2
4
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
id1
1
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
id2
1
set global innodb_optimize_fulltext_only=1;
optimize table t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
set global innodb_optimize_fulltext_only=0;
UPDATE t1 SET a1 = "changing column - on update cascade" , b1 = "to check foreign constraint" WHERE
MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id1
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id2
6
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('+update +cascade' IN BOOLEAN MODE) ;
id1
4
2
6
5
3
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('+update +cascade' IN BOOLEAN MODE) ;
id2
4
2
6
5
3
SELECT id2 FROM t2 WHERE a2 LIKE '%UPDATE CASCADE%';
id2
2
3
4
5
6
DROP TABLE t2 , t1;
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on update cascade) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s2 = 'Rainbows' where s2 <> 'Sunshine';
commit;
select * from t2 where match(s2) against ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on delete cascade) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
delete from t1 where s2 <> 'Sunshine';
select * from t2 where match(s2) against ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on delete set null) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
delete from t1 where s2 <> 'Sunshine';
select * from t2 where match(s2) against ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on update set null) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s2 = 'Rainbows' where s2 <> 'Sunshine';
commit;
select * from t2 where match(s2) against ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
create table t1 (s1 bigint unsigned not null, s2 varchar(200),
primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (FTS_DOC_ID BIGINT UNSIGNED NOT NULL, s2 varchar(200),
foreign key (FTS_DOC_ID) references t1 (s1)
on update cascade) ENGINE = InnoDB;
create fulltext index idx on t2(s2);
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`FTS_DOC_ID` bigint(20) unsigned NOT NULL,
`s2` varchar(200) DEFAULT NULL,
KEY `FTS_DOC_ID` (`FTS_DOC_ID`),
FULLTEXT KEY `idx` (`s2`),
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s1 = 3 where s1=1;
select * from t2 where match(s2) against ('sunshine');
FTS_DOC_ID s2
3 Sunshine
update t1 set s1 = 1 where s1=3;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
DROP TABLE t2 , t1;
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) PRIMARY KEY,
b1 TEXT character set utf8 ,
FULLTEXT KEY (a1,b1)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT character set utf8 ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON DELETE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...'),
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
DELETE FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id2 a2 b2
SELECT * FROM t1 WHERE a1 LIKE '%tutorial%';
id1 a1 b1
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
SELECT * FROM t2 WHERE a2 LIKE '%tutorial%';
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
DROP TABLE t2 , t1;
DROP TABLE IF EXISTS t2,t1;
SET NAMES utf8;
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) ,
b1 TEXT ,
FULLTEXT KEY (a1,b1), PRIMARY KEY(a1, id1)
) CHARACTER SET = utf8 , ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON UPDATE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
START TRANSACTION;
INSERT INTO t1 (id1,a1,b1) VALUES
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE)
DELETE FROM t1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE)
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ;
id1 a1 b1
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial') ;
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id1 a1 b1
3 Optimizing MySQL In this tutorial we will show ...
2 How To Use MySQL Well After you went through a ...
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id2 a2 b2
3 Optimizing MySQL In this tutorial we will show ...
2 How To Use MySQL Well After you went through a ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial' WITH QUERY EXPANSION) ;
id1 a1 b1
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
2 How To Use MySQL Well After you went through a ...
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial' WITH QUERY EXPANSION) ;
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
2 How To Use MySQL Well After you went through a ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
id1 a1 b1
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('root') ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('root') ;
id2 a2 b2
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('mysqld (+root)' IN BOOLEAN MODE) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('mysqld (-root)' IN BOOLEAN MODE) ;
id2 a2 b2
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('root' WITH QUERY EXPANSION) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('root' WITH QUERY EXPANSION) ;
id2 a2 b2
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('"database comparison"@02' IN BOOLEAN MODE) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('"database comparison"@02' IN BOOLEAN MODE) ;
id2 a2 b2
SELECT * FROM t1;
id1 a1 b1
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
2 How To Use MySQL Well After you went through a ...
6 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
5 MySQL vs. YourSQL In the following database comparison ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t2;
id2 a2 b2
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
COMMIT;
START TRANSACTION;
UPDATE t1 SET a1 = "changing column - on UPDATE cascade" , b1 = "to check foreign constraint" WHERE
MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
COMMIT;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id1 a1 b1
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
id2 a2 b2
6 changing column - on UPDATE cascade When configured properly, MySQL ...
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('+UPDATE +cascade' IN BOOLEAN MODE) ;
id1 a1 b1
4 changing column - on UPDATE cascade to check foreign constraint
2 changing column - on UPDATE cascade to check foreign constraint
6 changing column - on UPDATE cascade to check foreign constraint
5 changing column - on UPDATE cascade to check foreign constraint
3 changing column - on UPDATE cascade to check foreign constraint
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('+UPDATE +cascade' IN BOOLEAN MODE) ;
id2 a2 b2
4 changing column - on UPDATE cascade 1. Never run mysqld as root. 2. ...
2 changing column - on UPDATE cascade After you went through a ...
6 changing column - on UPDATE cascade When configured properly, MySQL ...
5 changing column - on UPDATE cascade In the following database comparison ...
3 changing column - on UPDATE cascade In this tutorial we will show ...
SELECT * FROM t2 WHERE a2 LIKE '%UPDATE CASCADE%';
id2 a2 b2
2 changing column - on UPDATE cascade After you went through a ...
3 changing column - on UPDATE cascade In this tutorial we will show ...
4 changing column - on UPDATE cascade 1. Never run mysqld as root. 2. ...
5 changing column - on UPDATE cascade In the following database comparison ...
6 changing column - on UPDATE cascade When configured properly, MySQL ...
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
s1 s2
DROP TABLE t2 , t1;
set global innodb_file_format="Barracuda";
set global innodb_file_per_table=1;
set global innodb_large_prefix=1;
set names utf8;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = utf8, ROW_FORMAT=COMPRESSED, ENGINE = InnoDB;
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
ALTER TABLE t1 ADD FULLTEXT INDEX idx (a,b);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`a` varchar(200) DEFAULT NULL,
`b` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `idx` (`a`,`b`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED
INSERT INTO t1 (a,b) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
ANALYZE TABLE t1;
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
select * from t1 where MATCH(a,b) AGAINST("+tutorial +VÐƷWİ" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
select * from t1 where MATCH(a,b) AGAINST("+-VÐƷWİ" IN BOOLEAN MODE);
id a b
select * from t1 where MATCH(a,b) AGAINST("+Mysql +(tricks never)" IN BOOLEAN MODE);
id a b
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
select * from t1 where MATCH(a,b) AGAINST("+mysql -(tricks never)" IN BOOLEAN MODE);
id a b
6 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
5 MySQL vs. YourSQL In the following database comparison ...
select *, MATCH(a,b) AGAINST("mysql stands" IN BOOLEAN MODE) as x from t1;
id a b x
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ... 0.6055193543434143
2 How To Use MySQL Well After you went through a ... 0.000000001885928302414186
3 Optimizing MySQL In this tutorial we will show ... 0.000000001885928302414186
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ... 0.000000001885928302414186
5 MySQL vs. YourSQL In the following database comparison ... 0.000000001885928302414186
6 MySQL Security When configured properly, MySQL ... 0.000000003771856604828372
select * from t1 where MATCH a,b AGAINST ("+database* +VÐƷW*" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
select * from t1 where MATCH a,b AGAINST ('"security mysql"' IN BOOLEAN MODE);
id a b
select * from t1 where MATCH(a,b) AGAINST ("VÐƷWİ" WITH QUERY EXPANSION);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
2 How To Use MySQL Well After you went through a ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
ALTER TABLE t1 DROP INDEX idx;
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
select * from t1 where MATCH(a,b) AGAINST("+tutorial +VÐƷWİ" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
select * from t1 where MATCH(a,b) AGAINST("+dbms" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
select * from t1 where MATCH(a,b) AGAINST("+Mysql +(tricks never)" IN BOOLEAN MODE);
id a b
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
select * from t1 where MATCH(a,b) AGAINST("+mysql -(tricks never)" IN BOOLEAN MODE);
id a b
6 MySQL Security When configured properly, MySQL ...
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
5 MySQL vs. YourSQL In the following database comparison ...
select *, MATCH(a,b) AGAINST("mysql VÐƷWİ" IN BOOLEAN MODE) as x from t1;
id a b x
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ... 0.6055193543434143
2 How To Use MySQL Well After you went through a ... 0.000000001885928302414186
3 Optimizing MySQL In this tutorial we will show ... 0.000000001885928302414186
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ... 0.000000001885928302414186
5 MySQL vs. YourSQL In the following database comparison ... 0.000000001885928302414186
6 MySQL Security When configured properly, MySQL ... 0.000000003771856604828372
select * from t1 where MATCH a,b AGAINST ('"security mysql"' IN BOOLEAN MODE);
id a b
select * from t1 where MATCH(a,b) AGAINST ("VÐƷWİ" WITH QUERY EXPANSION);
id a b
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
3 Optimizing MySQL In this tutorial we will show ...
5 MySQL vs. YourSQL In the following database comparison ...
6 MySQL Security When configured properly, MySQL ...
2 How To Use MySQL Well After you went through a ...
4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ...
INSERT INTO t1 (a,b) VALUES ('test query expansion','for database ...');
INSERT INTO t1 (a,b) VALUES
('test proximity search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test proximity fts search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test more proximity fts search, test, more proximity and phrase',
'search, with proximity innodb');
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@2' IN BOOLEAN MODE);
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@1' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@3' IN BOOLEAN MODE);
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
10 test more proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"test proximity"@5' IN BOOLEAN MODE);
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
10 test more proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more test proximity"@2' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more test proximity"@3' IN BOOLEAN MODE);
id a b
10 test more proximity fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more fts proximity"@03' IN BOOLEAN MODE);
id a b
10 test more proximity fts search, test, more proximity and phrase search, with proximity innodb
UPDATE t1 SET a = UPPER(a) , b = UPPER(b) ;
UPDATE t1 SET a = UPPER(a) , b = LOWER(b) ;
select * from t1 where MATCH(a,b) AGAINST("+tutorial +dbms" IN BOOLEAN MODE);
id a b
1 MYSQL TUTORIAL dbms stands for database vðʒwi...
select * from t1 where MATCH(a,b) AGAINST("+VÐƷWİ" IN BOOLEAN MODE);
id a b
1 MYSQL TUTORIAL dbms stands for database vðʒwi...
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id a b
1 MYSQL TUTORIAL dbms stands for database vðʒwi...
3 OPTIMIZING MYSQL in this tutorial we will show ...
DELETE FROM t1 WHERE MATCH (a,b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DELETE FROM t1 WHERE MATCH (a,b) AGAINST ('"proximity search"@14' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id a b
SELECT * FROM t1;
id a b
2 HOW TO USE MYSQL WELL after you went through a ...
4 1001 MYSQL TRICKS 1. never run mysqld as root. 2. ...
5 MYSQL VS. YOURSQL in the following database comparison ...
6 MYSQL SECURITY when configured properly, mysql ...
7 TEST QUERY EXPANSION for database ...
DROP TABLE t1;
set names utf8;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = utf8, ENGINE=InnoDB;
INSERT INTO t1 (a,b) VALUES
('Я могу есть стекло', 'оно мне не вредит'),
('Мога да ям стъкло', 'то не ми вреди'),
('Μπορῶ νὰ φάω σπασμένα' ,'γυαλιὰ χωρὶς νὰ πάθω τίποτα'),
('Příliš žluťoučký kůň', 'úpěl ďábelské kódy'),
('Sævör grét', 'áðan því úlpan var ónýt'),
('うゐのおくやま','けふこえて'),
('いろはにほへど ちりぬる','あさきゆめみじ ゑひもせず');
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','request docteam@oraclehelp.com ...') ,
('Trial version','query performace @1255 minute on 2.1Hz Memory 2GB...') ,
('when To Use MySQL Well','for free faq mail@xyz.com ...');
CREATE FULLTEXT INDEX idx on t1 (a,b);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("вредит χωρὶς");
id a b
1 Я могу есть стекло оно мне не вредит
3 Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("оно" WITH QUERY EXPANSION);
id a b
1 Я могу есть стекло оно мне не вредит
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("вред*" IN BOOLEAN MODE);
id a b
1 Я могу есть стекло оно мне не вредит
2 Мога да ям стъкло то не ми вреди
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+γυαλιὰ +tutorial" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+tutorial +(Мога τίποτα)" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("ちりぬる" WITH QUERY EXPANSION);
id a b
7 いろはにほへど ちりぬる あさきゆめみじ ゑひもせず
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("+あさきゆめみじ +ゑひもせず" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("うゐのおく*" IN BOOLEAN MODE);
id a b
6 うゐのおくやま けふこえて
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
id a b
5 Sævör grét áðan því úlpan var ónýt
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"γυαλιὰ χωρὶς"@2' IN BOOLEAN MODE);
id a b
3 Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"query performace"@02' IN BOOLEAN MODE);
id a b
9 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"πάθω τίποτα"@2' IN BOOLEAN MODE);
id a b
3 Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"あさきゆめみじ ゑひもせず"@1' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"あさきゆめみじ ゑひもせず"@2' IN BOOLEAN MODE);
id a b
7 いろはにほへど ちりぬる あさきゆめみじ ゑひもせず
ALTER TABLE t1 DROP INDEX idx;
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
id a b
7 いろはにほへど ちりぬる あさきゆめみじ ゑひもせず
UPDATE t1 SET a = "Pchnąć w tę łódź jeża" , b = "lub osiem skrzyń fig" WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
UPDATE t1 SET a = "В чащах юга жил-был цитрус? Да", b = "но фальшивый экземпляр! ёъ" WHERE MATCH(a,b) AGAINST ("вред*" IN BOOLEAN MODE);
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("łódź osiem");
id a b
7 Pchnąć w tę łódź jeża lub osiem skrzyń fig
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("вред*" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("фальшив*" IN BOOLEAN MODE);
id a b
1 В чащах юга жил-был цитрус? Да но фальшивый экземпляр! ёъ
2 В чащах юга жил-был цитрус? Да но фальшивый экземпляр! ёъ
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"łódź jeża"@2' IN BOOLEAN MODE);
id a b
7 Pchnąć w tę łódź jeża lub osiem skrzyń fig
SELECT * FROM t1;
id a b
1 В чащах юга жил-был цитрус? Да но фальшивый экземпляр! ёъ
2 В чащах юга жил-был цитрус? Да но фальшивый экземпляр! ёъ
3 Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα
4 Příliš žluťoučký kůň úpěl ďábelské kódy
6 うゐのおくやま けふこえて
7 Pchnąć w tę łódź jeża lub osiem skrzyń fig
8 MySQL Tutorial request docteam@oraclehelp.com ...
9 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
10 when To Use MySQL Well for free faq mail@xyz.com ...
DROP TABLE t1;
CREATE TABLE t1(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
ID no_fts_field fts_field
1 AAA BBB
UPDATE t1 SET fts_field='anychange' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
ID no_fts_field fts_field
1 AAA anychange
UPDATE t1 SET no_fts_field='anychange' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
ID no_fts_field fts_field
1 anychange anychange
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
ID no_fts_field fts_field
1 anychange other
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
ID no_fts_field fts_field
DROP INDEX f on t1;
UPDATE t1 SET fts_field='anychange' where id = 1;
UPDATE t1 SET no_fts_field='anychange' where id = 1;
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where id = 1;
CREATE FULLTEXT INDEX f ON t1(FTS_FIELD);
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
ID no_fts_field fts_field
1 anychange other
DROP TABLE t1;
CREATE TABLE t1(`FTS_DOC_ID` serial,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
UPDATE t1 SET fts_field='anychange' where FTS_DOC_ID = 1;
ERROR HY000: Invalid InnoDB FTS Doc ID
UPDATE t1 SET fts_field='anychange', FTS_DOC_ID = 2 where FTS_DOC_ID = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
FTS_DOC_ID no_fts_field fts_field
2 AAA anychange
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
FTS_DOC_ID no_fts_field fts_field
UPDATE t1 SET no_fts_field='anychange' where FTS_DOC_ID = 2;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
FTS_DOC_ID no_fts_field fts_field
2 anychange anychange
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where FTS_DOC_ID = 2;
ERROR HY000: Invalid InnoDB FTS Doc ID
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
FTS_DOC_ID no_fts_field fts_field
UPDATE t1 SET FTS_DOC_ID = 1 where FTS_DOC_ID = 2;
ERROR HY000: Invalid InnoDB FTS Doc ID
DROP INDEX f ON t1;
UPDATE t1 SET fts_field='newchange' where FTS_DOC_ID = 2;
UPDATE t1 SET no_fts_field='anychange' where FTS_DOC_ID = 2;
SELECT * FROM t1;
FTS_DOC_ID no_fts_field fts_field
2 anychange newchange
DROP TABLE t1;
CREATE TABLE t1(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field), index k(fts_field)) ENGINE=INNODB;
CREATE TABLE t2(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field),
INDEX k2(fts_field),
FOREIGN KEY(fts_field) REFERENCES
t1(fts_field) ON UPDATE CASCADE) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
INSERT INTO t2 VALUES (1, 'AAA', 'BBB');
update t1 set fts_field='newchange' where id =1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
ID no_fts_field fts_field
SELECT * FROM t2 WHERE MATCH(fts_field) against("BBB");
ID no_fts_field fts_field
SELECT * FROM t1 WHERE MATCH(fts_field) against("newchange");
ID no_fts_field fts_field
1 AAA newchange
SELECT * FROM t2 WHERE MATCH(fts_field) against("newchange");
ID no_fts_field fts_field
1 AAA newchange
DROP TABLE t2;
DROP TABLE t1;
CREATE TABLE t1(id INT PRIMARY KEY,
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
CREATE TABLE t2(id INT PRIMARY KEY,
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 values (1,'100'),(2,'200'),(3,'300'),(4,'400'),(5,'500'),(6,'600'), (7,'700'),(8,'800'),(9,'900'),(10,'1000'),(11,'1100'),(12,'1200');
INSERT INTO t2 values (1,'100'),(2,'200'),(3,'300'),(4,'400'),(5,'500'),(6,'600'), (7,'700'),(8,'800');
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'foo');
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'foo') WHERE t1.fts_field = "100foo";
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'xoo'), t2.fts_field = CONCAT(t1.fts_field, 'xoo') where t1.fts_field=CONCAT(t2.fts_field, 'foo');
SELECT * FROM t1 WHERE MATCH(fts_field) against("100foofoo");
id fts_field
1 100foofoo
SELECT * FROM t1 WHERE MATCH(fts_field) against("100foo");
id fts_field
SELECT * FROM t1 WHERE MATCH(fts_field) against("100");
id fts_field
SELECT * FROM t2 WHERE MATCH(fts_field) against("400fooxoo");
id fts_field
4 400fooxoo
SELECT * FROM t2 WHERE MATCH(fts_field) against("100");
id fts_field
1 100
SELECT * FROM t2 WHERE MATCH(fts_field) against("200");
id fts_field
SELECT * FROM t2 WHERE MATCH(fts_field) against("400");
id fts_field
DROP TABLE t1;
DROP TABLE t2;
BUG#13701973/64274: MYSQL THREAD WAS SUSPENDED WHEN EXECUTE UPDATE QUERY
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
CREATE TABLE t1 (
t1_id INT(10) UNSIGNED NOT NULL,
t2_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (t1_id),
FOREIGN KEY (t2_id) REFERENCES t2 (t2_id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
CREATE TABLE t2 (
t1_id INT(10) UNSIGNED NOT NULL,
t2_id INT(10) UNSIGNED NOT NULL,
t3_id INT(10) UNSIGNED NOT NULL,
t4_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (t2_id),
FOREIGN KEY (t1_id) REFERENCES t1 (t1_id),
FOREIGN KEY (t3_id) REFERENCES t3 (t3_id)
ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (t4_id) REFERENCES t4 (t4_id)
) ENGINE=InnoDB;
CREATE TABLE t3 (
t3_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
payload char(3),
PRIMARY KEY (t3_id)
) ENGINE=InnoDB;
INSERT INTO t3 VALUES (1, '100');
CREATE TABLE t4 (
t2_id INT(10) UNSIGNED DEFAULT NULL,
t4_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (t4_id),
FOREIGN KEY (t2_id) REFERENCES t2 (t2_id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
SET FOREIGN_KEY_CHECKS=1;
UPDATE t3 SET payload='101' WHERE t3_id=1;
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

View File

@ -0,0 +1,96 @@
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
DROP INDEX title ON articles;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
BEGIN;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...');
SET SESSION debug_dbug="+d,crash_commit_before";
COMMIT;
ERROR HY000: Lost connection to MySQL server during query
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...');
CREATE FULLTEXT INDEX idx ON articles (title,body);
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
5 MySQL vs. YourSQL In the following database comparison ...
7 MySQL Tutorial DBMS stands for DataBase ...
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
BEGIN;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...');
SET SESSION debug_dbug="+d,crash_commit_before";
COMMIT;
ERROR HY000: Lost connection to MySQL server during query
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...');
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
id title body
1 MySQL Tutorial DBMS stands for DataBase ...
5 MySQL vs. YourSQL In the following database comparison ...
7 MySQL Tutorial DBMS stands for DataBase ...
8 MySQL Tutorial DBMS stands for DataBase ...
12 MySQL vs. YourSQL In the following database comparison ...
14 MySQL Tutorial DBMS stands for DataBase ...
DROP TABLE articles;
CREATE TABLE articles (
id int PRIMARY KEY,
FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
CREATE FULLTEXT INDEX idx1 on articles (title, body);
INSERT INTO articles VALUES
(1, 10, 'MySQL Tutorial','DBMS stands for DataBase ...') ,
(2, 1, 'How To Use MySQL Well','After you went through a ...'),
(3, 2, 'Optimizing MySQL','In this tutorial we will show ...'),
(4, 11, '1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5, 6, 'MySQL vs. YourSQL','In the following database comparison ...'),
(7, 4, 'MySQL Security','When configured properly, MySQL ...');
BEGIN;
INSERT INTO articles VALUES
(100, 200, 'MySQL Tutorial','DBMS stands for DataBase ...');
SET SESSION debug_dbug="+d,crash_commit_before";
COMMIT;
ERROR HY000: Lost connection to MySQL server during query
INSERT INTO articles VALUES (8, 12, 'MySQL Tutorial','DBMS stands for DataBase ...');
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id FTS_DOC_ID title body
3 2 Optimizing MySQL In this tutorial we will show ...
1 10 MySQL Tutorial DBMS stands for DataBase ...
8 12 MySQL Tutorial DBMS stands for DataBase ...
DROP TABLE articles;
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
SET SESSION debug_dbug="+d,ib_dict_create_index_tree_fail";
CREATE FULLTEXT INDEX idx ON articles(body);
ERROR HY000: Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use 'ulimit' to allow mysqld to use more memory or you can add more swap space
SET SESSION debug_dbug="-d,ib_dict_create_index_tree_fail";
ALTER TABLE articles STATS_PERSISTENT=DEFAULT;
DROP TABLE articles;

View File

@ -0,0 +1,213 @@
drop table if exists t1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) ENGINE = InnoDB STATS_PERSISTENT=0;
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
ALTER TABLE t1 ADD FULLTEXT INDEX idx_1 (a);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
ALTER TABLE t1 ADD FULLTEXT INDEX idx_2 (b);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`a` varchar(200) DEFAULT NULL,
`b` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `idx_1` (`a`),
FULLTEXT KEY `idx_2` (`b`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 STATS_PERSISTENT=0
START TRANSACTION;
INSERT INTO t1 (a,b) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
ROLLBACK;
SELECT * FROM t1 WHERE MATCH (a)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(a) AGAINST("+mysql +Tutorial" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(b) AGAINST("+Tutorial" IN BOOLEAN MODE);
id a b
3 Optimizing MySQL In this tutorial we will show ...
select * from t1 where MATCH(b) AGAINST("+stands +(DataBase)" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(b) AGAINST("+DataBase -(comparison)" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select *, MATCH(a) AGAINST("Optimizing MySQL" IN BOOLEAN MODE) as x from t1;
id a b x
1 MySQL Tutorial DBMS stands for DataBase ... 0.0906190574169159
2 How To Use MySQL Well After you went through a ... 0.0906190574169159
3 Optimizing MySQL In this tutorial we will show ... 0.6961383819580078
select *, MATCH(b) AGAINST("collections support" IN BOOLEAN MODE) as x from t1;
id a b x
1 MySQL Tutorial DBMS stands for DataBase ... 0
2 How To Use MySQL Well After you went through a ... 0
3 Optimizing MySQL In this tutorial we will show ... 0
select * from t1 where MATCH a AGAINST ("+Optimiz* +Optimiz*" IN BOOLEAN MODE);
id a b
3 Optimizing MySQL In this tutorial we will show ...
select * from t1 where MATCH b AGAINST ('"DBMS stands"' IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH b AGAINST ('"DBMS STANDS"' IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(b) AGAINST ("DataBase" WITH QUERY EXPANSION);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(a) AGAINST ("Security" WITH QUERY EXPANSION);
id a b
ALTER TABLE t1 DROP INDEX idx_1;
ALTER TABLE t1 DROP INDEX idx_2;
ALTER TABLE t1 ADD FULLTEXT INDEX idx_1 (a);
ALTER TABLE t1 ADD FULLTEXT INDEX idx_2 (b);
SELECT * FROM t1 WHERE MATCH (a)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(a) AGAINST("+mysql +Tutorial" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(b) AGAINST("+Tutorial" IN BOOLEAN MODE);
id a b
3 Optimizing MySQL In this tutorial we will show ...
select * from t1 where MATCH(b) AGAINST("+stands +(DataBase)" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(b) AGAINST("+DataBase -(comparison)" IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select *, MATCH(a) AGAINST("Optimizing MySQL" IN BOOLEAN MODE) as x from t1;
id a b x
1 MySQL Tutorial DBMS stands for DataBase ... 0.0906190574169159
2 How To Use MySQL Well After you went through a ... 0.0906190574169159
3 Optimizing MySQL In this tutorial we will show ... 0.6961383819580078
select *, MATCH(b) AGAINST("collections support" IN BOOLEAN MODE) as x from t1;
id a b x
1 MySQL Tutorial DBMS stands for DataBase ... 0
2 How To Use MySQL Well After you went through a ... 0
3 Optimizing MySQL In this tutorial we will show ... 0
select * from t1 where MATCH a AGAINST ("+Optimiz* +Optimiz*" IN BOOLEAN MODE);
id a b
3 Optimizing MySQL In this tutorial we will show ...
select * from t1 where MATCH b AGAINST ('"DBMS stands"' IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH b AGAINST ('"DBMS STANDS"' IN BOOLEAN MODE);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(b) AGAINST ("DataBase" WITH QUERY EXPANSION);
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
select * from t1 where MATCH(a) AGAINST ("Security" WITH QUERY EXPANSION);
id a b
INSERT INTO t1 (a,b) VALUES ('test query expansion','for database ...');
INSERT INTO t1 (a,b) VALUES
('test proximity search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test proximity fts search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test more of proximity for fts search, test, more proximity and phrase',
'search, with proximity innodb');
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"proximity search"@3' IN BOOLEAN MODE);
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"proximity search"@2' IN BOOLEAN MODE);
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (b)
AGAINST ('"proximity innodb"@4' IN BOOLEAN MODE);
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
10 test more of proximity for fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"test proximity"@3' IN BOOLEAN MODE);
id a b
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
10 test more of proximity for fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"more test proximity"@3' IN BOOLEAN MODE);
id a b
10 test more of proximity for fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"more test proximity"@2' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"more fts proximity"@02' IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE CONCAT(t1.a,t1.b) IN (
SELECT CONCAT(a,b) FROM t1 AS t2 WHERE
MATCH (t2.a) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)
) OR t1.id = 3 ;
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t1 WHERE CONCAT(t1.a,t1.b) IN (
SELECT CONCAT(a,b) FROM t1 AS t2
WHERE MATCH (t2.a) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)
AND t2.id != 3) ;
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
SELECT * FROM t1 WHERE id IN (SELECT MIN(id) FROM t1 WHERE
MATCH (b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)) OR id = 3 ;
id a b
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t1 WHERE id NOT IN (SELECT MIN(id) FROM t1
WHERE MATCH (b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)) ;
id a b
1 MySQL Tutorial DBMS stands for DataBase ...
2 How To Use MySQL Well After you went through a ...
7 test query expansion for database ...
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
10 test more of proximity for fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1 WHERE EXISTS (SELECT t2.id FROM t1 AS t2 WHERE
MATCH (t2.b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)
AND t1.id = t2.id) ;
id a b
3 Optimizing MySQL In this tutorial we will show ...
SELECT * FROM t1 WHERE NOT EXISTS (SELECT t2.id FROM t1 AS t2 WHERE
MATCH (t2.a) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)
AND t1.id = t2.id) ;
id a b
2 How To Use MySQL Well After you went through a ...
3 Optimizing MySQL In this tutorial we will show ...
7 test query expansion for database ...
8 test proximity search, test, proximity and phrase search, with proximity innodb
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
10 test more of proximity for fts search, test, more proximity and phrase search, with proximity innodb
SELECT * FROM t1 WHERE t1.id = (SELECT MAX(t2.id) FROM t1 AS t2 WHERE
MATCH(t2.a) AGAINST ('"proximity search"@3' IN BOOLEAN MODE));
id a b
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
SELECT * FROM t1 WHERE t1.id > (SELECT MIN(t2.id) FROM t1 AS t2 WHERE
MATCH(t2.b) AGAINST ('"proximity innodb"@3' IN BOOLEAN MODE));
id a b
9 test proximity fts search, test, proximity and phrase search, with proximity innodb
10 test more of proximity for fts search, test, more proximity and phrase search, with proximity innodb
DROP TABLE t1;

View File

@ -0,0 +1,228 @@
drop table if exists t1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) ENGINE= InnoDB;
CREATE FULLTEXT INDEX idx on t1 (a,b);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
INSERT INTO t1 (a,b) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...');
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("where will");
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("when");
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("what" WITH QUERY EXPANSION);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("whe*" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+what +will" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+from" IN BOOLEAN MODE);
id a b
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+where +(show what)" IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"where will"@6' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"where will"@9' IN BOOLEAN MODE);
id a b
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','request docteam@oraclehelp.com ...') ,
('Trial version','query performace @1255 minute on 2.1Hz Memory 2GB...') ,
('when To Use MySQL Well','for free faq mail@xyz.com ...');
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"request"@10' IN BOOLEAN MODE);
id a b
4 MySQL Tutorial request docteam@oraclehelp.com ...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"Trial version"@0' IN BOOLEAN MODE);
id a b
5 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"request docteam@oraclehelp.com"@10' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"1255 minute"@1' IN BOOLEAN MODE);
id a b
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"1255 minute"@2' IN BOOLEAN MODE);
id a b
5 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"1255"@10' IN BOOLEAN MODE);
id a b
5 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('1255' WITH QUERY EXPANSION);
id a b
5 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"request docteam"@2' IN BOOLEAN MODE);
id a b
4 MySQL Tutorial request docteam@oraclehelp.com ...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"1255 minute"' IN BOOLEAN MODE);
id a b
5 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('request docteam@oraclehelp.com');
id a b
4 MySQL Tutorial request docteam@oraclehelp.com ...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"MySQL request"@3' IN BOOLEAN MODE);
id a b
4 MySQL Tutorial request docteam@oraclehelp.com ...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"Trial memory"@10' IN BOOLEAN MODE);
id a b
5 Trial version query performace @1255 minute on 2.1Hz Memory 2GB...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"Trial memory"@9' IN BOOLEAN MODE);
id a b
DROP TABLE t1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = UTF8, ENGINE= InnoDB;
INSERT INTO t1 (a,b) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...');
CREATE FULLTEXT INDEX idx on t1 (a,b);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','request docteam@oraclehelp.com ...') ,
('Trial version','query performace @1255 minute on 2.1Hz Memory 2GB...'),
('when To Use MySQL Well','for free faq mail@xyz.com ...');
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"mysql use"@2' IN BOOLEAN MODE);
id a b
2 when To Use MySQL Well After that you went through a ...
6 when To Use MySQL Well for free faq mail@xyz.com ...
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"mysql use"@1' IN BOOLEAN MODE);
id a b
INSERT INTO t1 (a,b) VALUES ('XYZ, long blob', repeat("a", 9000));
INSERT INTO t1 (a,b) VALUES (repeat("b", 9000), 'XYZ, long blob');
Warnings:
Warning 1265 Data truncated for column 'a' at row 1
SELECT count(*) FROM t1
WHERE MATCH (a,b)
AGAINST ('"xyz blob"@3' IN BOOLEAN MODE);
count(*)
2
DROP TABLE t1;
set global innodb_file_format="Barracuda";
set global innodb_file_per_table=1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT,
c TEXT
) CHARACTER SET = UTF8, ROW_FORMAT=DYNAMIC, ENGINE= InnoDB;
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000), 'XYZ, long text', 'very long blob');
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000), 'XYZ, very little long blob very much blob', 'very long blob');
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000),"very 租车 供 blob","new 供需分析information");
CREATE FULLTEXT INDEX idx on t1 (a,b,c);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
INSERT INTO t1 (a,b,c) VALUES (repeat("x", 19000), 'new, long text', 'very new blob');
INSERT INTO t1 (a,b,c) VALUES ('interesting, long text', repeat("x", 19000), 'very very good new blob');
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@3' IN BOOLEAN MODE);
count(*)
3
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very long blob"@0' IN BOOLEAN MODE);
count(*)
2
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@4' IN BOOLEAN MODE);
count(*)
4
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"interesting blob"@9' IN BOOLEAN MODE);
count(*)
1
SELECT COUNT(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"interesting blob"@9 "very long blob"@0' IN BOOLEAN MODE);
COUNT(*)
3
SELECT COUNT(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@4 - "interesting blob"@9' IN BOOLEAN MODE);
COUNT(*)
3
DROP TABLE t1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = UTF8, ENGINE= InnoDB;
INSERT INTO t1 (a,b) VALUES
('MySQL from Tutorial','DBMS stands for + DataBase ...');
CREATE FULLTEXT INDEX idx on t1 (a,b);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"stands database"@3' IN BOOLEAN MODE);
id a b
1 MySQL from Tutorial DBMS stands for + DataBase ...
DROP TABLE t1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT,
c TEXT
) CHARACTER SET = UTF8, ROW_FORMAT=DYNAMIC, ENGINE= InnoDB;
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000), 'XYZ, long text', 'very long blob');
INSERT INTO t1 (a,b,c) VALUES ('XYZ, 租车 very little long blob very much blob', repeat("b", 19000), 'very long but smaller blob');
CREATE FULLTEXT INDEX idx on t1 (a,b,c);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
DELETE FROM t1;
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000), 'XYZ, long text', 'very long blob');
INSERT INTO t1 (a,b,c) VALUES ('XYZ, 租车 very little long blob is a very much longer blob', repeat("b", 19000), 'this is very long but smaller blob');
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@4' IN BOOLEAN MODE);
count(*)
2
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@3' IN BOOLEAN MODE);
count(*)
1
DROP TABLE t1;
SET GLOBAL innodb_file_format=Antelope;
SET GLOBAL innodb_file_per_table=1;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,678 @@
#
# Test of fulltext index
#
--source include/have_innodb.inc
--disable_warnings
drop table if exists t1,t2,t3;
--enable_warnings
CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('MySQL has now support', 'for full-text search'),
('Full-text indexes', 'are called collections'),
('Only MyISAM tables','support collections'),
('Function MATCH ... AGAINST()','is used to do a search'),
('Full-text search in MySQL', 'implements vector space model');
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
SHOW INDEX FROM t1;
# nl search
select * from t1 where MATCH(a,b) AGAINST ("collections");
explain extended select * from t1 where MATCH(a,b) AGAINST ("collections");
select * from t1 where MATCH(a,b) AGAINST ("indexes");
select * from t1 where MATCH(a,b) AGAINST ("indexes collections");
select * from t1 where MATCH(a,b) AGAINST ("only");
# query expansion
select * from t1 where MATCH(a,b) AGAINST ("collections" WITH QUERY EXPANSION);
select * from t1 where MATCH(a,b) AGAINST ("indexes" WITH QUERY EXPANSION);
select * from t1 where MATCH(a,b) AGAINST ("indexes collections" WITH QUERY EXPANSION);
# IN NATURAL LANGUAGE MODE
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN NATURAL LANGUAGE MODE);
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION);
--error 1064
select * from t1 where MATCH(a,b) AGAINST ("indexes" IN BOOLEAN MODE WITH QUERY EXPANSION);
# add_ft_keys() tests
explain select * from t1 where MATCH(a,b) AGAINST ("collections");
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>0;
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>1;
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>=0;
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>=1;
explain select * from t1 where 0<MATCH(a,b) AGAINST ("collections");
explain select * from t1 where 1<MATCH(a,b) AGAINST ("collections");
explain select * from t1 where 0<=MATCH(a,b) AGAINST ("collections");
explain select * from t1 where 1<=MATCH(a,b) AGAINST ("collections");
explain select * from t1 where MATCH(a,b) AGAINST ("collections")>0 and a like '%ll%';
# boolean search
select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE);
explain extended select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("support collections" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("support +collections" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("sear*" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+support +collections" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+search" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+search +(support vector)" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+search -(support vector)" IN BOOLEAN MODE);
select *, MATCH(a,b) AGAINST("support collections" IN BOOLEAN MODE) as x from t1;
select *, MATCH(a,b) AGAINST("collections support" IN BOOLEAN MODE) as x from t1;
select * from t1 where MATCH a,b AGAINST ("+call* +coll*" IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"support now"' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"Now sUPPort"' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"now support"' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"text search" "now support"' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"text search" -"now support"' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"text search" +"now support"' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"text i"' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"xt indexes"' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('+(support collections) +foobar*' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('+(+(support collections)) +foobar*' IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('+collections -supp* -foobar*' IN BOOLEAN MODE);
# bug#2708, bug#3870 crash
select * from t1 where MATCH a,b AGAINST('"space model' IN BOOLEAN MODE);
# INNODB_FTS: No FTS index on column a or b. InnoDB do now support
# FT type search when there is no FTS INDEX
# select * from t1 where MATCH a AGAINST ("search" IN BOOLEAN MODE);
# select * from t1 where MATCH b AGAINST ("sear*" IN BOOLEAN MODE);
# UNION of fulltext's
#select * from t1 where MATCH(a,b) AGAINST ("collections") UNION ALL select * from t1 where MATCH(a,b) AGAINST ("indexes");
#update/delete with fulltext index
delete from t1 where a like "MySQL%";
update t1 set a='some test foobar' where MATCH a,b AGAINST ('model');
delete from t1 where MATCH(a,b) AGAINST ("indexes");
select * from t1;
drop table t1;
#
# why to scan strings for trunc*
#
create table t1 (a varchar(200) not null, fulltext (a)) engine = innodb;
insert t1 values ("aaa10 bbb20"), ("aaa20 bbb15"), ("aaa30 bbb10");
select * from t1 where match a against ("+aaa* +bbb*" in boolean mode);
select * from t1 where match a against ("+aaa* +bbb1*" in boolean mode);
select * from t1 where match a against ("+aaa* +ccc*" in boolean mode);
select * from t1 where match a against ("+aaa10 +(bbb*)" in boolean mode);
# FTS_INNODB: INVESTIGATE
select * from t1 where match a against ("+(+aaa* +bbb1*)" in boolean mode);
select * from t1 where match a against ("(+aaa* +bbb1*)" in boolean mode);
drop table t1;
#
# Check bug reported by Matthias Urlichs
#
CREATE TABLE t1 (
id int(11),
ticket int(11),
KEY ti (id),
KEY tit (ticket)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES (2,3),(1,2);
CREATE TABLE t2 (
ticket int(11),
inhalt text,
KEY tig (ticket),
fulltext index tix (inhalt)
) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1,'foo'),(2,'bar'),(3,'foobar');
#select t1.id FROM t2 as ttxt,t1,t1 as ticket2
#WHERE ticket2.id = ttxt.ticket AND t1.id = ticket2.ticket and
#match(ttxt.inhalt) against ('foobar');
# In the following query MySQL didn't use the fulltext index
#select ticket2.id FROM t2 as ttxt,t2 INNER JOIN t1 as ticket2 ON
#ticket2.id = t2.ticket
#WHERE ticket2.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar');
INSERT INTO t1 VALUES (3,3);
-- disable_result_log
ANALYZE TABLE t1;
ANALYZE TABLE t2;
-- enable_result_log
select ticket2.id FROM t2 as ttxt,t2
INNER JOIN t1 as ticket2 ON ticket2.id = t2.ticket
WHERE ticket2.id = ticket2.ticket and
match(ttxt.inhalt) against ('foobar');
# Check that we get 'fulltext' index in SHOW CREATE
show keys from t2;
show create table t2;
# check for bug reported by Stephan Skusa
select * from t2 where MATCH inhalt AGAINST (NULL);
# MATCH in HAVING (pretty useless, but still it should work)
select * from t2 where MATCH inhalt AGAINST ('foobar');
# INNODB_FTS: INVESTIGATE
select * from t2 having MATCH inhalt AGAINST ('foobar');
#
# check of fulltext errors
#
--error 1283
CREATE TABLE t3 (t int(11),i text,fulltext tix (t,i));
--error 1283
CREATE TABLE t3 (t int(11),i text,
j varchar(200) CHARACTER SET latin2,
fulltext tix (i,j));
CREATE TABLE t3 (
ticket int(11),
inhalt text,
KEY tig (ticket),
fulltext index tix (inhalt)
) ENGINE = InnoDB;
--error 1210
select * from t2 where MATCH inhalt AGAINST (t2.inhalt);
--error 1191
select * from t2 where MATCH ticket AGAINST ('foobar');
--error 1210
select * from t2,t3 where MATCH (t2.inhalt,t3.inhalt) AGAINST ('foobar');
drop table t1,t2,t3;
#
# three more bugtests
#
CREATE TABLE t1 (
id int(11) auto_increment,
title varchar(100) default '',
PRIMARY KEY (id),
KEY ind5 (title)
) ENGINE = InnoDB;
CREATE FULLTEXT INDEX ft1 ON t1(title);
insert into t1 (title) values ('this is a test');
select * from t1 where match title against ('test' in boolean mode);
update t1 set title='this is A test' where id=1;
check table t1;
update t1 set title='this test once revealed a bug' where id=1;
select * from t1;
update t1 set title=NULL where id=1;
drop table t1;
# one more bug - const_table related
CREATE TABLE t1 (a int(11), b text, FULLTEXT KEY (b)) ENGINE = InnoDB;
insert into t1 values (1,"I wonder why the fulltext index doesnt work?");
SELECT * from t1 where MATCH (b) AGAINST ('apples');
insert into t1 values (2,"fullaaa fullzzz");
select * from t1 where match b against ('full*' in boolean mode);
drop table t1;
CREATE TABLE t1 ( id int(11) NOT NULL auto_increment primary key, mytext text NOT NULL, FULLTEXT KEY mytext (mytext)) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1,'my small mouse'),(2,'la-la-la'),(3,'It is so funny'),(4,'MySQL Tutorial');
select 8 from t1;
drop table t1;
#
# Check bug reported by Julian Ladisch
# ERROR 1030: Got error 127 from table handler
#
create table t1 (a text, fulltext key (a)) ENGINE = InnoDB;
insert into t1 values ('aaaa');
# INNODB_FTS: InnoDB do not support "repair" command
# repair table t1;
select * from t1 where match (a) against ('aaaa');
drop table t1;
#
# bug #283 by jocelyn fournier <joc@presence-pc.com>
# FULLTEXT index on a TEXT filed converted to a CHAR field doesn't work anymore
#
create table t1 ( ref_mag text not null, fulltext (ref_mag)) ENGINE = InnoDB;
insert into t1 values ('test');
select ref_mag from t1 where match ref_mag against ('+test' in boolean mode);
alter table t1 change ref_mag ref_mag char (255) not null;
select ref_mag from t1 where match ref_mag against ('+test' in boolean mode);
drop table t1;
#
# bug #942: JOIN
# NOTE: Not related to FTS, no FTS index created
create table t1 (t1_id int(11) primary key, name varchar(32)) ENGINE = InnoDB;
insert into t1 values (1, 'data1');
insert into t1 values (2, 'data2');
create table t2 (t2_id int(11) primary key, t1_id int(11), name varchar(32)) ENGINE = InnoDB;
insert into t2 values (1, 1, 'xxfoo');
insert into t2 values (2, 1, 'xxbar');
insert into t2 values (3, 1, 'xxbuz');
# INNODB_FTS: Note there is no fulltext index on table. InnoDB do not support
# Fulltext search in such case, will return 1739
--error ER_TABLE_HAS_NO_FT
select * from t1 join t2 using(`t1_id`) where match (t1.name, t2.name) against('xxfoo' in boolean mode);
#
# Bug #7858: bug with many short (< ft_min_word_len) words in boolean search
#
# INNODB_FTS: Note there is no fulltext index on table. InnoDB do not support
# Fulltext search in such case, will return 1739
--error ER_TABLE_HAS_NO_FT
select * from t2 where match name against ('*a*b*c*d*e*f*' in boolean mode);
drop table t1,t2;
#
# bug with repair-by-sort and incorrect records estimation
#
create table t1 (a text, fulltext key (a)) ENGINE = InnoDB;
insert into t1 select "xxxx yyyy zzzz";
drop table t1;
#
# UTF8
# INNODB_FTS: Charset Support (FIX)
SET NAMES latin1;
CREATE TABLE t1 (t text character set utf8 not null, fulltext(t)) ENGINE = InnoDB;
INSERT t1 VALUES ('Mit freundlichem Grüß'), ('aus Osnabrück');
SET NAMES koi8r;
INSERT t1 VALUES ("üÔÏ ÍÙ - ÏÐÉÌËÉ"),("ïÔÌÅÚØ, ÇÎÉÄÁ!"),
("îÅ ×ÌÅÚÁÊ, ÕÂØÅÔ!"),("É ÂÕÄÅÔ ÐÒÁ×!");
SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('ïðéìëé');
#SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('ðÒá*' IN BOOLEAN MODE);
#SELECT * FROM t1 WHERE MATCH t AGAINST ('ÜÔÏ' IN BOOLEAN MODE);
#SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabrück');
#SET NAMES latin1;
#SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabrück');
#SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabrueck');
#SELECT t, collation(t),FORMAT(MATCH t AGAINST ('Osnabruck'),6) FROM t1 WHERE MATCH t AGAINST ('Osnabruck');
#alter table t1 modify t text character set latin1 collate latin1_german2_ci not null;
#alter table t1 modify t varchar(200) collate latin1_german2_ci not null;
#SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabrück');
#SELECT t, collation(t) FROM t1 WHERE MATCH t AGAINST ('Osnabrueck');
DROP TABLE t1;
#
# bug#3964
#
CREATE TABLE t1 (s varchar(255), FULLTEXT (s)) ENGINE = InnoDB DEFAULT CHARSET=utf8;
insert into t1 (s) values ('pära para para'),('para para para');
select * from t1 where match(s) against('para' in boolean mode);
select * from t1 where match(s) against('par*' in boolean mode);
DROP TABLE t1;
#
# icc -ip bug (ip = interprocedural optimization)
# bug#5528
#
CREATE TABLE t1 (h text, FULLTEXT (h)) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('Jesses Hasse Ling and his syncopators of Swing');
# INNODB_FTS: InnoDB do not support "repair" command
# REPAIR TABLE t1;
select count(*) from t1;
drop table t1;
#
# testing out of bounds memory access in ft_nlq_find_relevance()
# (bug#8522); visible in valgrind.
#
CREATE TABLE t1 ( a TEXT, FULLTEXT (a) ) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('testing ft_nlq_find_relevance');
SELECT MATCH(a) AGAINST ('nosuchword') FROM t1;
DROP TABLE t1;
#
# bug#6784
# mi_flush_bulk_insert (on dup key error in mi_write)
# was mangling info->dupp_key_pos
#
create table t1 (a int primary key, b text, fulltext(b)) ENGINE = InnoDB;
create table t2 (a int, b text) ENGINE = InnoDB;
insert t1 values (1, "aaaa"), (2, "bbbb");
insert t2 values (10, "aaaa"), (2, "cccc");
replace t1 select * from t2;
drop table t1, t2;
#
# bug#8351
#
# INNODB_FTS: Charset Support
CREATE TABLE t1 (t VARCHAR(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci, FULLTEXT (t)) ENGINE = InnoDB;
SET NAMES latin1;
INSERT INTO t1 VALUES('Mit freundlichem Grüß aus Osnabrück');
SELECT COUNT(*) FROM t1 WHERE MATCH(t) AGAINST ('"osnabrück"' IN BOOLEAN MODE);
DROP TABLE t1;
#
# BUG#11684 - repair crashes mysql when table has fulltext index
#
CREATE TABLE t1 (a VARCHAR(30), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb');
# INNODB_FTS: InnoDB do not support repair
#SET myisam_repair_threads=2;
#REPAIR TABLE t1;
#SET myisam_repair_threads=@@global.myisam_repair_threads;
#
# BUG#5686 - #1034 - Incorrect key file for table - only utf8
#
INSERT INTO t1 VALUES('testword\'\'');
SELECT a FROM t1 WHERE MATCH a AGAINST('testword' IN BOOLEAN MODE);
SELECT a FROM t1 WHERE MATCH a AGAINST('testword\'\'' IN BOOLEAN MODE);
#
# BUG#14194: Problem with fulltext boolean search and apostrophe
#
# INNODB_FTS: Add "apostrophe" support
INSERT INTO t1 VALUES('test\'s');
SELECT a FROM t1 WHERE MATCH a AGAINST('test' IN BOOLEAN MODE);
DROP TABLE t1;
#
# BUG#13835: max key length is 1000 bytes when trying to create
# a fulltext index
#
CREATE TABLE t1 (a VARCHAR(10000), FULLTEXT(a)) ENGINE = InnoDB;
SHOW CREATE TABLE t1;
DROP TABLE t1;
#
# BUG#14496: Crash or strange results with prepared statement,
# MATCH and FULLTEXT
#
CREATE TABLE t1 (a TEXT, FULLTEXT KEY(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('test'),('test1'),('test');
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
PREPARE stmt from "SELECT a, FORMAT(MATCH(a) AGAINST('test1 test'),6) FROM t1 WHERE MATCH(a) AGAINST('test1 test')";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
#
# BUG#25951 - ignore/use index does not work with fulltext
#
CREATE TABLE t1 (a VARCHAR(255), FULLTEXT(a)) ENGINE = InnoDB;
SELECT * FROM t1 IGNORE INDEX(a) WHERE MATCH(a) AGAINST('test');
# INNODB_FTS: InnoDB do have have this option (disable keys)
# ALTER TABLE t1 DISABLE KEYS;
# --error 1191
SELECT * FROM t1 WHERE MATCH(a) AGAINST('test');
DROP TABLE t1;
#
# BUG#11392 - fulltext search bug
#
CREATE TABLE t1(a TEXT, fulltext(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES(' aaaaa aaaa');
SELECT * FROM t1 WHERE MATCH(a) AGAINST ('"aaaa"' IN BOOLEAN MODE);
DROP TABLE t1;
#
# BUG#29445 - match ... against () never returns
#
CREATE TABLE t1(a VARCHAR(20), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('Offside'),('City Of God');
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city of*' IN BOOLEAN MODE);
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city (of*)' IN BOOLEAN MODE);
SELECT a FROM t1 WHERE MATCH a AGAINST ('+city* of*' IN BOOLEAN MODE);
DROP TABLE t1;
# End of 4.1 tests
#
# bug#34374 - mysql generates incorrect warning
#
create table t1(a text,b date,fulltext index(a)) ENGINE = InnoDB;
insert into t1 set a='water',b='2008-08-04';
select 1 from t1 where match(a) against ('water' in boolean mode) and b>='2008-08-01';
drop table t1;
show warnings;
#
# BUG#38842 - Fix for 25951 seems incorrect
#
CREATE TABLE t1 (a VARCHAR(255), b INT, FULLTEXT(a), KEY(b)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('test', 1),('test', 1),('test', 1),('test', 1),
('test', 1),('test', 2),('test', 3),('test', 4);
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
EXPLAIN SELECT * FROM t1
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
EXPLAIN SELECT * FROM t1 USE INDEX(a)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
EXPLAIN SELECT * FROM t1 FORCE INDEX(a)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
EXPLAIN SELECT * FROM t1 IGNORE INDEX(a)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
EXPLAIN SELECT * FROM t1 USE INDEX(b)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
EXPLAIN SELECT * FROM t1 FORCE INDEX(b)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
DROP TABLE t1;
#
# BUG#37245 - Full text search problem
#
CREATE TABLE t1(a CHAR(10), fulltext(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('aaa15');
SELECT MATCH(a) AGAINST('aaa1* aaa14 aaa16' IN BOOLEAN MODE) FROM t1;
SELECT MATCH(a) AGAINST('aaa1* aaa14 aaa15 aaa16' IN BOOLEAN MODE) FROM t1;
DROP TABLE t1;
#
# BUG#36737 - having + full text operator crashes mysql
#
CREATE TABLE t1(a TEXT) ENGINE = InnoDB;
--error ER_WRONG_ARGUMENTS
SELECT GROUP_CONCAT(a) AS st FROM t1 HAVING MATCH(st) AGAINST('test' IN BOOLEAN MODE);
DROP TABLE t1;
#
# BUG#42907 - Multi-term boolean fulltext query containing a single
# quote fails in 5.1.x
#
CREATE TABLE t1(a VARCHAR(64), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('awrd bwrd cwrd'),('awrd bwrd cwrd'),('awrd bwrd cwrd');
SELECT * FROM t1 WHERE MATCH(a) AGAINST('+awrd bwrd* +cwrd*' IN BOOLEAN MODE);
DROP TABLE t1;
#
# BUG#37740 Server crashes on execute statement with full text search and match against
#
CREATE TABLE t1 (col text, FULLTEXT KEY full_text (col)) ENGINE = InnoDB;
PREPARE s FROM
"SELECT MATCH (col) AGAINST('findme') FROM t1 ORDER BY MATCH (col) AGAINST('findme')"
;
EXECUTE s;
DEALLOCATE PREPARE s;
DROP TABLE t1;
--echo #
--echo # Bug #49250 : spatial btree index corruption and crash
--echo # Part two : fulltext syntax check
--echo #
--error ER_PARSE_ERROR
CREATE TABLE t1(col1 TEXT,
FULLTEXT INDEX USING BTREE (col1));
CREATE TABLE t2(col1 TEXT) ENGINE = InnoDB;
--error ER_PARSE_ERROR
CREATE FULLTEXT INDEX USING BTREE ON t2(col);
--error ER_PARSE_ERROR
ALTER TABLE t2 ADD FULLTEXT INDEX USING BTREE (col1);
DROP TABLE t2;
--echo End of 5.0 tests
--echo #
--echo # Bug #47930: MATCH IN BOOLEAN MODE returns too many results
--echo # inside subquery
--echo #
CREATE TABLE t1 (a int) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1), (2);
CREATE TABLE t2 (a int, b2 char(10), FULLTEXT KEY b2 (b2)) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1,'Scargill');
CREATE TABLE t3 (a int, b int) ENGINE = InnoDB;
INSERT INTO t3 VALUES (1,1), (2,1);
--echo # t2 should use full text index
EXPLAIN
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2, t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);
# INNODB_FTS: INVESTIGATE
--echo # should return 0
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2, t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);
--echo # should return 0
SELECT count(*) FROM t1 WHERE
not exists(
SELECT 1 FROM t2 IGNORE INDEX (b2), t3
WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
);
DROP TABLE t1,t2,t3;
#
# BUG#50351 - ft_min_word_len=2 Causes query to hang
#
CREATE TABLE t1 (a VARCHAR(4), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('awrd'),('cwrd'),
('awrd');
SELECT COUNT(*) FROM t1 WHERE MATCH(a) AGAINST("+awrd bwrd* +cwrd*" IN BOOLEAN MODE);
DROP TABLE t1;
--echo #
--echo # Bug #49445: Assertion failed: 0, file .\item_row.cc, line 55 with
--echo # fulltext search and row op
--echo #
CREATE TABLE t1(a CHAR(1),FULLTEXT(a)) ENGINE = InnoDB;
SELECT 1 FROM t1 WHERE MATCH(a) AGAINST ('') AND ROW(a,a) > ROW(1,1);
DROP TABLE t1;
--echo #
--echo # BUG#51866 - crash with repair by sort and fulltext keys
--echo #
CREATE TABLE t1(a CHAR(4), FULLTEXT(a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES('aaaa');
# INNODB_FTS: Do not support "set myisam_sort_buffer" commands
#SET myisam_sort_buffer_size=4;
#REPAIR TABLE t1;
#SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
DROP TABLE t1;
--echo #
--echo # Bug#54484 explain + prepared statement: crash and Got error -1 from storage engine
--echo #
CREATE TABLE t1(f1 VARCHAR(6) NOT NULL, FULLTEXT KEY(f1), UNIQUE(f1)) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('test');
--disable_warnings
SELECT 1 FROM t1 WHERE 1 >
ALL((SELECT 1 FROM t1 JOIN t1 a
ON (MATCH(t1.f1) against (""))
WHERE t1.f1 GROUP BY t1.f1)) xor f1;
PREPARE stmt FROM
'SELECT 1 FROM t1 WHERE 1 >
ALL((SELECT 1 FROM t1 RIGHT OUTER JOIN t1 a
ON (MATCH(t1.f1) against (""))
WHERE t1.f1 GROUP BY t1.f1)) xor f1';
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM
'SELECT 1 FROM t1 WHERE 1 >
ALL((SELECT 1 FROM t1 JOIN t1 a
ON (MATCH(t1.f1) against (""))
WHERE t1.f1 GROUP BY t1.f1))';
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
--enable_warnings
DROP TABLE t1;
--echo End of 5.1 tests

View File

@ -0,0 +1,236 @@
#
# test of new fulltext search features
#
#
# two-level tree
#
--source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (
i int(10) unsigned not null auto_increment primary key,
a varchar(255) not null,
FULLTEXT KEY (a)
) ENGINE = INNODB;
# two-level entry, second-level tree with depth 2
--disable_query_log
let $1=260;
while ($1)
{
eval insert t1 (a) values ('aaaxxx');
dec $1;
}
# two-level entry, second-level tree has only one page
let $1=255;
while ($1)
{
eval insert t1 (a) values ('aaazzz');
dec $1;
}
# one-level entry (entries)
let $1=250;
while ($1)
{
eval insert t1 (a) values ('aaayyy');
dec $1;
}
--enable_query_log
# converting to two-level
# INNODB_FTS: Do not support repair
#repair table t1 quick;
check table t1;
#optimize table t1; # BUG#5327 - mi_sort_index() of 2-level tree
#check table t1;
select count(*) from t1 where match a against ('aaaxxx');
select count(*) from t1 where match a against ('aaayyy');
select count(*) from t1 where match a against ('aaazzz');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz');
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz' in boolean mode);
select count(*) from t1 where match a against ('aaax*' in boolean mode);
select count(*) from t1 where match a against ('aaay*' in boolean mode);
select count(*) from t1 where match a against ('aaa*' in boolean mode);
# mi_write:
insert t1 (a) values ('aaaxxx'),('aaayyy');
# call to enlarge_root() below
insert t1 (a) values ('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz');
select count(*) from t1 where match a against ('aaaxxx');
select count(*) from t1 where match a against ('aaayyy');
select count(*) from t1 where match a against ('aaazzz');
# mi_delete
insert t1 (a) values ('aaaxxx 000000');
select count(*) from t1 where match a against ('000000');
delete from t1 where match a against ('000000');
select count(*) from t1 where match a against ('000000');
select count(*) from t1 where match a against ('aaaxxx');
delete from t1 where match a against ('aaazzz');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
# double-check without index
select count(*) from t1 where a = 'aaaxxx';
select count(*) from t1 where a = 'aaayyy';
select count(*) from t1 where a = 'aaazzz';
# update
insert t1 (a) values ('aaaxxx 000000');
select count(*) from t1 where match a against ('000000');
update t1 set a='aaazzz' where match a against ('000000');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
update t1 set a='aaazzz' where a = 'aaaxxx';
update t1 set a='aaaxxx' where a = 'aaayyy';
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
drop table t1;
CREATE TABLE t1 (
i int(10) unsigned not null auto_increment primary key,
a varchar(255) not null,
FULLTEXT KEY (a)
) ENGINE = INNODB;
#
# now same as about but w/o repair table
# 2-level tree created by mi_write
#
# two-level entry, second-level tree with depth 2
--disable_query_log
let $1=260;
while ($1)
{
eval insert t1 (a) values ('aaaxxx');
dec $1;
}
let $1=255;
while ($1)
{
eval insert t1 (a) values ('aaazzz');
dec $1;
}
let $1=250;
while ($1)
{
eval insert t1 (a) values ('aaayyy');
dec $1;
}
--enable_query_log
select count(*) from t1 where match a against ('aaaxxx');
select count(*) from t1 where match a against ('aaayyy');
select count(*) from t1 where match a against ('aaazzz');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz');
select count(*) from t1 where match a against ('aaaxxx aaayyy aaazzz' in boolean mode);
select count(*) from t1 where match a against ('aaax*' in boolean mode);
select count(*) from t1 where match a against ('aaay*' in boolean mode);
select count(*) from t1 where match a against ('aaa*' in boolean mode);
# mi_write:
insert t1 (a) values ('aaaxxx'),('aaayyy');
insert t1 (a) values ('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz'),('aaazzz');
select count(*) from t1 where match a against ('aaaxxx');
select count(*) from t1 where match a against ('aaayyy');
select count(*) from t1 where match a against ('aaazzz');
# mi_delete
insert t1 (a) values ('aaaxxx 000000');
select count(*) from t1 where match a against ('000000');
delete from t1 where match a against ('000000');
select count(*) from t1 where match a against ('000000');
select count(*) from t1 where match a against ('aaaxxx');
delete from t1 where match a against ('aaazzz');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
# double-check without index
select count(*) from t1 where a = 'aaaxxx';
select count(*) from t1 where a = 'aaayyy';
select count(*) from t1 where a = 'aaazzz';
# update
insert t1 (a) values ('aaaxxx 000000');
select count(*) from t1 where match a against ('000000');
update t1 set a='aaazzz' where match a against ('000000');
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
update t1 set a='aaazzz' where a = 'aaaxxx';
update t1 set a='aaaxxx' where a = 'aaayyy';
select count(*) from t1 where match a against ('aaaxxx' in boolean mode);
select count(*) from t1 where match a against ('aaayyy' in boolean mode);
select count(*) from t1 where match a against ('aaazzz' in boolean mode);
drop table t1;
#
# BUG#11336
#
# for uca collation isalnum and strnncollsp don't agree on whether
# 0xC2A0 is a space (strnncollsp is right, isalnum is wrong).
#
# they still don't, the bug was fixed by avoiding strnncollsp
#
set names utf8;
eval create table t1(a text,fulltext(a)) ENGINE = INNODB collate=utf8_swedish_ci;
insert into t1 values('test test '),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test'),
('test'),('test'),('test'),('test'),('test'),('test'),('test'),('test');
delete from t1 limit 1;
#
# BUG#16489: utf8 + fulltext leads to corrupt index file.
#
truncate table t1;
insert into t1 values('ab c d');
update t1 set a='ab c d';
select * from t1 where match a against('ab c' in boolean mode);
select * from t1 where match a against('ab c' in boolean mode);
drop table t1;
set names latin1;
# End of 4.1 tests
#
# BUG#19580 - FULLTEXT search produces wrong results on UTF-8 columns
# INNODB_FTS: Investigate
SET NAMES utf8;
CREATE TABLE t1(a VARCHAR(255), FULLTEXT(a)) ENGINE = INNODB DEFAULT CHARSET=utf8;
INSERT INTO t1 VALUES('„MySQL“');
SELECT a FROM t1 WHERE MATCH a AGAINST('“MySQL„' IN BOOLEAN MODE);
DROP TABLE t1;
SET NAMES latin1;

View File

@ -0,0 +1,37 @@
--source include/have_gbk.inc
#
# test of new fulltext search features
#
--source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
let $default_engine = `select @@SESSION.default_storage_engine`;
#
# BUG#29299 - repeatable myisam fulltext index corruption
#
# INNODB_FTS: Not yet support gbk charset
CREATE TABLE t1(a VARCHAR(255) CHARACTER SET gbk, FULLTEXT(a)) ENGINE = InnoDB;
SET NAMES utf8;
# INSERT INTO t1 VALUES(0xF043616161),(0xBEF361616197C22061616161);
# SELECT HEX(a) FROM t1 WHERE MATCH(a) AGAINST(0x97C22061616161 IN BOOLEAN MODE);
DELETE FROM t1 LIMIT 1;
#CHECK TABLE t1;
SET NAMES latin1;
DROP TABLE t1;
# End of 5.0 tests
#
# BUG#29464 - load data infile into table with big5 chinese fulltext index
# hangs 100% cpu
#
--replace_result $default_engine <default_engine>
EVAL CREATE TABLE t1(a VARCHAR(2) CHARACTER SET big5 COLLATE big5_chinese_ci,
FULLTEXT(a)) ENGINE=$default_engine;
# INSERT INTO t1 VALUES(0xA3C2);
DROP TABLE t1;
# End of 5.1 tests

View File

@ -0,0 +1,55 @@
#
# Bugreport due to Roy Nasser <roy@vem.ca>
#
--source include/have_innodb.inc
--disable_warnings
drop table if exists t1, t2;
--enable_warnings
CREATE TABLE t1 (
id int(10) unsigned NOT NULL auto_increment,
q varchar(255) default NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1,'aaaaaaaaa dsaass de');
INSERT INTO t1 VALUES (2,'ssde df s fsda sad er');
CREATE TABLE t2 (
id int(10) unsigned NOT NULL auto_increment,
id2 int(10) unsigned default NULL,
item varchar(255) default NULL,
PRIMARY KEY (id),
FULLTEXT KEY item(item)
) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1,1,'sushi');
INSERT INTO t2 VALUES (2,1,'Bolo de Chocolate');
INSERT INTO t2 VALUES (3,1,'Feijoada');
INSERT INTO t2 VALUES (4,1,'Mousse de Chocolate');
INSERT INTO t2 VALUES (5,2,'um copo de Vodka');
INSERT INTO t2 VALUES (6,2,'um chocolate Snickers');
INSERT INTO t2 VALUES (7,1,'Bife');
INSERT INTO t2 VALUES (8,1,'Pizza de Salmao');
-- disable_result_log
ANALYZE TABLE t1;
ANALYZE TABLE t2;
-- enable_result_log
SELECT t1.q, t2.item, t2.id, round(MATCH t2.item AGAINST ('sushi'),6)
as x FROM t1, t2 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi' IN BOOLEAN MODE)
as x FROM t1, t2 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
SELECT t1.q, t2.item, t2.id, round(MATCH t2.item AGAINST ('sushi'),6)
as x FROM t2, t1 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
SELECT t1.q, t2.item, t2.id, MATCH t2.item AGAINST ('sushi' IN BOOLEAN MODE)
as x FROM t2, t1 WHERE (t2.id2 = t1.id) ORDER BY x DESC,t2.id;
drop table t1, t2;
# End of 4.1 tests

View File

@ -0,0 +1,48 @@
#
# Test of fulltext index
# bug reported by Tibor Simko <tibor.simko@cern.ch>
#
--source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
CREATE TABLE t1 (
id mediumint unsigned NOT NULL auto_increment,
tag char(6) NOT NULL default '',
value text NOT NULL default '',
PRIMARY KEY (id),
KEY kt(tag),
KEY kv(value(15)),
FULLTEXT KEY kvf(value)
) ENGINE = InnoDB;
CREATE TABLE t2 (
id_t2 mediumint unsigned NOT NULL default '0',
id_t1 mediumint unsigned NOT NULL default '0',
field_number tinyint unsigned NOT NULL default '0',
PRIMARY KEY (id_t2,id_t1,field_number),
KEY id_t1(id_t1)
) ENGINE = InnoDB;
INSERT INTO t1 (tag,value) VALUES ('foo123','bar111');
INSERT INTO t1 (tag,value) VALUES ('foo123','bar222');
INSERT INTO t1 (tag,value) VALUES ('bar345','baz333 ar');
INSERT INTO t2 VALUES (2231626,64280,0);
INSERT INTO t2 VALUES (2231626,64281,0);
INSERT INTO t2 VALUES (12346, 3, 1);
SELECT * FROM t1; SELECT * FROM t2;
SELECT DISTINCT t2.id_t2 FROM t2, t1
WHERE MATCH (t1.value) AGAINST ('baz333') AND t1.id = t2.id_t1;
SELECT DISTINCT t2.id_t2 FROM t2, t1
WHERE MATCH (t1.value) AGAINST ('baz333' IN BOOLEAN MODE)
AND t1.id = t2.id_t1;
DROP TABLE t1, t2;
# End of 4.1 tests

View File

@ -0,0 +1,131 @@
#
# Test for bug from Jean-Cédric COSTA <jean-cedric.costa@ensmp.fr>
#
--source include/have_innodb.inc
--disable_warnings
drop table if exists t1, t2;
--enable_warnings
CREATE TABLE t1 (
id VARCHAR(255) NOT NULL PRIMARY KEY,
sujet VARCHAR(255),
motsclefs TEXT,
texte MEDIUMTEXT,
FULLTEXT(sujet, motsclefs, texte)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES('123','toto','essai','test');
INSERT INTO t1 VALUES('456','droit','penal','lawyer');
INSERT INTO t1 VALUES('789','aaaaa','bbbbb','cccccc');
CREATE TABLE t2 (
id VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL
) ENGINE = InnoDB;
INSERT INTO t2 VALUES('123', 'moi');
INSERT INTO t2 VALUES('123', 'lui');
INSERT INTO t2 VALUES('456', 'lui');
-- disable_result_log
ANALYZE TABLE t1;
ANALYZE TABLE t2;
-- enable_result_log
select round(match(t1.texte,t1.sujet,t1.motsclefs) against('droit'),5)
from t1 left join t2 on t2.id=t1.id;
select match(t1.texte,t1.sujet,t1.motsclefs) against('droit' IN BOOLEAN MODE)
from t1 left join t2 on t2.id=t1.id;
drop table t1, t2;
#
# BUG#484, reported by Stephen Brandon <stephen@brandonitconsulting.co.uk>
#
create table t1 (venue_id int(11) default null, venue_text varchar(255) default null, dt datetime default null) ENGINE = InnoDB;
insert into t1 (venue_id, venue_text, dt) values (1, 'a1', '2003-05-23 19:30:00'),(null, 'a2', '2003-05-23 19:30:00');
eval create table t2 (name varchar(255) not null default '', entity_id int(11) not null auto_increment, primary key (entity_id), fulltext key name (name)) engine= innodb;
insert into t2 (name, entity_id) values ('aberdeen town hall', 1), ('glasgow royal concert hall', 2), ('queen\'s hall, edinburgh', 3);
-- disable_result_log
ANALYZE TABLE t1;
ANALYZE TABLE t2;
-- enable_result_log
select * from t1 left join t2 on venue_id = entity_id where match(name) against('aberdeen' in boolean mode) and dt = '2003-05-23 19:30:00';
select * from t1 left join t2 on venue_id = entity_id where match(name) against('aberdeen') and dt = '2003-05-23 19:30:00';
select * from t1 left join t2 on (venue_id = entity_id and match(name) against('aberdeen' in boolean mode)) where dt = '2003-05-23 19:30:00';
select * from t1 left join t2 on (venue_id = entity_id and match(name) against('aberdeen')) where dt = '2003-05-23 19:30:00';
drop table t1,t2;
#
# BUG#14708
# Inconsistent treatment of NULLs in LEFT JOINed FULLTEXT matching without index
#
create table t1 (id int not null primary key, d char(200) not null, e char(200), fulltext (d, e)) ENGINE = InnoDB;
insert into t1 values (1, 'aword', null), (2, 'aword', 'bword'), (3, 'bword', null), (4, 'bword', 'aword'), (5, 'aword and bword', null);
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
select * from t1 where match(d, e) against ('+aword +bword' in boolean mode);
# INNODB_FTS: Investigate Full Text search on joined result
create table t2 (m_id int not null, f char(200), key (m_id), fulltext (f)) engine = InnoDB;
insert into t2 values (1, 'bword'), (3, 'aword'), (5, '');
-- disable_result_log
ANALYZE TABLE t2;
-- enable_result_log
select * from t1 left join t2 on m_id = id where match(d, e, f) against ('+aword +bword' in boolean mode);
drop table t1,t2;
#
# BUG#25637: LEFT JOIN with BOOLEAN FULLTEXT loses left table matches
# (this is actually the same bug as bug #14708)
#
CREATE TABLE t1 (
id int(10) NOT NULL auto_increment,
link int(10) default NULL,
name mediumtext default NULL,
PRIMARY KEY (id),
FULLTEXT (name)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1, 1, 'string');
INSERT INTO t1 VALUES (2, 0, 'string');
CREATE TABLE t2 (
id int(10) NOT NULL auto_increment,
name mediumtext default NULL,
PRIMARY KEY (id),
FULLTEXT (name)
) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1, 'string');
-- disable_result_log
ANALYZE TABLE t1;
ANALYZE TABLE t2;
-- enable_result_log
SELECT t1.*, MATCH(t1.name) AGAINST('string') AS relevance
FROM t1 LEFT JOIN t2 ON t1.link = t2.id
WHERE MATCH(t1.name, t2.name) AGAINST('string' IN BOOLEAN MODE);
DROP TABLE t1,t2;
# End of 4.1 tests
#
# BUG#25729 - boolean full text search is confused by NULLs produced by LEFT
# JOIN
#
CREATE TABLE t1 (a INT) ENGINE = InnoDB;
CREATE TABLE t2 (b INT, c TEXT, KEY(b), FULLTEXT(c)) ENGINE = InnoDB;
INSERT INTO t1 VALUES(1);
INSERT INTO t2(b,c) VALUES(2,'castle'),(3,'castle');
-- disable_result_log
ANALYZE TABLE t1;
ANALYZE TABLE t2;
-- enable_result_log
SELECT * FROM t1 LEFT JOIN t2 ON a=b WHERE MATCH(c) AGAINST('+castle' IN BOOLEAN MODE);
DROP TABLE t1, t2;

View File

@ -0,0 +1,215 @@
#
# Fulltext configurable parameters
#
--source include/have_innodb.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
--echo #
--echo # Bug#56814 Explain + subselect + fulltext crashes server
--echo #
CREATE TABLE t1(f1 VARCHAR(6) NOT NULL,FULLTEXT KEY(f1),UNIQUE(f1)) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('test');
EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT 1 FROM t1 JOIN t1 a ON (MATCH(t1.f1) AGAINST (""))
WHERE t1.f1 GROUP BY t1.f1));
PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT 1 FROM t1 RIGHT OUTER JOIN t1 a
ON (MATCH(t1.f1) AGAINST (""))
WHERE t1.f1 GROUP BY t1.f1))';
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT 1 FROM t1 JOIN t1 a
ON (MATCH(t1.f1) AGAINST (""))
WHERE t1.f1 GROUP BY t1.f1))';
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
#try to crash gcc 2.96
--disable_warnings
drop table if exists t1;
--enable_warnings
CREATE TABLE t1 (
kodoboru varchar(10) default NULL,
obor tinytext,
aobor tinytext,
UNIQUE INDEX kodoboru (kodoboru),
FULLTEXT KEY obor (obor),
FULLTEXT KEY aobor (aobor)
) ENGINE = InnoDB;
drop table t1;
CREATE TABLE t1 (
kodoboru varchar(10) default NULL,
obor tinytext,
aobor tinytext,
UNIQUE INDEX kodoboru (kodoboru),
FULLTEXT KEY obor (obor)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES ('0101000000','aaa','AAA');
INSERT INTO t1 VALUES ('0102000000','bbb','BBB');
INSERT INTO t1 VALUES ('0103000000','ccc','CCC');
INSERT INTO t1 VALUES ('0104000000','xxx','XXX');
select * from t1;
drop table t1;
# End of 4.1 tests
#
# Bug#20503: Server crash due to the ORDER clause isn't taken into account
# while space allocation
#
create table t1 (c1 varchar(1), c2 int, c3 int, c4 int, c5 int, c6 int,
c7 int, c8 int, c9 int, fulltext key (`c1`)) ENGINE = InnoDB;
select distinct match (`c1`) against ('z') , c2, c3, c4,c5, c6,c7, c8
from t1 where c9=1 order by c2, c2;
drop table t1;
#
# VIEW with full text
#
CREATE TABLE t1 (c1 int not null auto_increment primary key, c2 varchar(20), fulltext(c2)) ENGINE = InnoDB;
insert into t1 (c2) VALUES ('real Beer'),('Water'),('Kossu'),('Coca-Cola'),('Vodka'),('Wine'),('almost real Beer');
select * from t1 WHERE match (c2) against ('Beer');
CREATE VIEW v1 AS SELECT * from t1 WHERE match (c2) against ('Beer');
select * from v1;
drop view v1;
drop table t1;
# Test case for bug 6447
create table t1 (mytext text, FULLTEXT (mytext)) ENGINE = InnoDB;
insert t1 values ('aaabbb');
# INNODB_FTS: These variables are not support in InnoDB
check table t1;
# set @my_key_cache_block_size= @@global.key_cache_block_size;
# set GLOBAL key_cache_block_size=2048;
check table t1;
drop table t1;
# Restore the changed variable value
#set global key_cache_block_size= @my_key_cache_block_size;
#
# BUG#12075 - FULLTEXT non-functional for big5 strings
#
# INNODB_FTS: Not yet support big5
#CREATE TABLE t1 (a CHAR(50) CHARACTER SET big5 NOT NULL, FULLTEXT(a)) ENGINE = InnoDB;
#INSERT INTO t1 VALUES(0xA741ADCCA66EB6DC20A7DAADCCABDCA66E);
#SELECT HEX(a) FROM t1 WHERE MATCH(a) AGAINST (0xA741ADCCA66EB6DC IN BOOLEAN MODE);
#DROP TABLE t1;
#
create table t1 (a varchar(10), fulltext key(a)) ENGINE = InnoDB;
insert into t1 values ('a');
select hex(concat(match (a) against ('a'))) from t1;
create table t2 ENGINE = InnoDB as select concat(match (a) against ('a')) as a from t1;
show create table t2;
drop table t1, t2;
#
# BUG#31159 - fulltext search on ucs2 column crashes server
#
CREATE TABLE t1(a TEXT CHARSET ucs2 COLLATE ucs2_unicode_ci) ENGINE = InnoDB;
INSERT INTO t1 VALUES('abcd');
# INNODB_FTS: Please Note this table do not have FTS. InnoDB return 1214 error
--error ER_TABLE_HAS_NO_FT
SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abcd' IN BOOLEAN MODE);
DROP TABLE t1;
#
# Some other simple tests with the current character set
#
create table t1 (a varchar(10), key(a), fulltext (a)) ENGINE = InnoDB;
insert into t1 values ("a"),("abc"),("abcd"),("hello"),("test");
select * from t1 where a like "abc%";
select * from t1 where a like "test%";
select * from t1 where a like "te_t";
# InnoDB_FTS: we don't support the postfix "+0"
select * from t1 where match a against ("te*" in boolean mode)+0;
drop table t1;
--echo #
--echo # Bug #49734: Crash on EXPLAIN EXTENDED UNION ... ORDER BY
--echo # <any non-const-function>
--echo #
CREATE TABLE t1 (a VARCHAR(10), FULLTEXT KEY a (a)) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT) ENGINE = InnoDB;
INSERT INTO t2 VALUES (1),(2);
--echo # Should not crash
EXPLAIN EXTENDED
SELECT * FROM t1 UNION SELECT * FROM t1 ORDER BY a + 12;
--echo # Should not crash
SELECT * FROM t1 UNION SELECT * FROM t1 ORDER BY a + 12;
--echo # Should not crash
--error ER_CANT_USE_OPTION_HERE
EXPLAIN EXTENDED
SELECT * FROM t1 UNION SELECT * FROM t1
ORDER BY MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE);
--echo # Should not crash
--error ER_CANT_USE_OPTION_HERE
SELECT * FROM t1 UNION SELECT * FROM t1
ORDER BY MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE);
# FIXME: Valgrind in MySQL code _MI_WRITE_BLOB_RECORD, bug #13389854
#--echo # Should not crash
#(SELECT * FROM t1) UNION (SELECT * FROM t1)
# ORDER BY MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE);
--echo # Should not crash
EXPLAIN EXTENDED
SELECT * FROM t1 UNION SELECT * FROM t1
ORDER BY (SELECT a FROM t2 WHERE b = 12);
--echo # Should not crash
--disable_result_log
SELECT * FROM t1 UNION SELECT * FROM t1
ORDER BY (SELECT a FROM t2 WHERE b = 12);
--enable_result_log
--echo # Should not crash
SELECT * FROM t2 UNION SELECT * FROM t2
ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE));
DROP TABLE t1,t2;
--echo End of 5.1 tests

View File

@ -0,0 +1,41 @@
# several FULLTEXT indexes in one table test
--source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (
a int(11) NOT NULL auto_increment,
b text,
c varchar(254) default NULL,
PRIMARY KEY (a),
FULLTEXT KEY bb(b),
FULLTEXT KEY cc(c),
FULLTEXT KEY a(b,c)
) ENGINE = InnoDB;
drop table t1;
CREATE TABLE t1 (
a int(11) NOT NULL auto_increment,
b text,
c varchar(254) default NULL,
PRIMARY KEY (a),
FULLTEXT KEY a(b,c)
) ENGINE = InnoDB;
INSERT INTO t1 VALUES (1,'lala lolo lili','oooo aaaa pppp');
INSERT INTO t1 VALUES (2,'asdf fdsa','lkjh fghj');
INSERT INTO t1 VALUES (3,'qpwoei','zmxnvb');
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
SELECT a, round(MATCH b,c AGAINST ('lala lkjh'),5) FROM t1;
SELECT a, round(MATCH c,c AGAINST ('lala lkjh'),5) FROM t1;
SELECT a, round(MATCH b,c AGAINST ('lala lkjh'),5) FROM t1;
drop table t1;
# End of 4.1 tests

View File

@ -0,0 +1,168 @@
--source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3;
--enable_warnings
CREATE TABLE t1 (
a INT AUTO_INCREMENT PRIMARY KEY,
message CHAR(20),
FULLTEXT(message)
) ENGINE = InnoDB comment = 'original testcase by sroussey@network54.com';
INSERT INTO t1 (message) VALUES ("Testing"),("table"),("testbug"),
("steve"),("is"),("cool"),("steve is cool");
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
# basic MATCH
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE MATCH (message) AGAINST ('steve');
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE MATCH (message) AGAINST ('steve');
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE MATCH (message) AGAINST ('steve' IN BOOLEAN MODE);
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE MATCH (message) AGAINST ('steve' IN BOOLEAN MODE);
# MATCH + ORDER BY (with ft-ranges)
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY a;
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) ORDER BY a;
# MATCH + ORDER BY (with normal ranges) + UNIQUE
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE a in (2,7,4) and MATCH (message) AGAINST ('steve') ORDER BY a DESC;
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE a in (2,7,4) and MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) ORDER BY a DESC;
# MATCH + ORDER BY + UNIQUE (const_table)
SELECT a, FORMAT(MATCH (message) AGAINST ('steve'),6) FROM t1 WHERE a=7 and MATCH (message) AGAINST ('steve') ORDER BY 1;
SELECT a, MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) FROM t1 WHERE a=7 and MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) ORDER BY 1;
# ORDER BY MATCH
# INNODB_FTS: INVESITGATE
SELECT if(a in (4,7),2,1), FORMAT(MATCH (message) AGAINST ('steve'),6) as rel FROM t1 ORDER BY rel;
SELECT if(a in (4,7),2,1), MATCH (message) AGAINST ('steve' IN BOOLEAN MODE) as rel FROM t1 ORDER BY rel;
#
# BUG#6635 - test_if_skip_sort_order() thought it can skip filesort
# for fulltext searches too
#
alter table t1 add key m (message);
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
explain SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message;
SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message desc;
drop table t1;
#
# reused boolean scan bug
#
CREATE TABLE t1 (
a INT AUTO_INCREMENT PRIMARY KEY,
message CHAR(20),
FULLTEXT(message)
) ENGINE = InnoDB;
INSERT INTO t1 (message) VALUES ("testbug"),("testbug foobar");
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
SELECT a, MATCH (message) AGAINST ('t* f*' IN BOOLEAN MODE) as rel FROM t1;
SELECT a, MATCH (message) AGAINST ('t* f*' IN BOOLEAN MODE) as rel FROM t1 ORDER BY rel,a;
drop table t1;
# BUG#11869
CREATE TABLE t1 (
id int(11) NOT NULL auto_increment,
thread int(11) NOT NULL default '0',
beitrag longtext NOT NULL,
PRIMARY KEY (id),
KEY thread (thread),
FULLTEXT KEY beitrag (beitrag)
) ENGINE =InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7923 ;
CREATE TABLE t2 (
id int(11) NOT NULL auto_increment,
text varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY text (text)
) ENGINE = InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=63 ;
CREATE TABLE t3 (
id int(11) NOT NULL auto_increment,
forum int(11) NOT NULL default '0',
betreff varchar(70) NOT NULL default '',
PRIMARY KEY (id),
KEY forum (forum),
FULLTEXT KEY betreff (betreff)
) ENGINE = InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=996 ;
--error ER_CANT_USE_OPTION_HERE
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(b.betreff) against ('+abc' in boolean mode)
group by a.text, b.id, b.betreff
union
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(c.beitrag) against ('+abc' in boolean mode)
group by
a.text, b.id, b.betreff
order by
match(b.betreff) against ('+abc' in boolean mode) desc;
--error ER_CANT_USE_OPTION_HERE
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(b.betreff) against ('+abc' in boolean mode)
union
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(c.beitrag) against ('+abc' in boolean mode)
order by
match(b.betreff) against ('+abc' in boolean mode) desc;
--error ER_CANT_USE_OPTION_HERE
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(b.betreff) against ('+abc' in boolean mode)
union
select a.text, b.id, b.betreff
from
t2 a inner join t3 b on a.id = b.forum inner join
t1 c on b.id = c.thread
where
match(c.beitrag) against ('+abc' in boolean mode)
order by
match(betreff) against ('+abc' in boolean mode) desc;
# BUG#11869 part2: used table type doesn't support FULLTEXT indexes error
(select b.id, b.betreff from t3 b) union
(select b.id, b.betreff from t3 b)
order by match(betreff) against ('+abc' in boolean mode) desc;
--error 1191
(select b.id, b.betreff from t3 b) union
(select b.id, b.betreff from t3 b)
order by match(betreff) against ('+abc') desc;
select distinct b.id, b.betreff from t3 b
order by match(betreff) against ('+abc' in boolean mode) desc;
select b.id, b.betreff from t3 b group by b.id+1
order by match(betreff) against ('+abc' in boolean mode) desc;
drop table t1,t2,t3;
# End of 4.1 tests

View File

@ -0,0 +1,34 @@
#
# Test for bug by voi@ims.at
#
--source include/have_innodb.inc
--disable_warnings
drop table if exists test;
--enable_warnings
let $default_engine = `select @@SESSION.default_storage_engine`;
# --replace_result $default_engine <default_engine>
CREATE TABLE test (
gnr INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
url VARCHAR(80) DEFAULT '' NOT NULL,
shortdesc VARCHAR(200) DEFAULT '' NOT NULL,
longdesc text DEFAULT '' NOT NULL,
description VARCHAR(80) DEFAULT '' NOT NULL,
name VARCHAR(80) DEFAULT '' NOT NULL,
FULLTEXT(url,description,shortdesc,longdesc),
PRIMARY KEY(gnr)
) ENGINE = InnoDB;
insert into test (url,shortdesc,longdesc,description,name) VALUES
("http:/test.at", "kurz", "lang","desc", "name");
insert into test (url,shortdesc,longdesc,description,name) VALUES
("http:/test.at", "kurz", "","desc", "name");
update test set url='test', description='ddd', name='nam' where gnr=2;
update test set url='test', shortdesc='ggg', longdesc='mmm',
description='ddd', name='nam' where gnr=2;
check table test;
drop table test;
# End of 4.1 tests

View File

@ -0,0 +1,42 @@
#
# Fulltext configurable parameters
#
--source include/have_innodb.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
# Save ft_boolean_syntax variable
let $saved_ft_boolean_syntax=`select @@global.ft_boolean_syntax`;
show variables like "ft\_%";
# INNODB_FTS: Please note original table do not have fulltext index.
# InnoDB will return 1214. I added "fulltext(b)" to the create table statement
# In addition, we do not support MyISAM configure parameter
create table t1 (b text not null, fulltext(b)) engine = innodb;
insert t1 values ('aaaaaa bbbbbb cccccc');
insert t1 values ('bbbbbb cccccc');
insert t1 values ('aaaaaa cccccc');
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
-- error 1229
set ft_boolean_syntax=' +-><()~*:""&|';
set global ft_boolean_syntax=' +-><()~*:""&|';
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
set global ft_boolean_syntax='@ -><()~*:""&|';
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
select * from t1 where match b against ('+aaaaaa @bbbbbb' in boolean mode);
-- error 1231
set global ft_boolean_syntax='@ -><()~*:""@|';
-- error 1231
set global ft_boolean_syntax='+ -><()~*:""@!|';
drop table t1;
# Restore ft_boolean_syntax variable
--disable_query_log
eval set global ft_boolean_syntax='$saved_ft_boolean_syntax';
--enable_query_log
# End of 4.1 tests

View File

@ -0,0 +1,19 @@
#
# Test innobase_drop_fts_index_table()
#
-- source include/have_innodb.inc
# Must have debug code to use SET SESSION debug
-- source include/have_debug.inc
-- source include/not_embedded.inc
CREATE TABLE t (a INT, b TEXT) engine=innodb;
SET debug_dbug='+d,alter_table_rollback_new_index';
-- error ER_UNKNOWN_ERROR
ALTER TABLE t ADD FULLTEXT INDEX (b(64));
SET debug_dbug='-d,alter_table_rollback_new_index';
DROP TABLE t;

View File

@ -0,0 +1,213 @@
# This is the basic function tests for innodb FTS
-- source include/have_innodb.inc
# Create FTS table
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
-- disable_result_log
ANALYZE TABLE articles;
-- enable_result_log
# Look for 'Database' in table article
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
SELECT COUNT(*) FROM articles
WHERE MATCH (title,body)
AGAINST ('database' IN NATURAL LANGUAGE MODE);
SELECT * FROM articles
WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT COUNT(IF(MATCH (title,body)
AGAINST ('database' IN NATURAL LANGUAGE MODE), 1, NULL))
AS count FROM articles;
# Select Relevance Ranking
SELECT id, body, MATCH (title,body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE) AS score
FROM articles;
# 'MySQL' treated as stopword (stopword functionality not yet supported)
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN NATURAL LANGUAGE MODE);
# Boolean search
# Select rows contain "MySQL" but not "YourSQL"
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);
# Select rows contain at least one of the two words
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('DBMS Security' IN BOOLEAN MODE);
# Select rows contain both "MySQL" and "YourSQL"
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL +YourSQL' IN BOOLEAN MODE);
# Select rows contain "MySQL" but rank rows with "YourSQL" higher
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL YourSQL' IN BOOLEAN MODE);
# Test negation operator. Select rows contain MySQL,
# if the row contains "YourSQL", rank it lower
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL ~YourSQL' IN BOOLEAN MODE);
# Test wild card search operator
# Notice row with "the" will not get fetched due to
# stopword filtering
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('t*' IN BOOLEAN MODE);
# Test wild card search, notice row 6 with 2 "MySQL" rank first
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('MY*' IN BOOLEAN MODE);
# Another wild card search
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('ru*' IN BOOLEAN MODE);
# Test ">" and "<" Operator, the ">" operator increases
# the word relevance rank and the "<" operator decreases it
# Following test puts rows with "Well" on top and rows
# with "stands" at the bottom
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+ MySQL >Well < stands' IN BOOLEAN MODE);
# Test sub-expression boolean search. Find rows contain
# "MySQL" but not "Well" or "stands".
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+ MySQL - (Well stands)' IN BOOLEAN MODE);
# Test sub-expression boolean search. Find rows contain
# "MySQL" and "Well" or "MySQL" and "stands". But rank the
# doc with "Well" higher, and doc with "stands" lower.
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+ MySQL + (>Well < stands)' IN BOOLEAN MODE);
# Test nested sub-expression.
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('YourSQL + (+MySQL - (Tricks Security))' IN BOOLEAN MODE);
# Find rows with "MySQL" but not "Tricks", "Security" nor "YourSQL"
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('(+MySQL - (Tricks Security)) - YourSQL' IN BOOLEAN MODE);
# Test query expansion
SELECT COUNT(*) FROM articles
WHERE MATCH (title,body)
AGAINST ('database' WITH QUERY EXPANSION);
INSERT INTO articles (title,body) VALUES
('test query expansion','for database ...');
# This query will return result containing word "database" as
# the query expand from "test" to words in document just
# inserted above
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('test' WITH QUERY EXPANSION);
# This is to test the proximity search, search two word
# "following" and "comparison" within 19 character space
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"following comparison"@3' IN BOOLEAN MODE);
# This is to test the proximity search, search two word
# "following" and "comparison" within 19 character space
# This search should come with no return result
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"following comparison"@2' IN BOOLEAN MODE);
# This is to test the phrase search, searching phrase
# "following database"
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"following database"' IN BOOLEAN MODE);
# Insert into table with similar word of different distances
INSERT INTO articles (title,body) VALUES
('test proximity search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO articles (title,body) VALUES
('test my proximity fts new search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO articles (title,body) VALUES
('test more of proximity fts search, test, more proximity and phrase',
'search, with proximity innodb');
# This should only return the first document
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"proximity search"@3' IN BOOLEAN MODE);
# This would return no document
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"proximity search"@2' IN BOOLEAN MODE);
# This give you all three documents
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"proximity search"@5' IN BOOLEAN MODE);
# Similar boundary testing for the words
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"test proximity"@5' IN BOOLEAN MODE);
# No document will be returned
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"test proximity"@1' IN BOOLEAN MODE);
# All three documents will be returned
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"test proximity"@4' IN BOOLEAN MODE);
# Only two document will be returned.
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"test proximity"@3' IN BOOLEAN MODE);
# Test with more word The last document will return, please notice there
# is no ordering requirement for proximity search.
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"more test proximity"@4' IN BOOLEAN MODE);
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"more test proximity"@3' IN BOOLEAN MODE);
# The phrase search will not require exact word ordering
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('"more test proximity"' IN BOOLEAN MODE);
drop table articles;

View File

@ -0,0 +1,272 @@
# This is the DDL function tests for innodb FTS
-- source include/have_innodb.inc
# Create FTS table
CREATE TABLE fts_test (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
# Insert six rows
INSERT INTO fts_test (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# Create the FTS index
CREATE FULLTEXT INDEX idx on fts_test (title, body);
# Select word "tutorial" in the table
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
# Drop the FTS idx
DROP INDEX idx ON fts_test;
# Continue insert some rows
INSERT INTO fts_test (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# Recreate the FTS index
CREATE FULLTEXT INDEX idx on fts_test (title, body);
# Select word "tutorial" in the table
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
# Boolean search
# Select rows contain "MySQL" but not "YourSQL"
SELECT * FROM fts_test WHERE MATCH (title,body)
AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);
# Truncate table
TRUNCATE TABLE fts_test;
DROP INDEX idx ON fts_test;
# Continue insert some rows
INSERT INTO fts_test (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# Recreate the FTS index
CREATE FULLTEXT INDEX idx on fts_test (title, body);
# Select word "tutorial" in the table
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DROP TABLE fts_test;
# Create FTS table
CREATE TABLE fts_test (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
create unique index FTS_DOC_ID_INDEX on fts_test(FTS_DOC_ID);
# Insert six rows
INSERT INTO fts_test (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# Create the FTS index
# We could support online fulltext index creation when a FTS_DOC_ID
# column already exists. This has not been implemented yet.
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
CREATE FULLTEXT INDEX idx on fts_test (title, body) LOCK=NONE;
CREATE FULLTEXT INDEX idx on fts_test (title, body);
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
ALTER TABLE fts_test ROW_FORMAT=REDUNDANT, LOCK=NONE;
ALTER TABLE fts_test ROW_FORMAT=REDUNDANT;
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
# Drop and recreate
drop index idx on fts_test;
CREATE FULLTEXT INDEX idx on fts_test (title, body);
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
# Drop the FTS_DOC_ID_INDEX and try again
drop index idx on fts_test;
drop index FTS_DOC_ID_INDEX on fts_test;
CREATE FULLTEXT INDEX idx on fts_test (title, body);
SELECT * FROM fts_test WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
drop table fts_test;
# Test FTS_DOC_ID and FTS_DOC_ID_INDEX all in the create table clause
CREATE TABLE fts_test (
FTS_DOC_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL DEFAULT '',
text mediumtext NOT NULL,
PRIMARY KEY (FTS_DOC_ID),
UNIQUE KEY FTS_DOC_ID_INDEX (FTS_DOC_ID),
FULLTEXT KEY idx (title,text)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
set @@auto_increment_increment=10;
INSERT INTO fts_test (title, text) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
-- disable_result_log
ANALYZE TABLE fts_test;
-- enable_result_log
set @@auto_increment_increment=1;
select *, match(title, text) AGAINST ('database') as score
from fts_test order by score desc;
drop index idx on fts_test;
drop table fts_test;
# This should fail:
# Create a FTS_DOC_ID of the wrong type (should be bigint)
--error 1166
CREATE TABLE fts_test (
FTS_DOC_ID int(20) unsigned NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL DEFAULT '',
text mediumtext NOT NULL,
PRIMARY KEY (FTS_DOC_ID),
UNIQUE KEY FTS_DOC_ID_INDEX (FTS_DOC_ID),
FULLTEXT KEY idx (title,text)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
# This should fail:
# Create a FTS_DOC_ID_INDEX of the wrong type (should be unique)
--error ER_INNODB_FT_WRONG_DOCID_INDEX
CREATE TABLE fts_test (
FTS_DOC_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL DEFAULT '',
text mediumtext NOT NULL,
PRIMARY KEY (FTS_DOC_ID),
KEY FTS_DOC_ID_INDEX (FTS_DOC_ID),
FULLTEXT KEY idx (title,text)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
CREATE TABLE articles (
FTS_DOC_ID BIGINT UNSIGNED NOT NULL ,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
INSERT INTO articles (FTS_DOC_ID, title, body) VALUES
(9, 'MySQL Tutorial','DBMS stands for DataBase ...'),
(10, 'How To Use MySQL Well','After you went through a ...'),
(12, 'Optimizing MySQL','In this tutorial we will show ...'),
(14,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(19, 'MySQL vs. YourSQL','In the following database comparison ...'),
(20, 'MySQL Security','When configured properly, MySQL ...');
--error ER_INNODB_FT_LIMIT
ALTER TABLE articles ADD FULLTEXT INDEX idx3 (title),
ADD FULLTEXT INDEX idx5 (title);
CREATE FULLTEXT INDEX idx on articles (title);
ALTER TABLE articles ADD FULLTEXT INDEX idx3 (title);
ALTER TABLE articles ADD INDEX t20 (title(20)), LOCK=NONE;
ALTER TABLE articles DROP INDEX t20;
INSERT INTO articles (FTS_DOC_ID, title, body) VALUES
(29, 'MySQL Tutorial','DBMS stands for DataBase ...'),
(30, 'How To Use MySQL Well','After you went through a ...'),
(32, 'Optimizing MySQL','In this tutorial we will show ...'),
(34,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(39, 'MySQL vs. YourSQL','In the following database comparison ...'),
(40, 'MySQL Security','When configured properly, MySQL ...');
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DROP INDEX idx ON articles;
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
CREATE FULLTEXT INDEX idx on articles (title, body);
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DROP TABLE articles;
create table articles(`FTS_DOC_ID` serial,
`col32` timestamp not null,`col115` text) engine=innodb;
create fulltext index `idx5` on articles(`col115`) ;
alter ignore table articles add primary key (`col32`) ;
drop table articles;
# Create a table with FTS index, this will create hidden column FTS_DOC_ID
CREATE TABLE articles (
id INT UNSIGNED NOT NULL,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
INSERT INTO articles VALUES
(1, 'MySQL Tutorial','DBMS stands for DataBase ...') ,
(2, 'How To Use MySQL Well','After you went through a ...'),
(3, 'Optimizing MySQL','In this tutorial we will show ...'),
(4, '1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5, 'MySQL vs. YourSQL','In the following database comparison ...'),
(6, 'MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on articles (title, body);
# Drop the FTS index, however, this will keep the FTS_DOC_ID hidden
# column (to avoid a table rebuild)
DROP INDEX idx ON articles;
# Now create cluster index on id online; The rebuild should still
# have the FTS_DOC_ID
CREATE UNIQUE INDEX idx2 ON articles(id);
# Recreate FTS index, this should not require a rebuild,
# since the FTS_DOC_ID is still there
CREATE FULLTEXT INDEX idx on articles (title, body);
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DROP TABLE articles;

View File

@ -0,0 +1,231 @@
# This is the basic function tests for innodb FTS
-- source include/have_innodb.inc
# Create FTS table
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# Create the FTS index
CREATE FULLTEXT INDEX idx on articles (title, body);
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT COUNT(*) FROM articles
WHERE MATCH (title, body)
AGAINST ('database' IN NATURAL LANGUAGE MODE);
SELECT * FROM articles
WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT COUNT(IF(MATCH (title, body)
AGAINST ('database' IN NATURAL LANGUAGE MODE), 1, NULL))
AS count FROM articles;
ANALYZE TABLE articles;
# Boolean search
# Select rows contain "MySQL" but not "YourSQL"
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);
# Select rows contain at least one of the two words
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('DBMS Security' IN BOOLEAN MODE);
# Select rows contain both "MySQL" and "YourSQL"
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL +YourSQL' IN BOOLEAN MODE);
DROP INDEX idx ON articles;
# Create the FTS index
CREATE FULLTEXT INDEX idx on articles (title, body);
CREATE FULLTEXT INDEX idx1 on articles (title);
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DROP INDEX idx ON articles;
DROP INDEX idx1 ON articles;
CREATE FULLTEXT INDEX idx1 on articles (title);
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
drop table articles;
# Create FTS table
CREATE TABLE articles (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
create unique index FTS_DOC_ID_INDEX on articles(FTS_DOC_ID);
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# Create the FTS index
CREATE FULLTEXT INDEX idx on articles (title, body);
# "the" is in the default stopword, it would not be selected
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
drop table articles;
# Create FTS table
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
CREATE FULLTEXT INDEX idx on articles (title);
CREATE FULLTEXT INDEX idx2 on articles (body);
# "the" is in the default stopword, it would not be selected
--error 1191
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT * FROM articles WHERE MATCH (body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
drop index idx2 on articles;
--error 1191
SELECT * FROM articles WHERE MATCH (body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
CREATE FULLTEXT INDEX idx2 on articles (body);
SELECT * FROM articles WHERE MATCH (body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
UPDATE articles set title = 'aaaa'
WHERE MATCH(title) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT * FROM articles WHERE MATCH (title)
AGAINST ('aaaa' IN NATURAL LANGUAGE MODE);
drop table articles;
CREATE TABLE articles (
FTS_DOC_ID BIGINT UNSIGNED NOT NULL ,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
CREATE FULLTEXT INDEX idx on articles (title);
INSERT INTO articles VALUES (9, 'MySQL Tutorial','DBMS stands for DataBase ...');
# This should fail since we did not supply a new Doc ID
-- error 182
UPDATE articles set title = 'bbbb' WHERE MATCH(title) AGAINST ('tutorial' IN NATURAL LANGUAGE MODE);
# This should fail, since the Doc ID supplied is less than the old value 9
-- error 182
UPDATE articles set title = 'bbbb', FTS_DOC_ID=8 WHERE MATCH(title) AGAINST ('tutorial' IN NATURAL LANGUAGE MODE);
# This should be successful
UPDATE articles set title = 'bbbb', FTS_DOC_ID=10 WHERE MATCH(title) AGAINST ('tutorial' IN NATURAL LANGUAGE MODE);
# Check update to be successful
SELECT * FROM articles WHERE MATCH (title) AGAINST ('bbbb' IN NATURAL LANGUAGE MODE);
SELECT * FROM articles WHERE MATCH (title) AGAINST ('tutorial' IN NATURAL LANGUAGE MODE);
CREATE FULLTEXT INDEX idx2 ON articles (body);
SELECT * FROM articles WHERE MATCH (body) AGAINST ('database' IN NATURAL LANGUAGE MODE);
UPDATE articles set body = 'bbbb', FTS_DOC_ID=11 WHERE MATCH(body) AGAINST ('database' IN NATURAL LANGUAGE MODE);
drop table articles;
create table `articles`(`a` varchar(2) not null)engine=innodb;
# This create index should fail. FTS_DOC_ID_INDEX is reserved as a unique
# index on FTS_DOC_ID
--error ER_INNODB_FT_WRONG_DOCID_INDEX
create fulltext index `FTS_DOC_ID_INDEX` on `articles`(`a`);
create unique index `a` on `articles`(`a`);
drop table articles;
# We will check validity of FTS_DOC_ID, which must be of an UNSIGNED
# NOT NULL bigint
CREATE TABLE wp(
FTS_DOC_ID bigint PRIMARY KEY,
title VARCHAR(255) NOT NULL DEFAULT '',
text MEDIUMTEXT NOT NULL ) ENGINE=InnoDB;
INSERT INTO wp (FTS_DOC_ID, title, text) VALUES
(1, 'MySQL Tutorial','DBMS stands for DataBase ...'),
(2, 'How To Use MySQL Well','After you went through a ...');
--error ER_INNODB_FT_WRONG_DOCID_COLUMN
CREATE FULLTEXT INDEX idx ON wp(title, text);
DROP TABLE wp;
CREATE TABLE wp(
FTS_DOC_ID bigint unsigned PRIMARY KEY,
title VARCHAR(255) NOT NULL DEFAULT '',
text MEDIUMTEXT NOT NULL ) ENGINE=InnoDB;
INSERT INTO wp (FTS_DOC_ID, title, text) VALUES
(1, 'MySQL Tutorial','DBMS stands for DataBase ...'),
(2, 'How To Use MySQL Well','After you went through a ...');
CREATE FULLTEXT INDEX idx ON wp(title, text);
SELECT FTS_DOC_ID, MATCH(title, text) AGAINST ('database')
FROM wp;
DROP TABLE wp;

View File

@ -0,0 +1 @@
--loose-innodb-ft-default-stopword

View File

@ -0,0 +1,670 @@
# This is the basic function tests for innodb FTS
-- source include/have_innodb.inc
select * from information_schema.innodb_ft_default_stopword;
# Create FTS table
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# "the" is in the default stopword, it would not be selected
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('the' IN NATURAL LANGUAGE MODE);
let $innodb_ft_server_stopword_table_orig=`select @@innodb_ft_server_stopword_table`;
let $innodb_ft_enable_stopword_orig=`select @@innodb_ft_enable_stopword`;
let $innodb_ft_user_stopword_table_orig=`select @@innodb_ft_user_stopword_table`;
select @@innodb_ft_server_stopword_table;
select @@innodb_ft_enable_stopword;
select @@innodb_ft_user_stopword_table;
# Provide user defined stopword table, if not (correctly) defined,
# it will be rejected
--error 1231
set global innodb_ft_server_stopword_table = "not_defined";
# Define a correct formated user stopword table
create table user_stopword(value varchar(30)) engine = innodb;
# The set operation should be successful
set global innodb_ft_server_stopword_table = "test/user_stopword";
drop index title on articles;
create fulltext index idx on articles(title, body);
# Now we should be able to find "the"
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('the' IN NATURAL LANGUAGE MODE);
# Nothing inserted into the default stopword, so essentially
# nothing get screened. The new stopword could only be
# effective for table created thereafter
CREATE TABLE articles_2 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles_2 (title, body)
VALUES ('test for stopwords','this is it...');
# Now we can find record with "this"
SELECT * FROM articles_2 WHERE MATCH (title,body)
AGAINST ('this' IN NATURAL LANGUAGE MODE);
# Ok, let's instantiate some value into user supplied stop word
# table
insert into user_stopword values("this");
# Ok, let's repeat with the new table again.
CREATE TABLE articles_3 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles_3 (title, body)
VALUES ('test for stopwords','this is it...');
# Now we should NOT find record with "this"
SELECT * FROM articles_3 WHERE MATCH (title,body)
AGAINST ('this' IN NATURAL LANGUAGE MODE);
# Test session level stopword control "innodb_user_stopword_table"
create table user_stopword_session(value varchar(30)) engine = innodb;
insert into user_stopword_session values("session");
set session innodb_ft_user_stopword_table="test/user_stopword_session";
CREATE TABLE articles_4 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles_4 (title, body)
VALUES ('test for session stopwords','this should also be excluded...');
# "session" is excluded
SELECT * FROM articles_4 WHERE MATCH (title,body)
AGAINST ('session' IN NATURAL LANGUAGE MODE);
# But we can find record with "this"
SELECT * FROM articles_4 WHERE MATCH (title,body)
AGAINST ('this' IN NATURAL LANGUAGE MODE);
--connect (con1,localhost,root,,)
CREATE TABLE articles_5 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
INSERT INTO articles_5 (title, body)
VALUES ('test for session stopwords','this should also be excluded...');
# "session" should be found since the stopword table is session specific
SELECT * FROM articles_5 WHERE MATCH (title,body)
AGAINST ('session' IN NATURAL LANGUAGE MODE);
--connection default
drop table articles;
drop table articles_2;
drop table articles_3;
drop table articles_4;
drop table articles_5;
drop table user_stopword;
drop table user_stopword_session;
eval SET GLOBAL innodb_ft_enable_stopword=$innodb_ft_enable_stopword_orig;
eval SET GLOBAL innodb_ft_server_stopword_table=default;
#---------------------------------------------------------------------------------------
# Behavior :
# The stopword is loaded into memory at
# 1) create fulltext index time,
# 2) boot server,
# 3) first time FTs is used
# So if you already created a FTS index, and then turn off stopword
# or change stopword table content it won't affect the FTS
# that already created since the stopword list are already loaded.
# It will only affect the new FTS index created after you changed
# the settings.
# Create FTS table
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT `idx` (title,body)
) ENGINE=InnoDB;
SHOW CREATE TABLE articles;
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','In what tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# Case : server_stopword=default
# Try to Search default stopword from innodb, "where", "will", "what"
# and "when" are all stopwords
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
# boolean No result expected
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
# no result expected
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
# no result expected
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
INSERT INTO articles(title,body) values ('the record will' , 'not index the , will words');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
# Not going to update as where condition can not find record
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
# Update the record
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE id = 7;
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
# Delete will not work as where condition do not return
DELETE FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE id = 7;
DELETE FROM articles WHERE id = 7;
# Case : Turn OFF stopword list variable and search stopword on OLD index.
# disable stopword list
#SET global innodb_ft_server_stopword_table = "";
SET SESSION innodb_ft_enable_stopword = 0;
select @@innodb_ft_enable_stopword;
#SET global innodb_ft_user_stopword_table = "";
# search default stopword with innodb_ft_enable_stopword is OFF.
# No records expected even though we turned OFF stopwod filtering
# (refer Behavior (at the top of the test) for explanation )
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
INSERT INTO articles(title,body) values ('the record will' , 'not index the , will words');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
# Not going to update as where condition can not find record
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
# Update the record
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE id = 8;
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
SELECT * FROM articles WHERE id = 8;
# Delete will not work as where condition do not return
DELETE FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE id = 8;
DELETE FROM articles WHERE id = 8;
# Case : Turn OFF stopword list variable and search stopword on NEW index.
# Drop index
ALTER TABLE articles DROP INDEX idx;
SHOW CREATE TABLE articles;
# Create the FTS index Using Alter Table.
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
ANALYZE TABLE articles;
# search default stopword with innodb_ft_enable_stopword is OFF.
# All records expected as stopwod filtering is OFF and we created
# new FTS index.
# (refer Behavior (at the top of the test) for explanation )
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
INSERT INTO articles(title,body) values ('the record will' , 'not index the , will words');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
# Update will succeed.
UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT COUNT(*),max(id) FROM articles;
# Update the record - uncommet on fix
#UPDATE articles SET title = "update the record" , body = 'to see will is indexed or not'
#WHERE id = 9;
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
# Delete will succeed.
DELETE FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE id = 9;
DROP TABLE articles;
eval SET SESSION innodb_ft_enable_stopword=$innodb_ft_enable_stopword_orig;
#eval SET GLOBAL innodb_ft_server_stopword_table=$innodb_ft_server_stopword_table_orig;
eval SET GLOBAL innodb_ft_server_stopword_table=default;
#eval SET GLOBAL innodb_ft_user_stopword_table=$innodb_ft_user_stopword_table_orig;
eval SET SESSION innodb_ft_user_stopword_table=default;
#---------------------------------------------------------------------------------------
select @@innodb_ft_server_stopword_table;
select @@innodb_ft_enable_stopword;
select @@innodb_ft_user_stopword_table;
# Create FTS table
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT `idx` (title,body)
) ENGINE=InnoDB;
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','In what tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# No records expeced for select
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
# Define a correct formated user stopword table
create table user_stopword(value varchar(30)) engine = innodb;
# The set operation should be successful
set session innodb_ft_user_stopword_table = "test/user_stopword";
# Define a correct formated server stopword table
create table server_stopword(value varchar(30)) engine = innodb;
# The set operation should be successful
set global innodb_ft_server_stopword_table = "test/server_stopword";
# Add values into user supplied stop word table
insert into user_stopword values("this"),("will"),("the");
# Drop existing index and create the FTS index Using Alter Table.
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
# Add values into server supplied stop word table
insert into server_stopword values("what"),("where");
# Follwoing should return result as server stopword list was empty at create index time
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
# Delete stopword from user list
DELETE FROM user_stopword;
# Drop existing index and create the FTS index Using Alter Table.
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
# Follwoing should return result even though to server stopword list
# conatin these words. Session level stopword list takes priority
# Here user_stopword is set using innodb_ft_user_stopword_table
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
# Follwoing should return result as user stopword list was empty at create index time
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
# Add values into user supplied stop word table
insert into user_stopword values("this"),("will"),("the");
# Drop existing index and create the FTS index Using Alter Table.
ALTER TABLE articles DROP INDEX idx;
SET SESSION innodb_ft_enable_stopword = 0;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
# Session level stopword list takes priority
SET SESSION innodb_ft_enable_stopword = 1;
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
# Make user stopword list deafult so as to server stopword list takes priority
SET SESSION innodb_ft_enable_stopword = 1;
SET SESSION innodb_ft_user_stopword_table = default;
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
DROP TABLE articles,user_stopword,server_stopword;
# Restore Defaults
eval SET SESSION innodb_ft_enable_stopword=$innodb_ft_enable_stopword_orig;
eval SET GLOBAL innodb_ft_server_stopword_table=default;
eval SET SESSION innodb_ft_user_stopword_table=default;
select @@innodb_ft_server_stopword_table;
select @@innodb_ft_enable_stopword;
select @@innodb_ft_user_stopword_table;
#---------------------------------------------------------------------------------------
# Create FTS table
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT `idx` (title,body)
) ENGINE=InnoDB;
SHOW CREATE TABLE articles;
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','In what tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# No records expeced for select
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
# Define a correct formated user stopword table
create table user_stopword(value varchar(30)) engine = innodb;
# The set operation should be successful
set session innodb_ft_user_stopword_table = "test/user_stopword";
insert into user_stopword values("mysqld"),("DBMS");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+DBMS +mysql" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('mysqld');
# Drop existing index and create the FTS index Using Alter Table.
# user stopword list will take effect.
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+DBMS +mysql" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('mysqld');
# set user stopword list empty
set session innodb_ft_user_stopword_table = default;
# Define a correct formated user stopword table
create table server_stopword(value varchar(30)) engine = innodb;
# The set operation should be successful
set global innodb_ft_server_stopword_table = "test/server_stopword";
insert into server_stopword values("root"),("properly");
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+root +mysql" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('properly');
# set user stopword list empty
set session innodb_ft_user_stopword_table = "test/user_stopword";
# The set operation should be successful
set global innodb_ft_server_stopword_table = "test/server_stopword";
# user stopword list take effect as its session level
# Result expected for select
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+root +mysql" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('properly');
# set user stopword list
set session innodb_ft_user_stopword_table = "test/user_stopword";
DELETE FROM user_stopword;
# The set operation should be successful
set global innodb_ft_server_stopword_table = "test/server_stopword";
DELETE FROM server_stopword;
# user stopword list take affect as its session level
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+wha* +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('what');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+root +mysql" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('properly');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+DBMS +mysql" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('mysqld');
DROP TABLE articles,user_stopword,server_stopword;
# Restore Values
eval SET SESSION innodb_ft_enable_stopword=$innodb_ft_enable_stopword_orig;
eval SET GLOBAL innodb_ft_server_stopword_table=default;
eval SET SESSION innodb_ft_user_stopword_table=default;
#------------------------------------------------------------------------------
# FTS stopword list test - check varaibles across sessions
# Create FTS table
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT `idx` (title,body)
) ENGINE=InnoDB;
SHOW CREATE TABLE articles;
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','In what tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# session varaible innodb_ft_enable_stopword=0 will take effect for new FTS index
SET SESSION innodb_ft_enable_stopword = 0;
select @@innodb_ft_enable_stopword;
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
--echo "In connection 1"
--connection con1
select @@innodb_ft_enable_stopword;
ANALYZE TABLE articles;
# result expected as index created before setting innodb_ft_enable_stopword varaible off
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
SET SESSION innodb_ft_enable_stopword = 1;
select @@innodb_ft_enable_stopword;
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
# no result expected turned innodb_ft_enable_stopword is ON
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
--echo "In connection default"
--connection default
select @@innodb_ft_enable_stopword;
# no result expected as word not indexed from connection 1
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("where will");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("when");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST ("what" WITH QUERY EXPANSION);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("whe*" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+what +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+from" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+where +(show what)" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@6' IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"where will"@9' IN BOOLEAN MODE);
INSERT INTO articles(title,body) values ('the record will' , 'not index the , will words');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
SET SESSION innodb_ft_enable_stopword = 1;
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+the +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"the will"@11' IN BOOLEAN MODE);
--echo "In connection 1"
--connection con1
SET SESSION innodb_ft_enable_stopword = 1;
# Define a correct formated user stopword table
create table user_stopword(value varchar(30)) engine = innodb;
# The set operation should be successful
set session innodb_ft_user_stopword_table = "test/user_stopword";
# Add values into user supplied stop word table
insert into user_stopword values("this"),("will"),("the");
# Drop existing index and create the FTS index Using Alter Table.
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
# no result expected as innodb_ft_user_stopword_table filter it
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
--echo "In connection default"
--connection default
# no result expected as innodb_ft_user_stopword_table filter it from connection1
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+show +will" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('will');
select @@innodb_ft_user_stopword_table;
# Define a correct formated user stopword table
create table user_stopword_1(value varchar(30)) engine = innodb;
# The set operation should be successful
set session innodb_ft_user_stopword_table = "test/user_stopword_1";
insert into user_stopword_1 values("when");
SET SESSION innodb_ft_enable_stopword = 1;
# result expected
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+when" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('when');
# Drop existing index and create the FTS index Using Alter Table.
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
# no result expected
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+when" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('when');
--echo "In connection 1"
--connection con1
SET SESSION innodb_ft_enable_stopword = 1;
SET SESSION innodb_ft_user_stopword_table=default;
select @@innodb_ft_user_stopword_table;
select @@innodb_ft_server_stopword_table;
# Define a correct formated server stopword table
create table server_stopword(value varchar(30)) engine = innodb;
# The set operation should be successful
SET GLOBAL innodb_ft_server_stopword_table = "test/server_stopword";
select @@innodb_ft_server_stopword_table;
insert into server_stopword values("when"),("the");
# Drop existing index and create the FTS index Using Alter Table.
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
# no result expected
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+when" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('the');
disconnect con1;
--source include/wait_until_disconnected.inc
--echo "In connection default"
--connection default
SET SESSION innodb_ft_enable_stopword = 1;
SET SESSION innodb_ft_user_stopword_table=default;
select @@innodb_ft_server_stopword_table;
# result expected
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+will +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('where');
insert into server_stopword values("where"),("will");
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+will +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('where');
ALTER TABLE articles DROP INDEX idx;
ALTER TABLE articles ADD FULLTEXT INDEX idx (title,body);
# no result expected
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+when" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('the');
SELECT * FROM articles WHERE MATCH(title,body) AGAINST("+will +where" IN BOOLEAN MODE);
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('where');
DROP TABLE articles,user_stopword,user_stopword_1,server_stopword;
# Restore Values
eval SET SESSION innodb_ft_enable_stopword=$innodb_ft_enable_stopword_orig;
eval SET GLOBAL innodb_ft_server_stopword_table=default;
eval SET SESSION innodb_ft_user_stopword_table=default;

View File

@ -0,0 +1,381 @@
# This test for FTS index with big records
# case a) more words in single record
# b) more words across records
--source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
# Create FTS table
EVAL CREATE TABLE t1 (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT
) ENGINE = InnoDB;
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
let $counter = 1;
--disable_query_log
# Generate input file using perl
perl;
use strict;
my $fname= "$ENV{'MYSQLTEST_VARDIR'}/tmp/fts_input_data1.txt";
open FH,">$fname";
my $record_counter = 1;
while ($record_counter < 50) {
my $word_counter = 1;
my ($col1,$col2);
while ($word_counter < 51) {
$col1 = $col1. "row".$record_counter."col1"."word".$word_counter." ";
$col2 = $col2. "row".$record_counter."col2"."word".$word_counter." ";
$word_counter++;
}
print FH "$col1,$col2\n";
$record_counter++;
}
close FH;
EOF
EVAL LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/fts_input_data1.txt' INTO
TABLE t1 FIELDS TERMINATED BY ',' (a,b);
--enable_query_log
--echo "Loading data using LOAD DATA Command , File <MYSQLTEST_VARDIR>/tmp/fts_input_data1.txt"
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT COUNT(*) FROM t1;
# Select word "tutorial" in the table
SELECT FTS_DOC_ID FROM t1 WHERE MATCH (a,b)
AGAINST ('row35col2word49' IN NATURAL LANGUAGE MODE);
# boolean mode
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row5col2word49" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row35col2word49 +(row35col1word49 row35col2word40)" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row35col2word49 -(row45col2word49)" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("row5col2word49 row5col2word40" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ("+row5col2word* +row5col1word49*" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ('"row35col2word49"' IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ('"ROW35col2WORD49"' IN BOOLEAN MODE);
# query expansion
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST ("row5col2word49" WITH QUERY EXPANSION);
SELECT FTS_DOC_ID FROM t1
WHERE MATCH (a,b)
AGAINST ('"row5col2word48 row5col2word49"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"row5col2word48 row5col2word49"@1' IN BOOLEAN MODE);
UPDATE t1 SET a = "using update" , b = "changing fulltext index record", FTS_DOC_ID = FTS_DOC_ID + 10000
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("changing fulltext" IN BOOLEAN MODE);
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
--remove_file '$MYSQLTEST_VARDIR/tmp/fts_input_data1.txt';
DROP TABLE t1;
#--------------------------------------------------------------------------------------------
# Create FTS table
EVAL CREATE TABLE t1 (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT
) ENGINE = InnoDB;
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
let $counter = 1;
--disable_query_log
# Generate input file using perl
perl;
use strict;
my $fname= "$ENV{'MYSQLTEST_VARDIR'}/tmp/fts_input_data2.txt";
open FH,">$fname";
my $record_counter = 1;
while ($record_counter < 101) {
my $word_counter = 1;
my ($col1,$col2);
while ($word_counter < 50) {
$col1 = $col1. "row".$record_counter."col1"."word".$word_counter." ";
$col2 = $col2. "row".$record_counter."col2"."word".$word_counter." ";
$word_counter++;
}
print FH "$col1,$col2\n";
$record_counter++;
}
close FH;
EOF
EVAL LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/fts_input_data2.txt'
INTO TABLE t1 FIELDS TERMINATED BY ',' (a,b);
--enable_query_log
--echo "Loading data using LOAD DATA Command , File <MYSQLTEST_VARDIR>/tmp/fts_input_data2.txt"
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT COUNT(*) FROM t1;
SELECT FTS_DOC_ID from t1 WHERE b like '%row300col2word30%';
SELECT FTS_DOC_ID FROM t1 WHERE MATCH (a,b)
AGAINST ('row35col2word49' IN NATURAL LANGUAGE MODE);
# boolean mode
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row5col2word49" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row35col2word49 +(row35col1word49 row35col2word40)" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+row35col2word49 -(row45col2word49)" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("row5col2word49 row5col2word40" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ("+row5col2word* +row5col1word49*" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ('"row35col2word49"' IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ('"ROW35col2WORD49"' IN BOOLEAN MODE);
# query expansion
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST ("row5col2word49" WITH QUERY EXPANSION);
SELECT FTS_DOC_ID FROM t1
WHERE MATCH (a,b)
AGAINST ('"row5col2word48 row5col2word49"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"row5col2word48 row5col2word49"@1' IN BOOLEAN MODE);
UPDATE t1 SET a = "using update" , b = "changing fulltext index record", FTS_DOC_ID = FTS_DOC_ID + 10000
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
SELECT a,b FROM t1
WHERE MATCH(a,b) AGAINST("+row5col2word49 +row5col1word49" IN BOOLEAN MODE);
SELECT a,b FROM t1
WHERE MATCH(a,b) AGAINST("changing fulltext" IN BOOLEAN MODE);
SELECT a,b FROM t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
SELECT a,b FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
ALTER TABLE t1 DROP INDEX idx;
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
UPDATE t1 SET a = NULL , b = NULL, FTS_DOC_ID= 6000 + FTS_DOC_ID;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
ALTER TABLE t1 DROP INDEX idx;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
--remove_file '$MYSQLTEST_VARDIR/tmp/fts_input_data2.txt';
DROP TABLE t1;
#--------------------------------------------------------------------------------------------
# Create FTS table
EVAL CREATE TABLE t1 (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT
) ENGINE = InnoDB;
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
let $counter = 1;
--disable_query_log
# Generate input file using perl
perl;
use strict;
my $fname= "$ENV{'MYSQLTEST_VARDIR'}/tmp/fts_input_data3.txt";
open FH,">$fname";
my $record_counter = 1;
while ($record_counter < 101) {
my $word_counter = 1;
my ($col1,$col2);
while ($word_counter < 50) {
$col1 = $col1. "samerowword" ." ";
$col2 = $col2. "samerowword" ." ";
$word_counter++;
}
print FH "$col1,$col2\n";
$record_counter++;
}
close FH;
EOF
EVAL LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/fts_input_data3.txt'
INTO TABLE t1 FIELDS TERMINATED BY ',' (a,b);
--enable_query_log
--echo "Loading data using LOAD DATA Command , File <MYSQLTEST_VARDIR>/tmp/fts_input_data3.txt"
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT COUNT(*) FROM t1;
SELECT COUNT(*) from t1 WHERE b like '%samerowword%';
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b)
AGAINST ('samerowword' IN NATURAL LANGUAGE MODE);
# boolean mode
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword +samerowword" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword -(row45col2word49)" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH a,b AGAINST ("+sameroww" IN BOOLEAN MODE);
# query expansion
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST ("samerowword" WITH QUERY EXPANSION);
UPDATE t1 SET a = "using update" , b = "changing fulltext index record",
FTS_DOC_ID = FTS_DOC_ID + 10000
WHERE MATCH(a,b) AGAINST("+samerowword +samerowword" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword +samerowword" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("changing fulltext" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
ALTER TABLE t1 DROP INDEX idx;
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
UPDATE t1 SET a = NULL , b = NULL ;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
ALTER TABLE t1 DROP INDEX idx;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
--remove_file '$MYSQLTEST_VARDIR/tmp/fts_input_data3.txt';
DROP TABLE t1;
#--------------------------------------------------------------------------------------------
# Create FTS with same word and numbers
EVAL CREATE TABLE t1 (
FTS_DOC_ID BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT
) ENGINE = InnoDB;
CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
let $counter = 1;
--disable_query_log
# Generate input file using perl
perl;
use strict;
my $fname= "$ENV{'MYSQLTEST_VARDIR'}/tmp/fts_input_data4.txt";
open FH,">$fname";
my $record_counter = 1;
while ($record_counter < 101) {
my $word_counter = 1001;
my ($col1,$col2);
while ($word_counter < 1101) {
$col1 = $col1. "samerowword" ." ";
$col2 = $col2. "$word_counter" ." ";
$word_counter++;
}
print FH "$col1,$col2\n";
$record_counter++;
}
close FH;
EOF
EVAL LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/fts_input_data4.txt'
INTO TABLE t1 FIELDS TERMINATED BY ',' (a,b);
--enable_query_log
--echo "Loading data using LOAD DATA Command , File <MYSQLTEST_VARDIR>/tmp/fts_input_data4.txt"
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT COUNT(*) FROM t1;
SELECT COUNT(*) from t1 WHERE a like '%samerowword%';
SELECT COUNT(*) FROM t1 WHERE MATCH (a,b)
AGAINST ('samerowword' IN NATURAL LANGUAGE MODE);
# boolean mode
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST("+samerowword +1050" IN BOOLEAN MODE);
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST("+samerowword" IN BOOLEAN MODE);
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST("+samerowword -(1050)" IN BOOLEAN MODE);
SELECT COUNT(*) from t1 WHERE MATCH a,b AGAINST ("+2001" IN BOOLEAN MODE);
# query expansion
SELECT COUNT(*) from t1 WHERE MATCH(a,b) AGAINST ("samerowword" WITH QUERY EXPANSION);
UPDATE t1 SET a = "using update" , b = "changing fulltext index record",
FTS_DOC_ID = FTS_DOC_ID + 10000
WHERE MATCH(a,b) AGAINST("+samerowword +1050" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword +1050" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+samerowword" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("changing fulltext" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
DELETE FROM t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
SELECT COUNT(*) from t1
WHERE MATCH(a,b) AGAINST("+chang* +fulltext" IN BOOLEAN MODE);
ALTER TABLE t1 DROP INDEX idx;
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
UPDATE t1 SET a = NULL , b = NULL ;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
ALTER TABLE t1 DROP INDEX idx;
SELECT COUNT(*) FROM t1 WHERE a IS NULL AND b IS NULL;
--remove_file '$MYSQLTEST_VARDIR/tmp/fts_input_data4.txt';
DROP TABLE t1;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,904 @@
#------------------------------------------------------------------------------
# FTS with FK and update cascade
#-------------------------------------------------------------------------------
--source include/have_innodb.inc
--disable_warnings
drop table if exists t2,t1;
--enable_warnings
set names utf8;
# Create FTS table
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) ,
b1 TEXT ,
FULLTEXT KEY (a1,b1), PRIMARY KEY (a1, id1)
) CHARACTER SET = utf8 , ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON UPDATE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...');
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
# Insert rows in t2 fk table
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
# Insert rows t2 fk table
INSERT INTO t2 (a2,b2) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# error on violating fk constraint
--error 1452
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
# error on delete from parent table
--error 1451
DELETE FROM t1;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ;
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial') ;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial' WITH QUERY EXPANSION) ;
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial' WITH QUERY EXPANSION) ;
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
set global innodb_optimize_fulltext_only=1;
optimize table t1;
set global innodb_optimize_fulltext_only=0;
# Updating parent table hence child table should get updated due to 'update cascade' clause
UPDATE t1 SET a1 = "changing column - on update cascade" , b1 = "to check foreign constraint" WHERE
MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# no records expected
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# InnoDB:Error child table shows records which is incorrect - UPADTE on Fix
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# it shows updated record
SELECT id1 FROM t1 WHERE MATCH (a1,b1) AGAINST ('+update +cascade' IN BOOLEAN MODE) ;
# InnoDB:Error child table does not show the expected record
SELECT id2 FROM t2 WHERE MATCH (a2,b2) AGAINST ('+update +cascade' IN BOOLEAN MODE) ;
SELECT id2 FROM t2 WHERE a2 LIKE '%UPDATE CASCADE%';
DROP TABLE t2 , t1;
# on update cascade
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on update cascade) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s2 = 'Rainbows' where s2 <> 'Sunshine';
commit;
select * from t2 where match(s2) against ('Lollipops');
DROP TABLE t2 , t1;
# on delete cascade
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on delete cascade) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
delete from t1 where s2 <> 'Sunshine';
select * from t2 where match(s2) against ('Lollipops');
DROP TABLE t2 , t1;
# on delete set NULL
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on delete set null) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
delete from t1 where s2 <> 'Sunshine';
select * from t2 where match(s2) against ('Lollipops');
DROP TABLE t2 , t1;
# on update set NULL
create table t1 (s1 int, s2 varchar(200), primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (s1 int, s2 varchar(200),
fulltext key(s2),
foreign key (s1,s2) references t1 (s1,s2) on update set null) ENGINE = InnoDB;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s2 = 'Rainbows' where s2 <> 'Sunshine';
commit;
select * from t2 where match(s2) against ('Lollipops');
DROP TABLE t2 , t1;
# When Doc ID is involved
create table t1 (s1 bigint unsigned not null, s2 varchar(200),
primary key (s1,s2)) ENGINE = InnoDB;
create table t2 (FTS_DOC_ID BIGINT UNSIGNED NOT NULL, s2 varchar(200),
foreign key (FTS_DOC_ID) references t1 (s1)
on update cascade) ENGINE = InnoDB;
create fulltext index idx on t2(s2);
show create table t2;
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
insert into t2 values (1,'Sunshine'),(2,'Lollipops');
update t1 set s1 = 3 where s1=1;
select * from t2 where match(s2) against ('sunshine');
# FTS Doc ID cannot be reused
--error 1451
update t1 set s1 = 1 where s1=3;
DROP TABLE t2 , t1;
#------------------------------------------------------------------------------
# FTS with FK and delete casecade
#------------------------------------------------------------------------------
# Create FTS table
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) PRIMARY KEY,
b1 TEXT character set utf8 ,
FULLTEXT KEY (a1,b1)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT character set utf8 ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON DELETE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...'),
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
# Insert rows in t2
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# delete records from parent
DELETE FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# no records expected
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t1 WHERE a1 LIKE '%tutorial%';
SELECT * FROM t2 WHERE a2 LIKE '%tutorial%';
DROP TABLE t2 , t1;
#------------------------------------------------------------------------------
# FTS with FK+transactions and UPDATE casecade with transaction
#-------------------------------------------------------------------------------
--disable_warnings
DROP TABLE IF EXISTS t2,t1;
--enable_warnings
SET NAMES utf8;
# Create FTS table
CREATE TABLE t1 (
id1 INT ,
a1 VARCHAR(200) ,
b1 TEXT ,
FULLTEXT KEY (a1,b1), PRIMARY KEY(a1, id1)
) CHARACTER SET = utf8 , ENGINE = InnoDB;
CREATE TABLE t2 (
id2 INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a2 VARCHAR(200),
b2 TEXT ,
FOREIGN KEY (a2) REFERENCES t1(a1) ON UPDATE CASCADE,
FULLTEXT KEY (b2,a2)
) CHARACTER SET = utf8 ,ENGINE = InnoDB;
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(1,'MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
(2,'How To Use MySQL Well','After you went through a ...'),
(3,'Optimizing MySQL','In this tutorial we will show ...');
# Insert rows in t2 fk table
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
START TRANSACTION;
# Insert rows
INSERT INTO t1 (id1,a1,b1) VALUES
(4,'1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5,'MySQL vs. YourSQL','In the following database comparison ...'),
(6,'MySQL Security','When configured properly, MySQL ...');
# Insert rows t2 fk table
INSERT INTO t2 (a2,b2) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# error on violating fk constraint
--error 1452
INSERT INTO t2 (a2,b2) VALUES
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
# error on DELETE FROM parent table
--error 1451
DELETE FROM t1;
# records expected
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial') ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial' WITH QUERY EXPANSION) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial' WITH QUERY EXPANSION) ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('"dbms database"@4' IN BOOLEAN MODE) ;
# no records as data not COMMITted.
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('root') ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('root') ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('mysqld (+root)' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('mysqld (-root)' IN BOOLEAN MODE) ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('root' WITH QUERY EXPANSION) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('root' WITH QUERY EXPANSION) ;
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('"database comparison"@02' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('"database comparison"@02' IN BOOLEAN MODE) ;
SELECT * FROM t1;
SELECT * FROM t2;
COMMIT;
START TRANSACTION;
# Updating parent table hence child table should get updated due to 'UPDATE cascade' clause
UPDATE t1 SET a1 = "changing column - on UPDATE cascade" , b1 = "to check foreign constraint" WHERE
MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
COMMIT;
# no records expected
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('tutorial (+mysql -VÐƷWİ)' IN BOOLEAN MODE) ;
# it shows updated record
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('+UPDATE +cascade' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE MATCH (a2,b2) AGAINST ('+UPDATE +cascade' IN BOOLEAN MODE) ;
SELECT * FROM t2 WHERE a2 LIKE '%UPDATE CASCADE%';
DROP TABLE t2 , t1;
# FTS with FK+transactions - UPDATE cascade
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - on DELETE cascade
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - DELETE SET NULL
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - UPDATE SET NULL
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
COMMIT;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
#-----------------------------------------------------------------------------
# FTS with FK+transactions - UPDATE cascade
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - DELETE cascade
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE cascade) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - DELETE SET NULL
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on DELETE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
DELETE FROM t1 WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
# FTS with FK+transactions - UPDATE SET NULL
CREATE TABLE t1 (s1 INT, s2 VARCHAR(200), PRIMARY KEY (s1,s2)) ENGINE = InnoDB;
CREATE TABLE t2 (s1 INT, s2 VARCHAR(200),
FULLTEXT KEY(s2),
FOREIGN KEY (s1,s2) REFERENCES t1 (s1,s2) on UPDATE SET NULL) ENGINE = InnoDB;
START TRANSACTION;
INSERT INTO t1 VALUES (1,'Sunshine'),(2,'Lollipops');
INSERT INTO t2 VALUES (1,'Sunshine'),(2,'Lollipops');
UPDATE t1 set s2 = 'Rainbows' WHERE s2 <> 'Sunshine';
ROLLBACK;
SELECT * FROM t2 WHERE MATCH(s2) AGAINST ('Lollipops');
DROP TABLE t2 , t1;
#------------------------------------------------------------------------------
# FTS index with compressed row format
#------------------------------------------------------------------------------
# Save innodb variables
--disable_query_log
let $innodb_file_format_orig=`select @@innodb_file_format`;
let $innodb_file_per_table_orig=`select @@innodb_file_per_table`;
let $innodb_file_format_max_orig=`select @@innodb_file_format_max`;
let $innodb_large_prefix_orig=`select @@innodb_large_prefix`;
--enable_query_log
# Set Innodb file format as feature works for Barracuda file format
set global innodb_file_format="Barracuda";
set global innodb_file_per_table=1;
set global innodb_large_prefix=1;
set names utf8;
# Create FTS table
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = utf8, ROW_FORMAT=COMPRESSED, ENGINE = InnoDB;
# Insert rows
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','DBMS stands for DataBase VÐƷWİ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
# Create the FTS index Using Alter Table
ALTER TABLE t1 ADD FULLTEXT INDEX idx (a,b);
EVAL SHOW CREATE TABLE t1;
# Insert rows
INSERT INTO t1 (a,b) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
# Select word "tutorial" in the table
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
# boolean mode
select * from t1 where MATCH(a,b) AGAINST("+tutorial +VÐƷWİ" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+-VÐƷWİ" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+Mysql +(tricks never)" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+mysql -(tricks never)" IN BOOLEAN MODE);
select *, MATCH(a,b) AGAINST("mysql stands" IN BOOLEAN MODE) as x from t1;
select * from t1 where MATCH a,b AGAINST ("+database* +VÐƷW*" IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"security mysql"' IN BOOLEAN MODE);
# query expansion
select * from t1 where MATCH(a,b) AGAINST ("VÐƷWİ" WITH QUERY EXPANSION);
# Drop index
ALTER TABLE t1 DROP INDEX idx;
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
-- disable_query_log
-- disable_result_log
ANALYZE TABLE t1;
-- enable_result_log
-- enable_query_log
# Select word "tutorial" in the table
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
# boolean mode
select * from t1 where MATCH(a,b) AGAINST("+tutorial +VÐƷWİ" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+dbms" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+Mysql +(tricks never)" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+mysql -(tricks never)" IN BOOLEAN MODE);
select *, MATCH(a,b) AGAINST("mysql VÐƷWİ" IN BOOLEAN MODE) as x from t1;
# Innodb:Assert eval0eval.c line 148
#select * from t1 where MATCH a,b AGAINST ("+database* +VÐƷWİ*" IN BOOLEAN MODE);
select * from t1 where MATCH a,b AGAINST ('"security mysql"' IN BOOLEAN MODE);
# query expansion
select * from t1 where MATCH(a,b) AGAINST ("VÐƷWİ" WITH QUERY EXPANSION);
# insert for proximity search
INSERT INTO t1 (a,b) VALUES ('test query expansion','for database ...');
# Insert into table with similar word of different distances
INSERT INTO t1 (a,b) VALUES
('test proximity search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test proximity fts search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test more proximity fts search, test, more proximity and phrase',
'search, with proximity innodb');
# This should only return the first document
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@2' IN BOOLEAN MODE);
# This would return no document
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@1' IN BOOLEAN MODE);
# This give you all three documents
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"proximity search"@3' IN BOOLEAN MODE);
# Similar boundary testing for the words
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"test proximity"@5' IN BOOLEAN MODE);
# Test with more word The last document will return, please notice there
# is no ordering requirement for proximity search.
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more test proximity"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more test proximity"@3' IN BOOLEAN MODE);
# The phrase search will not require exact word ordering
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"more fts proximity"@03' IN BOOLEAN MODE);
UPDATE t1 SET a = UPPER(a) , b = UPPER(b) ;
UPDATE t1 SET a = UPPER(a) , b = LOWER(b) ;
select * from t1 where MATCH(a,b) AGAINST("+tutorial +dbms" IN BOOLEAN MODE);
select * from t1 where MATCH(a,b) AGAINST("+VÐƷWİ" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DELETE FROM t1 WHERE MATCH (a,b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DELETE FROM t1 WHERE MATCH (a,b) AGAINST ('"proximity search"@14' IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH (a,b)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
SELECT * FROM t1;
DROP TABLE t1;
--disable_query_log
eval SET GLOBAL innodb_file_format=$innodb_file_format_orig;
eval SET GLOBAL innodb_file_per_table=$innodb_file_per_table_orig;
eval SET GLOBAL innodb_file_format_max=$innodb_file_format_max_orig;
eval SET GLOBAL innodb_large_prefix=$innodb_large_prefix_orig;
--enable_query_log
#------------------------------------------------------------------------------
# FTS index with utf8 character testcase
#------------------------------------------------------------------------------
set names utf8;
# Create FTS table
EVAL CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = utf8, ENGINE=InnoDB;
# Insert rows from different languages
INSERT INTO t1 (a,b) VALUES
('Я могу есть стекло', 'оно мне не вредит'),
('Мога да ям стъкло', 'то не ми вреди'),
('Μπορῶ νὰ φάω σπασμένα' ,'γυαλιὰ χωρὶς νὰ πάθω τίποτα'),
('Příliš žluťoučký kůň', 'úpěl ďábelské kódy'),
('Sævör grét', 'áðan því úlpan var ónýt'),
('うゐのおくやま','けふこえて'),
('いろはにほへど ちりぬる','あさきゆめみじ ゑひもせず');
# insert english text
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','request docteam@oraclehelp.com ...') ,
('Trial version','query performace @1255 minute on 2.1Hz Memory 2GB...') ,
('when To Use MySQL Well','for free faq mail@xyz.com ...');
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
# FTS Queries
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("вредит χωρὶς");
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("оно" WITH QUERY EXPANSION);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("вред*" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+γυαλιὰ +tutorial" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+tutorial +(Мога τίποτα)" IN BOOLEAN MODE);
# Innodb:error - no result returned (update result of query once fixed) (innodb limit , does not understand character boundry for japanses like charcter set)
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("ちりぬる" WITH QUERY EXPANSION);
# Innodb:error - no result returned (update result of query once fixed) (innodb limit , does not understand character boundry for japanses like charcter set)
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("+あさきゆめみじ +ゑひもせず" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("うゐのおく*" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"γυαλιὰ χωρὶς"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"query performace"@02' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"πάθω τίποτα"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"あさきゆめみじ ゑひもせず"@1' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"あさきゆめみじ ゑひもせず"@2' IN BOOLEAN MODE);
ALTER TABLE t1 DROP INDEX idx;
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
# Innodb:error - no result returned (update result of query once fixed) (innodb limit , does not understand character boundry for japanses like charcter set)
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
# Update fails because where condition do not succeed which is incorrect (update result of query once fixed)
UPDATE t1 SET a = "Pchnąć w tę łódź jeża" , b = "lub osiem skrzyń fig" WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
UPDATE t1 SET a = "В чащах юга жил-был цитрус? Да", b = "но фальшивый экземпляр! ёъ" WHERE MATCH(a,b) AGAINST ("вред*" IN BOOLEAN MODE);
DELETE FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
# Innodb error - no result returned
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("あさきゆめみじ ゑひもせず");
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("łódź osiem");
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("вред*" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("фальшив*" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+Sævör +úlpan" IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"łódź jeża"@2' IN BOOLEAN MODE);
SELECT * FROM t1;
DROP TABLE t1;
# This is to test the update operation on FTS indexed and non-indexed
# column
CREATE TABLE t1(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
# Update FULLTEXT indexed column, Doc ID will be updated
UPDATE t1 SET fts_field='anychange' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
# Update non-FULLTEXT indexed column, Doc ID stay to be the same
UPDATE t1 SET no_fts_field='anychange' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
# Update both FULLTEXT indexed and non-indexed column, Doc ID will be updated
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where id = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
# FTS index dropped, the DOC_ID column is kept, however, the ID will not
# change
DROP INDEX f on t1;
UPDATE t1 SET fts_field='anychange' where id = 1;
UPDATE t1 SET no_fts_field='anychange' where id = 1;
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where id = 1;
CREATE FULLTEXT INDEX f ON t1(FTS_FIELD);
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
DROP TABLE t1;
# Test on user supplied 'FTS_DOC_ID'
CREATE TABLE t1(`FTS_DOC_ID` serial,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
# Doc ID must be updated as well (HA_FTS_INVALID_DOCID).
--error 182
UPDATE t1 SET fts_field='anychange' where FTS_DOC_ID = 1;
UPDATE t1 SET fts_field='anychange', FTS_DOC_ID = 2 where FTS_DOC_ID = 1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
# "BBB" should be marked as deleted.
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
UPDATE t1 SET no_fts_field='anychange' where FTS_DOC_ID = 2;
SELECT * FROM t1 WHERE MATCH(fts_field) against("anychange");
# "HA_FTS_INVALID_DOCID"
--error 182
UPDATE t1 SET no_fts_field='anychange', fts_field='other' where FTS_DOC_ID = 2;
SELECT * FROM t1 WHERE MATCH(fts_field) against("other");
# Doc ID must be monotonically increase (HA_FTS_INVALID_DOCID)
--error 182
UPDATE t1 SET FTS_DOC_ID = 1 where FTS_DOC_ID = 2;
DROP INDEX f ON t1;
# After FULLTEXT index dropped, we can update the fields freely
UPDATE t1 SET fts_field='newchange' where FTS_DOC_ID = 2;
UPDATE t1 SET no_fts_field='anychange' where FTS_DOC_ID = 2;
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field), index k(fts_field)) ENGINE=INNODB;
CREATE TABLE t2(ID INT PRIMARY KEY,
no_fts_field VARCHAR(10),
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field),
INDEX k2(fts_field),
FOREIGN KEY(fts_field) REFERENCES
t1(fts_field) ON UPDATE CASCADE) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 'AAA', 'BBB');
INSERT INTO t2 VALUES (1, 'AAA', 'BBB');
update t1 set fts_field='newchange' where id =1;
SELECT * FROM t1 WHERE MATCH(fts_field) against("BBB");
SELECT * FROM t2 WHERE MATCH(fts_field) against("BBB");
SELECT * FROM t1 WHERE MATCH(fts_field) against("newchange");
SELECT * FROM t2 WHERE MATCH(fts_field) against("newchange");
DROP TABLE t2;
DROP TABLE t1;
# Testcases adopted from innodb_multi_update.test
CREATE TABLE t1(id INT PRIMARY KEY,
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
CREATE TABLE t2(id INT PRIMARY KEY,
fts_field VARCHAR(10),
FULLTEXT INDEX f(fts_field)) ENGINE=INNODB;
INSERT INTO t1 values (1,'100'),(2,'200'),(3,'300'),(4,'400'),(5,'500'),(6,'600'), (7,'700'),(8,'800'),(9,'900'),(10,'1000'),(11,'1100'),(12,'1200');
INSERT INTO t2 values (1,'100'),(2,'200'),(3,'300'),(4,'400'),(5,'500'),(6,'600'), (7,'700'),(8,'800');
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'foo');
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'foo') WHERE t1.fts_field = "100foo";
# Update two tables in the same statement
UPDATE t1, t2 set t1.fts_field = CONCAT(t1.fts_field, 'xoo'), t2.fts_field = CONCAT(t1.fts_field, 'xoo') where t1.fts_field=CONCAT(t2.fts_field, 'foo');
# Following selects shows whether the correct Doc ID are updated
# This row should present in table t1
SELECT * FROM t1 WHERE MATCH(fts_field) against("100foofoo");
# Following rows should be dropped
SELECT * FROM t1 WHERE MATCH(fts_field) against("100foo");
SELECT * FROM t1 WHERE MATCH(fts_field) against("100");
# This row should present in table t2
SELECT * FROM t2 WHERE MATCH(fts_field) against("400fooxoo");
SELECT * FROM t2 WHERE MATCH(fts_field) against("100");
# Follow rows should be marked as dropped
SELECT * FROM t2 WHERE MATCH(fts_field) against("200");
SELECT * FROM t2 WHERE MATCH(fts_field) against("400");
DROP TABLE t1;
DROP TABLE t2;
--echo
--echo BUG#13701973/64274: MYSQL THREAD WAS SUSPENDED WHEN EXECUTE UPDATE QUERY
--echo
# FTS setup did not track which tables it had already looked at to see whether
# they need initialization. Hilarity ensued when hitting circular dependencies.
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
CREATE TABLE t1 (
t1_id INT(10) UNSIGNED NOT NULL,
t2_id INT(10) UNSIGNED DEFAULT NULL,
PRIMARY KEY (t1_id),
FOREIGN KEY (t2_id) REFERENCES t2 (t2_id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
CREATE TABLE t2 (
t1_id INT(10) UNSIGNED NOT NULL,
t2_id INT(10) UNSIGNED NOT NULL,
t3_id INT(10) UNSIGNED NOT NULL,
t4_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (t2_id),
FOREIGN KEY (t1_id) REFERENCES t1 (t1_id),
FOREIGN KEY (t3_id) REFERENCES t3 (t3_id)
ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (t4_id) REFERENCES t4 (t4_id)
) ENGINE=InnoDB;
CREATE TABLE t3 (
t3_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
payload char(3),
PRIMARY KEY (t3_id)
) ENGINE=InnoDB;
INSERT INTO t3 VALUES (1, '100');
CREATE TABLE t4 (
t2_id INT(10) UNSIGNED DEFAULT NULL,
t4_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (t4_id),
FOREIGN KEY (t2_id) REFERENCES t2 (t2_id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
SET FOREIGN_KEY_CHECKS=1;
UPDATE t3 SET payload='101' WHERE t3_id=1;
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

View File

@ -0,0 +1,209 @@
#------------------------------------------------------------------------------
# Misc FTS test on debug servers only
#------------------------------------------------------------------------------
--source include/have_innodb.inc
# Must have debug code to use SET SESSION debug
--source include/have_debug.inc
# Valgrind would complain about memory leaks when we crash on purpose.
--source include/not_valgrind.inc
# Embedded server does not support crashing
--source include/not_embedded.inc
# Avoid CrashReporter popup on Mac
--source include/not_crashrep.inc
# Following are test for crash recovery on FTS index, the first scenario
# is for bug Bug #14586855 INNODB: FAILING ASSERTION: (DICT_INDEX_GET_N_UNIQUE(
# PLAN->INDEX) <= PLAN->N_EXAC
# Scenario 1: Hidden FTS_DOC_ID column, and FTS index dropped
# Create FTS table
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
# Drop the FTS index before more insertion. The FTS_DOC_ID should
# be kept
DROP INDEX title ON articles;
# Insert six rows
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
BEGIN;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...');
# Request a crash on next execution of commit.
SET SESSION debug_dbug="+d,crash_commit_before";
#
# Write file to make mysql-test-run.pl start up the server again
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
#
# Execute the statement that causes the crash.
--error 2013
COMMIT;
--source include/wait_until_disconnected.inc
--sleep 2
# Turn on reconnect
--enable_reconnect
#
# Call script that will poll the server waiting for it to be back online again
--source include/wait_until_connected_again.inc
#
# Turn off reconnect again
--disable_reconnect
# This insert will re-initialize the Doc ID counter, it should not crash
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...');
# Recreate fulltext index to see if everything is OK
CREATE FULLTEXT INDEX idx ON articles (title,body);
# Should return 3 rows
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
# Scenario 2: Hidden FTS_DOC_ID column, with FTS index
# Now let's do more insertion and test a crash with FTS on
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
# Now let's crash the server with "crash_commit_before"
BEGIN;
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...');
# Request a crash on next execution of commit.
SET SESSION debug_dbug="+d,crash_commit_before";
#
# Write file to make mysql-test-run.pl start up the server again
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
#
# Execute the statement that causes the crash.
--error 2013
COMMIT;
--source include/wait_until_disconnected.inc
--sleep 2
# Turn on reconnect
--enable_reconnect
#
# Call script that will poll the server waiting for it to be back online again
--source include/wait_until_connected_again.inc
#
# Turn off reconnect again
--disable_reconnect
# This insert will re-initialize the Doc ID counter, it should not crash
INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...');
# Should return 6 rows
SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('Database' IN NATURAL LANGUAGE MODE);
DROP TABLE articles;
# Scenario 3: explicit FTS_DOC_ID column with FTS index
# Now let's test user defined FTS_DOC_ID
CREATE TABLE articles (
id int PRIMARY KEY,
FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
title VARCHAR(200),
body TEXT
) ENGINE=InnoDB;
CREATE FULLTEXT INDEX idx1 on articles (title, body);
# Note the FTS_DOC_ID is not fully ordered with primary index
INSERT INTO articles VALUES
(1, 10, 'MySQL Tutorial','DBMS stands for DataBase ...') ,
(2, 1, 'How To Use MySQL Well','After you went through a ...'),
(3, 2, 'Optimizing MySQL','In this tutorial we will show ...'),
(4, 11, '1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
(5, 6, 'MySQL vs. YourSQL','In the following database comparison ...'),
(7, 4, 'MySQL Security','When configured properly, MySQL ...');
# Now let's crash the server with "crash_commit_before"
BEGIN;
INSERT INTO articles VALUES
(100, 200, 'MySQL Tutorial','DBMS stands for DataBase ...');
# Request a crash on next execution of commit.
SET SESSION debug_dbug="+d,crash_commit_before";
#
# Write file to make mysql-test-run.pl start up the server again
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
#
# Execute the statement that causes the crash.
--error 2013
COMMIT;
--source include/wait_until_disconnected.inc
--sleep 2
# Turn on reconnect
--enable_reconnect
#
# Call script that will poll the server waiting for it to be back online again
--source include/wait_until_connected_again.inc
#
# This would re-initialize the FTS index and do the re-tokenization
# of above records
INSERT INTO articles VALUES (8, 12, 'MySQL Tutorial','DBMS stands for DataBase ...');
SELECT * FROM articles WHERE MATCH (title, body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
DROP TABLE articles;
# Following test is for Bug 14668777 - ASSERT ON IB_VECTOR_SIZE(
# TABLE->FTS->INDEXES, ALTER TABLE
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
# Abort the operation in dict_create_index_step by setting
# return status of dict_create_index_tree_step() to DB_OUT_OF_MEMORY
# The newly create dict_index_t should be removed from fts cache
SET SESSION debug_dbug="+d,ib_dict_create_index_tree_fail";
--error ER_OUT_OF_RESOURCES
CREATE FULLTEXT INDEX idx ON articles(body);
SET SESSION debug_dbug="-d,ib_dict_create_index_tree_fail";
# This simply go through ha_innobase::commit_inplace_alter_table
# and do a fts_check_cached_index()
ALTER TABLE articles STATS_PERSISTENT=DEFAULT;
DROP TABLE articles;

View File

@ -0,0 +1,174 @@
#------------------------------------------------------------------------------
# Test With two FTS index on same table + alter/create/drop index + tnx
#------------------------------------------------------------------------------
--source include/have_innodb.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
# Create FTS table
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) ENGINE = InnoDB STATS_PERSISTENT=0;
# Insert rows
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...') ,
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...');
# Create the 2 FTS index Using Alter on same table
ALTER TABLE t1 ADD FULLTEXT INDEX idx_1 (a);
ALTER TABLE t1 ADD FULLTEXT INDEX idx_2 (b);
EVAL SHOW CREATE TABLE t1;
# check mutiple index with transaction
START TRANSACTION;
# Insert rows
INSERT INTO t1 (a,b) VALUES
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
ROLLBACK;
# Select word "tutorial" in the table
SELECT * FROM t1 WHERE MATCH (a)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
# boolean mode
select * from t1 where MATCH(a) AGAINST("+mysql +Tutorial" IN BOOLEAN MODE);
select * from t1 where MATCH(b) AGAINST("+Tutorial" IN BOOLEAN MODE);
select * from t1 where MATCH(b) AGAINST("+stands +(DataBase)" IN BOOLEAN MODE);
select * from t1 where MATCH(b) AGAINST("+DataBase -(comparison)" IN BOOLEAN MODE);
select *, MATCH(a) AGAINST("Optimizing MySQL" IN BOOLEAN MODE) as x from t1;
select *, MATCH(b) AGAINST("collections support" IN BOOLEAN MODE) as x from t1;
select * from t1 where MATCH a AGAINST ("+Optimiz* +Optimiz*" IN BOOLEAN MODE);
select * from t1 where MATCH b AGAINST ('"DBMS stands"' IN BOOLEAN MODE);
select * from t1 where MATCH b AGAINST ('"DBMS STANDS"' IN BOOLEAN MODE);
# query expansion
select * from t1 where MATCH(b) AGAINST ("DataBase" WITH QUERY EXPANSION);
select * from t1 where MATCH(a) AGAINST ("Security" WITH QUERY EXPANSION);
# Drop index
ALTER TABLE t1 DROP INDEX idx_1;
ALTER TABLE t1 DROP INDEX idx_2;
# Create the FTS index again
ALTER TABLE t1 ADD FULLTEXT INDEX idx_1 (a);
ALTER TABLE t1 ADD FULLTEXT INDEX idx_2 (b);
# Select word "tutorial" in the table
SELECT * FROM t1 WHERE MATCH (a)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE);
# boolean mode
select * from t1 where MATCH(a) AGAINST("+mysql +Tutorial" IN BOOLEAN MODE);
select * from t1 where MATCH(b) AGAINST("+Tutorial" IN BOOLEAN MODE);
select * from t1 where MATCH(b) AGAINST("+stands +(DataBase)" IN BOOLEAN MODE);
select * from t1 where MATCH(b) AGAINST("+DataBase -(comparison)" IN BOOLEAN MODE);
select *, MATCH(a) AGAINST("Optimizing MySQL" IN BOOLEAN MODE) as x from t1;
select *, MATCH(b) AGAINST("collections support" IN BOOLEAN MODE) as x from t1;
select * from t1 where MATCH a AGAINST ("+Optimiz* +Optimiz*" IN BOOLEAN MODE);
select * from t1 where MATCH b AGAINST ('"DBMS stands"' IN BOOLEAN MODE);
select * from t1 where MATCH b AGAINST ('"DBMS STANDS"' IN BOOLEAN MODE);
# query expansion
select * from t1 where MATCH(b) AGAINST ("DataBase" WITH QUERY EXPANSION);
select * from t1 where MATCH(a) AGAINST ("Security" WITH QUERY EXPANSION);
# insert for proximity search
INSERT INTO t1 (a,b) VALUES ('test query expansion','for database ...');
# Insert into table with similar word of different distances
INSERT INTO t1 (a,b) VALUES
('test proximity search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test proximity fts search, test, proximity and phrase',
'search, with proximity innodb');
INSERT INTO t1 (a,b) VALUES
('test more of proximity for fts search, test, more proximity and phrase',
'search, with proximity innodb');
# This should only return the first document
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"proximity search"@3' IN BOOLEAN MODE);
# This would return no document
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"proximity search"@2' IN BOOLEAN MODE);
# This give you all three documents
SELECT * FROM t1
WHERE MATCH (b)
AGAINST ('"proximity innodb"@4' IN BOOLEAN MODE);
# Similar boundary testing for the words
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"test proximity"@3' IN BOOLEAN MODE);
# Test with more word The last document will return, please notice there
# is no ordering requirement for proximity search.
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"more test proximity"@3' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"more test proximity"@2' IN BOOLEAN MODE);
# The phrase search will not require exact word ordering
SELECT * FROM t1
WHERE MATCH (a)
AGAINST ('"more fts proximity"@02' IN BOOLEAN MODE);
# Select word "tutorial" in the table - innodb crash
SELECT * FROM t1 WHERE CONCAT(t1.a,t1.b) IN (
SELECT CONCAT(a,b) FROM t1 AS t2 WHERE
MATCH (t2.a) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)
) OR t1.id = 3 ;
# Select word "tutorial" in the table - innodb crash
SELECT * FROM t1 WHERE CONCAT(t1.a,t1.b) IN (
SELECT CONCAT(a,b) FROM t1 AS t2
WHERE MATCH (t2.a) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)
AND t2.id != 3) ;
# Select word "tutorial" in the table
SELECT * FROM t1 WHERE id IN (SELECT MIN(id) FROM t1 WHERE
MATCH (b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)) OR id = 3 ;
# Select word except "tutorial" in the table
SELECT * FROM t1 WHERE id NOT IN (SELECT MIN(id) FROM t1
WHERE MATCH (b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)) ;
# Select word "tutorial" in the table
SELECT * FROM t1 WHERE EXISTS (SELECT t2.id FROM t1 AS t2 WHERE
MATCH (t2.b) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)
AND t1.id = t2.id) ;
# Select not word like "tutorial" using subquery
SELECT * FROM t1 WHERE NOT EXISTS (SELECT t2.id FROM t1 AS t2 WHERE
MATCH (t2.a) AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE)
AND t1.id = t2.id) ;
SELECT * FROM t1 WHERE t1.id = (SELECT MAX(t2.id) FROM t1 AS t2 WHERE
MATCH(t2.a) AGAINST ('"proximity search"@3' IN BOOLEAN MODE));
SELECT * FROM t1 WHERE t1.id > (SELECT MIN(t2.id) FROM t1 AS t2 WHERE
MATCH(t2.b) AGAINST ('"proximity innodb"@3' IN BOOLEAN MODE));
DROP TABLE t1;

View File

@ -0,0 +1,262 @@
# This is the DDL function tests for innodb FTS
# Functional testing with FTS proximity search using '@'
# and try search default words
--source include/have_innodb.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
--disable_query_log
let $innodb_file_format_orig = `select @@innodb_file_format`;
let $innodb_file_per_table_orig = `select @@innodb_file_per_table`;
--enable_query_log
# Create FTS table
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) ENGINE= InnoDB;
# Create the FTS index again
CREATE FULLTEXT INDEX idx on t1 (a,b);
# Insert rows
INSERT INTO t1 (a,b) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...');
# Try to Search default stopword from innodb, "where", "will", "what"
# and "when" are all stopwords
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("where will");
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("when");
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST ("what" WITH QUERY EXPANSION);
# boolean No result expected
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("whe*" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+what +will" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+from" IN BOOLEAN MODE);
SELECT * FROM t1 WHERE MATCH(a,b) AGAINST("+where +(show what)" IN BOOLEAN MODE);
# no result expected. Words are filtered out as stopwords
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"where will"@6' IN BOOLEAN MODE);
# no result expected
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"where will"@9' IN BOOLEAN MODE);
# insert record with @ character which is used in proximity search
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','request docteam@oraclehelp.com ...') ,
('Trial version','query performace @1255 minute on 2.1Hz Memory 2GB...') ,
('when To Use MySQL Well','for free faq mail@xyz.com ...');
# proximity search with @ charcter
# We don't need more than one word in proximity search. Single word
# treated as single word search
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"request"@10' IN BOOLEAN MODE);
# If the distance is 0, it is treated as "phrase search"
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"Trial version"@0' IN BOOLEAN MODE);
# @ is word seperator
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"request docteam@oraclehelp.com"@10' IN BOOLEAN MODE);
# This should not return any document
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"1255 minute"@1' IN BOOLEAN MODE);
# This should return the first document. That is "1255" and "minutes" are
# in a two-word range (adjacent)
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"1255 minute"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"1255"@10' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('1255' WITH QUERY EXPANSION);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"request docteam"@2' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"1255 minute"' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('request docteam@oraclehelp.com');
# Test across fields search
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"MySQL request"@3' IN BOOLEAN MODE);
# Two words are in 10 words range
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"Trial memory"@10' IN BOOLEAN MODE);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"Trial memory"@9' IN BOOLEAN MODE);
DROP TABLE t1;
# test on utf8 encoded proximity search
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = UTF8, ENGINE= InnoDB;
INSERT INTO t1 (a,b) VALUES
('MySQL from Tutorial','DBMS stands for DataBase ...') ,
('when To Use MySQL Well','After that you went through a ...'),
('where will Optimizing MySQL','what In this tutorial we will show ...');
CREATE FULLTEXT INDEX idx on t1 (a,b);
INSERT INTO t1 (a,b) VALUES
('MySQL Tutorial','request docteam@oraclehelp.com ...') ,
('Trial version','query performace @1255 minute on 2.1Hz Memory 2GB...'),
('when To Use MySQL Well','for free faq mail@xyz.com ...');
# Should have 2 rows. Note proximity search does require words in order
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"mysql use"@2' IN BOOLEAN MODE);
# Should return 0 row
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"mysql use"@1' IN BOOLEAN MODE);
INSERT INTO t1 (a,b) VALUES ('XYZ, long blob', repeat("a", 9000));
INSERT INTO t1 (a,b) VALUES (repeat("b", 9000), 'XYZ, long blob');
# 2 rows match
SELECT count(*) FROM t1
WHERE MATCH (a,b)
AGAINST ('"xyz blob"@3' IN BOOLEAN MODE);
DROP TABLE t1;
set global innodb_file_format="Barracuda";
set global innodb_file_per_table=1;
# Test fts with externally stored long column
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT,
c TEXT
) CHARACTER SET = UTF8, ROW_FORMAT=DYNAMIC, ENGINE= InnoDB;
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000), 'XYZ, long text', 'very long blob');
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000), 'XYZ, very little long blob very much blob', 'very long blob');
# Note 租车 is count as one word
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000),"very 租车 供 blob","new 供需分析information");
CREATE FULLTEXT INDEX idx on t1 (a,b,c);
INSERT INTO t1 (a,b,c) VALUES (repeat("x", 19000), 'new, long text', 'very new blob');
INSERT INTO t1 (a,b,c) VALUES ('interesting, long text', repeat("x", 19000), 'very very good new blob');
# 3 rows should match
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@3' IN BOOLEAN MODE);
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very long blob"@0' IN BOOLEAN MODE);
# 4 rows should match
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@4' IN BOOLEAN MODE);
# 1 row should match
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"interesting blob"@9' IN BOOLEAN MODE);
# should have 3 rows
SELECT COUNT(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"interesting blob"@9 "very long blob"@0' IN BOOLEAN MODE);
# should have 3 rows
SELECT COUNT(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@4 - "interesting blob"@9' IN BOOLEAN MODE);
DROP TABLE t1;
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a VARCHAR(200),
b TEXT
) CHARACTER SET = UTF8, ENGINE= InnoDB;
# Space and special characters are not counted as word
INSERT INTO t1 (a,b) VALUES
('MySQL from Tutorial','DBMS stands for + DataBase ...');
CREATE FULLTEXT INDEX idx on t1 (a,b);
SELECT * FROM t1
WHERE MATCH (a,b)
AGAINST ('"stands database"@3' IN BOOLEAN MODE);
DROP TABLE t1;
# Test fts with externally stored long column
CREATE TABLE t1 (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
a TEXT,
b TEXT,
c TEXT
) CHARACTER SET = UTF8, ROW_FORMAT=DYNAMIC, ENGINE= InnoDB;
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000), 'XYZ, long text', 'very long blob');
INSERT INTO t1 (a,b,c) VALUES ('XYZ, 租车 very little long blob very much blob', repeat("b", 19000), 'very long but smaller blob');
CREATE FULLTEXT INDEX idx on t1 (a,b,c);
DELETE FROM t1;
INSERT INTO t1 (a,b,c) VALUES (repeat("b", 19000), 'XYZ, long text', 'very long blob');
INSERT INTO t1 (a,b,c) VALUES ('XYZ, 租车 very little long blob is a very much longer blob', repeat("b", 19000), 'this is very long but smaller blob');
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@4' IN BOOLEAN MODE);
SELECT count(*) FROM t1
WHERE MATCH (a,b,c)
AGAINST ('"very blob"@3' IN BOOLEAN MODE);
DROP TABLE t1;
eval SET GLOBAL innodb_file_format=$innodb_file_format_orig;
eval SET GLOBAL innodb_file_per_table=$innodb_file_per_table_orig;

File diff suppressed because it is too large Load Diff