Skip to content

Commit 254cd7f

Browse files
committed
Un-break whole-row Vars referencing domain-over-composite types.
In commit ec62cb0, I foolishly replaced ExecEvalWholeRowVar's lookup_rowtype_tupdesc_domain call with just lookup_rowtype_tupdesc, because I didn't see how a domain could be involved there, and there were no regression test cases to jog my memory. But the existing code was correct, so revert that change and add a test case showing why it's necessary. (Note: per comment in struct DatumTupleFields, it is correct to produce an output tuple that's labeled with the base composite type, not the domain; hence just blindly looking through the domain is correct here.) Per bug #17515 from Dan Kubb. Back-patch to v11 where domains over composites became a thing. Discussion: https://postgr.es/m/17515-a24737438363aca0@postgresql.org
1 parent 2bc7dff commit 254cd7f

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/backend/executor/execExprInterp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3991,8 +3991,12 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
39913991
* generates an INT4 NULL regardless of the dropped column type).
39923992
* If we find a dropped column and cannot verify that case (1)
39933993
* holds, we have to use the slow path to check (2) for each row.
3994+
*
3995+
* If vartype is a domain over composite, just look through that
3996+
* to the base composite type.
39943997
*/
3995-
var_tupdesc = lookup_rowtype_tupdesc(variable->vartype, -1);
3998+
var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
3999+
-1, false);
39964000

39974001
slot_tupdesc = slot->tts_tupleDescriptor;
39984002

src/test/regress/expected/domain.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,29 @@ Rules:
283283
ON DELETE TO dcomptable DO INSTEAD UPDATE dcomptable SET d1.r = (dcomptable.d1).r - 1::double precision, d1.i = (dcomptable.d1).i + 1::double precision
284284
WHERE (dcomptable.d1).i > 0::double precision
285285

286+
create function makedcomp(r float8, i float8) returns dcomptype
287+
as 'select row(r, i)' language sql;
288+
select makedcomp(1,2);
289+
makedcomp
290+
-----------
291+
(1,2)
292+
(1 row)
293+
294+
select makedcomp(2,1); -- fail
295+
ERROR: value for domain dcomptype violates check constraint "c1"
296+
select * from makedcomp(1,2) m;
297+
r | i
298+
---+---
299+
1 | 2
300+
(1 row)
301+
302+
select m, m is not null from makedcomp(1,2) m;
303+
m | ?column?
304+
-------+----------
305+
(1,2) | t
306+
(1 row)
307+
308+
drop function makedcomp(float8, float8);
286309
drop table dcomptable;
287310
drop type comptype cascade;
288311
NOTICE: drop cascades to type dcomptype

src/test/regress/sql/domain.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ create rule silly as on delete to dcomptable do instead
155155
update dcomptable set d1.r = (d1).r - 1, d1.i = (d1).i + 1 where (d1).i > 0;
156156
\d+ dcomptable
157157

158+
create function makedcomp(r float8, i float8) returns dcomptype
159+
as 'select row(r, i)' language sql;
160+
161+
select makedcomp(1,2);
162+
select makedcomp(2,1); -- fail
163+
select * from makedcomp(1,2) m;
164+
select m, m is not null from makedcomp(1,2) m;
165+
166+
drop function makedcomp(float8, float8);
158167
drop table dcomptable;
159168
drop type comptype cascade;
160169

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy