Skip to content

Commit b486e7f

Browse files
committed
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 :-(
1 parent 2925953 commit b486e7f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/backend/optimizer/plan/createplan.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.274 2010/03/28 22:59:32 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.275 2010/05/25 17:44:41 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -784,20 +784,34 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path)
784784
{
785785
Oid in_oper = lfirst_oid(l);
786786
Oid sortop;
787+
Oid eqop;
787788
TargetEntry *tle;
788789
SortGroupClause *sortcl;
789790

790791
sortop = get_ordering_op_for_equality_op(in_oper, false);
791792
if (!OidIsValid(sortop)) /* shouldn't happen */
792793
elog(ERROR, "could not find ordering operator for equality operator %u",
793794
in_oper);
795+
796+
/*
797+
* The Unique node will need equality operators. Normally these
798+
* are the same as the IN clause operators, but if those are
799+
* cross-type operators then the equality operators are the ones
800+
* for the IN clause operators' RHS datatype.
801+
*/
802+
eqop = get_equality_op_for_ordering_op(sortop, NULL);
803+
if (!OidIsValid(eqop)) /* shouldn't happen */
804+
elog(ERROR, "could not find equality operator for ordering operator %u",
805+
sortop);
806+
794807
tle = get_tle_by_resno(subplan->targetlist,
795808
groupColIdx[groupColPos]);
796809
Assert(tle != NULL);
810+
797811
sortcl = makeNode(SortGroupClause);
798812
sortcl->tleSortGroupRef = assignSortGroupRef(tle,
799813
subplan->targetlist);
800-
sortcl->eqop = in_oper;
814+
sortcl->eqop = eqop;
801815
sortcl->sortop = sortop;
802816
sortcl->nulls_first = false;
803817
sortList = lappend(sortList, sortcl);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy