在我的查询中,我遇到了FULLTEXT INDEX
无法分配给 a的问题DERIVED TABLE
,这似乎是正常的。
示例演示了data
不能被索引为FULLTEXT
,但是content
、text
和record
列已经被索引,FULLTEXT
因为它们在“真实”表中
SELECT `data` FROM SELECT(
SELECT `content` as `data` FROM `table1`
UNION SELECT `text` as `data` FROM `table2`
UNION SELECT `record` as `data` FROM `table3`
) as `search`
在我的实际代码中,我使用SELECT MATCH() AGAINST()
表中的分数并将它们联合在一起以获得score
每个表的分数,这些 UNIONS 是子查询和第一级(主)SELECT 然后将这些 UNIONS 选择为派生表并从中计算分数,但是这是尚未完成。发生错误,指出引用没有索引。(就像上面的例子一样)。
这就是为什么我决定询问是否可以通过 JOINS 实现我的目标的原因。
这是我的实际(工作)代码:
SELECT *,MATCH(`data`) AGAINST('keyword' IN BOOLEAN MODE) as `relevance`
FROM (
SELECT CONCAT(`title`,' ',`content`) as `data`,`id`,'tmp_pages' as `table`,
MATCH(`title`,`content`) AGAINST ('keyword') AS `score`
FROM `tmp_pages`
WHERE MATCH(`title`,`content`) AGAINST ('keyword')
UNION
SELECT CONCAT(`title`,' ',`content`) as `data`, `id`,'tmp_news' as `table`,
MATCH(`title`,`content`)
AGAINST ('keyword') AS `score`
FROM `tmp_news`
WHERE MATCH(`title`,`content`) AGAINST ('keyword')
UNION
SELECT CONCAT(`title`,' ',`content`) as `data`,`id`,'tmp_comments' as `table`,
MATCH(`title`, `content`)
AGAINST ('keyword') AS `score` FROM `tmp_comments`
WHERE MATCH(`title`, `content`) AGAINST('keyword')
UNION
SELECT CONCAT(`manufacturer`,' ',`model`,' ',`location`,' ',`other`,' ',`contact`) as `data`,`id`,'tmp_auction_auto' as `table`,
MATCH(`manufacturer`,`model`,`location`,`other`,`contact`) AGAINST ('keyword') AS `score`
FROM `tmp_auction_auto`
WHERE MATCH(`manufacturer`,`model`,`location`,`other`,`contact`)
AGAINST ('keyword')
) as `search` ORDER BY `relevance` DESC
我想知道是否可以将这部分转换JOIN
为查询类型,并使其按预期运行。如果是这样,我会问如何做到这一点。