2

2k レコードを格納するテーブルが 1 つあります。スキーマは次のとおりです。

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秒程度で問題ありません。

どうもうありがとう。

4

1 に答える 1

1

(Istoparticle, Isvisible, Date)このクエリに B ツリー (ハッシュではない) 複合インデックスを追加できます。

于 2012-06-23T21:53:18.980 に答える