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 1mFRUq-00030X-Kv for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Aug 2021 01:33:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mFRUp-0007G3-K6 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Aug 2021 01:32:59 +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 1mFRUp-0007Fv-CM for pgsql-hackers@lists.postgresql.org; Mon, 16 Aug 2021 01:32:59 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mFRUn-0004Yr-AG for pgsql-hackers@postgresql.org; Mon, 16 Aug 2021 01:32:58 +0000 Received: by mail-io1-xd32.google.com with SMTP id i7so20996883iow.1 for ; Sun, 15 Aug 2021 18:32:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GJGPDA4IxdxE8I72S+KVlXackiud4tD52Xvosmd5pU0=; b=hgTdzZPnxrC5viqBevn9ZXyaIyNKg4zfNKSjn85XTFfjyZbHDNiLHPdjMarOuuK/wR h8/CFtUwasCp+gdYQk/Bqp6YJBt++7jaVdHHwMugxIh44h8HRlo0Tpz7Z+hEcH/6+w1e 1NjkKi1i0vKwp2iEP/Yb9+CqHGjEW/LKX9me8ayoL6sobW7beCTnWJtg/hSW013q0yTC 7Mrwuc4mkoAl+2WY/qChvhnLEBsXtfiRr+l01cSUYRJu/NG4PZzUiNZkE9AsgAzVkh9O vjZ7cpJOrOUlcWY+hJYwecdGsLiD9ALFmTMHtdb0W0TXlx0Bow/EduEXDWkMOZ1KhyoU pQkw== 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:user-agent; bh=GJGPDA4IxdxE8I72S+KVlXackiud4tD52Xvosmd5pU0=; b=nAfVh8JZXoICFgK+cD/bqZvr6v61I9kfukJpdNhzlnUmuQMpYkQXUm/LnStZDebO50 Q6Hy1NtozBDvo1mPyq+OarsUtHjVW+9iLsWl6pDAyeoh8iKlclGAEdEUgJIze+bh7ZA2 HdL9GxSTnJYU0tgr+6pl9kSP9vTqlLyogR7rQjrbsbWHtCo64OoNaygK4Z7xBme0P55d deJvgOuipZ0BFdwFkvI6g0cjbvwvqY2jiKZ7fVqZ9aHfTMjrFk2lxc4icX3WcTUuUjgD 2JEcTpgYYAcdmfnllK6rpmBhZ2eATmd2LEKl1YjKV8e8Kx4jfHfaIAk/m0rrrIheue01 k5JA== X-Gm-Message-State: AOAM5304wRwO6AWVCfsf2nOAwR5cT/zZjLipG5FfDXCDXvKgEeAIaRz8 q2H7KQBzTPabw54bLvXKrtZ4hg== X-Google-Smtp-Source: ABdhPJwlQdvdiJtROcEM2dys38aOHgwbtc8brOTNzuMthHkOhIg5SodFnYpHYLOtsoqEpEZewD+2fg== X-Received: by 2002:a5d:928c:: with SMTP id s12mr10719816iom.151.1629077576699; Sun, 15 Aug 2021 18:32:56 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id r8sm4742039iov.39.2021.08.15.18.32.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Aug 2021 18:32:56 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 66708800A3C; Sun, 15 Aug 2021 20:32:55 -0500 (CDT) Date: Sun, 15 Aug 2021 20:32:55 -0500 From: Justin Pryzby To: Tomas Vondra Cc: Dean Rasheed , pgsql-hackers Subject: Re: PoC/WIP: Extended statistics on expressions Message-ID: <20210816013255.GS10479@telsasoft.com> References: <3fbbd68b-0b52-cb5a-d468-7e7280c33e6c@enterprisedb.com> <4654037b-8df8-77fb-2981-67be93aebdf1@enterprisedb.com> <20201123022604.GD24052@telsasoft.com> <6455e0ad-2a2e-bdb0-e1f8-fd4983d1c8aa@enterprisedb.com> <087086de-1384-8374-4efc-2e7915071d5c@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Dec 07, 2020 at 03:15:17PM +0100, Tomas Vondra wrote: > > Looking at the current behaviour, there are a couple of things that > > seem a little odd, even though they are understandable. For example, > > the fact that > > > > CREATE STATISTICS s (expressions) ON (expr), col FROM tbl; > > > > fails, but > > > > CREATE STATISTICS s (expressions, mcv) ON (expr), col FROM tbl; > > > > succeeds and creates both "expressions" and "mcv" statistics. Also, the syntax > > > > CREATE STATISTICS s (expressions) ON (expr1), (expr2) FROM tbl; > > > > tends to suggest that it's going to create statistics on the pair of > > expressions, describing their correlation, when actually it builds 2 > > independent statistics. Also, this error text isn't entirely accurate: > > > > CREATE STATISTICS s ON col FROM tbl; > > ERROR: extended statistics require at least 2 columns > > > > because extended statistics don't always require 2 columns, they can > > also just have an expression, or multiple expressions and 0 or 1 > > columns. > > > > I think a lot of this stems from treating "expressions" in the same > > way as the other (multi-column) stats kinds, and it might actually be > > neater to have separate documented syntaxes for single- and > > multi-column statistics: > > > > CREATE STATISTICS [ IF NOT EXISTS ] statistics_name > > ON (expression) > > FROM table_name > > > > CREATE STATISTICS [ IF NOT EXISTS ] statistics_name > > [ ( statistics_kind [, ... ] ) ] > > ON { column_name | (expression) } , { column_name | (expression) } [, ...] > > FROM table_name > > > > The first syntax would create single-column stats, and wouldn't accept > > a statistics_kind argument, because there is only one kind of > > single-column statistic. Maybe that might change in the future, but if > > so, it's likely that the kinds of single-column stats will be > > different from the kinds of multi-column stats. > > > > In the second syntax, the only accepted kinds would be the current > > multi-column stats kinds (ndistinct, dependencies, and mcv), and it > > would always build stats describing the correlations between the > > columns listed. It would continue to build standard/expression stats > > on any expressions in the list, but that's more of an implementation > > detail. > > > > It would no longer be possible to do "CREATE STATISTICS s > > (expressions) ON (expr1), (expr2) FROM tbl". Instead, you'd have to > > issue 2 separate "CREATE STATISTICS" commands, but that seems more > > logical, because they're independent stats. > > > > The parsing code might not change much, but some of the errors would > > be different. For example, the errors "building only extended > > expression statistics on simple columns not allowed" and "extended > > expression statistics require at least one expression" would go away, > > and the error "extended statistics require at least 2 columns" might > > become more specific, depending on the stats kind. This still seems odd: postgres=# CREATE STATISTICS asf ON i FROM t; ERROR: extended statistics require at least 2 columns postgres=# CREATE STATISTICS asf ON (i) FROM t; CREATE STATISTICS It seems wrong that the command works with added parens, but builds expression stats on a simple column (which is redundant with what analyze does without extended stats). -- Justin