X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8B1D6D877E for ; Tue, 18 Oct 2005 04:55:21 -0300 (ADT) 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 72546-09 for ; Tue, 18 Oct 2005 07:55:17 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 9B937D874A for ; Tue, 18 Oct 2005 04:55:18 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 200FD401E16; Tue, 18 Oct 2005 08:55:14 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id DE7DB15ED9; Tue, 18 Oct 2005 08:52:19 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 12305-08; Tue, 18 Oct 2005 08:52:16 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 2616515ED5; Tue, 18 Oct 2005 08:52:16 +0100 (BST) Message-ID: <4354A9AF.30300@archonet.com> Date: Tue, 18 Oct 2005 08:52:15 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Martin Nickel Cc: pgsql-performance@postgresql.org Subject: Re: Sequential scan on FK join References: <4353648C.8040507@archonet.com> <4353E342.2060708@archonet.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/261 X-Sequence-Number: 15029 Martin Nickel wrote: > When I turn of seqscan it does use the index - and it runs 20 to 30% > longer. Based on that, the planner is correctly choosing a sequential > scan - but that's just hard for me to comprehend. I'm joining on an int4 > key, 2048 per index page - I guess that's a lot of reads - then the data > -page reads. Still, the 8-minute query time seems excessive. You'll be getting (many) fewer than 2048 index entries per page. There's a page header and various pointers involved too, and index pages aren't going to be full. So - it needs to search the table on dates, fetch the id's and then assemble them for the hash join. Of course, if you have too many to join then all this will spill to disk slowing you further. Now, you'd rather get down below 8 minutes. There are a number of options: 1. Make sure your disk i/o is being pushed to its limit 2. Look into increasing the sort memory for this one query "set work_mem..." (see the runtime configuration section of the manual) 3. Actually - are you happy that your general configuration is OK? 4. Perhaps use a cursor - I'm guessing you want to process these mailings in some way and only want them one at a time in any case. 5. Try the query one day at a time and see if the balance tips the other way - you'll be dealing with substantially less data per query which might match your system better. Of course, this may not be practical for your applicaton. 6. If your lead table is updated only rarely, you could try a CLUSTER on the table by mailing_id - that should speed the scan. Read the manual for the cluster command first though. -- Richard Huxton Archonet Ltd