Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XaCUA-000180-ET for pgsql-performance@arkaria.postgresql.org; Fri, 03 Oct 2014 23:42:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XaCU9-0005KC-Ua for pgsql-performance@arkaria.postgresql.org; Fri, 03 Oct 2014 23:42:05 +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 1XaCU9-0005K2-50 for pgsql-performance@postgresql.org; Fri, 03 Oct 2014 23:42:05 +0000 Received: from smtp-out1.gransy.com ([77.78.126.51]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XaCU5-0007FT-Fz for pgsql-performance@postgresql.org; Fri, 03 Oct 2014 23:42:03 +0000 Received: from smtp-out.gransy.com (localhost [127.0.0.1]) by smtp-out1.gransy.com (Postfix) with ESMTP id 51AE2360039 for ; Sat, 4 Oct 2014 01:41:51 +0200 (CEST) Received: from smtp.gransy.com (smtp.simplia.cz [77.78.126.20]) by smtp-out1.gransy.com (Postfix) with ESMTP id 0B830360038 for ; Sat, 4 Oct 2014 01:41:51 +0200 (CEST) Received: from [192.168.1.163] (ip-78-45-139-138.net.upcbroadband.cz [78.45.139.138]) (Authenticated sender: tv@fuzzy.cz) by smtp.gransy.com (Postfix) with ESMTPSA id 81F0419A035E for ; Sat, 4 Oct 2014 01:41:50 +0200 (CEST) Message-ID: <542F343E.40906@fuzzy.cz> Date: Sat, 04 Oct 2014 01:41:50 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 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> <5420B71C.6010208@agliodbs.com> <5429D517.3090900@agliodbs.com> <542C4E60.3030505@agliodbs.com> <542DADEB.2080103@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 3.10.2014 02:54, Peter Geoghegan wrote: > On Thu, Oct 2, 2014 at 12:56 PM, Josh Berkus wrote: >> Yes, it's only intractable if you're wedded to the idea of a tiny, >> fixed-size sample. If we're allowed to sample, say, 1% of the >> table, we can get a MUCH more accurate n_distinct estimate using >> multiple algorithms, of which HLL is one. While n_distinct will >> still have some variance, it'll be over a much smaller range. > > I think that HyperLogLog, as a streaming algorithm, will always > require that the entire set be streamed. This doesn't need to be a > big deal - in the case of my abbreviated key patch, it appears to > basically be free because of the fact that we were streaming > everything anyway. It's a very cool algorithm, with fixed overhead > and constant memory usage. It makes very useful guarantees around > accuracy. I think you're mixing two things here - estimating the number of distinct values in a sample (which can be done very efficiently using HLL) and estimating the number of distinct values in the whole table. For that HLL is not usable, unless you process all the data. Sadly HLL is rather incompatible with the usual estimators, because the ones I'm aware of need to know the number of occurences for the distinct values etc. But couldn't we just piggyback this on autovacuum? One of the nice HLL features is that it's additive - you can build "partial counters" for ranges of blocks (say, a few MBs per range), and then merge them when needed. By keeping the parts it's possible to rebuild it separately. But maybe this idea is way too crazy ... regards Tomas -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance