在PostgreSQL中选择大小为N的bucket fast 请考虑下面的代码片段。我能用PostgreSQL以多快的速度做到这一点 create table target ( id bigserial not null primary key, my_id bigint, ); select id from (select id , count(*) over (partition by my_id) cnt from target) t1 where cnt = 2;

在PostgreSQL中选择大小为N的bucket fast 请考虑下面的代码片段。我能用PostgreSQL以多快的速度做到这一点 create table target ( id bigserial not null primary key, my_id bigint, ); select id from (select id , count(*) over (partition by my_id) cnt from target) t1 where cnt = 2;,sql,postgresql,indexing,Sql,Postgresql,Indexing,我认为targetmy_id上的索引应该表示为Bucket字典my_id=>id列表。是否可以按bucket的大小为该索引编制索引,以便我可以快速检索具有特定大小的bucket?没有索引可以帮助您进行此查询,它必须扫描整个表 你可以考虑一个实体化的观点;这可以编入索引。但它不包含最新数据,必须定期刷新。您正在查找width\u bucket吗?无关,但:identity是一个关键字,您不应该将其用作列名感谢identity,我已经修复了代码段。我认为width_bucket是不同的,在这里看不到

我认为targetmy_id上的索引应该表示为Bucket字典my_id=>id列表。是否可以按bucket的大小为该索引编制索引,以便我可以快速检索具有特定大小的bucket?

没有索引可以帮助您进行此查询,它必须扫描整个表


<>你可以考虑一个实体化的观点;这可以编入索引。但它不包含最新数据,必须定期刷新。

您正在查找width\u bucket吗?无关,但:identity是一个关键字,您不应该将其用作列名感谢identity,我已经修复了代码段。我认为width_bucket是不同的,在这里看不到如何应用。那么你的问题是什么?关于索引bucket。你在寻找索引吗?