这可能是个愚蠢的问题。我有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.

因为Order by C DESC and 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

09-16 06:16
查看更多