aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-05-25 17:44:47 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-05-25 17:44:47 +0000
commitbb6e270ae31e25d8a7d43056cffadfc061f61a12 (patch)
treee20adfc5231c6e44de758ff37689e26adde6863d
parent0870648c2f049f7c3979dba9fbfdfda5f1c54dc6 (diff)
downloadpostgresql-bb6e270ae31e25d8a7d43056cffadfc061f61a12.tar.gz
postgresql-bb6e270ae31e25d8a7d43056cffadfc061f61a12.zip
Fix oversight in construction of sort/unique plans for UniquePaths.
If the original IN operator is cross-type, for example int8 = int4, we need to use int4 < int4 to sort the inner data and int4 = int4 to unique-ify it. We got the first part of that right, but tried to use the original IN operator for the equality checks. Per bug #5472 from Vlad Romascanu. Backpatch to 8.4, where the bug was introduced by the patch that unified SortClause and GroupClause. I was able to take out a whole lot of on-the-fly calls of get_equality_op_for_ordering_op(), but failed to realize that I needed to put one back in right here :-(
-rw-r--r--src/backend/optimizer/plan/createplan.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 2a984388399..ab07acae8f5 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.260.2.1 2009/07/17 23:19:59 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.260.2.2 2010/05/25 17:44:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -784,6 +784,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path)
{
Oid in_oper = lfirst_oid(l);
Oid sortop;
+ Oid eqop;
TargetEntry *tle;
SortGroupClause *sortcl;
@@ -791,13 +792,26 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path)
if (!OidIsValid(sortop)) /* shouldn't happen */
elog(ERROR, "could not find ordering operator for equality operator %u",
in_oper);
+
+ /*
+ * The Unique node will need equality operators. Normally these
+ * are the same as the IN clause operators, but if those are
+ * cross-type operators then the equality operators are the ones
+ * for the IN clause operators' RHS datatype.
+ */
+ eqop = get_equality_op_for_ordering_op(sortop, NULL);
+ if (!OidIsValid(eqop)) /* shouldn't happen */
+ elog(ERROR, "could not find equality operator for ordering operator %u",
+ sortop);
+
tle = get_tle_by_resno(subplan->targetlist,
groupColIdx[groupColPos]);
Assert(tle != NULL);
+
sortcl = makeNode(SortGroupClause);
sortcl->tleSortGroupRef = assignSortGroupRef(tle,
subplan->targetlist);
- sortcl->eqop = in_oper;
+ sortcl->eqop = eqop;
sortcl->sortop = sortop;
sortcl->nulls_first = false;
sortList = lappend(sortList, sortcl);