--1. prepare bitmap heap scan data and table
--source data
create table x(a int, b int, c int);
create index on x(a);
insert into x select generate_series(1,200000000),floor(random()*(10001-1)+1),floor(random()*(10001-1)+1);

--create target table
create table testscan(a int, b int);
create table testscan_pk(a int primary key, b int);
create table testscan_index(a int, b int);
create index on testscan_index(a);


--1. begin test bitmap heap scan

--Test INSERT with parallel bitmap heap scan, target table without constraint
explain analyze verbose insert into testscan select a from x where a<80000 or (a%2=0 and a>199900000);

--Test INSERT with parallel bitmap heap scan, target table with PK
explain analyze verbose insert into testscan_pk select a from x where a<80000 or (a%2=0 and a>199900000);

--Test INSERT with parallel bitmap heap scan, target table with btree index
explain analyze verbose insert into testscan_index select a from x where a<80000 or (a%2=0 and a>199900000);


truncate testscan;
truncate testscan_pk;
truncate testscan_index;