未正确使用Mysql索引
我在一个简单的MySQL索引中遇到了一个奇怪的问题 我得到了下表:未正确使用Mysql索引,mysql,indexing,Mysql,Indexing,我在一个简单的MySQL索引中遇到了一个奇怪的问题 我得到了下表: CREATE TABLE `import` ( `import_id` int(11) NOT NULL AUTO_INCREMENT, `import_title` text, `import_url` text, `import_description` text, `import_completed` enum('y','n') NOT NULL DEFAULT 'n', `import_user`
CREATE TABLE `import` (
`import_id` int(11) NOT NULL AUTO_INCREMENT,
`import_title` text,
`import_url` text,
`import_description` text,
`import_completed` enum('y','n') NOT NULL DEFAULT 'n',
`import_user` int(11) DEFAULT NULL,
`import_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`import_id`),
KEY `import_added` (`import_added`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
该表中有几千行,我想用下面的Select子句得到前100行:
SELECT
import_id,
import_title,
import_url,
import_description,
import_user,
import_added
FROM import
WHERE import_completed = 'n'
ORDER by import_added ASC
LIMIT 0,100
当我使用descripe仔细查看查询时,我的本地机器使用“added”索引,并在几毫秒内像预期的那样返回100行
当我在“生产”服务器上使用具有相同结构和内容的同一数据库并在其中使用descripe时,它显示也使用了索引,但它返回该表中的所有行,查询大约需要6秒钟
我错过了什么?为什么索引不能正常工作 索引的错误使用
...
KEY `import_added` (import_completed, import_added) ...
并执行查询执行计划
desc extended SELECT
import_id,
import_title,
import_url,
import_description,
import_user,
import_added
FROM import
WHERE import_completed = 'n'
ORDER by import_added ASC
LIMIT 0,100;
尝试在
(import\u completed,import\u added)
零件将使用import\u completed的位置建立索引,对于订单,零件将使用import\u added。(我希望这在MyIsam上能起作用-在Innodb上这就是行为)哇,太快了!谢谢!我必须说我现在觉得自己很愚蠢:)@Bastian-你犯的错误越多,你获得的经验就越多你的本地机器可能使用了旧的import_added键,因为行数很少。