From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: David Rowley <david.rowley@2ndquadrant.com>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Julien Rouhaud <julien.rouhaud@dalibo.com>
Cc: Simon Riggs <simon@2ndquadrant.com>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Stefan Huehner <stefan@huehner.org>
Cc: PostgreSQL mailing lists <pgsql-hackers@postgresql.org>
Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates)
Date: Wed, 04 May 2016 17:02:04 -0400
Message-ID: <31780.1462395724@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+TgmoZ8ccdAgQmr46DrBc8PuBA+Hr03Ou7LKB53p-ETGC_v0g@mail.gmail.com>
References: <20160429102531.GA13701@huehner.biz>
<CAB7nPqRj2EsGdoNESsWVC-RHV918Scd1xQEcYt3dK9Rs5RpuAQ@mail.gmail.com>
<572384D7.1020602@dalibo.com>
<17639.1461945908@sss.pgh.pa.us>
<57238E64.8010702@dalibo.com>
<22731.1462037712@sss.pgh.pa.us>
<8344835e-18af-9d40-aed7-bd2261be9162@2ndquadrant.com>
<CAKJS1f9VMZGfPCDWeuLoD1rgvTr5JzGLh7vc4YWQCSDrmRCKbQ@mail.gmail.com>
<CAKJS1f-Eqa23_K1x_jpgVn97TigcTm7RucuD=tpSEpGpLx4ULw@mail.gmail.com>
<16807.1462388069@sss.pgh.pa.us>
<CA+TgmoZ8ccdAgQmr46DrBc8PuBA+Hr03Ou7LKB53p-ETGC_v0g@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
Robert Haas <robertmhaas@gmail.com> writes:
> On Wed, May 4, 2016 at 2:54 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> My other design-level complaint is that basing this on foreign keys is
>> fundamentally the wrong thing. What actually matters is the unique index
>> underlying the FK; that is, if we have "a.x = b.y" and there's a
>> compatible unique index on b.y, we can conclude that no A row will match
>> more than one B row, whether or not an explicit FK relationship has been
>> declared. So we should drive this off unique indexes instead of FKs,
>> first because we will find more cases, and second because the planner
>> already examines indexes and doesn't need any additional catalog lookups
>> to get the required data. (IOW, the relcache additions that were made in
>> this patch series should go away too.)
> Without prejudice to anything else in this useful and detailed review,
> I have a question about this. A unique index proves that no A row
> will match more than one B row, and I agree that deriving that from
> unique indexes is sensible. However, ISTM that an FK provides
> additional information: we know that, modulo filter conditions on B,
> every A row will match *exactly* one row B row, which can prevent us
> from *underestimating* the size of the join product. A unique index
> can't do that.
Very good point, but unless I'm missing something, that is not what the
current patch does. I'm not sure offhand whether that's an important
estimation failure mode currently, or if it is whether it would be
sensible to try to implement that rule entirely separately from the "at
most one" aspect, or if it isn't sensible, whether that's a sufficiently
strong reason to confine the "at most one" logic to working only with FKs
and not with bare unique indexes.
On the whole, that seems like another argument why this needs more time.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, robertmhaas@gmail.com, david.rowley@2ndquadrant.com, tomas.vondra@2ndquadrant.com, julien.rouhaud@dalibo.com, simon@2ndquadrant.com, michael.paquier@gmail.com, stefan@huehner.org
Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates)
In-Reply-To: <31780.1462395724@sss.pgh.pa.us>
References: <20160429102531.GA13701@huehner.biz> <CAB7nPqRj2EsGdoNESsWVC-RHV918Scd1xQEcYt3dK9Rs5RpuAQ@mail.gmail.com> <572384D7.1020602@dalibo.com> <17639.1461945908@sss.pgh.pa.us> <57238E64.8010702@dalibo.com> <22731.1462037712@sss.pgh.pa.us> <8344835e-18af-9d40-aed7-bd2261be9162@2ndquadrant.com> <CAKJS1f9VMZGfPCDWeuLoD1rgvTr5JzGLh7vc4YWQCSDrmRCKbQ@mail.gmail.com> <CAKJS1f-Eqa23_K1x_jpgVn97TigcTm7RucuD=tpSEpGpLx4ULw@mail.gmail.com> <16807.1462388069@sss.pgh.pa.us> <CA+TgmoZ8ccdAgQmr46DrBc8PuBA+Hr03Ou7LKB53p-ETGC_v0g@mail.gmail.com> <31780.1462395724@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox