aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-10-12 12:10:49 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-10-12 12:11:22 -0400
commit71e58dcfb9ee47064a3ccfeba66a5bdf026380b5 (patch)
treec626748287384a77f70fb3c3a7c5a5db246bad27 /src/include
parente583ffe947de7a6e3be49a0f267234616f390485 (diff)
downloadpostgresql-71e58dcfb9ee47064a3ccfeba66a5bdf026380b5.tar.gz
postgresql-71e58dcfb9ee47064a3ccfeba66a5bdf026380b5.zip
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.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/nodes/primnodes.h6
-rw-r--r--src/include/optimizer/clauses.h2
2 files changed, 6 insertions, 2 deletions
diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index cd4561dcf49..daabcb6cf9a 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -317,6 +317,12 @@ typedef enum CoercionContext
/*
* CoercionForm - information showing how to display a function-call node
+ *
+ * NB: equal() ignores CoercionForm fields, therefore this *must* not carry
+ * any semantically significant information. We need that behavior so that
+ * the planner will consider equivalent implicit and explicit casts to be
+ * equivalent. In cases where those actually behave differently, the coercion
+ * function's arguments will be different.
*/
typedef enum CoercionForm
{
diff --git a/src/include/optimizer/clauses.h b/src/include/optimizer/clauses.h
index ac75bd4d6ea..acff7ba1b79 100644
--- a/src/include/optimizer/clauses.h
+++ b/src/include/optimizer/clauses.h
@@ -79,8 +79,6 @@ extern void CommuteRowCompareExpr(RowCompareExpr *clause);
extern Node *strip_implicit_coercions(Node *node);
-extern void set_coercionform_dontcare(Node *node);
-
extern Node *eval_const_expressions(PlannerInfo *root, Node *node);
extern Node *estimate_expression_value(PlannerInfo *root, Node *node);