X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D93729DD585 for ; Wed, 22 Mar 2006 13:17:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 94123-09 for ; Wed, 22 Mar 2006 13:17:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from isb.com.pl (isb.com.pl [212.160.150.140]) by postgresql.org (Postfix) with ESMTP id C24DD9DCB8B for ; Wed, 22 Mar 2006 13:17:17 -0400 (AST) Received: from maciek (sembrz [192.168.1.50]) by isb.com.pl (Postfix) with ESMTP id ABC6457842 for ; Wed, 22 Mar 2006 18:13:52 +0100 (CET) Date: Wed, 22 Mar 2006 18:17:15 +0100 From: Maciej Piekielniak X-Mailer: The Bat! (v1.62r) Reply-To: Maciej Piekielniak X-Priority: 3 (Normal) Message-ID: <827987076.20060322181715@isb.com.pl> To: pgsql-sql@postgresql.org Subject: How to optimize this query? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.096 required=5 tests=[AWL=0.096] X-Spam-Score: 0.096 X-Spam-Level: X-Archive-Number: 200603/353 X-Sequence-Number: 24699 Hello pgsql-sql, I have postgresql 8.1.3 and database with about 2,7GB (90% large objects). When I execute this query postgresql calculate this 2min 50sec. How can I optimize this query? select towar.id_towar,towar.key2,towar.nazwa,0 as min,0 as max,towar.ilosc_jed,towar.ilosc_nom,towar.ilosc_paczkowa,dostawcy.id_dostawcy,jednostka_miary.jednostka,0.0 AS ilosc_magazyn,(select sum(zlecenia_towar.ilosc*zlecenia_elementy.ilosc) from zlecenia_towar,zlecenia_elementy,zlecenia where zlecenia_towar.id_towar=towar.id_towar and zlecenia_towar.id_zlecenia_elementy=zlecenia_elementy.id_zlecenia_elementy and zlecenia_elementy.id_zlecenia=zlecenia.id_zlecenia and (zlecenia.id_paczka in (52,50,53))) as z_zamowien,towar.key1 from (towar LEFT JOIN dostawcy ON (towar.id_dostawcy = dostawcy.id_dostawcy) LEFT JOIN jednostka_miary ON (towar.id_jednostka_miary = jednostka_miary.id_jednostka_miary)) where towar.policzalne=True group by towar.id_towar,towar.key2,towar.nazwa,towar.min1,towar.max1,towar.ilosc_jed,towar.ilosc_nom,dostawcy.id_dostawcy , jednostka_miary.jednostka,towar.ilosc_paczkowa,towar.key1 order by id_dostawcy; -- Best regards, Maciej mailto:piechcio@isb.com.pl