summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-09-06 16:38:18 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-09-06 16:38:18 -0400
commitccbb54c72990d412552fbc50098b2e998b888359 (patch)
treef4406982fc2fe69bd507b780a69e299679148957 /src/test
parent43e409cea4687ec1abdcfe82cd0b80a87a8d6adc (diff)
Further fixes for MULTIEXPR_SUBLINK fix.
Some more things I didn't think about in commits 3f7323cbb et al: MULTIEXPR_SUBLINK subplans might have been converted to initplans instead of regular subplans, in which case they won't show up in the modified targetlist. Fortunately, this would only happen if they have no input parameters, which means that the problem we originally needed to fix can't happen with them. Therefore, there's no need to clone their output parameters, and thus it doesn't hurt that we'll fail to see them in the first pass over the targetlist. Nonetheless, this complicates matters greatly, because now we have to distinguish output Params of initplans (which shouldn't get renumbered) from those of regular subplans (which should). This also breaks the simplistic scheme I used of assuming that the subplans found in the targetlist have consecutive subLinkIds. We really can't avoid the need to know the subplans' subLinkIds in this code. To fix that, add subLinkId as the last field of SubPlan. We can get away with that change in back branches because SubPlan nodes will never be stored in the catalogs, and there's no ABI break for external code that might be looking at the existing fields of SubPlan. Secondly, rewriteTargetListIU might have rolled up multiple FieldStores or SubscriptingRefs into one targetlist entry, breaking the assumption that there's at most one Param to fix per targetlist entry. (That assumption is OK I think in the ruleutils.c code I stole the logic from in 18f51083c, because that only deals with pre-rewrite query trees. But it's definitely not OK here.) Abandon that shortcut and just do a full tree walk on the targetlist to ensure we find all the Params we have to change. Per bug #17606 from Andre Lin. As before, only v10-v13 need the patch. Discussion: https://postgr.es/m/17606-e5c8ad18d31db96a@postgresql.org
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/inherit.out41
-rw-r--r--src/test/regress/sql/inherit.sql16
2 files changed, 42 insertions, 15 deletions
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out
index ed99bdde7f8..658fed79226 100644
--- a/src/test/regress/expected/inherit.out
+++ b/src/test/regress/expected/inherit.out
@@ -1717,23 +1717,36 @@ reset enable_bitmapscan;
--
-- Check handling of MULTIEXPR SubPlans in inherited updates
--
-create table inhpar(f1 int, f2 text[]);
+create table inhpar(f1 int, f2 text[], f3 int);
insert into inhpar select generate_series(1,10);
create table inhcld() inherits(inhpar);
insert into inhcld select generate_series(11,10000);
vacuum analyze inhcld;
vacuum analyze inhpar;
explain (verbose, costs off)
-update inhpar set (f1, f2[1]) = (select p2.unique2, p2.stringu1
- from int4_tbl limit 1)
+update inhpar set
+ (f1, f2[1]) = (select p2.unique2, p2.stringu1 from int4_tbl limit 1),
+ (f2[2], f2[3]) = (select 'x', 'y' from int4_tbl limit 1),
+ (f3, f2[4]) = (select p2.unique2, p2.stringu1 from int4_tbl limit 1),
+ (f2[5], f2[6]) = (select 'x', 'y' from int4_tbl limit 1)
from onek p2 where inhpar.f1 = p2.unique1;
- QUERY PLAN
------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Update on public.inhpar
Update on public.inhpar
Update on public.inhcld inhpar_1
+ InitPlan 2 (returns $4,$5)
+ -> Limit
+ Output: 'x'::text, 'y'::text
+ -> Seq Scan on public.int4_tbl int4_tbl_1
+ Output: 'x'::text, 'y'::text
+ InitPlan 4 (returns $10,$11)
+ -> Limit
+ Output: 'x'::text, 'y'::text
+ -> Seq Scan on public.int4_tbl int4_tbl_3
+ Output: 'x'::text, 'y'::text
-> Merge Join
- Output: $4, inhpar.f2[1] := $5, (SubPlan 1 (returns $2,$3)), inhpar.ctid, p2.ctid
+ Output: $12, (((((inhpar.f2[1] := $13)[2] := $4)[3] := $5)[4] := $15)[5] := $10)[6] := $11, $14, (SubPlan 1 (returns $2,$3)), NULL::record, (SubPlan 3 (returns $8,$9)), NULL::record, inhpar.ctid, p2.ctid
Merge Cond: (p2.unique1 = inhpar.f1)
-> Index Scan using onek_unique1 on public.onek p2
Output: p2.unique2, p2.stringu1, p2.ctid, p2.unique1
@@ -1747,8 +1760,13 @@ from onek p2 where inhpar.f1 = p2.unique1;
Output: (p2.unique2), (p2.stringu1)
-> Seq Scan on public.int4_tbl
Output: p2.unique2, p2.stringu1
+ SubPlan 3 (returns $8,$9)
+ -> Limit
+ Output: (p2.unique2), (p2.stringu1)
+ -> Seq Scan on public.int4_tbl int4_tbl_2
+ Output: p2.unique2, p2.stringu1
-> Hash Join
- Output: $6, inhpar_1.f2[1] := $7, (SubPlan 1 (returns $2,$3)), inhpar_1.ctid, p2.ctid
+ Output: $16, (((((inhpar_1.f2[1] := $17)[2] := $4)[3] := $5)[4] := $19)[5] := $10)[6] := $11, $18, (SubPlan 1 (returns $2,$3)), NULL::record, (SubPlan 3 (returns $8,$9)), NULL::record, inhpar_1.ctid, p2.ctid
Hash Cond: (inhpar_1.f1 = p2.unique1)
-> Seq Scan on public.inhcld inhpar_1
Output: inhpar_1.f2, inhpar_1.ctid, inhpar_1.f1
@@ -1756,10 +1774,13 @@ from onek p2 where inhpar.f1 = p2.unique1;
Output: p2.unique2, p2.stringu1, p2.ctid, p2.unique1
-> Seq Scan on public.onek p2
Output: p2.unique2, p2.stringu1, p2.ctid, p2.unique1
-(27 rows)
+(42 rows)
-update inhpar set (f1, f2[1]) = (select p2.unique2, p2.stringu1
- from int4_tbl limit 1)
+update inhpar set
+ (f1, f2[1]) = (select p2.unique2, p2.stringu1 from int4_tbl limit 1),
+ (f2[2], f2[3]) = (select 'x', 'y' from int4_tbl limit 1),
+ (f3, f2[4]) = (select p2.unique2, p2.stringu1 from int4_tbl limit 1),
+ (f2[5], f2[6]) = (select 'x', 'y' from int4_tbl limit 1)
from onek p2 where inhpar.f1 = p2.unique1;
drop table inhpar cascade;
NOTICE: drop cascades to table inhcld
diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql
index 7d3813704e1..a4a33a3da8b 100644
--- a/src/test/regress/sql/inherit.sql
+++ b/src/test/regress/sql/inherit.sql
@@ -632,7 +632,7 @@ reset enable_bitmapscan;
--
-- Check handling of MULTIEXPR SubPlans in inherited updates
--
-create table inhpar(f1 int, f2 text[]);
+create table inhpar(f1 int, f2 text[], f3 int);
insert into inhpar select generate_series(1,10);
create table inhcld() inherits(inhpar);
insert into inhcld select generate_series(11,10000);
@@ -640,11 +640,17 @@ vacuum analyze inhcld;
vacuum analyze inhpar;
explain (verbose, costs off)
-update inhpar set (f1, f2[1]) = (select p2.unique2, p2.stringu1
- from int4_tbl limit 1)
+update inhpar set
+ (f1, f2[1]) = (select p2.unique2, p2.stringu1 from int4_tbl limit 1),
+ (f2[2], f2[3]) = (select 'x', 'y' from int4_tbl limit 1),
+ (f3, f2[4]) = (select p2.unique2, p2.stringu1 from int4_tbl limit 1),
+ (f2[5], f2[6]) = (select 'x', 'y' from int4_tbl limit 1)
from onek p2 where inhpar.f1 = p2.unique1;
-update inhpar set (f1, f2[1]) = (select p2.unique2, p2.stringu1
- from int4_tbl limit 1)
+update inhpar set
+ (f1, f2[1]) = (select p2.unique2, p2.stringu1 from int4_tbl limit 1),
+ (f2[2], f2[3]) = (select 'x', 'y' from int4_tbl limit 1),
+ (f3, f2[4]) = (select p2.unique2, p2.stringu1 from int4_tbl limit 1),
+ (f2[5], f2[6]) = (select 'x', 'y' from int4_tbl limit 1)
from onek p2 where inhpar.f1 = p2.unique1;
drop table inhpar cascade;