pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Edward Di Geronimo Jr. <edigeronimo@xtracards.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Performance issues with custom functions
Date: Wed, 26 Oct 2005 19:18:37 -0400
Message-ID: <12437.1130368717@sss.pgh.pa.us> (raw)
In-Reply-To: <435FE820.4070701@xtracards.com>
References: <435FE820.4070701@xtracards.com>

"Edward Di Geronimo Jr." <edigeronimo@xtracards.com> writes:
> ... I'd like to know exactly what causes 
> the bottleneck in the original query, and if there are other approaches 
> to solving the issue in case I need them in future queries.

This is fairly hard to read ... it would help a lot if you had shown the
view definitions that the query relies on, so that we could match up the
plan elements with the query a bit better.

However, I'm thinking the problem is with this IN clause:

>         where pl.network_id in (select ns.network_id
>                         from development.network_state ns
>                           where ns.from_date < current_time
>                             and (ns.thru_date > current_time or 
> ns.thru_date is null)
>                         and (ns.state_cd = pl.state_cd or ns.state_cd='')
>                           )

Because the sub-SELECT references pl.state_cd (an outer variable
reference), there's no chance of optimizing this into a join-style IN.
So the sub-SELECT has to be re-executed for each row of the outer query.

BTW, it's not apparent to me that your "flattened" query gives the same
answers as the original.  What if a pl row can join to more than one
row of the ns output?

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <12437.1130368717@sss.pgh.pa.us>
Permalink:  ../12437.1130368717@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/12437.1130368717@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, edigeronimo@xtracards.com
  Subject: Re: Performance issues with custom functions
  In-Reply-To: <12437.1130368717@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