pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: bricklen <bricklen@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: Huge overestimation in rows expected results in bad plan
Date: Tue, 9 Nov 2010 16:10:33 -0800
Message-ID: <AANLkTimDn9UmbTMHOKHWaCP6Kxcfij60pdZbNCvYKmo5@mail.gmail.com> (raw)
In-Reply-To: <20765.1289346912@sss.pgh.pa.us>
References: <AANLkTim=JS-tu5G1CvrPnvfSTj7=YSxu=kwNUP+hLVfG@mail.gmail.com>
	<20388.1289345380@sss.pgh.pa.us>
	<AANLkTimxv5HeSSuL5_+6bUDvicE39wNheToT2Ow3mC1x@mail.gmail.com>
	<20765.1289346912@sss.pgh.pa.us>

On Tue, Nov 9, 2010 at 3:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> bricklen <bricklen@gmail.com> writes:
>> On Tue, Nov 9, 2010 at 3:29 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> The query doesn't seem to match the plan.  Where is that OR (c.id =
>>> 38441828354::bigint) condition coming from?
>
>> Ah sorry, I was testing it with and without that part. Here is the
>> corrected query, with that as part of the join condition:
>
>> explain analyze
>> select c.id, c.transactionid, c.clickgenerated, c.confirmed,
>> c.rejected, cr.rejectedreason
>> from conversion c
>> inner join conversionrejected cr on cr.idconversion = c.id or c.id = 38441828354
>> where date = '2010-11-06'
>> and idaction = 12906
>> and idaffiliate = 198338
>> order by transactionid;
>
> Hm.  Well, the trouble with that query is that if there is any
> conversion row with c.id = 38441828354, it will join to *every* row of
> conversionrejected.  The planner not unreasonably assumes there will be
> at least one such row, so it comes up with a join size estimate that's
>>= size of conversionrejected; and it also tends to favor a seqscan
> since it thinks it's going to have to visit every row of
> conversionrejected anyway.
>
> If you have reason to think the c.id = 38441828354 test is usually dead
> code, you might see if you can get rid of it, or at least rearrange the
> query as a UNION of two independent joins.
>
>                        regards, tom lane
>

Okay, thanks. I'll talk to the developer that wrote that query and see
what he has to say about it.


Cheers,

Bricklen



view thread (7+ messages)

Message-ID: <AANLkTimDn9UmbTMHOKHWaCP6Kxcfij60pdZbNCvYKmo5@mail.gmail.com>
Permalink:  ../AANLkTimDn9UmbTMHOKHWaCP6Kxcfij60pdZbNCvYKmo5@mail.gmail.com/
Also on:    postgresql.org/message-id/AANLkTimDn9UmbTMHOKHWaCP6Kxcfij60pdZbNCvYKmo5@mail.gmail.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-performance@postgresql.org
  Cc: bricklen@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: Huge overestimation in rows expected results in bad plan
  In-Reply-To: <AANLkTimDn9UmbTMHOKHWaCP6Kxcfij60pdZbNCvYKmo5@mail.gmail.com>
  References: <AANLkTim=JS-tu5G1CvrPnvfSTj7=YSxu=kwNUP+hLVfG@mail.gmail.com> <20388.1289345380@sss.pgh.pa.us> <AANLkTimxv5HeSSuL5_+6bUDvicE39wNheToT2Ow3mC1x@mail.gmail.com> <20765.1289346912@sss.pgh.pa.us> <AANLkTimDn9UmbTMHOKHWaCP6Kxcfij60pdZbNCvYKmo5@mail.gmail.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