我在我的MySQL數據庫這兩個表:上優化MySQL查詢/數據庫結構
CREATE TABLE IF NOT EXISTS `articles` (
`id` bigint(20) NOT NULL,
`url` varchar(255) collate utf8_bin NOT NULL,
`img` varchar(255) collate utf8_bin NOT NULL,
`name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
`url_key` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
`type_code` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
`likes_count` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `type` (`type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE IF NOT EXISTS `articles_types` (
`id` int(11) NOT NULL auto_increment,
`code` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
`url_key` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
`name` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`code`),
KEY `type` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
而且我試圖運行此查詢:
SELECT a.* FROM `articles` a INNER JOIN articles_types at ON at.`code`=a.type ORDER BY p.likes_count DESC LIMIT 1
它返回1行,在1秒。
表中的文章大約包含超過70k行,articles_types僅包含大約70行。
是否有機會優化該表的結構(可能是引擎?),還是優化查詢本身以使其更快?
你對這些表的索引創建索引?如果是這樣,讓我們知道哪些列被覆蓋。 – 2010-09-11 22:20:26
2Dustin:正如您在上面看到的那樣,表格由許多索引組成,現在我已經爲articles.like_count添加了一個新索引,因爲結果按此列排序。但它沒有幫助。 – 2010-09-12 07:36:51
2Damien:感謝considiring有關:-)相信我,如果我能真正回答,哪個能解決我的問題,我會接受這個答案。 – 2010-09-12 07:38:37