Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XZgua-0000Wh-9s for pgsql-performance@arkaria.postgresql.org; Thu, 02 Oct 2014 13:59:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XZguZ-0008ES-P5 for pgsql-performance@arkaria.postgresql.org; Thu, 02 Oct 2014 13:59:15 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XZguX-0008Bb-W2 for pgsql-performance@postgresql.org; Thu, 02 Oct 2014 13:59:14 +0000 Received: from bureau83.ns.utoronto.ca ([128.100.132.183]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XZguU-0003RK-RP for pgsql-performance@postgresql.org; Thu, 02 Oct 2014 13:59:12 +0000 Received: from [192.168.1.8] (c-174-52-129-56.hsd1.ut.comcast.net [174.52.129.56]) (authenticated bits=0) by bureau83.ns.utoronto.ca (8.13.8/8.13.8) with ESMTP id s92Dx63C019644 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 2 Oct 2014 09:59:08 -0400 Message-ID: <542D5A24.1080308@cs.utoronto.ca> Date: Thu, 02 Oct 2014 07:59:00 -0600 From: Ryan Johnson User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: pgsql-performance@postgresql.org 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> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -4.4 (----) 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 29/09/2014 9:00 AM, Merlin Moncure wrote: > On Fri, Sep 26, 2014 at 3:06 AM, Simon Riggs wrote: >> The problem, as I see it, is different. We assume that if there are >> 100 distinct values and you use LIMIT 1 that you would only need to >> scan 1% of rows. We assume that the data is arranged in the table in a >> very homogenous layout. When data is not, and it seldom is, we get >> problems. > Hm, good point -- 'data proximity'. At least in theory, can't this be > measured and quantified? For example, given a number of distinct > values, you could estimate the % of pages read (or maybe non > sequential seeks relative to the number of pages) you'd need to read > all instances of a particular value in the average (or perhaps the > worst) case. One way of trying to calculate that would be to look at > proximity of values in sampled pages (and maybe a penalty assigned for > high update activity relative to table size). Data proximity would > then become a cost coefficient to the benefits of LIMIT. Latecomer to the conversation here, but it seems like this issue (unlike some) is really easy to recognize at runtime. The optimizer assumed the scan would access O(1) pages; if the scan has not returned enough results after k pages, that would be a really good indication that it's time to rethink the plan, and probably before too much work has been done higher in the plan (esp. if there's any kind of buffering between operators, perhaps intentionally so in special cases like this) Not sure pgsql has any dynamic reoptimization infrastructure in place, tho. If not, these sorts of dangerous plans are best left alone IMO. Ryan -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance