From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: 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 03:40:30 +0200
Message-ID: <039fca3d-890a-d09a-e0df-e045187eb69e@2ndquadrant.com> (raw)
In-Reply-To: <28109.1465064127@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>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
Hi,
While this thread was effectively superseded by the 'new design' thread
[1], I'd like to address a few points raised here, as they are relevant
for the new design (at least I believe so).
[1] https://www.postgresql.org/message-id/31041.1465069446@sss.pgh.pa.us
On 06/04/2016 08:15 PM, Tom Lane wrote:
...
>
> * Make RelationGetFKeyList cache a list of ForeignKeyOptInfo structs,
> not just constraint OIDs. It's insane that the relcache scans
> pg_constraint to collect those OIDs and then the planner re-reads all
> those same rows on every planning cycle. Allow the relcache to return
> a pointer to the list in-cache, and require the planner to copy that
> data before making any more cache requests. The planner would run
> through the list, skipping single-key entries and entries leading to
> irrelevant tables, and copy out just the items that are useful for
> the current query (probably adding query-specific table RTE indexes
> at the same time).
That seems like a fairly straightforward change, and I'm not opposed to
doing that. However RelationGetFKeyList is basically a modified copy of
RelationGetIndexList, so it shares the same general behavior, including
caching of OIDs and then constructing IndexOptInfo objects on each
get_relation_info() call. Why is it 'insane' for foreign keys but not
for indexes? Or what am I missing?
>
> * Personally I'd probably handle the "ignore irrelevant tables" test
> with a list_member_oid test on a list of relation OIDs, not a
> hashtable. It's unlikely that there are enough tables in the query to
> justify building a hashtable.
OK
>
> * All of the above should happen only if the query contains multiple
> tables; there is no reason to expend even one cycle on loading FK data
> in a simple single-table query.
OK
>
> ... snip the part about nested loops (new design thread) ...
>
> Also, there are serious bugs remaining, even without considering planning
> speed. An example I just noticed is that quals_match_foreign_key actually
> fails entirely to ensure that it's found a match to the FK, because there
> is no check on whether foreignrel has anything to do with the FK. That
> is, this bit:
>
> * We make no attempt in checking that this foreign key actually
> * references 'foreignrel', the reasoning here is that we may be able
> * to match the foreign key to an eclass member Var of a RestrictInfo
> * that's in qualslist, this Var may belong to some other relation.
>
> would be okay if you checked after identifying a matching eclass member
> that it belonged to the FK's referenced table, but AFAICS there is no such
> check anywhere.
>
Perhaps I'm missing something, but I thought this is checked by these
conditions in quals_match_foreign_key():
1) with ECs (line 3990)
if (foreignrel->relid == var->varno &&
fkinfo->confkeys[i] == var->varattno)
foundvarmask |= 1;
2) without ECs (line 4019)
if ((foreignrel->relid == leftvar->varno) &&
(fkrel->relid == rightvar->varno) &&
(fkinfo->confkeys[i] == leftvar->varattno) &&
(fkinfo->conkeys[i] == rightvar->varattno))
{
...
}
else if ((foreignrel->relid == rightvar->varno) &&
(fkrel->relid == leftvar->varno) &&
(fkinfo->confkeys[i] == rightvar->varattno) &&
(fkinfo->conkeys[i] == leftvar->varattno))
{
...
}
Or does that fail for some reason?
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
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: <039fca3d-890a-d09a-e0df-e045187eb69e@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>
* 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