1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-29 22:49:41 +03:00

Change CREATE STATISTICS syntax

Previously, we had the WITH clause in the middle of the command, where
you'd specify both generic options as well as statistic types.  Few
people liked this, so this commit changes it to remove the WITH keyword
from that clause and makes it accept statistic types only.  (We
currently don't have any generic options, but if we invent in the
future, we will gain a new WITH clause, probably at the end of the
command).

Also, the column list is now specified without parens, which makes the
whole command look more similar to a SELECT command.  This change will
let us expand the command to supporting expressions (not just columns
names) as well as multiple tables and their join conditions.

Tom added lots of code comments and fixed some parts of the CREATE
STATISTICS reference page, too; more changes in this area are
forthcoming.  He also fixed a potential problem in the alter_generic
regression test, reducing verbosity on a cascaded drop to avoid
dependency on message ordering, as we do in other tests.

Tom also closed a security bug: we documented that table ownership was
required in order to create a statistics object on it, but didn't
actually implement it.

Implement tab-completion for statistics objects.  This can stand some
more improvement.

Authors: Alvaro Herrera, with lots of cleanup by Tom Lane
Discussion: https://postgr.es/m/20170420212426.ltvgyhnefvhixm6i@alvherre.pgsql
This commit is contained in:
Alvaro Herrera
2017-05-12 14:59:23 -03:00
parent 46052d9ef3
commit bc085205c8
21 changed files with 325 additions and 290 deletions

View File

@@ -3835,31 +3835,29 @@ ExistingIndex: USING INDEX index_name { $$ = $3; }
/*****************************************************************************
*
* QUERY :
* CREATE STATISTICS stats_name WITH (options) ON (columns) FROM relname
* CREATE STATISTICS stats_name [(stat types)]
* ON expression-list FROM from_list
*
* Note: the expectation here is that the clauses after ON are a subset of
* SELECT syntax, allowing for expressions and joined tables, and probably
* someday a WHERE clause. Much less than that is currently implemented,
* but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
* errors as necessary at execution.
*
*****************************************************************************/
CreateStatsStmt: CREATE STATISTICS any_name opt_reloptions ON '(' columnList ')' FROM qualified_name
{
CreateStatsStmt *n = makeNode(CreateStatsStmt);
n->defnames = $3;
n->relation = $10;
n->keys = $7;
n->options = $4;
n->if_not_exists = false;
$$ = (Node *)n;
}
| CREATE STATISTICS IF_P NOT EXISTS any_name opt_reloptions ON '(' columnList ')' FROM qualified_name
{
CreateStatsStmt *n = makeNode(CreateStatsStmt);
n->defnames = $6;
n->relation = $13;
n->keys = $10;
n->options = $7;
n->if_not_exists = true;
$$ = (Node *)n;
}
CreateStatsStmt:
CREATE opt_if_not_exists STATISTICS any_name
opt_name_list ON expr_list FROM from_list
{
CreateStatsStmt *n = makeNode(CreateStatsStmt);
n->defnames = $4;
n->stat_types = $5;
n->exprs = $7;
n->relations = $9;
n->if_not_exists = $2;
$$ = (Node *)n;
}
;
/*****************************************************************************