gpt4 book ai didi

Mysql-这是一个很好的优化查询吗?

转载 作者:搜寻专家 更新时间:2023-10-30 20:11:37 25 4
gpt4 key购买 nike

这可能是个愚蠢的问题。我有超过 3000 万条记录。

Table 1

Column A(int) - Column B(Boolean) - Column C(int) - Column D(DateTime)

我将在 (A,B,C,D) 上创建一个复合索引。

查询如下:

Select * from table1 where A=12 and B!=0 ORDER BY C DESC ,D ASC.

因为 按 C DESC 和 D ASC 排序是不可能的。每次插入记录时,我都将 C 乘以 (-1) 进行反向排序。

现在我尝试执行的查询将是:

Select * from table1 where A=12 and B!=0 ORDER BY C ASC ,D ASC.

考虑到 where 子句和 order by 中的两个条件,上面的查询是否会充分利用索引?或者还有其他更好的解决方案吗?

最佳答案

有一个非常有用的SQL命令,叫做EXPLAIN。

它正是这样做的 - 解释了 RDBMS 如何计算查询。

http://dev.mysql.com/doc/refman/5.0/en/explain.html

关于Mysql-这是一个很好的优化查询吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9556823/

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