pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michal Hlavac <hlavki@medium13.sk>
To: pgsql-general@postgresql.org
Subject: Optimize query
Date: Mon, 05 Apr 2004 15:48:29 +0200
Message-ID: <407163AD.1060406@medium13.sk> (raw)

Hello,

I have one main table and 2 many-to-many relation tables and 2
one-to-many relation table. Main table has 150 000 rows and many-to-many
tables have about 300 000 rows.

I am creating web portal.
In my query I must call distinct with many-to-many relation. But this
query is too slow for web application. This query costs 8,5 seconds.
For example:

SELECT distinct(i_part_id), i_is_special, a.v_name, d.v_company,
f_price, t_description
FROM v_part a
	JOIN l_model_to_part b USING (i_part_id)
	JOIN l_part_to_cat c USING (i_part_id)
	JOIN k_seller d USING (i_seller_id)
	JOIN c_part_cat e USING (i_part_cat_id)
WHERE TRUE AND condition ORDER BY i_is_special DESC, v_name;

So, I created another way, how to grow up performace. I created 
temporary table with result of query, which has only one column (id of 
product). And finally I do a join of temporary table with main table. 
This query costs 0,5 seconds with everything.

It is 8,5 seconds versus 0,5 seconds...

Is this the right way, how to increase the performance of the queries??? 
I know, that every problem is specific. I mean this philosophical.

thanx, miso





view thread (14+ messages)  latest in thread

Message-ID: <407163AD.1060406@medium13.sk>
Permalink:  ../407163AD.1060406@medium13.sk/
Also on:    postgresql.org/message-id/407163AD.1060406@medium13.sk

 · 

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-general@postgresql.org
  Cc: hlavki@medium13.sk
  Subject: Re: Optimize query
  In-Reply-To: <407163AD.1060406@medium13.sk>
  References: <407163AD.1060406@medium13.sk>

* 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