Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xz70O-0003ct-Qf for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Dec 2014 16:54:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xz70O-0000V0-B5 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Dec 2014 16:54:20 +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 1Xz70N-0000Uh-Bi for pgsql-hackers@postgresql.org; Thu, 11 Dec 2014 16:54:19 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xz70J-0006BT-VC for pgsql-hackers@postgresql.org; Thu, 11 Dec 2014 16:54:17 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id E66B0289CC; Thu, 11 Dec 2014 08:54:12 -0800 (PST) Received: from EX13-CAS-008.vmware.com (EX13-CAS-008.vmware.com [10.113.191.58]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id E152918E1B; Thu, 11 Dec 2014 08:54:12 -0800 (PST) Received: from EX13-MBX-024.vmware.com (10.113.191.44) by EX13-MBX-010.vmware.com (10.113.191.30) with Microsoft SMTP Server (TLS) id 15.0.913.22; Thu, 11 Dec 2014 08:55:25 -0800 Received: from [192.168.1.90] (10.113.160.246) by EX13-MBX-024.vmware.com (10.113.191.44) with Microsoft SMTP Server (TLS) id 15.0.913.22; Thu, 11 Dec 2014 08:54:11 -0800 Message-ID: <5489CC1F.70401@vmware.com> Date: Thu, 11 Dec 2014 18:53:51 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 MIME-Version: 1.0 To: Tomas Vondra , Subject: Re: WIP: multivariate statistics / proof of concept References: <543AFA15.4080608@fuzzy.cz> In-Reply-To: <543AFA15.4080608@fuzzy.cz> Content-Type: text/plain; charset="iso-8859-2"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.113.160.246] X-ClientProxiedBy: EX13-CAS-013.vmware.com (10.113.191.65) To EX13-MBX-024.vmware.com (10.113.191.44) X-Pg-Spam-Score: -6.9 (------) 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 10/13/2014 01:00 AM, Tomas Vondra wrote: > Hi, > > attached is a WIP patch implementing multivariate statistics. Great! Really glad to see you working on this. > + * FIXME This sample sizing is mostly OK when computing stats for > + * individual columns, but when computing multi-variate stats > + * for multivariate stats (histograms, mcv, ...) it's rather > + * insufficient. For small number of dimensions it works, but > + * for complex stats it'd be nice use sample proportional to > + * the table (say, 0.5% - 1%) instead of a fixed size. I don't think a fraction of the table is appropriate. As long as the sample is random, the accuracy of a sample doesn't depend much on the size of the population. For example, if you sample 1,000 rows from a table with 100,000 rows, or 1000 rows from a table with 100,000,000 rows, the accuracy is pretty much the same. That doesn't change when you go from a single variable to multiple variables. You do need a bigger sample with multiple variables, however. My gut feeling is that if you sample N rows for a single variable, with two variables you need to sample N^2 rows to get the same accuracy. But it's not proportional to the table size. (I have no proof for that, but I'm sure there is literature on this.) > + * Multivariate histograms > + * > + * Histograms are a collection of buckets, represented by n-dimensional > + * rectangles. Each rectangle is delimited by an array of lower and > + * upper boundaries, so that for for the i-th attribute > + * > + * min[i] <= value[i] <= max[i] > + * > + * Each bucket tracks frequency (fraction of tuples it contains), > + * information about the inequalities, number of distinct values in > + * each dimension (which is used when building the histogram) etc. > + * > + * The boundaries may be either inclusive or exclusive, or the whole > + * dimension may be NULL. > + * > + * The buckets may overlap (assuming the build algorithm keeps the > + * frequencies additive) or may not cover the whole space (i.e. allow > + * gaps). This entirely depends on the algorithm used to build the > + * histogram. That sounds pretty exotic. These buckets are quite different from the single-dimension buckets we currently have. The paper you reference in partition_bucket() function, M. Muralikrishna, David J. DeWitt: Equi-Depth Histograms For Estimating Selectivity Factors For Multi-Dimensional Queries. SIGMOD Conference 1988: 28-36, actually doesn't mention overlapping buckets at all. I haven't read the code in detail, but if it implements the algorithm from that paper, there will be no overlap. - Heikki -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers