X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 53073329DC4 for ; Tue, 14 Sep 2004 05:58:04 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86210-02 for ; Tue, 14 Sep 2004 04:57:58 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 2ACBC329C70 for ; Tue, 14 Sep 2004 05:57:59 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8E4vpjk002396; Tue, 14 Sep 2004 00:57:51 -0400 (EDT) To: Vijay Moses Cc: pgsql-performance@postgresql.org Subject: Re: Four table join with million records - performance improvement? In-reply-to: <17b0d951040912213055195d56@mail.gmail.com> References: <17b0d951040912213055195d56@mail.gmail.com> Comments: In-reply-to Vijay Moses message dated "Mon, 13 Sep 2004 10:00:41 +0530" Date: Tue, 14 Sep 2004 00:57:51 -0400 Message-ID: <2395.1095137871@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/109 X-Sequence-Number: 8237 Vijay Moses writes: > Hi i have four sample tables ename, esal, edoj and esum > All of them have 1000000 records. Im running the following > query : select ename.eid, name, sal, doj, summary from > ename,esal,edoj,esum where ename.eid=esal.eid and ename.eid=edoj.eid > and ename.eid=esum.eid. Its a join of all four tables which returns > all 1 million records. The eid field in ename is a Primary Key and the > eid in all other tables are Foreign Keys. I have created an index for > all Foreign Keys. This query takes around 16 MINUTES to complete. Can > this time be reduced? The indexes will be completely useless for that sort of query; the reasonable choices are sort/merge or hashjoin. For either one, your best way to speed it up is to increase sort_mem. regards, tom lane