From: Simon Riggs <simon@2ndQuadrant.com>
To: Gregory Stark <stark@enterprisedb.com>
Cc: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Cc: List pgsql-patches <pgsql-patches@postgresql.org>
Subject: Re: WIP Join Removal
Date: Tue, 02 Sep 2008 14:48:44 +0100
Message-ID: <1220363324.4371.421.camel@ebony.2ndQuadrant> (raw)
In-Reply-To: <87od36u7st.fsf@oxford.xeocode.com>
References: <1220176372.4371.118.camel@ebony.2ndQuadrant>
<48BC4127.30706@enterprisedb.com>
<1220348487.4371.307.camel@ebony.2ndQuadrant>
<48BD1374.4030504@enterprisedb.com>
<1220352112.4371.349.camel@ebony.2ndQuadrant>
<48BD1852.1070904@enterprisedb.com>
<1220352898.4371.355.camel@ebony.2ndQuadrant>
<87od36u7st.fsf@oxford.xeocode.com>
On Tue, 2008-09-02 at 12:05 +0100, Gregory Stark wrote:
> I wonder if it would be more worthwhile to remove them and have a subsequent
> phase where we look for possible joins to *add*. So even if the user writes
> "select * from invoices where customer_id=?" the planner might be able to
> discover that it can find those records quicker by scanning customer, finding
> the matching <company_id,customer_id> and then using an index to look them up
> in invoices.
This seems a less useful idea now just simply because it is such a
special case.
We would need to have a case where we have a table A that does not have
an index on a specific column, yet table B does have an index on the
specific column. But also when A references B as a foreign key and where
the column is a subset of the columns of the primary key of B.
That means only queries like
select ...
from a
where a.col2 = x;
can be transformed into
select ...
from a join b on (foreign key cols)
where a.col2 = x;
and then because a.col2 is a subset of foreign key columns we can infer
that b.col2 = x.
So the pre-conditions for this to be useful are:
* constraint on subset of a FK
* subset of FK is indexed on B
* subset of FK is not indexed on A
Which doesn't seem that likely to occur.
Thanks both to Heikki and Greg for good, fast input on this patch.
Nothing more needed now while I rework patch.
--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support
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-patches@postgresql.org
Cc: simon@2ndQuadrant.com, stark@enterprisedb.com, heikki.linnakangas@enterprisedb.com
Subject: Re: WIP Join Removal
In-Reply-To: <1220363324.4371.421.camel@ebony.2ndQuadrant>
References: <1220176372.4371.118.camel@ebony.2ndQuadrant> <48BC4127.30706@enterprisedb.com> <1220348487.4371.307.camel@ebony.2ndQuadrant> <48BD1374.4030504@enterprisedb.com> <1220352112.4371.349.camel@ebony.2ndQuadrant> <48BD1852.1070904@enterprisedb.com> <1220352898.4371.355.camel@ebony.2ndQuadrant> <87od36u7st.fsf@oxford.xeocode.com> <1220363324.4371.421.camel@ebony.2ndQuadrant>
* 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