From: | Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Jesper Pedersen <jesper(dot)pedersen(at)redhat(dot)com>, "Hou, Zhijie" <houzj(dot)fnst(at)cn(dot)fujitsu(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Floris Van Nee <florisvannee(at)optiver(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, "rushabh(dot)lathia(at)gmail(dot)com" <rushabh(dot)lathia(at)gmail(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com> |
Subject: | Re: [PATCH] Keeps tracking the uniqueness with UniqueKey |
Date: | 2020-12-06 03:38:55 |
Message-ID: | CAKU4AWp1RT3jvHBW49QvRgCdT9vGHetauqvcUaiwhp4S3VduEg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Thank you Tom and Heikki for your input.
On Sun, Dec 6, 2020 at 4:40 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Heikki Linnakangas <hlinnaka(at)iki(dot)fi> writes:
> >> I can understand why we need EquivalenceClass for UniqueKey, but I can't
> >> understand why we need opfamily here.
>
> > Thinking a bit harder, I guess we don't. Because EquivalenceClass
> > includes the operator family already, in the ec_opfamilies field.
>
> No. EquivalenceClasses only care about equality, which is why they
> might potentially mention several opfamilies that share an equality
> operator. If you care about sort order, you *cannot* rely on an
> EquivalenceClass to depict that. Now, abstract uniqueness also only
> cares about equality, but if you are going to implement it via sort-
> and-unique then you need to settle on a sort order.
>
I think UniqueKey only cares about equality. Even DISTINCT / groupBy
can be implemented with sort, but UniqueKey only care about the result
of DISTINCT/GROUPBY, so it doesn't matter IIUC.
>
> I agree we are overspecifying DISTINCT by settling on a sort operator at
> parse time, rather than considering all the possibilities at plan time.
> But given that opfamilies sharing equality are mostly a hypothetical
> use-case, I'm not in a big hurry to fix it. Before we had ASC/DESC
> indexes, there was a real use-case for making a "reverse sort" opclass,
> with the same equality as the type's regular opclass but the opposite sort
> order. But that's ancient history now, and I've seen few other plausible
> use-cases.
>
> I have not been following this thread closely enough to understand
> why we need a new "UniqueKeys" data structure at all.
Currently the UniqueKey is defined as a List of Expr, rather than
EquivalenceClasses.
A complete discussion until now can be found at [1] (The messages I replied
to also
care a lot and the information is completed). This patch has stopped at
this place for
a while, I'm planning to try EquivalenceClasses, but any suggestion would
be welcome.
> But if the
> motivation is only to remove this overspecification, I humbly suggest
> that it ain't worth the trouble.
>
> regards, tom lane
>
--
Best Regards
Andy Fan
From | Date | Subject | |
---|---|---|---|
Next Message | Laurenz Albe | 2020-12-06 05:22:27 | Re: Change definitions of bitmap flags to bit-shifting style |
Previous Message | Alvaro Herrera | 2020-12-06 01:33:46 | Re: A few new options for CHECKPOINT |