On Thu, Jan 9, 2025 at 12:44 PM David Rowley <dgrowleyml@gmail.com> wrote:
> On Tue, 7 Jan 2025 at 02:14, Richard Guo <guofenglinux@gmail.com> wrote:
> > --- a/src/backend/optimizer/plan/planner.c
> > +++ b/src/backend/optimizer/plan/planner.c
> > @@ -8091,6 +8091,9 @@ generate_setop_child_grouplist(SetOperationStmt
> > *op, List *targetlist)
> > {
> > TargetEntry *tle = (TargetEntry *) lfirst(lt);
> > SortGroupClause *sgc;
> > + Oid opfamily,
> > + opcintype;
> > + int16 strategy;
> >
> > /* resjunk columns could have sortgrouprefs. Leave these alone */
> > if (tle->resjunk)
> > @@ -8101,6 +8104,18 @@ generate_setop_child_grouplist(SetOperationStmt
> > *op, List *targetlist)
> > sgc = (SortGroupClause *) lfirst(lg);
> > lg = lnext(grouplist, lg);
> >
> > + if (!OidIsValid(sgc->sortop))
> > + return NIL;
> > +
> > + /* Find the operator in pg_amop --- failure shouldn't happen */
> > + if (!get_ordering_op_properties(sgc->sortop,
> > + &opfamily, &opcintype, &strategy))
> > + elog(ERROR, "operator %u is not a valid ordering operator",
> > + sgc->sortop);
> > +
> > + if (exprType((Node *) tle->expr) != opcintype)
> > + return NIL;
> > +
> > /* assign a tleSortGroupRef, or reuse the existing one */
> > sgc->tleSortGroupRef = assignSortGroupRef(tle, targetlist);
> > }
>
> Can't you just look up the setop's type from op->colTypes instead of
> looking the type up via the sortop? i.e. the attached?
Yeah, right. Using SetOperationStmt.colTypes is more convenient here.
Thanks
Richard