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 1mM0JH-0000m3-JU for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Sep 2021 03:56:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mM0JG-0005hB-1P for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Sep 2021 03:56:10 +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 1mM0JF-0005h2-Ml for pgsql-hackers@lists.postgresql.org; Fri, 03 Sep 2021 03:56:09 +0000 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mM0JA-0007Rl-0w for pgsql-hackers@postgresql.org; Fri, 03 Sep 2021 03:56:08 +0000 Received: by mail-io1-xd30.google.com with SMTP id f6so5292614iox.0 for ; Thu, 02 Sep 2021 20:56:03 -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=hFBAxL/tKivSryyRtcWwdIc7SXOEzP6e+YnjXiu5krI=; b=WCGnV9yX1szVF3b5ZGLnVRZBpSTxFL/cQJbEdoMrHDriPauM9KMSxcxKsWecjJ0HbW KNZMNFCqR9gq6QJjyCeFQ6bd/OW4KLyxE+yxyUnau29L/6qjy4bUPTsC2/ayTprnAAP1 375gatRksg6AuSns/R6WDQgBIgV95Nj7XeXk/3OWc9hdWNmr3HCJeD8YG23zePyyFwSK M9FzJlvvpNDlmzMd2o3isiPAjJ2S5oDhSuOwy7+L8rHlRTz6tPeGMF8SPKen78DS6ErS qw9jkFwzwECcY3gcyjcAG6Soso3lcyQiiWQD2Y3edjdzHQRBxr/vDFdRo02IOq1exp8z r9zQ== 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=hFBAxL/tKivSryyRtcWwdIc7SXOEzP6e+YnjXiu5krI=; b=jxmjiHer80dvmfIb4s7XYwovX5K3b3z0lqHcbtLsJta2YFIrr9nRgQnB3dFwa06zTV mWuswfXdyGvueGLPGQ6vDFA4fhpuK/NjGxcOoMdzGzOkNPOlUq0P2ymG0lFyv0iq6KPd zgVGh69Uwb19/f/yex4p6FLsq+dUvLNEmZwQz9+kDH+4JHQvvJT0lCQBB3E8lmWIriGl 1JW7Lnm+Ee4+5v5xQdj+UHJrI5f9c6/rG26aMTDwe72Xiqb4kUdoJKGKu/bcNLgzNYRv kMQo9spnZbG35DDa3Xqe7xEGEyiQnwZBapcaJHPzOu7Eaxg3OUWVEsTdKMUeZ6jImNCF u4Mg== X-Gm-Message-State: AOAM533sp1t7UVFgjKXMXr/dvjx13A8Hzh1lEvNOf/i0NXXyKApM3bbC 9UDHt71bqzrlAsTaTr+uEa/Rzw== X-Google-Smtp-Source: ABdhPJz7cJv36PaoDGWOBHCcusaM+RzEGXHQeJ1NZxl59jGOyS0901veffv4bwb2/FYMPSoapTjeCg== X-Received: by 2002:a02:c48c:: with SMTP id t12mr944716jam.82.1630641363345; Thu, 02 Sep 2021 20:56:03 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id x15sm1977197ilp.23.2021.09.02.20.56.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Sep 2021 20:56:02 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id CE0B7800BCE; Thu, 2 Sep 2021 22:56:01 -0500 (CDT) Date: Thu, 2 Sep 2021 22:56:01 -0500 From: Justin Pryzby To: Tomas Vondra Cc: Dean Rasheed , pgsql-hackers@postgresql.org Subject: Re: PoC/WIP: Extended statistics on expressions Message-ID: <20210903035601.GT26465@telsasoft.com> References: <20201123022604.GD24052@telsasoft.com> <6455e0ad-2a2e-bdb0-e1f8-fd4983d1c8aa@enterprisedb.com> <087086de-1384-8374-4efc-2e7915071d5c@enterprisedb.com> <20210816013255.GS10479@telsasoft.com> <20210824131320.GO10479@telsasoft.com> <6bc0ab0c-a807-2b7f-7df8-ac90c7839013@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6bc0ab0c-a807-2b7f-7df8-ac90c7839013@enterprisedb.com> 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 Wed, Sep 01, 2021 at 06:45:29PM +0200, Tomas Vondra wrote: > However while polishing the second patch, I realized we're allowing > statistics on expressions referencing system attributes. So this fails; > > CREATE STATISTICS s ON ctid, x FROM t; > > but this passes: > > CREATE STATISTICS s ON (ctid::text), x FROM t; > > IMO we should reject such expressions, just like we reject direct references > to system attributes - patch attached. Right, same as indexes. +1 > Furthermore, I wonder if we should reject expressions without any Vars? This > works now: > > CREATE STATISTICS s ON (11:text) FROM t; > > but it seems rather silly / useless, so maybe we should reject it. To my surprise, this is also allowed for indexes... But (maybe this is what I was remembering) it's prohibited to have a constant expression as a partition key. Expressions without a var seem like a case where the user did something deliberately silly, and dis-similar from the case of making a stats expression on a simple column - that seemed like it could be a legitimate mistake/confusion (it's not unreasonable to write an extra parenthesis, but it's strange if that causes it to behave differently). I think it's not worth too much effort to prohibit this: if they're determined, they can still write an expresion with a var which is constant. I'm not going to say it's worth zero effort, though. -- Justin