pgsql: Make equal() ignore CoercionForm fields for better planning with

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make equal() ignore CoercionForm fields for better planning with
Date: 2012-10-12 16:11:35
Message-ID: E1TMhpn-00012E-97@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/71e58dcfb9ee47064a3ccfeba66a5bdf026380b5

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2012-10-12 17:22:29 pgsql: Fix unportable format string.
Previous Message Andrew Dunstan 2012-10-11 16:41:43 pgsql: Unbreak MSVC builds after recent Makefile refactoring.