X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 52352D1B4F0 for ; Tue, 12 Aug 2003 00:01:31 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 61758-05 for ; Mon, 11 Aug 2003 20:59:58 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 1DF12D1B52C for ; Mon, 11 Aug 2003 21:01:16 -0300 (ADT) 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 h7BNxaSa027329; Mon, 11 Aug 2003 19:59:36 -0400 (EDT) To: josh@agliodbs.com Cc: pgsql-performance@postgresql.org Subject: Re: Odd problem with performance in duplicate database In-reply-to: <200308111651.01597.josh@agliodbs.com> References: <200308111559.09924.josh@agliodbs.com> <26934.1060644171@sss.pgh.pa.us> <200308111651.01597.josh@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Mon, 11 Aug 2003 16:51:01 -0700" Date: Mon, 11 Aug 2003 19:59:36 -0400 Message-ID: <27328.1060646376@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/184 X-Sequence-Number: 3001 Josh Berkus writes: > My reading is that the case is "borderline"; Well, clearly the planner is flipping to a much less desirable plan, but the core estimation error is not borderline by my standards. In the live DB we have this subplan: -> Nested Loop (cost=0.00..7.41 rows=1 width=12) (actual time=0.01..0.02 rows=1 loops=856) -> Index Scan using trial_groups_pkey on trial_groups (cost=0.00..3.49 rows=1 width=4) (actual time=0.01..0.01 rows=0 loops=856) -> Index Scan using idx_cases_tgroup on cases (cost=0.00..3.92 rows=1 width=8) (actual time=0.02..0.04 rows=4 loops=133) In the test DB, the identical subplan is estimated at: -> Nested Loop (cost=0.00..81.53 rows=887 width=12) (actual time=0.03..0.04 rows=1 loops=855) -> Index Scan using trial_groups_pkey on trial_groups (cost=0.00..3.49 rows=1 width=4) (actual time=0.02..0.02 rows=0 loops=855) -> Index Scan using idx_cases_tgroup on cases (cost=0.00..77.77 rows=43 width=8) (actual time=0.03..0.07 rows=6 loops=133) and that factor of 887 error in the output rows estimate is what's driving all the outer plan steps to make bad choices. The "trial_groups_pkey" estimate is the same in both databases, so it's presumably a problem with estimating the number of matches to a "trial_groups" row that will be found in "cases". This is dependent on the pg_stats entries for the relevant columns, which I'm still hoping to see ... regards, tom lane