Postgresql分区偏移量优化



我创建了一个表:

create table test (id serial, name varchar(20), rownumber serial) partition by range (id);

然后创建index

create index "test_rownumber_id_index" on test using btree (id,rownumber);

然后创建分区:

create table test_1_5 partition of test for values from (1) to (5);
create table test_5_10 partition of test for values from (5) to (10);

则插入9行。现在,我想模拟带有偏移量

的查询
select id from test where rownumber>5 limit 10;

explain select id from supertest2 where rowsnumber>5 limit 10;

Limit  (cost=0.00..0.77 rows=10 width=4)
->  Append  (cost=0.00..44.37 rows=574 width=4)
->  Seq Scan on test_1_5 test  (cost=0.00..20.75 rows=287 width=4)
Filter: (rownumber > 5)
->  Seq Scan on test_5_10 test  (cost=0.00..20.75 rows=287 width=4)
Filter: (rownumber > 5)

问题是Postgres如何做这个查询?postgres是线性地遍历分区test_1_5,还是只是在btree索引中找到值为&gt的行号?在他找到这个节点后得到线性极限?

我需要Postgres在这样的查询中忽略分区test_1_5。

当你按特定值进行分区时,你必须在WHERE条件下使用分区键

:

select id from test where id>5 limit 10;

最新更新