Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VwjgW-0005De-CQ for pgsql-performance@arkaria.postgresql.org; Sat, 28 Dec 2013 02:31:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VwjgV-000195-T3 for pgsql-performance@arkaria.postgresql.org; Sat, 28 Dec 2013 02:31:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VwjgU-00018x-Lz for pgsql-performance@postgresql.org; Sat, 28 Dec 2013 02:31:26 +0000 Received: from [2404:130:0:10::40:2] (helo=mail.catalyst.net.nz) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VwjgM-00023l-KV for pgsql-performance@postgresql.org; Sat, 28 Dec 2013 02:31:26 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id 6944732619; Sat, 28 Dec 2013 15:31:13 +1300 (NZDT) X-Virus-Scanned: Debian amavisd-new at catalyst.net.nz Received: from mail.catalyst.net.nz ([127.0.0.1]) by localhost (bertrand.catalyst.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 758y2f1mlBku; Sat, 28 Dec 2013 15:31:11 +1300 (NZDT) Received: from [192.168.1.64] (122-60-64-230.jetstream.xtra.co.nz [122.60.64.230]) (Authenticated sender: mark.kirkwood) by mail.catalyst.net.nz (Postfix) with ESMTPSA id B84033260E; Sat, 28 Dec 2013 15:31:11 +1300 (NZDT) Message-ID: <52BE37EF.7090109@catalyst.net.nz> Date: Sat, 28 Dec 2013 15:31:11 +1300 From: Mark Kirkwood User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Johann Spies , Tom Lane CC: pgsql-performance@postgresql.org Subject: Re: query not using index References: <8767.1387464535@sss.pgh.pa.us> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2404:130:0:10::40:2 (failed) X-Pg-Spam-Score: -1.1 (-) 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 On 23/12/13 21:58, Johann Spies wrote: > > > > On 19 December 2013 16:48, Tom Lane > wrote: > > 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. > > > Thanks Tom. Raising work_mem from 384MB to 512MB made a significant > difference. > > You said "hash or merge join id going to be a lot better than > nestloop". Is that purely in the hands of the query planner or what can > I do to get the planner to use that options apart from raising the work_mem? > > You can disable the hash and merge join options by doing: SET enable_hashjoin=off; SET enable_mergejoin=off; before running the query again. Timing it (or EXPLAIN ANALYZE) should demonstrate if that planner made the right call by choosing hash or merge in the first place. regards Mark -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance