0

我正在开发一个与标签链接的视频数据库,当我执行这个查询时,我需要等待很长时间,它会创建一个临时表等,但我认为这应该有一个更快的方法:

EXPLAIN SELECT SQL_NO_CACHE  `video_id` 
FROM  `video_tag_link` 
WHERE  `tag_id` 
IN (
'2752',  '36370'
)
GROUP BY  `video_id` 
HAVING COUNT(  `video_id` ) =2
LIMIT 0 , 20

MySQL Result: 1
SIMPLE
video_tag_link
range
PRIMARY,video_id
PRIMARY
4
NULL
300268
Using where; Using index; Using temporary; Using filesort

Mysql table
CREATE TABLE IF NOT EXISTS `video_tag_link` (
  `video_id` int(10) unsigned NOT NULL,
  `tag_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`tag_id`,`video_id`),
  KEY `video_id` (`video_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Total of 45mil records in this table.

任何人都可以帮助我解决这个问题吗?

4

1 回答 1

0

您可以尝试将标签 ID 用作整数吗

EXPLAIN SELECT SQL_NO_CACHE  `video_id` 
FROM  `video_tag_link` 
WHERE  `tag_id` 
**IN (2752,  36370)**
GROUP BY  `video_id` 
HAVING COUNT(  `video_id` ) =2
LIMIT 0 , 20
于 2015-06-21T09:17:00.253 回答