From: Tom Lane <tgl@sss.pgh.pa.us>
To: Edson Richter <edsonrichter@hotmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: [PERFORM] Inaccurate Explain Cost
Date: Wed, 26 Sep 2012 19:29:14 -0400
Message-ID: <6926.1348702154@sss.pgh.pa.us> (raw)
In-Reply-To: <BLU0-SMTP46616B9B80F299E088F5165CF9C0@phx.gbl>
References: <ED7ED14D0D304B2FB38B191F3C160A22@ticketevolution.com>
<50635F77.60008@optionshouse.com>
<BLU0-SMTP46616B9B80F299E088F5165CF9C0@phx.gbl>
Edson Richter <edsonrichter@hotmail.com> writes:
>> That said, looking at your actual query:
>>
>> SELECT COUNT(DISTINCT eu.id)
>> FROM exchange_uploads eu
>> JOIN upload_destinations ud ON ud.id = eu.upload_destination_id
>> LEFT JOIN uploads u ON u.id = eu.upload_id
>> LEFT JOIN import_errors ie ON ie.exchange_upload_id = eu.id
>> LEFT JOIN exchanges e ON e.id = ud.exchange_id
>> WHERE eu.created_at >= '2012-07-27 21:21:57.363944'
>> AND ud.office_id = 6;
>>
>> Doesn't need half of these joins. They're left joins, and never used
>> in the query results or where criteria. You could just use this:
> Interesting. I've similar situation, where user can choose a set of
> filters, and then the query must have several left joins "just in case"
> (user need in the filer).
> I know other database that is able to remove unnecessary outer joins
> from queries when they are not relevant and for instance become faster.
> Can't PostgreSQL do the same?
It does, and did - note the query plan is only scanning 3 of the 5
tables mentioned in the query. (The other left join appears to be
to a non-unique column, which makes it not redundant.)
regards, tom lane
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, edsonrichter@hotmail.com, pgsql-general@postgresql.org
Subject: Re: [PERFORM] Inaccurate Explain Cost
In-Reply-To: <6926.1348702154@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