X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 79E39D1D25F for ; Mon, 5 Apr 2004 13:47:53 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 66202-04 for ; Mon, 5 Apr 2004 10:48:16 -0300 (ADT) Received: from medium13.medium13.com (medium13.medium13.com [217.67.30.135]) by svr1.postgresql.org (Postfix) with ESMTP id F25DCD1B54E for ; Mon, 5 Apr 2004 10:47:45 -0300 (ADT) Received: from [213.215.72.86] (helo=medium13.sk) by medium13.medium13.com with asmtp (Exim 4.30) id 1BAUSa-0000cl-3x for pgsql-general@postgresql.org; Mon, 05 Apr 2004 15:48:20 +0200 Message-ID: <407163AD.1060406@medium13.sk> Date: Mon, 05 Apr 2004 15:48:29 +0200 From: Michal Hlavac User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Optimize query X-Enigmail-Version: 0.83.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/111 X-Sequence-Number: 59353 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