我有一张存储 2k 记录的表。架构是:
CREATE TABLE `tcms_articles` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`User_id` int(10) unsigned DEFAULT NULL,
`Category_id` int(10) unsigned DEFAULT NULL,
`Title` varchar(255) DEFAULT NULL,
`Value` longtext,
`Keywords` varchar(255) NOT NULL DEFAULT '',
`Description` varchar(255) NOT NULL DEFAULT '',
`Images` longtext NOT NULL,
`Votes` int(10) unsigned NOT NULL DEFAULT '1',
`Votes_sum` int(10) unsigned NOT NULL DEFAULT '5',
`Views` int(10) unsigned NOT NULL DEFAULT '0',
`Isvisible` tinyint(1) unsigned NOT NULL DEFAULT '1',
`Isfrontpage` tinyint(1) unsigned NOT NULL DEFAULT '0',
`Istoparticle` tinyint(1) unsigned NOT NULL DEFAULT '1',
`Expires_date` datetime NOT NULL DEFAULT '2099-12-31 00:00:00',
`Date` datetime NOT NULL,
PRIMARY KEY (`Id`),
KEY `article_users` (`User_id`) USING BTREE,
KEY `article_section` (`Category_id`) USING BTREE,
KEY `Isvisible_index` (`Isvisible`) USING BTREE,
KEY `Istoparticle_index` (`Istoparticle`) USING BTREE,
KEY `Expires_date_index` (`Expires_date`) USING BTREE,
KEY `isfrontpage` (`Isfrontpage`) USING BTREE,
KEY `Date_index` (`Date`) USING BTREE,
CONSTRAINT `tcms_articles_categories` FOREIGN KEY (`Category_id`) REFERENCES `tcms_categories` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `tcms_articles_ibfk_2` FOREIGN KEY (`User_id`) REFERENCES `tcms_users` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=80 DEFAULT CHARSET=utf8;
当我用这个查询搜索表时,我遇到了性能问题
select value from tcms_articles where istoparticle=1 and isvisible=1 order by date limit 1;
大约需要 1.50+ 秒!
但是当我这样搜索时:
select value from tcms_articles where istoparticle=1 order by date limit 1;
我没有任何问题,大约需要 0.02 秒。
非常感谢。