pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Travis Whitton <tinymountain@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Performance Problem with sub-select using array
Date: Thu, 24 Aug 2006 15:01:39 -0400
Message-ID: <cf9b4f3e0608241201l51a2e61cxd15d2ddbbdd710b9@mail.gmail.com> (raw)

Hello all, I'm running the following query on about 6,000 records worth of
data, and it takes about 8 seconds to complete. Can anyone provide any
suggestions to improve performance? I have an index on two columns in the
transacts table (program_id, customer_id). If I specify a number for
customer.id in the sub-select, query time is reduced to about 2 seconds,
which still seems like a million years for only 6,000 records, but I'm
guessing that the sub-select can't resolve the id since it's done before the
outer query, so it scans the entre recordset for every row? Transacts is a
many to many table for customers and programs. I know this query doesn't
even reference any columns from programs; however, I dynamically insert
where clauses to constrain the result set.

SELECT distinct customers.id, first_name, last_name, address1, contact_city,
contact_state, primary_phone, email, array(select programs.program_name from
transacts, programs where customer_id = customers.id and programs.id =
transacts.program_id and submit_status = 'success') AS partners from
customers, transacts, programs where transacts.customer_id = customers.idand
transacts.program_id = programs.id

view thread (4+ messages)  latest in thread

Message-ID: <cf9b4f3e0608241201l51a2e61cxd15d2ddbbdd710b9@mail.gmail.com>
Permalink:  ../cf9b4f3e0608241201l51a2e61cxd15d2ddbbdd710b9@mail.gmail.com/
Also on:    postgresql.org/message-id/cf9b4f3e0608241201l51a2e61cxd15d2ddbbdd710b9@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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tinymountain@gmail.com
  Subject: Re: Performance Problem with sub-select using array
  In-Reply-To: <cf9b4f3e0608241201l51a2e61cxd15d2ddbbdd710b9@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