默认情况下,当您对sphinx表执行查询时,Sphinx引擎会返回已按查询权重排序的行,并且确实很快。
所以,当我这样做时:
select
article.name
from article
left join article_ft on article._id=article_ft.id
where article_ft.query='some text;mode=any;';
其中:
article
就像表格一样InnoDB。
article_ft
是Sphinx表。
它们(article.name
和article_ft
)都包含这些数据(1行= 1行):
This is text.
This is also some text.
This is another text.
Sphinx引擎将返回如下行:
This is also some text.
This is text.
This is another text.
但是,如果我这样做:
select
article.name
from article
left join article_ft on article._id=article_ft.id
left join article_category on article.category=article_category._id
where article_ft.query='some text;mode=any;';
看来,MariaDB在这里按照自己的方式对其进行排序。
即使我提供Sphinx'排序'选项如下:
select
article.name
from article
left join article_ft on article._id=article_ft.id
left join article_category on article.category=article_category._id
where article_ft.query='some text;mode=any;sort=extended:@weight desc;';
仍然没有用。
更改join
的顺序也不起作用。
如果我使用order by article_ft.weight DESC
,MariaDB会返回错误消息,如:
Error: ER_ILLEGAL_HA: Storage engine SPHINX of the table `article_ft` doesn't have this option
如果article
没有可以匹配article.category=50
等条件的行。
article_ft
是使用以下方法创建的:
CREATE TABLE article_ft
(
id BIGINT NOT NULL,
weight INTEGER NOT NULL,
query VARCHAR(3072) NOT NULL,
INDEX(query)
) ENGINE=SPHINX CONNECTION="sphinx://192.168.1.98:9402/article_ft";
如何使用这个"魔法" sort by weight
功能,如果查询包含更多连接且没有错误返回?
谢谢,任何回复!
P.S。无法为您提供一个小提琴,因为我不知道任何支持Sphinx Tables的SQL小提琴在线服务。此外,如果您发现更多相关主题问题,我将会很感激。
答案 0 :(得分:1)
将article_ft
表放在查询的第一位。即... article_ft inner join article ...
或者可以使用FORCE INDEX
来强制使用query
索引。然后它可能会尊重排序顺序。
没有使用子查询?
(select name,weight from article_ft ... ) order by weight desc;