pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Noah Misch <noah@leadboat.com>
Cc: Simon Riggs <simon@2ndquadrant.com>
Cc: David Rowley <david.rowley@2ndquadrant.com>
Cc: Julien Rouhaud <julien.rouhaud@dalibo.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: Mon, 6 Jun 2016 19:23:42 +0200
Message-ID: <2a8adc56-6eb1-123e-8914-0cf025797262@2ndquadrant.com> (raw)
In-Reply-To: <24068.1465230882@sss.pgh.pa.us>
References: <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>
	<CAKJS1f-5WjfJLu0Y4hnfR01ZCBsd5FrDQ7kz5ayAt1t7DZ5vLQ@mail.gmail.com>
	<CAKJS1f8iHbN4KC+=BK=M_UTeCsTsfjqQWBZjN3w9NxqKKfL7dw@mail.gmail.com>
	<CA+TgmobPqrAVXOBMHTcpDq8hX7gCzcVhoUvC8s9V=d09+bt30w@mail.gmail.com>
	<20160529053601.GE496776@tornado.leadboat.com>
	<20160602012954.GA619629@tornado.leadboat.com>
	<CA+TgmoavPp9Xdo-DG1v8W0o+0GJwtevMqcEdh6WoT39ggv0oSg@mail.gmail.com>
	<28109.1465064127@sss.pgh.pa.us>
	<039fca3d-890a-d09a-e0df-e045187eb69e@2ndquadrant.com>
	<23385.1465229755@sss.pgh.pa.us>
	<24068.1465230882@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On 06/06/2016 06:34 PM, Tom Lane wrote:
> ... BTW, another thought occurred to me yesterday: it seems like the
> existing code hasn't thought through its behavior for multiple foreign
> keys very carefully.  That is, suppose we have both "A.J references B.K"
> and "A.X references B.Y", as separate FKs not a single multicolumn FK.
> The current code goes to some lengths to decide that one of these is
> better than the other and then ignore the other.  Why?  Seems to me
> that in such a case you want to behave more nearly as you would for a
> multicolumn FK, that is discard all the join quals matched to either FK
> in favor of a single selectivity estimate based on the number of rows in
> the referenced table.  Discarding only the A.J = B.K clause and then
> multiplying by the independent selectivity of A.X = B.Y is surely just as
> wrong as what we've historically done for multicolumn FKs.  (Correcting
> for nulls would take a bit of thought, but I wouldn't be surprised if it
> ends up being the same as for the multicolumn-FK case, at least to within
> the precision we can hope to get with the available stats for nulls.)

Yes, that can be improved. The plan was to improve the common case 
first, and then look at the more complicated cases. It might seem like a 
hand-waving but I'd bet 99% tables are joined on a single FK, so this 
seems like a reasonable approach.

When it comes to improving multiple (multi-column) foreign keys, I think 
it may get way more complicated that it might seem. What if the foreign 
keys overlap, for example? Or what if the keys go in opposite directions 
(cycle). And so on ...


regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (50+ messages)  latest in thread

Message-ID: <2a8adc56-6eb1-123e-8914-0cf025797262@2ndquadrant.com>
Permalink:  ../2a8adc56-6eb1-123e-8914-0cf025797262@2ndquadrant.com/
Also on:    postgresql.org/message-id/2a8adc56-6eb1-123e-8914-0cf025797262@2ndquadrant.com

 · 

reply

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: tomas.vondra@2ndquadrant.com, tgl@sss.pgh.pa.us, robertmhaas@gmail.com, noah@leadboat.com, simon@2ndquadrant.com, david.rowley@2ndquadrant.com, julien.rouhaud@dalibo.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: <2a8adc56-6eb1-123e-8914-0cf025797262@2ndquadrant.com>
  References: <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> <CAKJS1f-5WjfJLu0Y4hnfR01ZCBsd5FrDQ7kz5ayAt1t7DZ5vLQ@mail.gmail.com> <CAKJS1f8iHbN4KC+=BK=M_UTeCsTsfjqQWBZjN3w9NxqKKfL7dw@mail.gmail.com> <CA+TgmobPqrAVXOBMHTcpDq8hX7gCzcVhoUvC8s9V=d09+bt30w@mail.gmail.com> <20160529053601.GE496776@tornado.leadboat.com> <20160602012954.GA619629@tornado.leadboat.com> <CA+TgmoavPp9Xdo-DG1v8W0o+0GJwtevMqcEdh6WoT39ggv0oSg@mail.gmail.com> <28109.1465064127@sss.pgh.pa.us> <039fca3d-890a-d09a-e0df-e045187eb69e@2ndquadrant.com> <23385.1465229755@sss.pgh.pa.us> <24068.1465230882@sss.pgh.pa.us> <2a8adc56-6eb1-123e-8914-0cf025797262@2ndquadrant.com>

* 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