Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZKvPG-0000c0-8G for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Jul 2015 21:30:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZKvPF-0005ej-Kg for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Jul 2015 21:30:25 +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) (envelope-from ) id 1ZKvNw-0003es-De for pgsql-hackers@postgresql.org; Thu, 30 Jul 2015 21:29:04 +0000 Received: from mail-wi0-f181.google.com ([209.85.212.181]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZKvNo-0002IA-Qm for pgsql-hackers@postgresql.org; Thu, 30 Jul 2015 21:29:03 +0000 Received: by wibud3 with SMTP id ud3so36156809wib.1 for ; Thu, 30 Jul 2015 14:28:55 -0700 (PDT) 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:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=DsXRHl1s+LjvaPj+bi+/3QXwBuDSRzjiXvwIUfsNJ24=; b=HqZcMUrLtkZXbp3fBDlcorz4Iv8PENm35WZ44MhC9wRzyKwaxegEegp6i4ikyONl1u xMMrbRukX8fPb2u+Fx1DQXDsdPwKQy6GtF0Y16QBuonqLcw/nliPIUv4hB/GqFv6TyDQ svGsKD8n1MAkncqSUTfHF983JYApzJarPhUisSi+a/cnD1bm3SHgi611UWfEc4hnJK8t VU3Wrblxi2ryipFOdx9FmDp1xWyifXvuM/mn30wfvT1f6u/zAVRxI373bbnrtdH4/wqu VsKQFDoepgwk1kcduUJBxm7lZq+iq5m6wGVkpQe5zrATgFeMV6aIKV5YQJ2NOsbFIQUd fJaQ== X-Gm-Message-State: ALoCoQntkQ8oC2e4O5Y7pcZJgDFTqz4FpG7uWFeP+SmOckV+9mH0I8kB7Ssbhu2tOc7nQI4MgVYB X-Received: by 10.180.219.41 with SMTP id pl9mr325230wic.30.1438291735085; Thu, 30 Jul 2015 14:28:55 -0700 (PDT) Received: from [10.137.2.12] (ip-78-45-136-74.net.upcbroadband.cz. [78.45.136.74]) by smtp.gmail.com with ESMTPSA id lg6sm3786516wjb.10.2015.07.30.14.28.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jul 2015 14:28:54 -0700 (PDT) Message-ID: <55BA9712.9090608@2ndquadrant.com> Date: Thu, 30 Jul 2015 23:28:50 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Heikki Linnakangas , pgsql-hackers CC: Jeff Janes , Stephen Frost , Kyotaro HORIGUCHI Subject: Re: multivariate statistics / patch v7 References: <54C3FED3.1060600@2ndquadrant.com> <20150320.173307.249113775.horiguchi.kyotaro@lab.ntt.co.jp> <550C8E50.2010600@2ndquadrant.com> <20150324.143427.34552953.horiguchi.kyotaro@lab.ntt.co.jp> <5519E9B2.5080105@2ndquadrant.com> <20150428161310.GR30322@tamriel.snowman.net> <553FCE56.2000008@2ndquadrant.com> <554A73A6.2060603@2ndquadrant.com> <55638982.40904@2ndquadrant.com> <55B9DEA6.6030603@iki.fi> <55BA1ED6.4090302@2ndquadrant.com> <55BA57BF.7090901@iki.fi> In-Reply-To: <55BA57BF.7090901@iki.fi> 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 Hi, On 07/30/2015 06:58 PM, Heikki Linnakangas wrote: > > The problem with a threshold is that around that threshold, even a > small change in the data set can drastically change the produced > estimates. For example, imagine that we know from the stats that zip > code implies city. But then someone adds a single row to the table > with an odd zip code & city combination, which pushes the estimator > over the threshold, and the columns are no longer considered > dependent, and the estimates are now completely different. We should > avoid steep cliffs like that. > > BTW, what is the threshold in the current patch? There's not a simple threshold - the algorithm mining the functional dependencies is a bit more complicated. I tried to explain it in the comment before build_mv_dependencies (in dependencies.c), but let me briefly summarize it here. To mine dependency [A => B], build_mv_dependencies does this: (1) sort the sample by {A,B} (2) split the sample into groups with the same value of A (3) for each group, decide if it's consistent with the dependency (a) if the group is too small (less than 3 rows), ignore it (a) if the group is consistent, update n_supporting n_supporting_rows (b) if the group is inconsistent, update n_contradicting n_contradicting_rows (4) decide whether the dependency is "valid" by checking n_supporting_rows >= n_contradicting_rows * 10 The limit is rather arbitrary and yes - I can imagine a more complex condition (e.g. looking at average number of tuples per group etc.), but I haven't looked into that - the point was to use something very simple, only to illustrate the infrastructure. I think we might come up with some elaborate way of associating "degree" with the functional dependency, but at that point we really loose the simplicity, and also make it indistinguishable from the remaining statistics (because it won't be possible to reduce the clauses like this, before performing the regular estimation). Which is exactly what makes the functional dependencies so neat and efficient, so I'm not overly enthusiastic about doing that. What seems more interesting is implementing the ndistinct coefficient instead, as proposed by Kyotaro-san - that seems to have the nice "smooth" behavior you desire, while keeping the simplicity. Both statistics types (functional dependencies and ndistinct coeff) have one weak point, though - they somehow assume the queries use "compatible" values. For example if you use a query with WHERE city = 'New York' AND zip = 'zip for Detroit' they can't detect cases like this, because those statistics types are oblivious to individual values. I don't see this as a fatal flaw, though - it's rather a consequence of the nature of the stats. And I tend to look at the functional dependencies the same way. If you need stats without these "issues" you'll have to use MCV list or a histogram. Trying to fix the simple statistics types is futile, IMHO. regards Tomas -- 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