diff --git a/src/test/regress/input/parallel_partition_bitmapheapscan.source b/src/test/regress/input/parallel_partition_bitmapheapscan.source new file mode 100644 index 0000000000000000000000000000000000000000..0e4bab9e0de65420ff3068962c030355275ac670 --- /dev/null +++ b/src/test/regress/input/parallel_partition_bitmapheapscan.source @@ -0,0 +1,99 @@ +DROP schema if exists test_parallel_partition_bitmapheapscan cascade; +CREATE schema test_parallel_partition_bitmapheapscan; +set current_schema='test_parallel_partition_bitmapheapscan'; +-- create test table and index +DROP TABLE IF EXISTS parallel_partition_bitmapindex_01 cascade; +DROP INDEX if EXISTS index_parallel_partition_bitmapindex_01; + +--step1: create range partition table, expect:success +CREATE TABLE parallel_partition_bitmapindex_01 +( + c1 int, + c2 int, + c3 int +) +PARTITION by range(c1) +( + PARTITION P1 VALUES LESS THAN(2000), + PARTITION P2 VALUES LESS THAN(4000), + PARTITION P3 VALUES LESS THAN(6000), + PARTITION P4 VALUES LESS THAN(MAXVALUE) +)enable row movement; + +INSERT INTO parallel_partition_bitmapindex_01 VALUES (generate_series(1, 10000), generate_series(1,10000), generate_series(1, 10000)); + +CREATE INDEX index_parallel_partition_bitmapindex_01 on parallel_partition_bitmapindex_01(c1) global; +SET enable_seqscan = OFF; +SET enable_indexonlyscan = OFF; +SET enable_indexscan = OFF; +SET query_dop = 2; +-- encourage optimizer to choose parallel path +SET smp_thread_cost = 0; + +-- parallel bitmapindex scan in equality case +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100; +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c1=1000; +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c2=100; +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c2=3255; + +-- parallel bitmapindex scan in scope case +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1<1000; +SELECT COUNT(*) FROM parallel_partition_bitmapindex_01 WHERE c1<1000; +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1>1000 AND c1<2000; +SELECT COUNT(*) FROM parallel_partition_bitmapindex_01 WHERE c1>1000 AND c1<2000; +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1 in (10,100,1000) ORDER BY c1; +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1 in (10,100,1000) ORDER BY c1; + +DROP INDEX index_parallel_partition_bitmapindex_01; +CREATE INDEX index_parallel_partition_bitmapindex_01 on parallel_partition_bitmapindex_01(c1) local; + +-- parallel bitmapindex scan in equality case +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100; +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c1=1000; +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c2=100; +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c2=3255; + +-- parallel bitmapindex scan in scope case +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1<1000; +SELECT COUNT(*) FROM parallel_partition_bitmapindex_01 WHERE c1<1000; +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1>1000 AND c1<2000; +SELECT COUNT(*) FROM parallel_partition_bitmapindex_01 WHERE c1>1000 AND c1<2000; +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1 in (10,100,1000) ORDER BY c1; +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1 in (10,100,1000) ORDER BY c1; + +DROP TABLE if exists parallel_partition_bitmapindex_02 cascade; +DROP INDEX if exists index_parallel_partition_bitmapindex_02; + +CREATE TABLE parallel_partition_bitmapindex_02(c1 int,c2 int,c3 int,c4 text,c5 text,c6 text,c7 text) +PARTITION by range(c1) SUBPARTITION by range(c2) +( + PARTITION btreeindex_t1_p1 VALUES LESS THAN (2000) + ( + SUBPARTITION btreeindex_t1_p1_1 VALUES LESS THAN (1000), + SUBPARTITION btreeindex_t1_p1_2 VALUES LESS THAN (2000) + ), + PARTITION btreeindex_t1_p2 VALUES LESS THAN (4000) + ( + SUBPARTITION btreeindex_t1_p2_1 VALUES LESS THAN (3000), + SUBPARTITION btreeindex_t1_p2_2 VALUES LESS THAN (4000) + ) +); + +INSERT INTO parallel_partition_bitmapindex_02 select a,a,a,a || 'MOG',a || 'DB',a || 'YYY',a || 'YYY' from generate_series(1,3500) as a; +CREATE INDEX index_parallel_partition_bitmapindex_02 on parallel_partition_bitmapindex_02 USING btree(c1,c2,c3,c4,c5,c6,c7) GLOBAL; + +EXPLAIN (COSTS OFF) SELECT * from parallel_partition_bitmapindex_02 WHERE c1 = 2000; +SELECT * FROM parallel_partition_bitmapindex_02 WHERE c1 = 2000; + +DROP INDEX index_parallel_partition_bitmapindex_02; +CREATE INDEX index_parallel_partition_bitmapindex_02 ON parallel_partition_bitmapindex_02 USING btree(c1,c2,c3,c4,c5,c6,c7) LOCAL; +EXPLAIN (COSTS OFF) SELECT * from parallel_partition_bitmapindex_02 WHERE c1 = 2000; +SELECT * FROM parallel_partition_bitmapindex_02 WHERE c1 = 2000; + +--cleanup env +DROP SCHEMA test_parallel_partition_bitmapheapscan CASCADE; +RESET enable_seqscan; +RESET enable_indexonlyscan; +RESET enable_indexscan; +RESET query_dop; +RESET smp_thread_cost; diff --git a/src/test/regress/output/parallel_partition_bitmapheapscan.source b/src/test/regress/output/parallel_partition_bitmapheapscan.source new file mode 100644 index 0000000000000000000000000000000000000000..e601f9278169cd696f2051298ecf584e8a922df8 --- /dev/null +++ b/src/test/regress/output/parallel_partition_bitmapheapscan.source @@ -0,0 +1,261 @@ +DROP schema if exists test_parallel_partition_bitmapheapscan cascade; +NOTICE: schema "test_parallel_partition_bitmapheapscan" does not exist, skipping +CREATE schema test_parallel_partition_bitmapheapscan; +set current_schema='test_parallel_partition_bitmapheapscan'; +-- create test table and index +DROP TABLE IF EXISTS parallel_partition_bitmapindex_01 cascade; +NOTICE: table "parallel_partition_bitmapindex_01" does not exist, skipping +DROP INDEX if EXISTS index_parallel_partition_bitmapindex_01; +NOTICE: index "index_parallel_partition_bitmapindex_01" does not exist, skipping +--step1: create range partition table, expect:success +CREATE TABLE parallel_partition_bitmapindex_01 +( + c1 int, + c2 int, + c3 int +) +PARTITION by range(c1) +( + PARTITION P1 VALUES LESS THAN(2000), + PARTITION P2 VALUES LESS THAN(4000), + PARTITION P3 VALUES LESS THAN(6000), + PARTITION P4 VALUES LESS THAN(MAXVALUE) +)enable row movement; +INSERT INTO parallel_partition_bitmapindex_01 VALUES (generate_series(1, 10000), generate_series(1,10000), generate_series(1, 10000)); +CREATE INDEX index_parallel_partition_bitmapindex_01 on parallel_partition_bitmapindex_01(c1) global; +SET enable_seqscan = OFF; +SET enable_indexonlyscan = OFF; +SET enable_indexscan = OFF; +SET query_dop = 2; +-- encourage optimizer to choose parallel path +SET smp_thread_cost = 0; +-- parallel bitmapindex scan in equality case +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100; + c1 | c2 | c3 +-----+-----+----- + 100 | 100 | 100 +(1 row) + +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c1=1000; + c1 | c2 | c3 +----+----+---- +(0 rows) + +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c2=100; + c1 | c2 | c3 +-----+-----+----- + 100 | 100 | 100 +(1 row) + +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c2=3255; + c1 | c2 | c3 +----+----+---- +(0 rows) + +-- parallel bitmapindex scan in scope case +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1<1000; + QUERY PLAN +-------------------------------------------------------------------------- + Streaming(type: LOCAL GATHER dop: 1/2) + -> Bitmap Heap Scan on parallel_partition_bitmapindex_01 + Recheck Cond: (c1 < 1000) + -> Bitmap Index Scan on index_parallel_partition_bitmapindex_01 + Index Cond: (c1 < 1000) +(5 rows) + +SELECT COUNT(*) FROM parallel_partition_bitmapindex_01 WHERE c1<1000; + count +------- + 999 +(1 row) + +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1>1000 AND c1<2000; + QUERY PLAN +-------------------------------------------------------------------------- + Streaming(type: LOCAL GATHER dop: 1/2) + -> Bitmap Heap Scan on parallel_partition_bitmapindex_01 + Recheck Cond: ((c1 > 1000) AND (c1 < 2000)) + -> Bitmap Index Scan on index_parallel_partition_bitmapindex_01 + Index Cond: ((c1 > 1000) AND (c1 < 2000)) +(5 rows) + +SELECT COUNT(*) FROM parallel_partition_bitmapindex_01 WHERE c1>1000 AND c1<2000; + count +------- + 999 +(1 row) + +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1 in (10,100,1000) ORDER BY c1; + QUERY PLAN +-------------------------------------------------------------------------------- + Sort + Sort Key: c1 + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Bitmap Heap Scan on parallel_partition_bitmapindex_01 + Recheck Cond: (c1 = ANY ('{10,100,1000}'::integer[])) + -> Bitmap Index Scan on index_parallel_partition_bitmapindex_01 + Index Cond: (c1 = ANY ('{10,100,1000}'::integer[])) +(7 rows) + +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1 in (10,100,1000) ORDER BY c1; + c1 | c2 | c3 +------+------+------ + 10 | 10 | 10 + 100 | 100 | 100 + 1000 | 1000 | 1000 +(3 rows) + +DROP INDEX index_parallel_partition_bitmapindex_01; +CREATE INDEX index_parallel_partition_bitmapindex_01 on parallel_partition_bitmapindex_01(c1) local; +-- parallel bitmapindex scan in equality case +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100; + c1 | c2 | c3 +-----+-----+----- + 100 | 100 | 100 +(1 row) + +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c1=1000; + c1 | c2 | c3 +----+----+---- +(0 rows) + +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c2=100; + c1 | c2 | c3 +-----+-----+----- + 100 | 100 | 100 +(1 row) + +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1=100 AND c2=3255; + c1 | c2 | c3 +----+----+---- +(0 rows) + +-- parallel bitmapindex scan in scope case +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1<1000; + QUERY PLAN +-------------------------------------------------------------------------------------- + Streaming(type: LOCAL GATHER dop: 1/2) + -> Partitioned Bitmap Heap Scan on parallel_partition_bitmapindex_01 + Recheck Cond: (c1 < 1000) + Selected Partitions: 1 + -> Partitioned Bitmap Index Scan on index_parallel_partition_bitmapindex_01 + Index Cond: (c1 < 1000) + Selected Partitions: 1 +(7 rows) + +SELECT COUNT(*) FROM parallel_partition_bitmapindex_01 WHERE c1<1000; + count +------- + 999 +(1 row) + +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1>1000 AND c1<2000; + QUERY PLAN +-------------------------------------------------------------------------------------- + Streaming(type: LOCAL GATHER dop: 1/2) + -> Partitioned Bitmap Heap Scan on parallel_partition_bitmapindex_01 + Recheck Cond: ((c1 > 1000) AND (c1 < 2000)) + Selected Partitions: 1 + -> Partitioned Bitmap Index Scan on index_parallel_partition_bitmapindex_01 + Index Cond: ((c1 > 1000) AND (c1 < 2000)) + Selected Partitions: 1 +(7 rows) + +SELECT COUNT(*) FROM parallel_partition_bitmapindex_01 WHERE c1>1000 AND c1<2000; + count +------- + 999 +(1 row) + +EXPLAIN (COSTS OFF) SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1 in (10,100,1000) ORDER BY c1; + QUERY PLAN +-------------------------------------------------------------------------------------------- + Sort + Sort Key: c1 + -> Streaming(type: LOCAL GATHER dop: 1/2) + -> Partitioned Bitmap Heap Scan on parallel_partition_bitmapindex_01 + Recheck Cond: (c1 = ANY ('{10,100,1000}'::integer[])) + Selected Partitions: 1 + -> Partitioned Bitmap Index Scan on index_parallel_partition_bitmapindex_01 + Index Cond: (c1 = ANY ('{10,100,1000}'::integer[])) + Selected Partitions: 1 +(9 rows) + +SELECT * FROM parallel_partition_bitmapindex_01 WHERE c1 in (10,100,1000) ORDER BY c1; + c1 | c2 | c3 +------+------+------ + 10 | 10 | 10 + 100 | 100 | 100 + 1000 | 1000 | 1000 +(3 rows) + +DROP TABLE if exists parallel_partition_bitmapindex_02 cascade; +NOTICE: table "parallel_partition_bitmapindex_02" does not exist, skipping +DROP INDEX if exists index_parallel_partition_bitmapindex_02; +NOTICE: index "index_parallel_partition_bitmapindex_02" does not exist, skipping +CREATE TABLE parallel_partition_bitmapindex_02(c1 int,c2 int,c3 int,c4 text,c5 text,c6 text,c7 text) +PARTITION by range(c1) SUBPARTITION by range(c2) +( + PARTITION btreeindex_t1_p1 VALUES LESS THAN (2000) + ( + SUBPARTITION btreeindex_t1_p1_1 VALUES LESS THAN (1000), + SUBPARTITION btreeindex_t1_p1_2 VALUES LESS THAN (2000) + ), + PARTITION btreeindex_t1_p2 VALUES LESS THAN (4000) + ( + SUBPARTITION btreeindex_t1_p2_1 VALUES LESS THAN (3000), + SUBPARTITION btreeindex_t1_p2_2 VALUES LESS THAN (4000) + ) +); +INSERT INTO parallel_partition_bitmapindex_02 select a,a,a,a || 'MOG',a || 'DB',a || 'YYY',a || 'YYY' from generate_series(1,3500) as a; +CREATE INDEX index_parallel_partition_bitmapindex_02 on parallel_partition_bitmapindex_02 USING btree(c1,c2,c3,c4,c5,c6,c7) GLOBAL; +EXPLAIN (COSTS OFF) SELECT * from parallel_partition_bitmapindex_02 WHERE c1 = 2000; + QUERY PLAN +-------------------------------------------------------------------------- + Streaming(type: LOCAL GATHER dop: 1/2) + -> Bitmap Heap Scan on parallel_partition_bitmapindex_02 + Recheck Cond: (c1 = 2000) + -> Bitmap Index Scan on index_parallel_partition_bitmapindex_02 + Index Cond: (c1 = 2000) +(5 rows) + +SELECT * FROM parallel_partition_bitmapindex_02 WHERE c1 = 2000; + c1 | c2 | c3 | c4 | c5 | c6 | c7 +------+------+------+---------+--------+---------+--------- + 2000 | 2000 | 2000 | 2000MOG | 2000DB | 2000YYY | 2000YYY +(1 row) + +DROP INDEX index_parallel_partition_bitmapindex_02; +CREATE INDEX index_parallel_partition_bitmapindex_02 ON parallel_partition_bitmapindex_02 USING btree(c1,c2,c3,c4,c5,c6,c7) LOCAL; +EXPLAIN (COSTS OFF) SELECT * from parallel_partition_bitmapindex_02 WHERE c1 = 2000; + QUERY PLAN +-------------------------------------------------------------------------------------------- + Streaming(type: LOCAL GATHER dop: 1/2) + -> Partition Iterator + Iterations: 1, Sub Iterations: 2 + -> Partitioned Bitmap Heap Scan on parallel_partition_bitmapindex_02 + Recheck Cond: (c1 = 2000) + Selected Partitions: 2 + Selected Subpartitions: ALL + -> Partitioned Bitmap Index Scan on index_parallel_partition_bitmapindex_02 + Index Cond: (c1 = 2000) + Selected Partitions: 2 + Selected Subpartitions: ALL +(11 rows) + +SELECT * FROM parallel_partition_bitmapindex_02 WHERE c1 = 2000; + c1 | c2 | c3 | c4 | c5 | c6 | c7 +------+------+------+---------+--------+---------+--------- + 2000 | 2000 | 2000 | 2000MOG | 2000DB | 2000YYY | 2000YYY +(1 row) + +--cleanup env +DROP SCHEMA test_parallel_partition_bitmapheapscan CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table parallel_partition_bitmapindex_01 +drop cascades to table parallel_partition_bitmapindex_02 +RESET enable_seqscan; +RESET enable_indexonlyscan; +RESET enable_indexscan; +RESET query_dop; +RESET smp_thread_cost;