Re: Fix a wrong comment in setrefs.c - Mailing list pgsql-hackers

From Richard Guo
Subject Re: Fix a wrong comment in setrefs.c
Date
Msg-id CAMbWs498LZVXh1UkAET3Cd+w58QRv8TEqSer6YwqxUcWbnJznA@mail.gmail.com
Whole thread Raw
In response to Re: Fix a wrong comment in setrefs.c  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Fix a wrong comment in setrefs.c
Re: Fix a wrong comment in setrefs.c
List pgsql-hackers

On Tue, Sep 26, 2023 at 5:45 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Hmm.  This kind of makes me itch, because in principle a ressortgroupref
identifier should uniquely identify a sorting/grouping column.  If it
fails to do so here, maybe there are outright bugs lurking elsewhere?

I poked into it a little and determined that the problematic
ressortgroupref values are being assigned during prepunion.c,
which says

         * By convention, all non-resjunk columns in a setop tree have
         * ressortgroupref equal to their resno.  In some cases the ref isn't
         * needed, but this is a cleaner way than modifying the tlist later.

So at the end of that, we can have Vars in the upper relations'
targetlists that are associated by ressortgroupref with values
in the setop input relations' tlists, but don't match.
(You are right that added-on implicit coercions are one reason for
the expressions to be different, but it's not the only one.)

Ah.  Thanks for the investigation.
 
I'm inclined to write the comment more like "Usually the equal()
check is redundant, but in setop plans it may not be, since
prepunion.c assigns ressortgroupref equal to the column resno
without regard to whether that matches the topmost level's
sortgrouprefs and without regard to whether any implicit coercions
are added in the setop tree.  We might have to clean that up someday;
but for now, just ignore any false matches."

+1.  It explains the situation much more clearly and accurately.

Thanks
Richard

pgsql-hackers by date:

Previous
From: Japin Li
Date:
Subject: Re: How to update unicode mapping table?
Next
From: Japin Li
Date:
Subject: Could not run generate_unaccent_rules.py script when update unicode