pgsql: Make equal() ignore CoercionForm fields for better planning with - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Make equal() ignore CoercionForm fields for better planning with
Date
Msg-id E1TMhpn-00012G-AH@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Make equal() ignore CoercionForm fields for better planning with casts.

This change ensures that the planner will see implicit and explicit casts
as equivalent for all purposes, except in the minority of cases where
there's actually a semantic difference (as reflected by having a 3-argument
cast function).  In particular, this fixes cases where the EquivalenceClass
machinery failed to consider two references to a varchar column as
equivalent if one was implicitly cast to text but the other was explicitly
cast to text, as seen in bug #7598 from Vaclav Juza.  We have had similar
bugs before in other parts of the planner, so I think it's time to fix this
problem at the core instead of continuing to band-aid around it.

Remove set_coercionform_dontcare(), which represents the band-aid
previously in use for allowing matching of index and constraint expressions
with inconsistent cast labeling.  (We can probably get rid of
COERCE_DONTCARE altogether, but I don't think removing that enum value in
back branches would be wise; it's possible there's third party code
referring to it.)

Back-patch to 9.2.  We could go back further, and might want to once this
has been tested more; but for the moment I won't risk destabilizing plan
choices in long-since-stable branches.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/0fbd44387d8658c5f3dae39b78d1a593e7026e09

Modified Files
--------------
src/backend/nodes/equalfuncs.c       |   81 +++++-----------------------------
src/backend/optimizer/util/clauses.c |   42 -----------------
src/backend/optimizer/util/plancat.c |    6 ---
src/backend/utils/cache/relcache.c   |   12 -----
src/include/nodes/primnodes.h        |    6 +++
src/include/optimizer/clauses.h      |    2 -
6 files changed, 17 insertions(+), 132 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Make equal() ignore CoercionForm fields for better planning with
Next
From: Tom Lane
Date:
Subject: pgsql: Fix unportable format string.