Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id C9ACBB5DBD1 for ; Thu, 12 May 2011 18:31:48 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 99620-02 for ; Thu, 12 May 2011 21:31:41 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pv0-f174.google.com (mail-pv0-f174.google.com [74.125.83.174]) by mail.postgresql.org (Postfix) with ESMTP id 9DC04B5DBCE for ; Thu, 12 May 2011 18:31:41 -0300 (ADT) Received: by pvg12 with SMTP id 12so879514pvg.19 for ; Thu, 12 May 2011 14:31:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.143.19.5 with SMTP id w5mr377133wfi.40.1305234423342; Thu, 12 May 2011 14:07:03 -0700 (PDT) Received: by 10.142.191.14 with HTTP; Thu, 12 May 2011 14:07:03 -0700 (PDT) In-Reply-To: References: <4DA3608E.9090906@samsix.com> Date: Thu, 12 May 2011 14:07:03 -0700 Message-ID: Subject: Re: Poor performance when joining against inherited tables From: Maciek Sakrejda To: Lucas Madar Cc: Robert Haas , pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/193 X-Sequence-Number: 43702 > It says the sequential scan has a cost that's way too high, and I'm > presuming that's why it's choosing the extremely slow plan over the much > faster plan. Well, not exactly. It's giving you that cost because you disabled seqscan, which actually just bumps the cost really high: postgres=# create temporary table foo as select generate_series(1,3); SELECT postgres=# explain analyze select * from foo; QUERY PLAN ------------------------------------------------------------------------------------------------- Seq Scan on foo (cost=0.00..34.00 rows=2400 width=4) (actual time=0.010..0.012 rows=3 loops=1) Total runtime: 2.591 ms (2 rows) postgres=# set enable_seqscan to false; SET postgres=# explain analyze select * from foo; QUERY PLAN -------------------------------------------------------------------------------------------------------------------- Seq Scan on foo (cost=10000000000.00..10000000034.00 rows=2400 width=4) (actual time=0.004..0.007 rows=3 loops=1) Total runtime: 0.037 ms (2 rows) As far as I know, there is no hard way to disable any given plan option, since sometimes that may be the only choice. The (estimated) cost of the seq scan chosen here is *not* the same as the cost of the scan when the planner actually considers this plan (in fact, that will the same as the one in the first plan). However, note the cost of the Index Scan nodes in the second plan: they are *higher* than their corresponding Seq Scan nodes (in the first plan), which is why you get the first plan when seq can *is* enabled. Also, your plan output looks like plain EXPLAIN and not EXPLAIN ANALYZE (i.e., the "actual time" nodes are missing). Other than that, I think Shaun's comments apply. --- Maciek Sakrejda | System Architect | Truviso 1065 E. Hillsdale Blvd., Suite 215 Foster City, CA 94404 (650) 242-3500 Main www.truviso.com