ef6e3f86创建于 2025年2月20日历史提交
-- tests for tidrangescans
-- empty table
set enable_seqscan to off;
create table trs_empty(id int);
analyze trs_empty;

explain (costs off)
select * from trs_empty where ctid < '(1,0)';
select * from trs_empty where ctid < '(1,0)';

explain (costs off)
select * from trs_empty where ctid > '(9,0)';
select * from trs_empty where ctid > '(9,0)';

set enable_seqscan to on;

-- table with 10 full pages
create table trs_10p as select generate_series(1, 2260) id;
analyze trs_10p;

explain 
select * from trs_10p where ctid < '(1,0)';
select count(*) from trs_10p where ctid < '(1,0)';

explain 
select * from trs_10p where ctid > '(9,0)';
select count(*) from trs_10p where ctid > '(9,0)';

explain 
select * from trs_10p where ctid >= '(5,0)' and ctid <= '(6,0)';
select count(*) from trs_10p where ctid >= '(5,0)' and ctid <= '(6,0)';

explain
select * from trs_10p where ctid between '(5,0)' and '(6,0)';
select count(*) from trs_10p where ctid between '(5,0)' and '(6,0)';

explain
select * from trs_10p where ctid < '(1,0)' limit 10;
select count(*) from trs_10p where ctid < '(1,0)' limit 10;

update trs_10p set id = 1000000 where id = 1;
select count(*) from trs_10p where ctid < '(1,0)';

-- table with more than 65536 pages
create table trs_gt_65536p as select generate_series(1, 15000072) id;
analyze trs_gt_65536p;

explain
select * from trs_gt_65536p where ctid > '(65530,0)' and ctid < '(65540,0)';
select count(*) from trs_gt_65536p where ctid > '(65530,0)' and ctid < '(65540,0)';

-- table larger than 3 files (one file is approximately 131072 pages)
create table trs_gt_3f as select generate_series(1, 100000028) id;
analyze trs_gt_3f;

explain 
select * from trs_gt_3f where ctid > '(131000,0)' and ctid < '(262150,0)';
select count(*) from trs_gt_3f where ctid > '(131000,0)' and ctid < '(262150,0)';

-- ustore
create table trs_ustore with (storage_type=ustore) as select generate_series(1, 2260) id;
analyze trs_ustore;

explain 
select * from trs_ustore where ctid > '(9,0)';
select count(*) from trs_ustore where ctid > '(9,0)';

-- segment store
create table trs_seg with (segment=on) as select generate_series(1, 2260) id;
analyze trs_seg;

explain 
select * from trs_seg where ctid < '(1,0)';
select count(*) from trs_seg where ctid < '(1,0)';

explain 
select * from trs_seg where ctid > '(9,0)';
select count(*) from trs_seg where ctid > '(9,0)';

explain 
select * from trs_seg where ctid >= '(5,0)' and ctid <= '(6,0)';
select count(*) from trs_seg where ctid >= '(5,0)' and ctid <= '(6,0)';

explain
select * from trs_seg where ctid between '(5,0)' and '(6,0)';
select count(*) from trs_seg where ctid between '(5,0)' and '(6,0)';

explain
select * from trs_seg where ctid < '(1,0)' limit 10;
select count(*) from trs_seg where ctid < '(1,0)' limit 10;

update trs_seg set id = 1000000 where id = 1;
select count(*) from trs_seg where ctid < '(1,0)';