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 1khb6H-0006J1-3E for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Nov 2020 16:23:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1khb6F-0006mY-Un for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Nov 2020 16:23:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khb6F-0006mQ-OM for pgsql-hackers@lists.postgresql.org; Tue, 24 Nov 2020 16:23:27 +0000 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1khb6D-0004oL-Aq for pgsql-hackers@postgresql.org; Tue, 24 Nov 2020 16:23:27 +0000 Received: by mail-io1-xd2f.google.com with SMTP id i18so22534270ioa.3 for ; Tue, 24 Nov 2020 08:23:25 -0800 (PST) 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=ZsG24JHfQzl4NshA9/Te5SKv0fikNLlGT7EXB7KLkOg=; b=LSgsW5BMgUM9Z1pgXdt9nfA5UzositXaNBGCQMv6I8k3ysJouwLGwPEeP+P2n9RAJe GBNR/ELL/pv9TL0PDprMSXpoaoR0LCFDEX0BgSFYv7jRSSpTRF3YgWLOVAXEHmoFBGYh Z5M0BIMYIFyAYCPQnL99vMWVYfn5IgjZyuXjH0axsWha6b0Mp0P1bzg2kqtnYYN3OkN2 TsClASue30lYsZRiQ17IfwGjeOsr8zv0hDkdSUuObA7VEfuhlrcf3KbDBZATZBejIukG zmPSi+Dr2PUhJFSEUdIwyR/rpyelonk+8KT5yckdzBqAq1+qO2hjytO7UJfaMoWIj4r5 DCOA== 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=ZsG24JHfQzl4NshA9/Te5SKv0fikNLlGT7EXB7KLkOg=; b=P8BAubamNUqkM1xyYKtUQFJDf3LDNOdApXwFxA+vGIouJATYIFBudIUPCugqjgBg96 mtVbb01d7qEr/dN0uFwPdtdraAfQBvSrylE1e/nWAh7tzAWZUUqJQacOF3hpwXOMcW29 PVlNTIk8qcbNFvgl7+E69d21XczAYm/wyTHCbHKYLUbRw/5EiqS69S3FLWcixNLApHyq aQwK7XxKjw/Q+X8d/NIWI4Xt6wOhyYlrpfWLFZZsXCZo1zFaeeAGYChI26Y/5/s/EkSY nCVpl/aOcdk4opVs/fMpdb2eAreGSuWBeVhLEJsKes5whb54VS3VIjA2R2XW/yaphgOe +thg== X-Gm-Message-State: AOAM53272eoCj+cJMuh+5YNMvUqS2cK4DzEQYBAyBCOQocSXK/pByr1u edqcHsSKd+nWnYmzIwfFqhpRcQP4jj0upg== X-Google-Smtp-Source: ABdhPJwjUFFRz6wWzZA2wuf+F5fFyyHTIP+t/jnhNqz2RM7weOWyDxQzd7lDcJJd4+KpfZIHRdbPpw== X-Received: by 2002:a6b:dc0f:: with SMTP id s15mr4544947ioc.180.1606235003424; Tue, 24 Nov 2020 08:23:23 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 10sm8117043iou.50.2020.11.24.08.23.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Nov 2020 08:23:22 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id BA19780077C; Tue, 24 Nov 2020 10:23:20 -0600 (CST) Date: Tue, 24 Nov 2020 10:23:20 -0600 From: Justin Pryzby To: Tomas Vondra Cc: pgsql-hackers Subject: Re: PoC/WIP: Extended statistics on expressions Message-ID: <20201124162320.GR24052@telsasoft.com> References: <3fbbd68b-0b52-cb5a-d468-7e7280c33e6c@enterprisedb.com> <4654037b-8df8-77fb-2981-67be93aebdf1@enterprisedb.com> <20201123022604.GD24052@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: Precedence: bulk On Mon, Nov 23, 2020 at 04:30:26AM +0100, Tomas Vondra wrote: > 0004 - Seems fine. IMHO not really "silly errors" but OK. This is one of the same issues you pointed out - shadowing a variable. Could be backpatched. On Mon, Nov 23, 2020 at 04:30:26AM +0100, Tomas Vondra wrote: > > + errmsg("statistics expressions and predicates can refer only to the table being indexed"))); > > + * partial-index predicates. Create it in the per-index context to be > > > > I think these are copied and shouldn't mention "indexes" or "predicates". Or > > should statistics support predicates, too ? > > > > Right. Stupid copy-pasto. Right, but then I was wondering if CREATE STATS should actually support predicates, since one use case is to do what indexes do without their overhead. I haven't thought about it enough yet. > 0006 - Not sure. I think CreateStatistics can be fixed with less code, > keeping it more like PG13 (good for backpatching). Not sure why rename > extended statistics to multi-variate statistics - we use "extended" > everywhere. - if (build_expressions && (list_length(stxexprs) == 0)) + if (!build_expressions_only && (list_length(stmt->exprs) < 2)) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), - errmsg("extended expression statistics require at least one expression"))); + errmsg("multi-variate statistics require at least two columns"))); I think all of "CREATE STATISTICS" has been known as "extended stats", so I think it may be confusing to say that it requires two columns for the general facility. > Not sure what's the point of serialize_expr_stats changes, > that's code is mostly copy-paste from update_attstats. Right. I think "i" is poor variable name when it isn't a loop variable and not of limited scope. > 0007 - I suspect this makes the pg_stats_ext too complex to work with, > IMHO we should move this to a separate view. Right - then unnest() the whole thing and return one row per expression rather than array, as you've done. Maybe the docs should say that this returns one row per expression. Looking quickly at your new patch: I guess you know there's a bunch of lingering references to "indexes" and "predicates": I don't know if you want to go to the effort to prohibit this. postgres=# CREATE STATISTICS asf ON (tableoid::int+1) FROM t; CREATE STATISTICS I think a lot of people will find this confusing: 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 postgres=# CREATE STATISTICS asf (expressions) ON i FROM t; ERROR: extended expression statistics require at least one expression postgres=# CREATE STATISTICS asf (expressions) ON (i) FROM t; CREATE STATISTICS I haven't looked, but is it possible to make it work without parens ? -- Justin