1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Revise parse tree representation for VACUUM and ANALYZE.

Like commit f41551f61f, this aims
to make it easier to add non-Boolean options to VACUUM (or, in
this case, to ANALYZE).  Instead of building up a bitmap of
options directly in the parser, build up a list of DefElem
objects and let ExecVacuum() sort it out; right now, we make
no use of the fact that a DefElem can carry an associated value,
but it will be easy to make that change in the future.

Masahiko Sawada

Discussion: http://postgr.es/m/CAD21AoATE4sn0jFFH3NcfUZXkU2BMbjBWB_kDj-XWYA-LXDcQA@mail.gmail.com
This commit is contained in:
Robert Haas
2019-03-18 15:14:52 -04:00
parent f41551f61f
commit 6776142a07
7 changed files with 116 additions and 86 deletions

View File

@ -306,8 +306,9 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
create_extension_opt_item alter_extension_opt_item
%type <ival> opt_lock lock_type cast_context
%type <ival> vacuum_option_list vacuum_option_elem
analyze_option_list analyze_option_elem
%type <str> vac_analyze_option_name
%type <defelt> vac_analyze_option_elem
%type <list> vac_analyze_option_list
%type <boolean> opt_or_replace
opt_grant_grant_option opt_grant_admin_option
opt_nowait opt_if_exists opt_with_data
@ -10460,85 +10461,62 @@ cluster_index_specification:
VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
{
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_VACUUM;
n->options = NIL;
if ($2)
n->options |= VACOPT_FULL;
n->options = lappend(n->options,
makeDefElem("full", NULL, @2));
if ($3)
n->options |= VACOPT_FREEZE;
n->options = lappend(n->options,
makeDefElem("freeze", NULL, @3));
if ($4)
n->options |= VACOPT_VERBOSE;
n->options = lappend(n->options,
makeDefElem("verbose", NULL, @4));
if ($5)
n->options |= VACOPT_ANALYZE;
n->options = lappend(n->options,
makeDefElem("analyze", NULL, @5));
n->rels = $6;
n->is_vacuumcmd = true;
$$ = (Node *)n;
}
| VACUUM '(' vacuum_option_list ')' opt_vacuum_relation_list
| VACUUM '(' vac_analyze_option_list ')' opt_vacuum_relation_list
{
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_VACUUM | $3;
n->options = $3;
n->rels = $5;
n->is_vacuumcmd = true;
$$ = (Node *) n;
}
;
vacuum_option_list:
vacuum_option_elem { $$ = $1; }
| vacuum_option_list ',' vacuum_option_elem { $$ = $1 | $3; }
;
vacuum_option_elem:
analyze_keyword { $$ = VACOPT_ANALYZE; }
| VERBOSE { $$ = VACOPT_VERBOSE; }
| FREEZE { $$ = VACOPT_FREEZE; }
| FULL { $$ = VACOPT_FULL; }
| IDENT
{
if (strcmp($1, "disable_page_skipping") == 0)
$$ = VACOPT_DISABLE_PAGE_SKIPPING;
else if (strcmp($1, "skip_locked") == 0)
$$ = VACOPT_SKIP_LOCKED;
else
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("unrecognized VACUUM option \"%s\"", $1),
parser_errposition(@1)));
}
;
AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
{
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_ANALYZE;
n->options = NIL;
if ($2)
n->options |= VACOPT_VERBOSE;
n->options = lappend(n->options,
makeDefElem("verbose", NULL, @2));
n->rels = $3;
n->is_vacuumcmd = false;
$$ = (Node *)n;
}
| analyze_keyword '(' analyze_option_list ')' opt_vacuum_relation_list
| analyze_keyword '(' vac_analyze_option_list ')' opt_vacuum_relation_list
{
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_ANALYZE | $3;
n->options = $3;
n->rels = $5;
n->is_vacuumcmd = false;
$$ = (Node *) n;
}
;
analyze_option_list:
analyze_option_elem { $$ = $1; }
| analyze_option_list ',' analyze_option_elem { $$ = $1 | $3; }
;
analyze_option_elem:
VERBOSE { $$ = VACOPT_VERBOSE; }
| IDENT
vac_analyze_option_list:
vac_analyze_option_elem
{
if (strcmp($1, "skip_locked") == 0)
$$ = VACOPT_SKIP_LOCKED;
else
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("unrecognized ANALYZE option \"%s\"", $1),
parser_errposition(@1)));
$$ = list_make1($1);
}
| vac_analyze_option_list ',' vac_analyze_option_elem
{
$$ = lappend($1, $3);
}
;
@ -10547,6 +10525,18 @@ analyze_keyword:
| ANALYSE /* British */ {}
;
vac_analyze_option_elem:
vac_analyze_option_name
{
$$ = makeDefElem($1, NULL, @1);
}
;
vac_analyze_option_name:
NonReservedWord { $$ = $1; }
| analyze_keyword { $$ = "analyze"; }
;
opt_analyze:
analyze_keyword { $$ = true; }
| /*EMPTY*/ { $$ = false; }