gpt4 book ai didi

mysql - 什么是复合索引以及如何正确使用它?

转载 作者:行者123 更新时间:2023-12-01 00:35:26 26 4
gpt4 key购买 nike

我有一个非常慢的查询,它会重复很多次。我试过为各个字段编制索引,但似乎无济于事。 CPU 使用率仍然很高,查询仍然出现在慢查询日志中。看来我需要一个复合索引?

如何正确索引以下查询?

select *
from `to_attachments` left join
`attachments`
on `to_attachments`.`attachment_id` = `attachments`.`id`
where `to_attachments`.`object_type` = 'communicator' and `to_attachments`.`object_id` = '64328'
order by `attachments`.`created_at` desc;

解释结果:
1 SIMPLE to_attachments index NULL PRIMARY 775 NULL 244384 Using where;使用索引;使用临时的;使用文件排序
1 简单附件 eq_ref PRIMARY PRIMARY 4 quote.to_attachments.attachment_id 1 NULL

to_attachments 的索引 enter image description here

最佳答案

您需要在 to_attachments(object_type, object_id, attachment_id)attachments(id) 上建立索引。

关于mysql - 什么是复合索引以及如何正确使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52631347/

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