]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Identify simple column references in extended statistics
authorTomas Vondra <tomas.vondra@postgresql.org>
Wed, 1 Sep 2021 15:41:54 +0000 (17:41 +0200)
committerTomas Vondra <tomas.vondra@postgresql.org>
Wed, 1 Sep 2021 16:08:43 +0000 (18:08 +0200)
commit50ba70a957f9e018495a111fc4b5e5eb2ea62044
tree893632c00d63dc397fd13f04c1f0e7785c07f38c
parentd760d942c73c9a161feefb7dc4a0004b9b4e7787
Identify simple column references in extended statistics

Until now, when defining extended statistics, everything except a plain
column reference was treated as complex expression. So for example "a"
was a column reference, but "(a)" would be an expression. In most cases
this does not matter much, but there were a couple strange consequences.
For example

    CREATE STATISTICS s ON a FROM t;

would fail, because extended stats require at least two columns. But

    CREATE STATISTICS s ON (a) FROM t;

would succeed, because that requirement does not apply to expressions.
Moreover, that statistics object is useless - the optimizer will always
use the regular statistics collected for attribute "a".

So do a bit more work to identify those expressions referencing a single
column, and translate them to a simple column reference. Backpatch to
14, where support for extended statistics on expressions was introduced.

Reported-by: Justin Pryzby
Backpatch-through: 14
Discussion: https://postgr.es/m/20210816013255.GS10479%40telsasoft.com
src/backend/commands/statscmds.c
src/test/regress/expected/stats_ext.out
src/test/regress/sql/stats_ext.sql