Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jCRfh-0005cK-Gm for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2020 17:31:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jCRfg-0003D7-70 for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2020 17:31:00 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1jCRff-0003D0-R3 for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2020 17:30:59 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jCRfX-0000Dn-H8 for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2020 17:30:58 +0000 Received: by mail-wr1-x444.google.com with SMTP id m9so8525452wro.12 for ; Thu, 12 Mar 2020 10:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=co5GWlt6nX/Hn2nXgmU3bI0e5Ik8oMqWN6+O32pZqB8=; b=t4Z7r4vgpr/4+J87foJNmCDssQzWlKgUc5UCSBqrnbxLVt2kK+AfMeIv647qAO5xRs t1lPGo5WE1U9r7ASAol90l4zEbfjjYwLtPqed4wefuklSxdsVH3HlzsTYoyIvavRw3Mz yhEZQsEfyVI9LvfVLP8PtEZSo1mFOndiK0YLtoStK/kDYNCLvJZypNDOo+lyMHM/zZSI g8apmMPfsRJVvm0tiypskBMRyqw2enrWFccbSB46fO0ep14xIHZ6j1Amdl/74dDQBt+y BbGL6MA9PLswrCc+ZywlNVbJTqhZvpVGJBh/f/IxAa3MQuBQsMksmTzyk+P0ORHCuX8p EQCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=co5GWlt6nX/Hn2nXgmU3bI0e5Ik8oMqWN6+O32pZqB8=; b=odbWJVUjVAfHEcUK/rjWDgEtFoikKmI8a80OraG+8gJH0+OevgKneCViIdi/xzJ5Ro 3hijrZunm0ISzjWRH/KaT6UGyicUqsYEvCEasuFSJ8EvAQ4btMpue7sg8Zgzg5JavI1N iy8EYltzk4cdF3ZzBvLmZXIyml5j3dpDMvcKONaJW9qw5cYRf3s+Yxxnpga59NZCqhy1 ueuGop3vGnWOF9xewrAbdYX2NtcQZ0c9L9vql8ur59/Z0tcA5wgleQ8HnuI7TapluExL YKPKh8Wc1Mpd341m3Ol2c4jajXzmeWmu28N2IezR6mmpM6WuOID43AXOHnb4nZzf+Umy 5qkg== X-Gm-Message-State: ANhLgQ02F/AskPcaclTu02l/jHAZzgyx/NhSMI5Mu8E51Xr1P+pVmvZ5 8/qiK4Vj0AZe6YgtA9LKBswzJw== X-Google-Smtp-Source: ADFU+vtyefo8d097bm0k6AIvnB/3mwR+erbnFbqm+25KCliHbDkMQtfz92hPo+24hS4QdcB+znxlSA== X-Received: by 2002:adf:e50d:: with SMTP id j13mr12088533wrm.34.1584034250329; Thu, 12 Mar 2020 10:30:50 -0700 (PDT) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id b5sm4611691wrw.86.2020.03.12.10.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 10:30:49 -0700 (PDT) Date: Thu, 12 Mar 2020 18:30:47 +0100 From: Tomas Vondra To: Dean Rasheed Cc: Pierre Ducroquet , PostgreSQL Hackers Subject: Re: PATCH: add support for IN and @> in functional-dependency statistics use Message-ID: <20200312173047.stp55sxoj4sipn7q@development> References: <13902317.Eha0YfKkKy@pierred-pdoc> <20200201142446.aq5zf3gawj3ynrc2@development> <3937607.jCdSCb7NGl@pierred-pdoc> <20200202184134.swoqkqlqorqolrqv@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Mar 12, 2020 at 10:25:41AM +0000, Dean Rasheed wrote: >[ For the sake of the archives, some of the discussion on the other >thread [1-3] should really have been on this thread. ] > >On Sun, 2 Feb 2020 at 18:41, Tomas Vondra wrote: >> >> I think the challenge here is in applying the functional dependency >> computed for the whole array to individual elements. I'm not sure we can >> do that. >> >> For example, with a table like this: >> >> CREATE TABLE t (a int, b int[]); >> CREATE STATISTICS s (dependencies) ON a, b FROM t; >> >> Let's say the functional dependency is "perfect" i.e. has strength 1.0. >> But that only tells us dependency for complete array values, we don't >> know how much information we gain by knowledge of subset of the values. >> > >The more I think about this example, the more I think this is really >just a special case of the more general problem of compatibility of >clauses. Once you add support for IN (...) clauses, any query of the >form > > SELECT ... WHERE (any clauses on col a) AND (any clauses on col b) > >can be recast as > > SELECT ... WHERE a IN (...) AND b IN (...) > >so any counter-example with bad estimates produced with a query in the >first form can also be written in the second form. > >I think we should really be thinking in terms of making a strong >functional dependency (a => b) applicable generally to queries in the >first form, which will work well if the clauses on b are compatible >with those on b, but not if they're incompatible. However, that's not >so very different from the current state without extended stats, which >assumes independence, and will return poor estimates if the >columns/clauses aren't independent. > I'm sorry, but I don't see how we could do this for arbitrary clauses. I think we could do that for clauses that have equality semantics and reference column values as a whole. So I think it's possible to do this for IN clauses (which is what the first part of the patch does), but I don't think we can do it for the containment operator. I.e. we can do that for WHERE a IN (...) AND b IN (...) but I don't see how we could do that for WHERE a @> (...) AND b @> (...) I don't think the dependency degree gives us any reliable insight into statistical dependency of elements of the values. Or maybe we're just talking about different things? You seem to be talking abotu IN clauses (which I think is doable), but my question was about using functional dependencies to estimate array containment clauses (which I think is not really doable). >So I'd be tempted to apply a tidied up version of the patch from [3], >and then lift all restrictions from dependency_is_compatible_clause(), >other than the requirement that the clause refer to a single variable. > I haven't looked at the patch from [3] closely yet, but you're right P(A & B) <= Min(P(A), P(B)) and the approach you proposed seems reasonable. I don't think how we can just remove all the restriction on clause type - the restriction that dependencies only handle equality-like clauses seems pretty much baked into the dependencies. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services