Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMbWA-0004I9-3v for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Mar 2021 19:07:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lMbW8-0006vu-Vy for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Mar 2021 19:07:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMbW8-0006vn-P4 for pgsql-hackers@lists.postgresql.org; Wed, 17 Mar 2021 19:07:40 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lMbVv-0007NB-3t for pgsql-hackers@postgresql.org; Wed, 17 Mar 2021 19:07:39 +0000 Received: by mail-ej1-x632.google.com with SMTP id k10so98490ejg.0 for ; Wed, 17 Mar 2021 12:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=MyhLZbjFMY7mf0mxbF/WiysN41ivxHNDRa71oN3N0Ek=; b=FoEJ6KwKPrlc58OdfGmSrLra563XD7eb48UQW9mE9usCfHWW0Nj0E6jmdTj6Zcss9O iLX1ZQ5qOjFKjy2zfIObJNoxJVef/WN8sLURtlTVQLYEyeMZmeJhdeArpaoGvc1XLrLs Wh+/47ueU8tx4oKnGIVLLeWdLzbfb0bQdNlf4rF+FmIB4Wkk0nNpBhg0y88hdorQyN4h eMmbND+kKRuqHenF7rR8bdaV6WHbVUDyGOZquuoDF5RhapFp9m4kdlqhP8hCFbyw9hdf rP7uddWKKbGloc0CY/kc4qnSYtp8/4eta/BfTvpCHZlIJ/dSkJQmAyQmamgrDKCz79gA c1YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=MyhLZbjFMY7mf0mxbF/WiysN41ivxHNDRa71oN3N0Ek=; b=sAwSti/dSEpM2nVRLHjTr4keKyD4HJ8N7UGF+8zwQiXeBhOtXoaF0jqHvu8X+kXgeg +KKcL58Sp22WCbEXQqs5Fj8mpJ6Fy8XfIZY+NFvpJHFhwfMSBt93TBwX394Dsc/VKvEj FCHhePBp7I05DpJDeOY2VBe4M/Vp7UXbtoMwR8cT7eQ7/E99s1gS+QO2mliWfrNe5hW6 myN8FP0uTinu3YETBWPCuPaf4OfYpM+NC4sp6d3vRkv+HvXBvjjlbaIT4SAegzwCHQ/D kKy49ySrDa8JEDXhX8uoXZLKsOuF9UEKaTJaF5gjxJrW87pcIYBmLR10mAkHlD1JYQMQ S55g== X-Gm-Message-State: AOAM530YemeHKuWHnAYHm2tlyuav/ndn6awCiMGW5p3csMUB3kpxP27z 94rHj4UWedFlAEOLYzpKc0vAwqeM50MmZRbtdnHXITVUFP5m0l4lwU9+fWspBurRryqdWZ51Wmr dD/lsFcPm/GnCtiWCDYNqUZQISBf/asviYL6BJ5rTT7qlr8BQA8a5K/w040l7Wor1TCg0Kc4jNh kq41ySD7E37I4qw2In2GjwOKmb5dMrzWLPtW+0U60qhwAwEFwj20z05+ecLeaCR6d3oTbDMWyhO 2jhA7QjaLNGDnJw2vQ83WjeYNiD0b7b1ZdwGg== X-Google-Smtp-Source: ABdhPJy6I94vsJ3NTD6S/qlP1IXSGkJznnWhFCNzjx5PHQFWGIvR7AHZZqz1VYa4bNa+ixr4V+t4qA== X-Received: by 2002:a17:906:b2d6:: with SMTP id cf22mr36891202ejb.321.1616008044150; Wed, 17 Mar 2021 12:07:24 -0700 (PDT) Received: from [10.137.0.20] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id z9sm14243425edr.75.2021.03.17.12.07.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Mar 2021 12:07:23 -0700 (PDT) Subject: Re: PoC/WIP: Extended statistics on expressions To: Dean Rasheed Cc: Justin Pryzby , PostgreSQL Hackers References: <20210108023537.GA19743@telsasoft.com> <20210118045331.GF8560@telsasoft.com> <3f20da4d-89dc-0912-98d2-b6f0ef06c87f@enterprisedb.com> <20210122022958.GC27167@telsasoft.com> <2147e075-fef6-b1d5-e5f5-7f92ffefe827@enterprisedb.com> <1913c1fe-13da-7250-adf4-befeda397536@enterprisedb.com> From: Tomas Vondra Message-ID: Date: Wed, 17 Mar 2021 20:07:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/17/21 7:54 PM, Dean Rasheed wrote: > On Wed, 17 Mar 2021 at 17:26, Tomas Vondra > wrote: >> >> My concern is that the current behavior (where we prefer expression >> stats over multi-column stats to some extent) works fine as long as the >> parts are independent, but once there's dependency it's probably more >> likely to produce underestimates. I think underestimates for grouping >> estimates were a risk in the past, so let's not make that worse. >> > > I'm not sure the current behaviour really is preferring expression > stats over multi-column stats. In this example, where we're grouping > by (a+b), (c+d) and have stats on [(a+b),c] and (c+d), neither of > those multi-column stats actually match more than one > column/expression. If anything, I'd go the other way and say that it > was wrong to use the [(a+b),c] stats in the first case, where they > were the only stats available, since those stats aren't really > applicable to (c+d), which probably ought to be treated as > independent. IOW, it might have been better to estimate the first case > as > > ndistinct((a+b)) * ndistinct(c) * ndistinct(d) > > and the second case as > > ndistinct((a+b)) * ndistinct((c+d)) > OK. I might be confused, but isn't that what the algorithm currently does? Or am I just confused about what the first/second case refers to? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company