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 1jB5sO-0002SV-Ob for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2020 00:02:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jB5sN-0004XC-BE for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2020 00:02:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jB5sM-0004X5-Uz for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2020 00:02:31 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jB5sF-0003sS-CD for pgsql-hackers@postgresql.org; Mon, 09 Mar 2020 00:02:29 +0000 Received: by mail-wr1-x42c.google.com with SMTP id v2so8853180wrp.12 for ; Sun, 08 Mar 2020 17:02:23 -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=JD5PMu+INqv/z5r7k/n6sWzDJN1RZZRuw/htUc/oWQY=; b=QShWaxRkQ7FXtQlOGkDKtwIqqNrONXQuile1eNqUpX2rSaler0/s+bS8xGAAQdv+d5 jvKs1LdbRXaIh+l+a97/NRpbOXVq0ZIs9IOOxAc2LOYXIb0iJSFMRbmiZrpQeUFpGRvb n9qBGgdRLpTWX+wJvtsj3TnaR1jkrf6YvMq1sPps1Iv2iokwVMc6arJ2ToqJZQ143juc 83xtOyeO/PtJrz5xbWv22sq43WRU5gx5fal65AnF4thx2QQdj2INk9iUa8kRqcUOJpAl ELweZ1Z9IRU53w+XOlS8kfZXlYKtDMuoEGdtdkkpCCI4ojWJKzw2p4h7+lLvJebSEqkQ 14Wg== 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=JD5PMu+INqv/z5r7k/n6sWzDJN1RZZRuw/htUc/oWQY=; b=DxKNXS0Nty+ZwgpObJeaR5+acZE0jw2ZKMGYqlT2GoaEoon0k43BRe8RRhh3okQjEl UYoM73BNXYSwLHwq14ibhUsXrHCC/HrRx2i1htwbSR9W8n/v4JFJaGyw+/jcD7D6yIIc rBQZpwbZ08jSKVWwPW51WB5cZcMki2+RufluIEf8hVeR0kBwBP76ml6xy75eASIuVGhe iXeapk+rShkTcTe7cHF87ZE1aWlx0osokxeAfgnijFB9WtxGL3PMDIgfMsEqF+C1iG0x n7ow7aVVh7vjUuPkcPbtuuqCkehUcHRlTERcwChJvVlNyamWATqocikQn6y1TtQoV8Oj QwnA== X-Gm-Message-State: ANhLgQ00TH9G87En6QeDAS5SUj2kHcgElGpTEYbDwWKvH0UfW/T7miBZ oR24kf51CJBuREFET4Qx9+4USQ== X-Google-Smtp-Source: ADFU+vuPB28a4UIBAx9X72ZngJ8knMY974hQ/9vKDvu3L95x1Wxd+iy2VecYR/1x5JC6mVV83vwsIg== X-Received: by 2002:adf:ee48:: with SMTP id w8mr16853046wro.290.1583712120796; Sun, 08 Mar 2020 17:02:00 -0700 (PDT) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id a9sm12325927wrv.59.2020.03.08.17.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Mar 2020 17:02:00 -0700 (PDT) Date: Mon, 9 Mar 2020 01:01:57 +0100 From: Tomas Vondra To: Dean Rasheed Cc: PostgreSQL Hackers Subject: Re: Additional improvements to extended statistics Message-ID: <20200309000157.ig5tcrynvaqu4ixd@development> References: <20200113230008.g67iyk4cs3xbnjju@development> <20200306001556.il6altnuqgjxp55z@development> <20200306125800.wln6p5oltgdiqpxy@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 Sun, Mar 08, 2020 at 07:17:10PM +0000, Dean Rasheed wrote: >On Fri, 6 Mar 2020 at 12:58, Tomas Vondra wrote: >> >> Here is a rebased version of this patch series. I've polished the first >> two parts a bit - estimation of OR clauses and (Var op Var) clauses. >> > >Hi, > >I've been looking over the first patch (OR list support). It mostly >looks reasonable to me, except there's a problem with the way >statext_mcv_clauselist_selectivity() combines multiple stat_sel values >into the final result -- in the OR case, it needs to start with sel = >0, and then apply the OR formula to factor in each new estimate. I.e., >this isn't right for an OR list: > > /* Factor the estimate from this MCV to the oveall estimate. */ > sel *= stat_sel; > >(Oh and there's a typo in that comment: s/oveall/overall/). > >For example, with the regression test data, this isn't estimated well: > > SELECT * FROM mcv_lists_multi WHERE a = 0 OR b = 0 OR c = 0 OR d = 0; > >Similarly, if no extended stats can be applied it needs to return 0 >not 1, for example this query on the test data: > > SELECT * FROM mcv_lists WHERE a = 1 OR a = 2 OR d IS NOT NULL; > Ah, right. Thanks for noticing this. Attaches is an updated patch series with parts 0002 and 0003 adding tests demonstrating the issue and then fixing it (both shall be merged to 0001). >It might also be worth adding a couple more regression test cases like these. Agreed, 0002 adds a couple of relevant tests. Incidentally, I've been working on improving test coverage for extended stats over the past few days (it has ~80% lines covered, which is not bad nor great). I haven't submitted that to hackers yet, because it's mostly mechanical and it's would interfere with the two existing threads about extended stats ... Speaking of which, would you take a look at [1]? I think supporting SAOP is fine, but I wonder if you agree with my conclusion we can't really support inclusion @> as explained in [2]. [1] https://www.postgresql.org/message-id/flat/13902317.Eha0YfKkKy@pierred-pdoc [2] https://www.postgresql.org/message-id/20200202184134.swoqkqlqorqolrqv%40development regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services