Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VteuS-0001zU-58 for pgsql-performance@arkaria.postgresql.org; Thu, 19 Dec 2013 14:49:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VteuR-0006YY-2r for pgsql-performance@arkaria.postgresql.org; Thu, 19 Dec 2013 14:49:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VteuP-0006YR-U2 for pgsql-performance@postgresql.org; Thu, 19 Dec 2013 14:49:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VteuJ-0001zZ-Hr for pgsql-performance@postgresql.org; Thu, 19 Dec 2013 14:49:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id rBJEmtOF008768; Thu, 19 Dec 2013 09:48:55 -0500 From: Tom Lane To: Johann Spies cc: pgsql-performance@postgresql.org Subject: Re: query not using index In-reply-to: References: Comments: In-reply-to Johann Spies message dated "Thu, 19 Dec 2013 15:06:21 +0200" Date: Thu, 19 Dec 2013 09:48:55 -0500 Message-ID: <8767.1387464535@sss.pgh.pa.us> X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Johann Spies writes: > I would appreciate some help optimising the following query: It's a mistake to imagine that indexes are going to help much with a join of this size. Hash or merge join is going to be a lot better than nestloop. What you need to do is make sure those will perform as well as possible, and to that end, it'd likely help to raise work_mem. I'm not sure if you can sanely put it high enough to make the query operate totally in memory --- it looks like you'd need work_mem of 500MB or more to prevent any of the sorts or hashes from spilling to disk, and keep in mind that this query is going to use several times work_mem because there are multiple sorts/hashes going on. But if you can transiently dedicate a lot of RAM to this query, that should help some. I'd suggest increasing work_mem via a SET command in the particular session running this query --- you don't want such a high value to be the global default. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance