postgresql/src/test/regress
Tom Lane c12d570fa1 Support arrays over domains.
Allowing arrays with a domain type as their element type was left un-done
in the original domain patch, but not for any very good reason.  This
omission leads to such surprising results as array_agg() not working on
a domain column, because the parser can't identify a suitable output type
for the polymorphic aggregate.

In order to fix this, first clean up the APIs of coerce_to_domain() and
some internal functions in parse_coerce.c so that we consistently pass
around a CoercionContext along with CoercionForm.  Previously, we sometimes
passed an "isExplicit" boolean flag instead, which is strictly less
information; and coerce_to_domain() didn't even get that, but instead had
to reverse-engineer isExplicit from CoercionForm.  That's contrary to the
documentation in primnodes.h that says that CoercionForm only affects
display and not semantics.  I don't think this change fixes any live bugs,
but it makes things more consistent.  The main reason for doing it though
is that now build_coercion_expression() receives ccontext, which it needs
in order to be able to recursively invoke coerce_to_target_type().

Next, reimplement ArrayCoerceExpr so that the node does not directly know
any details of what has to be done to the individual array elements while
performing the array coercion.  Instead, the per-element processing is
represented by a sub-expression whose input is a source array element and
whose output is a target array element.  This simplifies life in
parse_coerce.c, because it can build that sub-expression by a recursive
invocation of coerce_to_target_type().  The executor now handles the
per-element processing as a compiled expression instead of hard-wired code.
The main advantage of this is that we can use a single ArrayCoerceExpr to
handle as many as three successive steps per element: base type conversion,
typmod coercion, and domain constraint checking.  The old code used two
stacked ArrayCoerceExprs to handle type + typmod coercion, which was pretty
inefficient, and adding yet another array deconstruction to do domain
constraint checking seemed very unappetizing.

In the case where we just need a single, very simple coercion function,
doing this straightforwardly leads to a noticeable increase in the
per-array-element runtime cost.  Hence, add an additional shortcut evalfunc
in execExprInterp.c that skips unnecessary overhead for that specific form
of expression.  The runtime speed of simple cases is within 1% or so of
where it was before, while cases that previously required two levels of
array processing are significantly faster.

Finally, create an implicit array type for every domain type, as we do for
base types, enums, etc.  Everything except the array-coercion case seems
to just work without further effort.

Tom Lane, reviewed by Andrew Dunstan

Discussion: https://postgr.es/m/9852.1499791473@sss.pgh.pa.us
2017-09-30 13:40:56 -04:00
..
data
expected Support arrays over domains. 2017-09-30 13:40:56 -04:00
input Test coverage for CREATE/ALTER FOREIGN DATA WRAPPER .. HANDLER. 2017-09-15 08:07:22 -04:00
output Test coverage for CREATE/ALTER FOREIGN DATA WRAPPER .. HANDLER. 2017-09-15 08:07:22 -04:00
sql Support arrays over domains. 2017-09-30 13:40:56 -04:00
.gitignore
GNUmakefile
Makefile
parallel_schedule Introduce 64-bit hash functions with a 64-bit seed. 2017-08-31 22:21:21 -04:00
pg_regress_main.c
pg_regress.c Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
pg_regress.h Initial pgindent run with pg_bsd_indent version 2.0. 2017-06-21 14:39:04 -04:00
README
regress.c Test coverage for CREATE/ALTER FOREIGN DATA WRAPPER .. HANDLER. 2017-09-15 08:07:22 -04:00
regressplans.sh
resultmap
serial_schedule Merge large_object.sql test into largeobject.source. 2017-07-17 15:28:20 -04:00
standby_schedule

Documentation concerning how to run these regression tests and interpret
the results can be found in the PostgreSQL manual, in the chapter
"Regression Tests".