Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bXS3g-0004SD-GM for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Aug 2016 11:52:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bXS3g-0000Ty-2c for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Aug 2016 11:52:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bXS2I-0007PX-R0 for pgsql-hackers@postgresql.org; Wed, 10 Aug 2016 11:51:02 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bXS2A-0003TJ-JO for pgsql-hackers@postgresql.org; Wed, 10 Aug 2016 11:51:01 +0000 Received: by mail-wm0-x235.google.com with SMTP id o80so98141215wme.1 for ; Wed, 10 Aug 2016 04:50:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=uMNIp4U77vsCEJjKwa2WN7nZtlyr/if3a5BunUzk9p0=; b=JcwHbPAJ0R/3imY1Yx2Bv2DeEgGek+HZoFApjy3gBIFG8IJZt835+z0U5gDVDpxnZz kpyD/uS3/0MXXOk84+9FW8vS6p+6btlsl59k/st8+rt+QLR2LPOUNvj3eKo/OxW1k33Q YRyqwQbJlCF9WEnRSXUujb+mtgCMjoeVdd89NI/7U9UyWCG57+RCEh/18sM2bEoi657W khJHNa2ZEKQXSqHATTUkX9mw6oxKimup5hNNQrPFS5hUhOpGtpw7bd6iCeAUWLGOHQIa 7XI1Jf9sS8DIaMNv5/8IaKo2z1PS/tWHGd9VZtykKOUkLCr1g/0XoXsI50zjB1CGuNsv lvwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=uMNIp4U77vsCEJjKwa2WN7nZtlyr/if3a5BunUzk9p0=; b=YHZKm+jr+d99PMX4KzcZ4p2pJwk4KUzSSpM4Vo81GBZitKZHXUfDn0/Ao8+jfdqzeA 6ArBKgKyGsoapDjVLsm+p04IxxuUYjiCBe/0x+aLq9yi0jiDTZJPXhtw6iQBlLzJaY2D cZoGHfiQpmRTRezBCmjKGC46ZYXROheY5z2v+5EsBx7QIt30stPv5bfyuQibrMZCoPsd nfPw3CQXRbBLPSTIvtHfMAqu6lwK6IXbBPLpdypeLhAihbaRJPNeoyK1Uctrz4TNaERM Af/z39ctcYDyHNIRqTvV8hwuHIWix9FyGLjzu8lbyJ/ULZqhEAsywsyrhaFJGDhNNWUk 2YwA== X-Gm-Message-State: AEkoouvEYKxp/4xaufaZvuArdd32GrJhrO7okI0b3TJftxeqG4kTrsA1xiMM9m/aKWpvIQxMDw1hP5fEg+RPwRJUphIESWNqXfjBdgVHlWuDWq/118wkVv1b1IRBAfoehPX30XSmIlUUHTOMSUjYaNzzHrRApgQfyqRW/NNyFT029aCAKdcy9mCSiBNz4nrYoQ== X-Received: by 10.28.131.199 with SMTP id f190mr2921407wmd.30.1470829851959; Wed, 10 Aug 2016 04:50:51 -0700 (PDT) Received: from [192.168.0.105] (150.123.broadband11.iol.cz. [90.178.123.150]) by smtp.gmail.com with ESMTPSA id k186sm8015059wmd.13.2016.08.10.04.50.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Aug 2016 04:50:51 -0700 (PDT) Subject: Re: multivariate statistics (v19) To: Tomas Vondra , Michael Paquier References: <5d1d62a6-6228-188c-e079-c1be59942168@2ndquadrant.com> <20160409.082146.2151665005996934911.t-ishii@sraoss.co.jp> <77be1e99-4f97-9a0c-64b7-472fa0ba4800@2ndquadrant.com> <20160410.023757.532440443943028713.t-ishii@sraoss.co.jp> <0924a7a9-a219-1366-d3bc-2ddd98bc9269@2ndquadrant.com> Cc: Tatsuo Ishii , Robert Haas , david@pgmasters.net, Tom Lane , Alvaro Herrera , jeff.janes@gmail.com, PostgreSQL mailing lists From: Petr Jelinek Message-ID: <3eb2a4b6-911b-29d9-7280-bbf4837acb05@2ndquadrant.com> Date: Wed, 10 Aug 2016 13:50:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed 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 10/08/16 13:33, Tomas Vondra wrote: > On 08/10/2016 06:41 AM, Michael Paquier wrote: >> On Wed, Aug 3, 2016 at 10:58 AM, Tomas Vondra >>> 2) combining multiple statistics >>> >>> I think the ability to combine multivariate statistics (covering >>> different >>> subsets of conditions) is important and useful, but I'm starting to >>> think >>> that the current implementation may not be the correct one (which is >>> why I >>> haven't written the SGML docs about this part of the patch series yet). >>> >>> Assume there's a table "t" with 3 columns (a, b, c), and that we're >>> estimating query: >>> >>> SELECT * FROM t WHERE a = 1 AND b = 2 AND c = 3 >>> >>> but that we only have two statistics (a,b) and (b,c). The current >>> patch does >>> about this: >>> >>> P(a=1,b=2,c=3) = P(a=1,b=2) * P(c=3|b=2) >>> >>> i.e. it estimates the first two conditions using (a,b), and then >>> estimates >>> (c=3) using (b,c) with "b=2" as a condition. Now, this is very >>> efficient, >>> but it only works as long as the query contains conditions >>> "connecting" the >>> two statistics. So if we remove the "b=2" condition from the query, this >>> stops working. >> >> This is trying to make the algorithm smarter than the user, which is >> something I'd think we could live without. In this case statistics on >> (a,c) or (a,b,c) are missing. And what if the user does not want to >> make use of stats for (a,c) because he only defined (a,b) and (b,c)? >> > > I don't think so. Obviously, if you have statistics covering all the > conditions - great, we can't really do better than that. > > But there's a crucial relation between the number of dimensions of the > statistics and accuracy of the statistics. Let's say you have statistics > on 8 columns, and you split each dimension twice to build a histogram - > that's 256 buckets right there, and we only get ~50% selectivity in each > dimension (the actual histogram building algorithm is more complex, but > you get the idea). > I think it makes sense to pursue this, but I also think we can easily live with not having it in the first version that gets committed and doing it as follow-up patch. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, 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