【发布时间】:2012-01-31 07:11:28
【问题描述】:
我有一个 MyISAM mysql 表:
CREATE TABLE IF NOT EXISTS `songs` (
`rid` int(11) NOT NULL auto_increment,
`aid` int(11) NOT NULL,
`song_title` varchar(256) NOT NULL,
`download_url` varchar(256) NOT NULL,
PRIMARY KEY (`rid`),
UNIQUE KEY `download_url` (`download_url`),
KEY `song_title` (`song_title`),
FULLTEXT KEY `song_title_2` (`song_title`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
它有大约 1400 万行。这是我第一次处理这么大的数据库,之前我并没有真正关心过优化。我一直在尝试各种方法来测试速度和准确性。
1) 全文
select song_title from songs
where match (song_title) againt ('search term') limit 0, 50
-- This gives me very unreliable results but speed is good.
2) 喜欢
select song_title from songs
where song_title LIKE '%search term%' limit 0, 50
-- Moderate matching results, speed is good when the query is
-- easily able to fetch the first 50 results... but when i
-- search for a term that does not exist then... here is the result..
-- MySQL returned an empty result set (i.e. zero rows). ( Query took 107.1371 sec )
3) 多个 LIKE
select song_title from songs
where song_title like '%word_1%' and
song_title like '%word_2%' and
song_title like '%word_3%' and
song_title like '%word_N%' LIMIT 0, 50;
-- It takes about 0.2 seconds when the search terms are easily found.
-- Ran this exact above query just now to find the execution time when
-- no results are found.
-- MySQL returned an empty result set (i.e. zero rows). ( Query took 30.8625 sec )
我正在寻找的是关于优化数据库/查询的速度和准确性方面的提示和建议。
我不能使用像 sphinx 这样的其他搜索引擎,因为我没有网站根目录之外的访问权限,也不能要求处理服务器的人进行设置。
【问题讨论】:
-
P.S.对这么多的编辑感到抱歉..这里的第一个问题,只是学习如何缩进代码块..但在一行左侧放置 4 个空格后,我似乎无法正确理解..
-
缩进代码块 - 突出显示并按 ctrl+k
-
你的服务器端语言是什么?
标签: mysql full-text-search query-optimization large-data