mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
Restructure creation of run-time pruning steps.
Previously, gen_partprune_steps() always built executor pruning steps using all suitable clauses, including those containing PARAM_EXEC Params. This meant that the pruning steps were only completely safe for executor run-time (scan start) pruning. To prune at executor startup, we had to ignore the steps involving exec Params. But this doesn't really work in general, since there may be logic changes needed as well --- for example, pruning according to the last operator's btree strategy is the wrong thing if we're not applying that operator. The rules embodied in gen_partprune_steps() and its minions are sufficiently complicated that tracking their incremental effects in other logic seems quite impractical. Short of a complete redesign, the only safe fix seems to be to run gen_partprune_steps() twice, once to create executor startup pruning steps and then again for run-time pruning steps. We can save a few cycles however by noting during the first scan whether we rejected any clauses because they involved exec Params --- if not, we don't need to do the second scan. In support of this, refactor the internal APIs in partprune.c to make more use of passing information in the GeneratePruningStepsContext struct, rather than as separate arguments. This is, I hope, the last piece of our response to a bug report from Alan Jackson. Back-patch to v11 where this code came in. Discussion: https://postgr.es/m/FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com
This commit is contained in:
@@ -3149,6 +3149,45 @@ select * from mc3p where a < 3 and abs(b) = 1;
|
||||
Filter: ((a < 3) AND (abs(b) = 1))
|
||||
(7 rows)
|
||||
|
||||
--
|
||||
-- Check that pruning with composite range partitioning works correctly when
|
||||
-- a combination of runtime parameters is specified, not all of whose values
|
||||
-- are available at the same time
|
||||
--
|
||||
set plan_cache_mode = force_generic_plan;
|
||||
prepare ps1 as
|
||||
select * from mc3p where a = $1 and abs(b) < (select 3);
|
||||
explain (analyze, costs off, summary off, timing off)
|
||||
execute ps1(1);
|
||||
QUERY PLAN
|
||||
-------------------------------------------------
|
||||
Append (actual rows=1 loops=1)
|
||||
InitPlan 1 (returns $0)
|
||||
-> Result (actual rows=1 loops=1)
|
||||
Subplans Removed: 2
|
||||
-> Seq Scan on mc3p1 (actual rows=1 loops=1)
|
||||
Filter: ((a = $1) AND (abs(b) < $0))
|
||||
(6 rows)
|
||||
|
||||
deallocate ps1;
|
||||
prepare ps2 as
|
||||
select * from mc3p where a <= $1 and abs(b) < (select 3);
|
||||
explain (analyze, costs off, summary off, timing off)
|
||||
execute ps2(1);
|
||||
QUERY PLAN
|
||||
-------------------------------------------------
|
||||
Append (actual rows=2 loops=1)
|
||||
InitPlan 1 (returns $0)
|
||||
-> Result (actual rows=1 loops=1)
|
||||
Subplans Removed: 1
|
||||
-> Seq Scan on mc3p0 (actual rows=1 loops=1)
|
||||
Filter: ((a <= $1) AND (abs(b) < $0))
|
||||
-> Seq Scan on mc3p1 (actual rows=1 loops=1)
|
||||
Filter: ((a <= $1) AND (abs(b) < $0))
|
||||
(8 rows)
|
||||
|
||||
deallocate ps2;
|
||||
reset plan_cache_mode;
|
||||
drop table mc3p;
|
||||
-- Ensure runtime pruning works with initplans params with boolean types
|
||||
create table boolvalues (value bool not null);
|
||||
|
||||
@@ -809,6 +809,24 @@ insert into mc3p values (0, 1, 1), (1, 1, 1), (2, 1, 1);
|
||||
explain (analyze, costs off, summary off, timing off)
|
||||
select * from mc3p where a < 3 and abs(b) = 1;
|
||||
|
||||
--
|
||||
-- Check that pruning with composite range partitioning works correctly when
|
||||
-- a combination of runtime parameters is specified, not all of whose values
|
||||
-- are available at the same time
|
||||
--
|
||||
set plan_cache_mode = force_generic_plan;
|
||||
prepare ps1 as
|
||||
select * from mc3p where a = $1 and abs(b) < (select 3);
|
||||
explain (analyze, costs off, summary off, timing off)
|
||||
execute ps1(1);
|
||||
deallocate ps1;
|
||||
prepare ps2 as
|
||||
select * from mc3p where a <= $1 and abs(b) < (select 3);
|
||||
explain (analyze, costs off, summary off, timing off)
|
||||
execute ps2(1);
|
||||
deallocate ps2;
|
||||
reset plan_cache_mode;
|
||||
|
||||
drop table mc3p;
|
||||
|
||||
-- Ensure runtime pruning works with initplans params with boolean types
|
||||
|
||||
Reference in New Issue
Block a user