X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E9B09476032 for ; Thu, 10 Apr 2003 16:23:53 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 0AD0D475F16 for ; Thu, 10 Apr 2003 16:23:52 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h3AKNm2L006397; Thu, 10 Apr 2003 16:23:49 -0400 (EDT) To: joostje@komputilo.org Cc: pgsql-sql@postgresql.org Subject: Re: estimates for nested loop very wrong? In-reply-to: <20030410194553.GB28537@co.uea.org> References: <20030410112144.GA22716@co.uea.org> <3742.1049984229@sss.pgh.pa.us> <20030410162902.GA28537@co.uea.org> <4867.1049993075@sss.pgh.pa.us> <20030410194553.GB28537@co.uea.org> Comments: In-reply-to joostje@komputilo.org message dated "Thu, 10 Apr 2003 21:45:53 +0200" Date: Thu, 10 Apr 2003 16:23:48 -0400 Message-ID: <6396.1050006228@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.5 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/174 X-Sequence-Number: 12875 joostje@komputilo.org writes: > Je 2003/04/10(4)/12:04, Tom Lane skribis: >> Please try increasing the statistics target (see ALTER TABLE) for db.id, then >> re-analyze and see if the estimates get better. The default setting is >> 10 --- try 20, 50, 100 to see what happens. > Well, the n_distinct estimates get better, but the cost estimates still > don't quite add up: `actual cost' is 23.24, cost estimate never gets > below 49930. How much RAM do you have on this machine? If the system is caching a goodly fraction of the tables, it'd be appropriate to lower random_page_cost (or increase effective_cache_size). I do recall a thread awhile back to the effect that the planner overestimates the cost of nestloop/indexscan plans because it doesn't account for the fact that successive indexscans aren't independent --- the top levels of the index btree, at least, are certain to remain in cache from loop to loop. That seems unlikely to account for as large an estimation error as you're showing here, though. Is there anything nonrandom about your data statistics? (For example, could it be that all the db rows matching a particular tmp0 row are physically bunched together?) regards, tom lane