检查 sql 中 rank() 函数使用的索引键

Checking index key used by rank() function in sql

使用 EXPLAIN SELECT * FROM table1 where condition1 = condition1 and condition2 = condition2 您可以检查正在使用的索引键(如果有的话)。

如果你有 SELECT * RANK() OVER (ORDER BY condition3 DESC, condition4 ASC) AS table2 FROM table1 ,你可以为 rank() 函数索引 condition3 和 condition4 吗?哎呀,如果你已经完成了索引,你怎么甚至在这里检查 rank() 函数正在使用的索引?

你的两个问题的答案都是肯定的,你的排名查询应该受益于以下索引:

CREATE INDEX idx ON table1 (condition3 DESC, condition4);

运行 EXPLAIN 上面的查询应该显示正在使用这个索引。