Skip to content

Commit 1218780

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 2172455 commit 1218780

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/backend/executor/execExprInterp.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -4138,8 +4138,12 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
41384138
* generates an INT4 NULL regardless of the dropped column type).
41394139
* If we find a dropped column and cannot verify that case (1)
41404140
* holds, we have to use the slow path to check (2) for each row.
4141+
*
4142+
* If vartype is a domain over composite, just look through that
4143+
* to the base composite type.
41414144
*/
4142-
var_tupdesc = lookup_rowtype_tupdesc(variable->vartype, -1);
4145+
var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
4146+
-1, false);
41434147

41444148
slot_tupdesc = slot->tts_tupleDescriptor;
41454149

src/test/regress/expected/domain.out

+23
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,29 @@ Rules:
277277
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
278278
WHERE (dcomptable.d1).i > 0::double precision
279279

280+
create function makedcomp(r float8, i float8) returns dcomptype
281+
as 'select row(r, i)' language sql;
282+
select makedcomp(1,2);
283+
makedcomp
284+
-----------
285+
(1,2)
286+
(1 row)
287+
288+
select makedcomp(2,1); -- fail
289+
ERROR: value for domain dcomptype violates check constraint "c1"
290+
select * from makedcomp(1,2) m;
291+
r | i
292+
---+---
293+
1 | 2
294+
(1 row)
295+
296+
select m, m is not null from makedcomp(1,2) m;
297+
m | ?column?
298+
-------+----------
299+
(1,2) | t
300+
(1 row)
301+
302+
drop function makedcomp(float8, float8);
280303
drop table dcomptable;
281304
drop type comptype cascade;
282305
NOTICE: drop cascades to type dcomptype

src/test/regress/sql/domain.sql

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

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

0 commit comments

Comments
 (0)