Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XZP4u-0004lq-AU for pgsql-performance@arkaria.postgresql.org; Wed, 01 Oct 2014 18:56:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XZP4t-00068A-Po for pgsql-performance@arkaria.postgresql.org; Wed, 01 Oct 2014 18:56:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XZP4s-000684-VP for pgsql-performance@postgresql.org; Wed, 01 Oct 2014 18:56:43 +0000 Received: from 01.zmailcloud.com ([192.198.85.104] helo=mx-out-1.zmailcloud.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XZP4o-0006WO-Kl for pgsql-performance@postgresql.org; Wed, 01 Oct 2014 18:56:41 +0000 Received: from smtp.01.com (smtp.01.com [10.10.0.43]) by mx-out-1.zmailcloud.com (Postfix) with ESMTP id D78FD564B19; Wed, 1 Oct 2014 13:56:36 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id CC4E7602A9; Wed, 1 Oct 2014 13:56:36 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s5ZBwyCj8u5K; Wed, 1 Oct 2014 13:56:36 -0500 (CDT) Received: from smtp.01.com (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id AA83C60358; Wed, 1 Oct 2014 13:56:36 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 9A54B60353; Wed, 1 Oct 2014 13:56:36 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id eAlOnERyAiPa; Wed, 1 Oct 2014 13:56:36 -0500 (CDT) Received: from [172.47.23.102] (70-36-143-82.dsl.dynamic.sonic.net [70.36.143.82]) by smtp-out-2.01.com (Postfix) with ESMTPSA id DA8C7602A9; Wed, 1 Oct 2014 13:56:35 -0500 (CDT) Message-ID: <542C4E60.3030505@agliodbs.com> Date: Wed, 01 Oct 2014 11:56:32 -0700 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Simon Riggs , Jeff Janes CC: Merlin Moncure , postgres performance list Subject: Re: Yet another abort-early plan disaster on 9.3 References: <541A2335.3060100@agliodbs.com> <541C7891.7000902@agliodbs.com> <541DC87F.3030800@agliodbs.com> <5420B71C.6010208@agliodbs.com> <5429D517.3090900@agliodbs.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 09/30/2014 04:01 PM, Simon Riggs wrote: > On 30 September 2014 18:28, Jeff Janes wrote: > >>> Anyway, in the particular case I posted fixing n_distinct to realistic >>> numbers (%) fixed the query plan. >> >> >> But wouldn't fixing the absolute number also have fixed the plan? > > There are two causes of this issue. > > 1. Poor estimates of n_distinct. Fixable by user. > > 2. Poor assumption of homogeneous distribution. No way for user to > fix. Insufficient stats detail to be able to solve in current planner. > > I see (2) as the main source of issues, since as we observe, (1) is fixable. I disagree that (1) is not worth fixing just because we've provided users with an API to override the stats. It would unquestionably be better for us to have a better n_distinct estimate in the first place. Further, this is an easier problem to solve, and fixing n_distinct estimates would fix a large minority of currently pathological queries. It's like saying "hey, we don't need to fix the leak in your radiator, we've given you a funnel in the dashboard you can pour water into." I do agree that (2) is worth fixing *as well*. In a first approximation, one possibility (as Tom suggests) would be to come up with a mathematical model for a selectivity estimate which was somewhere *between* homogenous distribution and the worst case. While that wouldn't solve a lot of cases, it would be a start towards having a better model. >> I don't think correlation is up to the task as a complete solution, although >> it might help a little. There is no way a simple correlation can encode >> that John retired 15 years ago and hasn't logged on since, while Johannes >> was hired yesterday and never logged on before then. > > Ah, OK, essentially the same example. > > Which is why I ruled out correlation stats based approaches and > suggested a risk-weighted cost approach. By "risk-weighted" you mean just adjusting cost estimates based on what the worst case cost looks like, correct? That seemed to be your proposal from an earlier post. If so, we're in violent agreement here. -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance