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 1mIWF9-0003b9-20 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Aug 2021 13:13:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mIWF7-00074F-Vo for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Aug 2021 13:13:29 +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 1mIWF7-000747-Kp for pgsql-hackers@lists.postgresql.org; Tue, 24 Aug 2021 13:13:29 +0000 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mIWF1-0000AL-1e for pgsql-hackers@postgresql.org; Tue, 24 Aug 2021 13:13:28 +0000 Received: by mail-il1-x12d.google.com with SMTP id z2so20497378iln.0 for ; Tue, 24 Aug 2021 06:13:22 -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=c1a/IPnHYHemxo/p27P/iI/0JE/I9as47A/uYmLneYQ=; b=mnScPCSxxMeGnzLB/1po6e8860Po69dkzgGxaMTA1467rCuUmbBeOmNEP+4kLfM/Yc dkpFvfUu7jebGWB0eBopn9z7PczXAASDVskxP4AxKK5Ujs2b81AWYkgfDJlVaJ5gKBvU KJKqAo3bItYeu2ocFhY2ouOSibIAHk5I5Eyfq4aiAReuxre4jADOKZxa0YjRalhHfhBI FFKB4VfmUqv+KgLd6kLrHQVVf4UO8V+yyBPqDK6mSZ3zGYhuIJj1HOWPq0OuK1todo11 ilYXQjP+9pafIy/ya3mlCgQKcYEVZ4SIdjPXqmokkcdpZtrEhrI/u+S8vJLvrPe50tG0 nnMw== 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=c1a/IPnHYHemxo/p27P/iI/0JE/I9as47A/uYmLneYQ=; b=TF/0CqjdEqq4kvAMlekdRzF9m3/VC5dBnEMn0C+0+1uaPUTKbbMDE1zdlg2loX4IwU 1JY0rI8Qm0B4LdGc5vnHXEiugLb1TOa/AMBrFYFdvx31SHBDClB62+oVoen7VIqOR0ZV p6s2XWQAKMPDRdK2jEvVKVimGJhpWj1I+lrMOTzgVDzrydKoXP7ApLEPwFs5+IVYScbH xIkDDWOtagX7jKWHUcG1mZPA5mkjJ8/i0tTM5ymG+yoMa4P8KGcWnMRsjrmKfoUEYfDL JZt8WenxBV4Ot3n8mSxJqHsiQWBcqciFRITMn8qJ9DLePhNRfiYQ9tOFN/Kq/yvuMvBQ 463w== X-Gm-Message-State: AOAM530ULZjN8ejSeVvAlduwpqU3JhafTKz+ZzDd66doSiY48SK6HxlV ecaLCY3GGI6o1uaUyjBN1oVxDA== X-Google-Smtp-Source: ABdhPJwnTftbu7WpQ/DBule/e6EwtysrMU6ourdapEC6lLZ3f6b0Cz+AtbbpA3cqbzvn7J98NDC2wA== X-Received: by 2002:a92:6802:: with SMTP id d2mr26120414ilc.40.1629810802118; Tue, 24 Aug 2021 06:13:22 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id b12sm9965667ilo.44.2021.08.24.06.13.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Aug 2021 06:13:21 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 98176800C52; Tue, 24 Aug 2021 08:13:20 -0500 (CDT) Date: Tue, 24 Aug 2021 08:13:20 -0500 From: Justin Pryzby To: Tomas Vondra Cc: Dean Rasheed , hackers Subject: Re: PoC/WIP: Extended statistics on expressions Message-ID: <20210824131320.GO10479@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> <20210816013255.GS10479@telsasoft.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, Aug 16, 2021 at 05:41:57PM +0200, Tomas Vondra wrote: > > 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). > > Well, yeah. But I think this is a behavior that was discussed somewhere in > this thread, and the agreement was that it's not worth the complexity, as > this comment explains > > * XXX We do only the bare minimum to separate simple attribute and > * complex expressions - for example "(a)" will be treated as a complex > * expression. No matter how elaborate the check is, there'll always be > * a way around it, if the user is determined (consider e.g. "(a+0)"), > * so it's not worth protecting against it. > > Patch 0001 fixes the "double parens" issue discussed elsewhere in this > thread, and patch 0002 tweaks CREATE STATISTICS to treat "(a)" as a simple > column reference. 0002 refuses to create expressional stats on a simple column reference like (a), which I think is helps to avoid a user accidentally creating useless ext stats objects (which are redundant with the table's column stats). 0002 does not attempt to refuse cases like (a+0), which I think is fine: we don't try to reject useless cases if someone insists on it. See 240971675, 701fd0bbc. So I am +1 to apply both patches. I added this as an Opened Item for increased visibility. -- Justin