2011-02-24 63 views
0

我的表xm_c是這樣創建的:
選擇:MySQL的全文索引用於MATCH()AGAINST但不適用於=

 
CREATE TABLE `xm_c` ( 
    `category_id` char(16) NOT NULL default '', 
    `label` char(64) NOT NULL default '', 
    `flags` smallint(5) unsigned default NULL, 
    `d0` date default NULL, 
    `d1` date default NULL, 
    `ct` int(6) unsigned default NULL, 
    `t_update` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, 
    PRIMARY KEY (`category_id`), 
    **FULLTEXT KEY `label` (`label`)** 
) ENGINE=MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1;

全文索引在下面的查詢不使用* from xm_c where label ='TomCruise';

其中,因爲它是這裏使用:
SELECT * FROM xm_c其中MATCH(標籤)AGAINST( '湯姆·克魯斯');


 
mysql> explain select * from xm_c where MATCH(label) AGAINST('TomCruise'); 

> 
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra 
**1 | SIMPLE  | xm_c | fulltext | label  | label | 0  |  | 1 | Using where** 




mysql> explain select * from xm_c where label = 'TomCruise'; 

> id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra 
**1 | SIMPLE  | xm_c | ALL | label   | NULL | NULL | NULL | 5673360 | Using where** 



有人能解釋一下嗎?不應該在這兩個查詢中使用INDEX?
使用FULLTEXT INDICES時是否存在語法約束?

回答

1

全文索引只能用於MATCH() ... AGAINST操作。一個=運算符是非常不同的,與fts無關,它只是不能使用這種類型的索引。有關fts的更多信息可在manual中找到。

一匹馬使用馬蹄鐵,一輛車使用輪胎。並且都可以將您從A帶到B.

+0

謝謝您的回答。據我所知,索引是爲一列或一組列創建的,以實現更快的搜索。那麼相應列的索引不應該用於涉及該列的任何搜索? – raghu 2011-03-07 12:01:52

相關問題