pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nikolaus Dilger <nikolaus@dilger.cc>
To: yusuf0478@netscape.net
Cc: pgsql-admin@postgresql.org
Subject: Re: Speed up a query - using a temp table
Date: Tue, 08 Apr 2003 20:48:20 -0700 (PDT)
Message-ID: <20030408204821.845.h018.c001.wm@mail.dilger.cc.criticalpath.net> (raw)

David,

You should post performance related items to the
PERFORMANCE mailing list.

To answer your question a few ideas to try.
I think you only pasted a partial query.
Why do you need the OUTTABLE in the first place?
If you do why not put the WHERE clause inside?

select contact.id
, contact.name
, (select SOMETHING_MISSING from detail inner join
myDetail using
(detail.id) ) as cost
from contact
inner join user using (user_id)
WHERE_CLAUS_MISSING???and user_id = 1
where cost > 30;


Regards,
Nikolaus Dilger


David Wendy wrote:

> 
> I have a query of the form:
> 
> select * from (
> select contact.id
> , contact.name
> , (select from detail inner join myDetail using
> (detail.id) ) as cost
> from contact
> inner join user using (user_id) and user_id = 1
> ) as OUTTABLE
> where cost > 30;
> 
> 
> The problem is that all the tables in the query are
> big, so it takes a
> long time to get results from OUTTABLE (around 20
> seconds) . When I
> add the where clause at the end (cost > 30), the query
> becomes too
> long (around 200 seconds sometimes).
> 
> To make the query run faster, I thought of creating a
> temp table to
> store OUTTABLE, and then just filter on the temp table
> using cost >
> 30. That would improve the speed of the query
> tremendously (total time
> was around 23 seconds) . The problem with that
approach
> is that I'm
> writing an application, and more than one user might
> need to run the
> query at the same time. (Different user should get
> different results
> because they have different user ids, and other
numbers
> in the query
> would be different). Also, I can't just create and
drop
> temp tables in
> an enterprise application (we are not using ejbs in
our
> applications
> either), it seems like bad style.
> 
> Anyhow, how could I make this query faster so that the
> values of
> OUTTABLE is retrieved first, then the where clause is
> evaluated to
> filter?
> 
> Thanks in advance.
> 
> 
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> <a
href="http://mail.dilger.cc/jump/http://archives.postgresql.org">http://archives.postgresql.org<...;




view thread (2+ messages)

Message-ID: <20030408204821.845.h018.c001.wm@mail.dilger.cc.criticalpath.net>
Permalink:  ../20030408204821.845.h018.c001.wm@mail.dilger.cc.criticalpath.net/
Also on:    postgresql.org/message-id/20030408204821.845.h018.c001.wm@mail.dilger.cc.criticalpath.net

 · 

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-admin@postgresql.org
  Cc: nikolaus@dilger.cc, yusuf0478@netscape.net
  Subject: Re: Speed up a query - using a temp table
  In-Reply-To: <20030408204821.845.h018.c001.wm@mail.dilger.cc.criticalpath.net>
  References: <20030408204821.845.h018.c001.wm@mail.dilger.cc.criticalpath.net>

* 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