Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YOHTz-0002Pf-8X for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2015 03:08:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YOHTy-0004iY-O6 for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2015 03:08:54 +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 1YOHTx-0004iC-H6 for pgsql-hackers@postgresql.org; Thu, 19 Feb 2015 03:08:53 +0000 Received: from mail-wi0-f173.google.com ([209.85.212.173]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YOHTt-0008Ro-I8 for pgsql-hackers@postgresql.org; Thu, 19 Feb 2015 03:08:51 +0000 Received: by mail-wi0-f173.google.com with SMTP id bs8so45230287wib.0 for ; Wed, 18 Feb 2015 19:08:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:organization:user-agent :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=V3+k3IIFn6wO5CB1bUD+C4OEK7VkdXOrKQlm/FkyzrA=; b=kjGO+CffwthOMgcP6HDJpLJahnMN3VWZCgVi1jonhmN45gO5cEDUttXPxdLo20Rze/ v44FDe12SQESEk1KNVPa2yuYgVI2v0pYm0nuHD5ToEsi9fuDfFMUTHprbiyIX3F4Sr8Z ZlMTBtfeqSKxGUBt+XjX01yTQGOc54Hc9h9vGN7OW8zkrT+/sl9bT2diIYL4HT5TPAN9 CV0oWa8PPyBUOiB8N049ynZFsPffDkNxCn6rBtR8au+0JrfuJJRvt4V6HKWuWZoOa0oQ vm1GUFzLFAkfHoXgCXheXN3igqFr4jbfwR14aIpev8px3oxod2Hx4ZeA6eoCGc4CLe3U XNfw== X-Gm-Message-State: ALoCoQm6FwaDzQHr7J+P0dcWkaN474i3aLvIsWum04TJZB6ZX267oj9dBpq7/0dQDJ4Pw3kDUfF/Lt0HcrDtVi6YIothpJuCrlGHn/dTRVag73yBcRqgnsQN78StD0eUpl702omrNz1voAuUbjCKexVIgDejbY7LGpC5bNI3jOCnG3lggcn7zdyIN0/N9mLma3qpV8LfHZG1 X-Received: by 10.180.87.33 with SMTP id u1mr6109430wiz.20.1424315327486; Wed, 18 Feb 2015 19:08:47 -0800 (PST) Received: from [192.168.1.163] (ip-78-45-139-138.net.upcbroadband.cz. [78.45.139.138]) by mx.google.com with ESMTPSA id df8sm28187479wib.2.2015.02.18.19.08.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Feb 2015 19:08:46 -0800 (PST) Message-ID: <54E553B1.6030601@2ndquadrant.com> Date: Thu, 19 Feb 2015 04:08:33 +0100 From: Tomas Vondra Organization: 2ndQuadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: pgsql-hackers@postgresql.org Subject: Re: PATCH: adaptive ndistinct estimator v3 (WAS: Re: [PERFORM] Yet another abort-early plan disaster on 9.3) References: <541A2335.3060100@agliodbs.com> <5429D517.3090900@agliodbs.com> <542C4E60.3030505@agliodbs.com> <542DADEB.2080103@agliodbs.com> <54381D20.9010501@fuzzy.cz> <5472416C.3080506@fuzzy.cz> <5483B346.6000203@fuzzy.cz> <549943DA.4090603@vmware.com> In-Reply-To: <549943DA.4090603@vmware.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 23.12.2014 11:28, Heikki Linnakangas wrote: > On 12/07/2014 03:54 AM, Tomas Vondra wrote: >> The one interesting case is the 'step skew' with statistics_target=10, >> i.e. estimates based on mere 3000 rows. In that case, the adaptive >> estimator significantly overestimates: >> >> values current adaptive >> ------------------------------ >> 106 99 107 >> 106 8 6449190 >> 1006 38 6449190 >> 10006 327 42441 >> >> I don't know why I didn't get these errors in the previous runs, because >> when I repeat the tests with the old patches I get similar results with >> a 'good' result from time to time. Apparently I had a lucky day back >> then :-/ >> >> I've been messing with the code for a few hours, and I haven't >> found any significant error in the implementation, so it seems that >> the estimator does not perform terribly well for very small samples >> (in this case it's 3000 rows out of 10.000.000 (i.e. ~0.03%). > > The paper [1] gives an equation for an upper bound of the error of this > GEE estimator. How do the above numbers compare with that bound? Well, that's a bit more complicated because the "Theorem 1" you mention does not directly specify upper boundary for a single estimate. It's formulated like this: Assume table with "N" rows, D distinct values and sample of "r" rows (all those values are fixed). Then there exists a dataset with those features, so that "ratio error" error(D, D') = max(D'/D, D/D') is greater than f(N, r, P) with probability at least "P". I.e. if you randomly choose a sample of 'r' rows, you'll get an error exceeding the ratio with probability P. So it's not not a hard limit, but speaks about probability of estimation error with some (unknown) dataset dataset. So it describes what you can achieve at best - if you think your estimator is better, there'll always be a dataset hiding in the shadows hissing "Theorem 1". Let's say we're looking for boundary that's crossed only in 1% (or 5%) of measurements. Applying this to the sample data I posted before, i.e. 10M rows with three sample sizes 'r' (3000, 30.000 and 300.000 rows), the ratio error boundary per the the paper is 3.000 30.000 300.000 ---------------------------------------- 1% 88 28 9 5% 70 22 7 At least that's what I get if I compute it using this python function: def err(N, r, p): return sqrt((N-r)/(2.0*r) * log(1.0/p)) So the estimates I posted before are not terribly good, I guess, especially the ones returning 6449190. I wonder whether there really is some stupid bug in the implementation. regards -- Tomas Vondra http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers