Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Slow Query problem


  • From: "Premsun Choltanwanich" <Premsun(at)nsasia(dot)co(dot)th>
  • To: <pgsql-sql(at)postgresql(dot)org>
  • Subject: Slow Query problem
  • Date: Mon, 28 Jan 2008 14:18:24 +0700
  • Message-id: <479DE418.C5F7.004C.0@nsasia.co.th> <text/plain>

<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-874">
<META content="MSHTML 6.00.2900.3243" name=GENERATOR></HEAD>
<BODY style="MARGIN: 4px 4px 1px; FONT: 10pt MS Sans Serif">
<DIV>Dear All,<BR>&nbsp;<BR>I am currently using PostgreSQL database version 8.0.13.&nbsp; My problem relates to a slow result when a query using a defined view joins to another table for a result.<BR>&nbsp;<BR>Background:&nbsp; I have 7 tables of invoice transactions.&nbsp; The tables are slightly different in that they record different data (some different columns in each table).&nbsp; There are about 250,000 records when a union view is created.&nbsp; A simply query on this union performs satisfactorily.</DIV>
<DIV>&nbsp;</DIV>
<DIV>The invoice table union view is then joined with a table of receipts (which have a total of about 150,000 records).&nbsp; </DIV>
<DIV>&nbsp;</DIV>
<DIV>It takes around 3.5 seconds for "select * from view_transaction where member_id = 999&nbsp; and receipt_no is null" (which returns unpaid invoices).</DIV>
<DIV>&nbsp;</DIV>
<DIV>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.&nbsp; This time for the same query improved to 1.8 seconds.</DIV>
<DIV>&nbsp;</DIV>
<DIV>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).</DIV>
<DIV>&nbsp;</DIV>
<DIV>I would prefer to be able to have completed the above by using unions and views.&nbsp; Is it possible to do this, or am I better creating a permanent table of invoices and writing the query as I did above?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Any comments on this and suggestions would be appreciated.&nbsp; If there is documentation where I can read up please let me have a link.<BR>&nbsp;<BR>Thank You,<BR>&nbsp;<BR>Premsun<BR>&nbsp;</DIV><BR>

    <p>
      <font size="2" color="#0033cc" face="Trebuchet MS"><b>NETsolutions Asia 
      Limited </b></font>
    </p>
    <p>
      <font size="2" color="#0033cc" face="Trebuchet MS"><b>+66 (2) 237 7247 </b></font>

    </p>
    <p>
      <a href="http://www.nsasia.co.th";><img border="0" alt="NETsolutions Asia Limited" src="cid:RQHFQWYUJULD.44e30700.jpg">
</a>    </p>
  </BODY></HTML>

image/jpg



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group