【发布时间】:2013-07-20 12:09:36
【问题描述】:
我有一个带有搜索功能的网站。运行 MySQL 数据库。我想知道它是否会从搜索引擎(Sphinx、Lucene 等)中受益?怎么样,如果会?我可以使用分面搜索吗?我知道如果有文本搜索会受益。但是,如果大多数查询都类似于以下内容,它会受益吗?
select SQL_CALC_FOUND_ROWS distinct tableA.id
from tableA as A
join tableB as B1 on A.id=B1.tablea_id
join tableB as B2 on A.id=B2.tablea_id
join tableB as B3 on A.id=B3.tablea_id
where
B1.value in ([list of ints here])
and
B2.value in ([another list of ints here])
and
B2.value in ([one more list of ints here])
order by ~A.updated_at
limit <from>,<amount>;
这个想法是从第一个列表中查找 tableA 中具有 tableB 中的值的行,然后过滤然后从第二个列表中留下那些在 tableB 中具有值的行,等等。对它们进行排序,计算所有找到并限制.
tableA 和tableB 是这样的:
create table tableA (
id int(11) not null autoincrement,
...
updated_at timestamp not null,
primary key (`id`),
key `ix_tablea_updated_at` (`updated_at`)
) engine=InnoDB;
create table tableB (
tablea_id int(11) not null,
value int(11) not null,
key `ix_tableb_tablea_id` (`tablea_id`),
key `ix_tableb_value` (`value`)
) engine=InnoDB;
tableA 包含约 200k 行。 tableB 包含约 120 万行。 B.value in ([list of ints]) 的数量因查询而异,lists of ints 也是如此。
如果我无法从搜索引擎中受益,我可以通过其他方式提高性能吗?
据我所知,问题在于order by ~A.updated_at 并计算找到的行数。有没有办法使用 MySQL 本身加快排序和计数?
PS。原谅我的英语。希望你能理解我。
【问题讨论】:
标签: mysql search lucene sphinx faceted-search