本文介绍了将ORDER BY从id更改为另一个索引列(具有较低的LIMIT)具有巨大的成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于500 000行表的查询。
I have a query on a 500 000 row table.
基本上
c一致。CREATE INDEX message_created_at_idx on message (created_at DESC NULLS LAST); ... ORDER BY messsage.created_at DESC NULLS LAST;
NULLs
NULLS FIRST
CREATE INDEX message_created_at_idx on message (created_at DESC); -- defaults to NULLS FIRST when DESC ... ORDER BY messsage.created_at DESC -- defaults to NULLS FIRST when DESC;
不为空
如果您的列是
NOT NULL
If your column is NOT NULL, don't bother with NULLS.
CREATE INDEX message_created_at_idx on message (created_at DESC); ... ORDER BY messsage.created_at DESC;这篇关于将ORDER BY从id更改为另一个索引列(具有较低的LIMIT)具有巨大的成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!