gpt4 book ai didi

c# - MySql 奇怪(对我来说)where 子句的性能

转载 作者:行者123 更新时间:2023-11-29 03:08:57 25 4
gpt4 key购买 nike

我有一个存储 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;

当我用这个查询搜索表时,我遇到了性能问题

从 tcms_articles 中选择值,其中 istoparticle=1 和 isvisible=1 按日期限制排序 1;

大约需要 1.50 多秒!

但是当我这样搜索时:

从 tcms_articles 中选择值,其中 istoparticle=1 按日期限制排序 1;

我没有任何问题,大约需要 0.02 秒。

非常感谢。

最佳答案

您可以为此查询在 (Istoparticle, Isvisible, Date) 上添加一个 B 树(不是哈希)复合索引。

关于c# - MySql 奇怪(对我来说)where 子句的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11173127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com