aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-04-15 12:01:39 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2023-04-15 12:01:39 -0400
commit048caf8d757a94db043ddbc4d0b1131c1544fee1 (patch)
tree213b8263df11d84a0cfe560adb6caf21edfd0606
parente76fbcf796d6167df83ca7ba13df93fa5f39b380 (diff)
downloadpostgresql-048caf8d757a94db043ddbc4d0b1131c1544fee1.tar.gz
postgresql-048caf8d757a94db043ddbc4d0b1131c1544fee1.zip
Fix assignment to array of domain over composite, redux.
Commit 3e310d837 taught isAssignmentIndirectionExpr() to look through CoerceToDomain nodes. That's not sufficient, because since commit 04fe805a1 it's been possible for the planner to simplify CoerceToDomain to RelabelType when the domain has no constraints to enforce. So we need to look through RelabelType too. Per bug #17897 from Alexander Lakhin. Although 3e310d837 was back-patched to v11, it seems sufficient to apply this change to v12 and later, since 04fe805a1 came in in v12. Dmitry Dolgov Discussion: https://postgr.es/m/17897-4216c546c3874044@postgresql.org
-rw-r--r--src/backend/executor/execExpr.c10
-rw-r--r--src/test/regress/expected/domain.out9
-rw-r--r--src/test/regress/sql/domain.sql4
3 files changed, 21 insertions, 2 deletions
diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c
index ac9a3004fe0..e2d1d101ba1 100644
--- a/src/backend/executor/execExpr.c
+++ b/src/backend/executor/execExpr.c
@@ -2839,8 +2839,8 @@ ExecInitSubscriptingRef(ExprEvalStep *scratch, SubscriptingRef *sbsref,
* trees in which each level of assignment has its own CaseTestExpr, and the
* recursive structure appears within the newvals or refassgnexpr field.
* There is an exception, though: if the array is an array-of-domain, we will
- * have a CoerceToDomain as the refassgnexpr, and we need to be able to look
- * through that.
+ * have a CoerceToDomain or RelabelType as the refassgnexpr, and we need to
+ * be able to look through that.
*/
static bool
isAssignmentIndirectionExpr(Expr *expr)
@@ -2867,6 +2867,12 @@ isAssignmentIndirectionExpr(Expr *expr)
return isAssignmentIndirectionExpr(cd->arg);
}
+ else if (IsA(expr, RelabelType))
+ {
+ RelabelType *r = (RelabelType *) expr;
+
+ return isAssignmentIndirectionExpr(r->arg);
+ }
return false;
}
diff --git a/src/test/regress/expected/domain.out b/src/test/regress/expected/domain.out
index d0ead069a42..ced3fbf7bfb 100644
--- a/src/test/regress/expected/domain.out
+++ b/src/test/regress/expected/domain.out
@@ -562,6 +562,15 @@ table dcomptable;
{"(1,5)"}
(1 row)
+-- if there's no constraints, a different code path is taken:
+alter domain dcomptype drop constraint dcomptype_check;
+update dcomptable set f1[1].cf1 = -1; -- now ok
+table dcomptable;
+ f1
+------------
+ {"(-1,5)"}
+(1 row)
+
drop table dcomptable;
drop type comptype cascade;
NOTICE: drop cascades to type dcomptype
diff --git a/src/test/regress/sql/domain.sql b/src/test/regress/sql/domain.sql
index ad3edcf4067..9e9f72ab527 100644
--- a/src/test/regress/sql/domain.sql
+++ b/src/test/regress/sql/domain.sql
@@ -289,6 +289,10 @@ table dcomptable;
update dcomptable set f1[1].cf1 = -1; -- fail
update dcomptable set f1[1].cf1 = 1;
table dcomptable;
+-- if there's no constraints, a different code path is taken:
+alter domain dcomptype drop constraint dcomptype_check;
+update dcomptable set f1[1].cf1 = -1; -- now ok
+table dcomptable;
drop table dcomptable;
drop type comptype cascade;