讨论 技术讨论 博客模块这句话很卡MySQL 该怎么调优 在哪里调优

博客模块这句话很卡MySQL 该怎么调优 在哪里调优

WX_gH 发表于    阅读:164    回复:8

# Time: 2023-04-25T11:55:36.706047Z

# User@Host: doumiao[doumiao] @ localhost []  Id: 402364

# Query_time: 8774.208720  Lock_time: 0.000340 Rows_sent: 1  Rows_examined: 87702

SET timestamp=1682423736;

select count(*) as aggregate from `blog` where `postTime` < '2023-04-25 09:29:22' and (`isPublished` = 1);


评论

增加一个联合索引,key(postTime, isPublished) .

 

想要修改这句话的话  这个语句再具体哪个控制器或者model里面?

 

要给 MySQL 数据库表 blog 增加一个联合索引 key(postTime, isPublished) ,可以使用如下 SQL 语句:

ALTER TABLE blog ADD INDEX idx_postTime_isPublished (postTime, isPublished);


这条语句会将表 blog 中的 postTime 和 isPublished 两个字段组成一个联合索引,索引名为 idx_postTime_isPublished。在使用这个联合索引时,MySQL 会优先按照 postTime 字段进行排序,然后再按照 isPublished 字段进行排序。这样可以提高查询效率,特别是在同时涉及到 postTime 和 isPublished 两个字段的查询时。


 

好的 谢谢

 

加了索引也不管用

 

数据表中有多少记录?

 

九万多条

另外 博客的列表页的地址是这样的 /blogs?page=3

怎么设置下hi才可以让他是伪静态的模式

 

可以通过优化增加缓存解决。

伪静态目前不支持,可以直接通过路由配置。

 
1
我来评论
QQ
微信