pgsql: Improve handling of domains over arrays.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Improve handling of domains over arrays.
Date: 2010-10-21 20:08:16
Message-ID: E1P91Qu-00051Q-Mx@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve handling of domains over arrays.

This patch eliminates various bizarre behaviors caused by sloppy thinking
about the difference between a domain type and its underlying array type.
In particular, the operation of updating one element of such an array
has to be considered as yielding a value of the underlying array type,
*not* a value of the domain, because there's no assurance that the
domain's CHECK constraints are still satisfied. If we're intending to
store the result back into a domain column, we have to re-cast to the
domain type so that constraints are re-checked.

For similar reasons, such a domain can't be blindly matched to an ANYARRAY
polymorphic parameter, because the polymorphic function is likely to apply
array-ish operations that could invalidate the domain constraints. For the
moment, we just forbid such matching. We might later wish to insert an
automatic downcast to the underlying array type, but such a change should
also change matching of domains to ANYELEMENT for consistency.

To ensure that all such logic is rechecked, this patch removes the original
hack of setting a domain's pg_type.typelem field to match its base type;
the typelem will always be zero instead. In those places where it's really
okay to look through the domain type with no other logic changes, use the
newly added get_base_element_type function in place of get_element_type.
catversion bumped due to change in pg_type contents.

Per bug #5717 from Richard Huxton and subsequent discussion.

Branch
------
master

Details
-------
http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=529cb267a6843a6a8190c86b75d091771d99d6a9

Modified Files
--------------
doc/src/sgml/catalogs.sgml | 5 +-
src/backend/commands/functioncmds.c | 17 +++++
src/backend/commands/typecmds.c | 18 ++---
src/backend/parser/parse_coerce.c | 11 ++--
src/backend/parser/parse_expr.c | 18 ++---
src/backend/parser/parse_node.c | 51 ++++++++++----
src/backend/parser/parse_oper.c | 4 +-
src/backend/parser/parse_target.c | 127 +++++++++++++++++++++++++---------
src/backend/utils/adt/format_type.c | 14 ++--
src/backend/utils/adt/ruleutils.c | 2 +-
src/backend/utils/adt/selfuncs.c | 2 +-
src/backend/utils/adt/xml.c | 2 +-
src/backend/utils/cache/lsyscache.c | 46 ++++++++++++
src/backend/utils/fmgr/fmgr.c | 4 +-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_type.h | 3 +-
src/include/parser/parse_node.h | 4 +-
src/include/utils/lsyscache.h | 3 +
src/pl/plpgsql/src/pl_exec.c | 35 ++++++++--
src/test/regress/expected/domain.out | 99 ++++++++++++++++++++++++++
src/test/regress/sql/domain.sql | 73 +++++++++++++++++++
21 files changed, 439 insertions(+), 101 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2010-10-21 22:00:13 pgsql: Mention limited usefulness of .pgpass database field.
Previous Message User Itagaki 2010-10-21 10:47:43 textsearch-ja - textsearch-ja: Adjust regression test to work on all