X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id B31789FA217 for ; Wed, 13 Sep 2006 03:41:58 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 35530-01 for ; Wed, 13 Sep 2006 06:41:55 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id E3F279FA1DE for ; Wed, 13 Sep 2006 03:41:54 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id CB74F56435; Wed, 13 Sep 2006 01:41:52 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Wed, 13 Sep 2006 01:41:52 -0500 Date: Wed, 13 Sep 2006 01:41:52 -0500 From: "Jim C. Nasby" To: Joshua Marsh Cc: pgsql-performance@postgresql.org Subject: Re: Performance With Joins on Large Tables Message-ID: <20060913064152.GC23173@nasby.net> References: <38242de90609121517y62517040v8622b9ae93cba23d@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <38242de90609121517y62517040v8622b9ae93cba23d@mail.gmail.com> X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060913:icub3d@gmail.com::v20ttAHuI9UNTH8l:02Juw X-Hashcash: 1:20:060913:pgsql-performance@postgresql.org::rIcMFRLx7gZ+if2l:00000 0000000000000000000000000Ic3 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200609/111 X-Sequence-Number: 20797 On Tue, Sep 12, 2006 at 04:17:34PM -0600, Joshua Marsh wrote: > data=# EXPLAIN SELECT v.phonedirect, v.editdrop, EXTRACT (EPOCH FROM > v.custdate), EXTRACT (YEAR FROM s.custdate) || '-' || EXTRACT (MONTH > FROM s.custdate) FROM view_505 v INNER JOIN r3s169 s ON v.dsiacctno = > s.dsiacctno; > QUERY PLAN > ----------------------------------------------------------------------------------------------- > Merge Join (cost=293767607.69..305744319.52 rows=285392608 width=11) > Merge Cond: ("outer".dsiacctno = "inner".dsiacctno) > -> Sort (cost=127304933.87..127585815.71 rows=112352736 width=20) > Sort Key: v.dsiacctno > -> Seq Scan on view_505 v (cost=100000000.00..104604059.36 > rows=112352736 width=20) > -> Sort (cost=166462673.82..167176155.34 rows=285392608 width=17) > Sort Key: s.dsiacctno > -> Seq Scan on r3s169 s (cost=100000000.00..106875334.08 > rows=285392608 width=17) > (8 rows) > > > Since enable_seqscan is off, my understanding is that in order for the query > planner to user a sequential scan it must think there is no other > alternative. > Both sides are indexed and anaylzed, so that confuses me a little. > > I tried it on a smaller sample set of the data and it works fine: Actually, enable_seqscan=off just adds a fixed overhead to the seqscan cost estimate. That's why the cost for the seqscans in that plan starts at 100000000. I've suggested changing that to a variable overhead based on the expected rowcount, but the counter-argument was that anyone with so much data that the fixed amount wouldn't work would most likely be having bigger issues anyway. Other things you can try to get the index scan back would be to reduce random_page_cost and to analyze the join fields in those tables with a higher statistics target (though I'm not 100% certain the join cost estimator actually takes that into account). Or if you don't mind patching your source code, it wouldn't be difficult to make enable_seqscan use a bigger 'penalty value' than 10000000. -- Jim Nasby jim@nasby.net EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)