mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Improve performance of partition pruning remapping a little.
ExecFindInitialMatchingSubPlans has to update the PartitionPruneState's subplan mapping data to account for the removal of subplans it prunes. However, that's only necessary if run-time pruning will also occur, so we can skip it when that won't happen, which should result in not needing to do the remapping in many cases. (We now need it only when some partitions are potentially startup-time prunable and others are potentially run-time prunable, which seems like an unusual case.) Also make some marginal performance improvements in the remapping itself. These will mainly win if most partitions got pruned by the startup-time pruning, which is perhaps a debatable assumption in this context. Also fix some bogus comments, and rearrange code to marginally reduce space consumption in the executor's query-lifespan context. David Rowley, reviewed by Yoshikazu Imai Discussion: https://postgr.es/m/CAKJS1f9+m6-di-zyy4B4AGn0y1B9F8UKDRigtBbNviXOkuyOpw@mail.gmail.com
This commit is contained in:
@ -2472,11 +2472,61 @@ select * from (select * from ab where a = 1 union all (values(10,5)) union all s
|
||||
Filter: (b = $0)
|
||||
(39 rows)
|
||||
|
||||
-- Another UNION ALL test, but containing a mix of exec init and exec run-time pruning.
|
||||
create table xy_1 (x int, y int);
|
||||
insert into xy_1 values(100,-10);
|
||||
set enable_bitmapscan = 0;
|
||||
set enable_indexscan = 0;
|
||||
set plan_cache_mode = 'force_generic_plan';
|
||||
prepare ab_q6 as
|
||||
select * from (
|
||||
select tableoid::regclass,a,b from ab
|
||||
union all
|
||||
select tableoid::regclass,x,y from xy_1
|
||||
union all
|
||||
select tableoid::regclass,a,b from ab
|
||||
) ab where a = $1 and b = (select -10);
|
||||
-- Ensure the xy_1 subplan is not pruned.
|
||||
explain (analyze, costs off, summary off, timing off) execute ab_q6(1);
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------
|
||||
Append (actual rows=0 loops=1)
|
||||
InitPlan 1 (returns $0)
|
||||
-> Result (actual rows=1 loops=1)
|
||||
Subplans Removed: 12
|
||||
-> Seq Scan on ab_a1_b1 (never executed)
|
||||
Filter: ((a = $1) AND (b = $0))
|
||||
-> Seq Scan on ab_a1_b2 (never executed)
|
||||
Filter: ((a = $1) AND (b = $0))
|
||||
-> Seq Scan on ab_a1_b3 (never executed)
|
||||
Filter: ((a = $1) AND (b = $0))
|
||||
-> Seq Scan on xy_1 (actual rows=0 loops=1)
|
||||
Filter: ((x = $1) AND (y = $0))
|
||||
Rows Removed by Filter: 1
|
||||
-> Seq Scan on ab_a1_b1 ab_a1_b1_1 (never executed)
|
||||
Filter: ((a = $1) AND (b = $0))
|
||||
-> Seq Scan on ab_a1_b2 ab_a1_b2_1 (never executed)
|
||||
Filter: ((a = $1) AND (b = $0))
|
||||
-> Seq Scan on ab_a1_b3 ab_a1_b3_1 (never executed)
|
||||
Filter: ((a = $1) AND (b = $0))
|
||||
(19 rows)
|
||||
|
||||
-- Ensure we see just the xy_1 row.
|
||||
execute ab_q6(100);
|
||||
tableoid | a | b
|
||||
----------+-----+-----
|
||||
xy_1 | 100 | -10
|
||||
(1 row)
|
||||
|
||||
reset enable_bitmapscan;
|
||||
reset enable_indexscan;
|
||||
reset plan_cache_mode;
|
||||
deallocate ab_q1;
|
||||
deallocate ab_q2;
|
||||
deallocate ab_q3;
|
||||
deallocate ab_q4;
|
||||
deallocate ab_q5;
|
||||
deallocate ab_q6;
|
||||
-- UPDATE on a partition subtree has been seen to have problems.
|
||||
insert into ab values (1,2);
|
||||
explain (analyze, costs off, summary off, timing off)
|
||||
|
@ -548,11 +548,39 @@ select * from (select * from ab where a = 1 union all select * from ab) ab where
|
||||
explain (analyze, costs off, summary off, timing off)
|
||||
select * from (select * from ab where a = 1 union all (values(10,5)) union all select * from ab) ab where b = (select 1);
|
||||
|
||||
-- Another UNION ALL test, but containing a mix of exec init and exec run-time pruning.
|
||||
create table xy_1 (x int, y int);
|
||||
insert into xy_1 values(100,-10);
|
||||
|
||||
set enable_bitmapscan = 0;
|
||||
set enable_indexscan = 0;
|
||||
set plan_cache_mode = 'force_generic_plan';
|
||||
|
||||
prepare ab_q6 as
|
||||
select * from (
|
||||
select tableoid::regclass,a,b from ab
|
||||
union all
|
||||
select tableoid::regclass,x,y from xy_1
|
||||
union all
|
||||
select tableoid::regclass,a,b from ab
|
||||
) ab where a = $1 and b = (select -10);
|
||||
|
||||
-- Ensure the xy_1 subplan is not pruned.
|
||||
explain (analyze, costs off, summary off, timing off) execute ab_q6(1);
|
||||
|
||||
-- Ensure we see just the xy_1 row.
|
||||
execute ab_q6(100);
|
||||
|
||||
reset enable_bitmapscan;
|
||||
reset enable_indexscan;
|
||||
reset plan_cache_mode;
|
||||
|
||||
deallocate ab_q1;
|
||||
deallocate ab_q2;
|
||||
deallocate ab_q3;
|
||||
deallocate ab_q4;
|
||||
deallocate ab_q5;
|
||||
deallocate ab_q6;
|
||||
|
||||
-- UPDATE on a partition subtree has been seen to have problems.
|
||||
insert into ab values (1,2);
|
||||
|
Reference in New Issue
Block a user