fulltext.test
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. #
  2. # Test of fulltext index
  3. #
  4. drop table if exists t1,t2;
  5. CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b));
  6. 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');
  7. select * from t1 where MATCH(a,b) AGAINST ("collections");
  8. select * from t1 where MATCH(a,b) AGAINST ("indexes");
  9. select * from t1 where MATCH(a,b) AGAINST ("indexes collections");
  10. delete from t1 where a like "MySQL%";
  11. drop table t1;
  12. #
  13. # Check bug reported by Matthias Urlichs
  14. #
  15. CREATE TABLE t1 (
  16.   id int(11),
  17.   ticket int(11),
  18.   KEY ti (id),
  19.   KEY tit (ticket)
  20. );
  21. INSERT INTO t1 VALUES (2,3),(1,2);
  22. CREATE TABLE t2 (
  23.   ticket int(11),
  24.   inhalt text,
  25.   KEY tig (ticket),
  26.   fulltext index tix (inhalt)
  27. );
  28. INSERT INTO t2 VALUES (1,'foo'),(2,'bar'),(3,'foobar');
  29. select t1.id FROM t2 as ttxt,t1,t1 as ticket2
  30. WHERE ticket2.id = ttxt.ticket AND t1.id = ticket2.ticket and
  31. match(ttxt.inhalt) against ('foobar');
  32. # In the following query MySQL didn't use the fulltext index
  33. select t1.id FROM t2 as ttxt,t1 INNER JOIN t1 as ticket2 ON
  34. ticket2.id = ttxt.ticket
  35. WHERE t1.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar');
  36. INSERT INTO t1 VALUES (3,3);
  37. select t1.id FROM t2 as ttxt,t1 INNER JOIN t1 as ticket2 ON ticket2.id = ttxt.ticket WHERE t1.id = ticket2.ticket and match(ttxt.inhalt) against ('foobar');
  38. # Check that we get 'fulltext' index in SHOW CREATE
  39. show keys from t2;
  40. show create table t2;
  41. # check for bug reported by Stephan Skusa
  42. select * from t2 where MATCH inhalt AGAINST (NULL);
  43. drop table t1,t2;