简体   繁体   English

postgres - 如何在使用 order by 扫描查询时跳过分区

[英]postgres - how to skip partitions when scanning query with order by

I'm trying to query a postgres partitioned by range table with order by and limit.我正在尝试使用 order by 和 limit 查询由范围表分区的 postgres。 Is there a way to make it scan partitions by order and skip the rest of partitions after it reached the limit of 20?有没有办法让它按顺序扫描分区并在达到20个限制后跳过分区的rest? (using postgres 11.3 but can upgrade if necessary) (使用 postgres 11.3 但必要时可以升级)

SELECT * FROM table ORDER BY timestamp DESC LIMIT 20 SELECT * FROM table ORDER BY timestamp DESC LIMIT 20

Not in v11.不在 v11 中。

This will work automatically provided you have an index starting with "timestamp", and you upgrade to at least v12.如果您有一个以“timestamp”开头的索引,并且您至少升级到 v12,这将自动工作。

It seems like this could work without the index (sorting each partition in turn, starting at the proper end of the range, until it gets its LIMIT), but I guess no one bothered to implement that.似乎这可以在没有索引的情况下工作(依次对每个分区进行排序,从范围的正确末端开始,直到它得到它的 LIMIT),但我想没有人会费心去实现它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM