X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx2.hub.org [200.46.204.254]) by postgresql.org (Postfix) with ESMTP id 6280011F696D for ; Fri, 14 Apr 2006 13:59:09 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: -0.276 X-Spam-Level: X-Spam-Status: No, score=-0.276 required=5 tests=[AWL=-1.493, BAYES_00=-2.599, SPF_HELO_SOFTFAIL=2.432, SPF_SOFTFAIL=1.384] Received: from postgresql.org ([200.46.204.71]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id x30S3hLZ2SNm for ; Fri, 14 Apr 2006 13:58:52 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id A7D4911F6260 for ; Fri, 14 Apr 2006 13:58:50 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k3EGwnG7011036; Fri, 14 Apr 2006 12:58:49 -0400 (EDT) To: Ian Westmacott cc: pgsql-performance@postgresql.org Subject: Re: merge>hash>loop In-reply-to: <1145033149.3422.41.camel@spectre.intellivid.com> References: <1145029009.3422.31.camel@spectre.intellivid.com> <10000.1145031205@sss.pgh.pa.us> <1145033149.3422.41.camel@spectre.intellivid.com> Comments: In-reply-to Ian Westmacott message dated "Fri, 14 Apr 2006 12:45:48 -0400" Date: Fri, 14 Apr 2006 12:58:49 -0400 Message-ID: <11035.1145033929@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200604/339 X-Sequence-Number: 18423 Ian Westmacott writes: > That's what I feared, thanks. But then if I simplify things a bit, > such that the row counts are quite good, and PG still chooses a > worse plan, can I conclude anything about my configuration settings > (like random_page_cost)? Well, the other thing that's going on here is that we know we are overestimating the cost of nestloop-with-inner-indexscan plans. The current estimation for that is basically "outer scan cost plus N times inner scan cost" where N is the estimated number of outer tuples; in other words the repeated indexscan probes are each assumed to happen from a cold start. In reality, caching of the upper levels of the index means that the later index probes are much cheaper than this model thinks. We've known about this for some time but no one's yet proposed a more reasonable cost model. In my mind this is tied into another issue, which is that the planner always costs on the basis of each query starting from zero. In a real environment it's much cheaper to use heavily-used indexes than this cost model suggests, because they'll already be swapped in due to use by previous queries. But we haven't got any infrastructure to keep track of what's been heavily used, let alone a cost model that could make use of the info. I think part of the reason that people commonly reduce random_page_cost to values much lower than physical reality would suggest is that it provides a crude way of partially compensating for this basic problem. regards, tom lane