【问题标题】:Fulltext search on innodb with two JOINs使用两个 JOIN 在 innodb 上进行全文搜索
【发布时间】:2014-01-19 23:02:07
【问题描述】:

我正在尝试在 mysql 5.6 上使用 innodb 进行全文搜索,并在 submissions.title, submissions.description 上添加了 FULLTEXT KEY。这是我的show create table submissions

Create Table: CREATE TABLE `submissions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `slug` varchar(255) NOT NULL,
  `description` mediumtext NOT NULL,
  `user_id` int(11) NOT NULL,
  `created` datetime NOT NULL,
  `type` enum('tip','request') NOT NULL,
  `thumbnail` varchar(64) CHARACTER SET latin1 DEFAULT NULL,
  `removed` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `keywords` varchar(255) NOT NULL,
  `ip` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  FULLTEXT KEY `title` (`title`,`description`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8

当我运行以下查询时:

SELECT s.*, MATCH (s.title, s.description) AGAINST ('whatever'), u.username, SUM( sv.up ) helpfulVotes
FROM submissions s
INNER JOIN users u ON s.user_id = u.id
LEFT JOIN submissions_votes sv ON s.id = sv.submission_id
GROUP BY s.id
ORDER BY s.created DESC 
LIMIT 0 , 30

我收到#1214 - The used table type doesn't support FULLTEXT indexes 错误。

这是否意味着我需要在我加入的其他字段中添加全文?没有任何意义,因为我没有搜索任何这些字段...

编辑:在我的 prod 机器上进行查询,它的 mysql 版本较旧,而且我的查询是错误的。

正确查询:

 SELECT s . * , u.username, SUM( sv.up ) helpfulVotes
 FROM submissions s
 INNER JOIN users u ON s.user_id = u.id
 LEFT JOIN submissions_votes sv ON s.id = sv.submission_id
 WHERE MATCH (
 s.title, s.description
 )
 AGAINST (
 'whatever'
 )
 LIMIT 0 , 30;

【问题讨论】:

  • 试试不加入吗?

标签: mysql sql full-text-search innodb


【解决方案1】:

我认为全文搜索只是 ISAM。

【讨论】:

  • @drewlander 。 . .错误不会出现在create table 执行而不是查询执行上吗?
  • 是的...... mihai 是正确的。自从上次我知道它已被添加到 innodb 中。现在你让我好奇......
  • @GodronLinoff,已编辑:我安装了 5.5,如果您从 MySQL 工作台运行它,它会在创建表时出错。 innodb_version 5.5.34 protocol_version 10 slave_type_conversions version 5.5.34 bob,你能粘贴这个命令的结果吗:show variables like "%version%";
  • +-------------------------+---------------------+ | Variable_name | Value | +-------------------------+---------------------+ | innodb_version | 5.6.13 | | protocol_version | 10 | | slave_type_conversions | | | version | 5.6.13 | | version_comment | Source distribution | | version_compile_machine | x86_64 | | version_compile_os | osx10.8 | +-------------------------+---------------------+
猜你喜欢
  • 2010-11-25
  • 1970-01-01
  • 2012-12-29
  • 2011-09-20
  • 1970-01-01
  • 2019-08-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多