Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在表mysql中使用时速度非常慢46.4878秒_Mysql_Sql_Performance_Indexing - Fatal编程技术网

在表mysql中使用时速度非常慢46.4878秒

在表mysql中使用时速度非常慢46.4878秒,mysql,sql,performance,indexing,Mysql,Sql,Performance,Indexing,在中使用时,查询速度非常慢 这个问题 SELECT * FROM engine4_comment WHERE sid IN (10,12,548,2110,5241,1255) 这个创建表 CREATE TABLE `engine4_comment` ( `id` int(11) NOT NULL AUTO_INCREMENT, `sid` int(11) NOT NULL, `rid` int(11) NOT NULL DEFAULT '0', `uid` int(11) N

在中使用时,查询速度非常慢

这个问题

SELECT *
FROM engine4_comment
WHERE sid IN (10,12,548,2110,5241,1255)
这个创建表

CREATE TABLE `engine4_comment` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `sid` int(11) NOT NULL,
  `rid` int(11) NOT NULL DEFAULT '0',
  `uid` int(11) NOT NULL,
  `text` longtext COLLATE utf8_unicode_ci NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `active` int(11) NOT NULL DEFAULT '1',
  `deleted` int(11) NOT NULL DEFAULT '0',
  `deleted_reason` text CHARACTER SET latin1 NOT NULL,
  `send_email` int(11) NOT NULL DEFAULT '1',
  `user_active` tinyint(4) NOT NULL DEFAULT '1',
  `dep_active` tinyint(4) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `dat_idx` (`date`),
  KEY `rid_idx` (`rid`),
  KEY `rsid_idx` (`rid`,`sid`)
) ENGINE=InnoDB AUTO_INCREMENT=719329 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
当使用explaine
explain时,从
engine4_comment
中选择*,其中sid位于(10,12548211052411255)

这是您的查询:

SELECT *
FROM engine4_comment
WHERE sid IN (10,12,548,2110,5241,1255)
为了提高性能,您需要在
sid
上建立索引。在
创建表
中包含
语句。或者,显式创建索引:

create index idx_engine4_comment_sid on engine4_comment(sid);

请注意,索引
rsid_idx
对该查询没有帮助,因为
sid
是第二列。
(sid,rid)
上的索引将有助于此查询。

删除了sql server标记,因为查询显然是MySQL语法。删除此rsid_idx怎么样
create index idx_engine4_comment_sid on engine4_comment(sid);