在单个查询中连接多个 SphinxSE 表
我正在尝试编写一个查询,将 MySQL 中的一些表与两个 SphinxSE 表连接起来。它基本上是一个“每行有两个名称”类型的数据库,这两个名称都是链接到 SphinxSE 表的索引......我的目标是进行基本上“其中一个名称与该字符串匹配”的搜索在狮身人面像”。
我尝试使用的查询是:
SELECT * from names
LEFT JOIN name_1_se ON name_1_se.id=names.name_1_id
LEFT JOIN name_2_se ON name_2_se.id=names.name_2_id
WHERE name_1_se.query=('some random name;mode=phrase;limit=100000;maxmatches=100000')
OR name_2_se.query=('some random name;mode=phrase;limit=100000;maxmatches=100000')
(name_1_se 和 name_2_se 表是 SphinxSE 表)。
如果我在 where 中仅使用一次查找,则效果很好...添加第二个子句(任一子句)强制执行两个 SphinxSE“查找”,强制结果返回空。
我正在尝试做的事情是否可行,或者这是 SphinxSE 的已知问题吗?我在 Sphinx 网站上能找到的最接近的是这个错误 http://sphinxsearch.com/bugs /view.php?id=255 来自 2008 年。
谢谢!
I'm trying to write a query that joins a handful of tables from MySQL with two SphinxSE tables. It's basically an "each row has two names" type database, and those two names are each an index that is linked to a SphinxSE table... my goal is to do a search that is basically "either one of the names match this string in Sphinx".
The query I've tried using is:
SELECT * from names
LEFT JOIN name_1_se ON name_1_se.id=names.name_1_id
LEFT JOIN name_2_se ON name_2_se.id=names.name_2_id
WHERE name_1_se.query=('some random name;mode=phrase;limit=100000;maxmatches=100000')
OR name_2_se.query=('some random name;mode=phrase;limit=100000;maxmatches=100000')
(The name_1_se and name_2_se tables are SphinxSE tables).
If I use just a single lookup in the where, it works fine... adding the second clause (either one) that forces two SphinxSE 'lookups' forces the results to return empty.
Is what I am trying to do possible, or is it a known issue with SphinxSE? The closest I could find on the Sphinx site was this bug http://sphinxsearch.com/bugs/view.php?id=255 from 2008.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这行不通。这是因为 sphinxSE/mysql 的“架构”。
Sphinx 当然不会向 mysql 提供真实的表。它假装它是一张桌子。它告诉 mysql 查询优化器通过索引工作得很好。因此,优化器应始终“首先”选择 SphinxSE 表,然后将其与真正的 mysql 表连接。
因此,对于每一行,它都会在 SphinxSE 表上进行索引扫描,从而获取 doc_ids。然后它在原始表(连接本身)中查找它们。
SphinxSE 不能存在于连接的“右侧”。始终必须是第一个(或左边)。
...你的查询(使用左连接)迫使mysql将sphinxSE表(好的表也不少!)放在右边,这根本不起作用。
您需要将查询改造成单个 sphinxSE 表。 sphinxSE 表可以一次搜索多个 sphinx 索引。或者可以改革您的实际索引以创建一次索引。
请记住,每个索引可以有多个字段 - 因此也许可以使用扩展查询
(@field1“一些随机名称”)| (@field2“一些随机名称”)
...结果一个 sphinxSE 表(在连接的左侧:))。
更新添加:
创建一个 sphinxSE 来同时搜索两个索引(就像 sql UNION 一样)很确定你可以做到,
但即使你不能,在查询时覆盖它也肯定可以工作,文档中的示例:
表中定义的索引将被忽略,因此可以使用任何 sphinxSE 表。
No this wont work. It because of the 'artitecture' of sphinxSE/mysql.
Sphinx of course doesnt present real tables to mysql. It pretends its a table. It tells the mysql query optimiser works very well via indexes. So the optimizer should always pick the SphinxSE table 'first', which is then joined with the real mysql table.
So for each row, it does an index scan on the SphinxSE table, which gets the doc_ids. and it then looks them up in the origial table (the join itself).
SphinxSE cant exist on the 'right' side of a Join. Always must be first (or left).
... your query (using left join) is forcing mysql to put the sphinxSE table (well tables no less!) on the right, which simply wont work.
You need to reform the query as a single sphinxSE table. A sphinxSE table can search multiple sphinx indexes at once. Or can maybe reform your actual indexes to make once index.
Remember can be multiple fields per index - so an extended query could perhaps be used
(@field1 "some random name") | (@field2 "some random name")
... result one sphinxSE table (on the left of the join :) ).
Updated to add:
Creating a sphinxSE to search two indexes at once (like a sql UNION) pretty sure you can do
but even if you cant, overriding it at query time should definitely work, example from the docs:
The index defined in the table will be ignored, so can use any sphinxSE table.