@@ -2005,20 +2005,17 @@ select explain_parallel_append('execute ab_q5 (2, 3, 3)');
2005
2005
(19 rows)
2006
2006
2007
2007
-- Try some params whose values do not belong to any partition.
2008
- -- We'll still get a single subplan in this case, but it should not be scanned.
2009
2008
select explain_parallel_append('execute ab_q5 (33, 44, 55)');
2010
- explain_parallel_append
2011
- -------------------------------------------------------------------------------
2009
+ explain_parallel_append
2010
+ -----------------------------------------------------------
2012
2011
Finalize Aggregate (actual rows=N loops=N)
2013
2012
-> Gather (actual rows=N loops=N)
2014
2013
Workers Planned: 2
2015
2014
Workers Launched: N
2016
2015
-> Partial Aggregate (actual rows=N loops=N)
2017
2016
-> Parallel Append (actual rows=N loops=N)
2018
- Subplans Removed: 8
2019
- -> Parallel Seq Scan on ab_a1_b1 ab_1 (never executed)
2020
- Filter: ((b < 4) AND (a = ANY (ARRAY[$1, $2, $3])))
2021
- (9 rows)
2017
+ Subplans Removed: 9
2018
+ (7 rows)
2022
2019
2023
2020
-- Test Parallel Append with PARAM_EXEC Params
2024
2021
select explain_parallel_append('select count(*) from ab where (a = (select 1) or a = (select 3)) and b = 2');
@@ -2854,16 +2851,13 @@ explain (analyze, costs off, summary off, timing off) execute q1 (2,2);
2854
2851
Filter: (b = ANY (ARRAY[$1, $2]))
2855
2852
(4 rows)
2856
2853
2857
- -- Try with no matching partitions. One subplan should remain in this case,
2858
- -- but it shouldn't be executed.
2854
+ -- Try with no matching partitions.
2859
2855
explain (analyze, costs off, summary off, timing off) execute q1 (0,0);
2860
- QUERY PLAN
2861
- ------------------------------------------------------
2856
+ QUERY PLAN
2857
+ --------------------------------
2862
2858
Append (actual rows=0 loops=1)
2863
- Subplans Removed: 1
2864
- -> Seq Scan on listp_1_1 listp_1 (never executed)
2865
- Filter: (b = ANY (ARRAY[$1, $2]))
2866
- (4 rows)
2859
+ Subplans Removed: 2
2860
+ (2 rows)
2867
2861
2868
2862
deallocate q1;
2869
2863
-- Test more complex cases where a not-equal condition further eliminates partitions.
@@ -2879,15 +2873,12 @@ explain (analyze, costs off, summary off, timing off) execute q1 (1,2,2,0);
2879
2873
(4 rows)
2880
2874
2881
2875
-- Both partitions allowed by IN clause, then both excluded again by <> clauses.
2882
- -- One subplan will remain in this case, but it should not be executed.
2883
2876
explain (analyze, costs off, summary off, timing off) execute q1 (1,2,2,1);
2884
- QUERY PLAN
2885
- -------------------------------------------------------------------------
2877
+ QUERY PLAN
2878
+ --------------------------------
2886
2879
Append (actual rows=0 loops=1)
2887
- Subplans Removed: 1
2888
- -> Seq Scan on listp_1_1 listp_1 (never executed)
2889
- Filter: ((b = ANY (ARRAY[$1, $2])) AND ($3 <> b) AND ($4 <> b))
2890
- (4 rows)
2880
+ Subplans Removed: 2
2881
+ (2 rows)
2891
2882
2892
2883
-- Ensure Params that evaluate to NULL properly prune away all partitions
2893
2884
explain (analyze, costs off, summary off, timing off)
@@ -2971,13 +2962,11 @@ select * from stable_qual_pruning
2971
2962
explain (analyze, costs off, summary off, timing off)
2972
2963
select * from stable_qual_pruning
2973
2964
where a = any(array['2010-02-01', '2020-01-01']::timestamptz[]);
2974
- QUERY PLAN
2975
- ---------------------------------------------------------------------------------------------------------------------------
2965
+ QUERY PLAN
2966
+ --------------------------------
2976
2967
Append (actual rows=0 loops=1)
2977
- Subplans Removed: 2
2978
- -> Seq Scan on stable_qual_pruning1 stable_qual_pruning_1 (never executed)
2979
- Filter: (a = ANY ('{"Mon Feb 01 00:00:00 2010 PST","Wed Jan 01 00:00:00 2020 PST"}'::timestamp with time zone[]))
2980
- (4 rows)
2968
+ Subplans Removed: 3
2969
+ (2 rows)
2981
2970
2982
2971
explain (analyze, costs off, summary off, timing off)
2983
2972
select * from stable_qual_pruning
@@ -3159,21 +3148,34 @@ execute mt_q1(25);
3159
3148
3160
3149
-- Ensure MergeAppend behaves correctly when no subplans match
3161
3150
explain (analyze, costs off, summary off, timing off) execute mt_q1(35);
3162
- QUERY PLAN
3163
- ----------------------------------------------------------------------------------
3151
+ QUERY PLAN
3152
+ --------------------------------------
3164
3153
Merge Append (actual rows=0 loops=1)
3165
3154
Sort Key: ma_test.b
3166
- Subplans Removed: 2
3167
- -> Index Scan using ma_test_p1_b_idx on ma_test_p1 ma_test_1 (never executed)
3168
- Filter: ((a >= $1) AND ((a % 10) = 5))
3169
- (5 rows)
3155
+ Subplans Removed: 3
3156
+ (3 rows)
3170
3157
3171
3158
execute mt_q1(35);
3172
3159
a
3173
3160
---
3174
3161
(0 rows)
3175
3162
3176
3163
deallocate mt_q1;
3164
+ set plan_cache_mode = force_generic_plan;
3165
+ prepare mt_q2 (int) as select * from ma_test where a >= $1 order by b limit 1;
3166
+ -- Ensure output list looks sane when the MergeAppend has no subplans.
3167
+ explain (analyze, verbose, costs off, summary off, timing off) execute mt_q2 (35);
3168
+ QUERY PLAN
3169
+ --------------------------------------------
3170
+ Limit (actual rows=0 loops=1)
3171
+ Output: ma_test.a, ma_test.b
3172
+ -> Merge Append (actual rows=0 loops=1)
3173
+ Sort Key: ma_test.b
3174
+ Subplans Removed: 3
3175
+ (5 rows)
3176
+
3177
+ deallocate mt_q2;
3178
+ reset plan_cache_mode;
3177
3179
-- ensure initplan params properly prune partitions
3178
3180
explain (analyze, costs off, summary off, timing off) select * from ma_test where a >= (select min(b) from ma_test_p2) order by b;
3179
3181
QUERY PLAN
@@ -3591,19 +3593,18 @@ from (
3591
3593
) s(a, b, c)
3592
3594
where s.a = $1 and s.b = $2 and s.c = (select 1);
3593
3595
explain (costs off) execute q (1, 1);
3594
- QUERY PLAN
3595
- ---------------------------------------------------------------
3596
+ QUERY PLAN
3597
+ ----------------------------------------------------
3596
3598
Append
3597
3599
InitPlan 1 (returns $0)
3598
3600
-> Result
3599
- Subplans Removed: 1
3600
3601
-> Seq Scan on p1 p
3601
- Filter: ((a = $ 1) AND (b = $2 ) AND (c = $0))
3602
+ Filter: ((a = 1) AND (b = 1 ) AND (c = $0))
3602
3603
-> Seq Scan on q111 q1
3603
- Filter: ((a = $ 1) AND (b = $2 ) AND (c = $0))
3604
+ Filter: ((a = 1) AND (b = 1 ) AND (c = $0))
3604
3605
-> Result
3605
- One-Time Filter: (( 1 = $1) AND (1 = $2) AND (1 = $0) )
3606
- (10 rows)
3606
+ One-Time Filter: (1 = $0 )
3607
+ (9 rows)
3607
3608
3608
3609
execute q (1, 1);
3609
3610
a | b | c
0 commit comments