pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Premsun Choltanwanich <Premsun@nsasia.co.th>
To: pgsql-sql@postgresql.org
Subject: Slow Query problem
Date: Mon, 28 Jan 2008 14:18:24 +0700
Message-ID: <479DE418.C5F7.004C.0@nsasia.co.th> (raw)

Dear All,
 
I am currently using PostgreSQL database version 8.0.13.  My problem relates to a slow result when a query using a defined view joins to another table for a result.
 
Background:  I have 7 tables of invoice transactions.  The tables are slightly different in that they record different data (some different columns in each table).  There are about 250,000 records when a union view is created.  A simply query on this union performs satisfactorily.
 
The invoice table union view is then joined with a table of receipts (which have a total of about 150,000 records).  
 
It takes around 3.5 seconds for "select * from view_transaction where member_id = 999  and receipt_no is null" (which returns unpaid invoices).
 
By hard coding I created a single table from the 7 invoice tables (instead of creating a union) and then used it with receipt table.  This time for the same query improved to 1.8 seconds.
 
To further improve things I tried to code the selection rather than to use a view, and so "select * from temp_transaction where member_id = 999 and receipt_no is null" provided the result in .5 second. (2 records returned containing the details of receipt_no, transaction_no, transaction_type, transaction_amount, member_id).
 
I would prefer to be able to have completed the above by using unions and views.  Is it possible to do this, or am I better creating a permanent table of invoices and writing the query as I did above?
 
Any comments on this and suggestions would be appreciated.  If there is documentation where I can read up please let me have a link.
 
Thank You,
 
Premsun
 

NETsolutions Asia Limited
+66 (2) 237 7247
http://www.nsasia.co.th

Attachments:

IMAGE.jpg (image/jpg, 6.3K) download view image

view thread (7+ messages)  latest in thread

Message-ID: <479DE418.C5F7.004C.0@nsasia.co.th>
Permalink:  ../479DE418.C5F7.004C.0@nsasia.co.th/
Also on:    postgresql.org/message-id/479DE418.C5F7.004C.0@nsasia.co.th

 · 

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: Premsun@nsasia.co.th
  Subject: Re: Slow Query problem
  In-Reply-To: <479DE418.C5F7.004C.0@nsasia.co.th>

* 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