Support domains over composite types.

Tom Lane <tgl@sss.pgh.pa.us>

Commit: 37a795a60b4f4b1def11c615525ec5e0e9449e05
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2017-10-26T17:47:45Z
Releases: 11.0
Support domains over composite types.

This is the last major omission in our domains feature: you can now
make a domain over anything that's not a pseudotype.

The major complication from an implementation standpoint is that places
that might be creating tuples of a domain type now need to be prepared
to apply domain_check().  It seems better that unprepared code fail
with an error like "<type> is not composite" than that it silently fail
to apply domain constraints.  Therefore, relevant infrastructure like
get_func_result_type() and lookup_rowtype_tupdesc() has been adjusted
to treat domain-over-composite as a distinct case that unprepared code
won't recognize, rather than just transparently treating it the same
as plain composite.  This isn't a 100% solution to the possibility of
overlooked domain checks, but it catches most places.

In passing, improve typcache.c's support for domains (it can now cache
the identity of a domain's base type), and rewrite the argument handling
logic in jsonfuncs.c's populate_record[set]_worker to reduce duplicative
per-call lookups.

I believe this is code-complete so far as the core and contrib code go.
The PLs need varying amounts of work, which will be tackled in followup
patches.

Discussion: https://postgr.es/m/4206.1499798337@sss.pgh.pa.us

Files

PathChange+/−
contrib/hstore/hstore_io.c modified +36 −10
doc/src/sgml/datatype.sgml modified +1 −2
doc/src/sgml/rowtypes.sgml modified +3 −2
doc/src/sgml/xfunc.sgml modified +35 −2
src/backend/catalog/pg_inherits.c modified +7 −2
src/backend/catalog/pg_proc.c modified +1 −1
src/backend/commands/tablecmds.c modified +4 −2
src/backend/commands/typecmds.c modified +7 −4
src/backend/executor/execExprInterp.c modified +5 −1
src/backend/executor/execSRF.c modified +3 −2
src/backend/executor/functions.c modified +13 −2
src/backend/executor/nodeFunctionscan.c modified +2 −1
src/backend/nodes/makefuncs.c modified +4 −2
src/backend/optimizer/util/clauses.c modified +8 −2
src/backend/parser/parse_coerce.c modified +43 −5
src/backend/parser/parse_func.c modified +5 −4
src/backend/parser/parse_relation.c modified +9 −9
src/backend/parser/parse_target.c modified +29 −20
src/backend/parser/parse_type.c modified +36 −2
src/backend/utils/adt/domains.c modified +5 −4
src/backend/utils/adt/jsonfuncs.c modified +281 −150
src/backend/utils/adt/ruleutils.c modified +4 −14
src/backend/utils/cache/lsyscache.c modified +16 −2
src/backend/utils/cache/typcache.c modified +110 −20
src/backend/utils/fmgr/funcapi.c modified +75 −18
src/include/access/htup_details.h modified +5 −0
src/include/access/tupdesc.h modified +6 −0
src/include/funcapi.h modified +9 −2
src/include/nodes/primnodes.h modified +9 −2
src/include/parser/parse_type.h modified +3 −1
src/include/utils/typcache.h modified +14 −3
src/test/regress/expected/domain.out modified +96 −0
src/test/regress/expected/jsonb.out modified +53 −0
src/test/regress/expected/json.out modified +53 −0
src/test/regress/sql/domain.sql modified +47 −0
src/test/regress/sql/jsonb.sql modified +23 −0
src/test/regress/sql/json.sql modified +23 −0

Documentation touched

Discussion