1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-15 19:21:59 +03:00

Further consolidation of DROP statement handling.

This gets rid of an impressive amount of duplicative code, with only
minimal behavior changes.  DROP FOREIGN DATA WRAPPER now requires object
ownership rather than superuser privileges, matching the documentation
we already have.  We also eliminate the historical warning about dropping
a built-in function as unuseful.  All operations are now performed in the
same order for all object types handled by dropcmds.c.

KaiGai Kohei, with minor revisions by me
This commit is contained in:
Robert Haas
2011-11-17 21:31:29 -05:00
parent 709aca5960
commit fc6d1006bd
21 changed files with 241 additions and 1148 deletions

View File

@ -3255,16 +3255,19 @@ opt_validator:
DropPLangStmt:
DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
{
DropPLangStmt *n = makeNode(DropPLangStmt);
n->plname = $4;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_LANGUAGE;
n->objects = list_make1(list_make1(makeString($4)));
n->arguments = NIL;
n->behavior = $5;
n->missing_ok = false;
$$ = (Node *)n;
}
| DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
{
DropPLangStmt *n = makeNode(DropPLangStmt);
n->plname = $6;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_LANGUAGE;
n->objects = list_make1(list_make1(makeString($6)));
n->behavior = $7;
n->missing_ok = true;
$$ = (Node *)n;
@ -3656,16 +3659,20 @@ opt_fdw_options:
DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
{
DropFdwStmt *n = makeNode(DropFdwStmt);
n->fdwname = $5;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_FDW;
n->objects = list_make1(list_make1(makeString($5)));
n->arguments = NIL;
n->missing_ok = false;
n->behavior = $6;
$$ = (Node *) n;
}
| DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
{
DropFdwStmt *n = makeNode(DropFdwStmt);
n->fdwname = $7;
{
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_FDW;
n->objects = list_make1(list_make1(makeString($7)));
n->arguments = NIL;
n->missing_ok = true;
n->behavior = $8;
$$ = (Node *) n;
@ -3812,16 +3819,20 @@ opt_foreign_server_version:
DropForeignServerStmt: DROP SERVER name opt_drop_behavior
{
DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
n->servername = $3;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_FOREIGN_SERVER;
n->objects = list_make1(list_make1(makeString($3)));
n->arguments = NIL;
n->missing_ok = false;
n->behavior = $4;
$$ = (Node *) n;
}
| DROP SERVER IF_P EXISTS name opt_drop_behavior
{
DropForeignServerStmt *n = makeNode(DropForeignServerStmt);
n->servername = $5;
{
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_FOREIGN_SERVER;
n->objects = list_make1(list_make1(makeString($5)));
n->arguments = NIL;
n->missing_ok = true;
n->behavior = $6;
$$ = (Node *) n;
@ -4193,23 +4204,23 @@ ConstraintAttributeElem:
DropTrigStmt:
DROP TRIGGER name ON qualified_name opt_drop_behavior
DROP TRIGGER name ON any_name opt_drop_behavior
{
DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = $5;
n->property = $3;
n->behavior = $6;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_TRIGGER;
n->objects = list_make1(lappend($5, makeString($3)));
n->arguments = NIL;
n->behavior = $6;
n->missing_ok = false;
$$ = (Node *) n;
}
| DROP TRIGGER IF_P EXISTS name ON qualified_name opt_drop_behavior
| DROP TRIGGER IF_P EXISTS name ON any_name opt_drop_behavior
{
DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = $7;
n->property = $5;
n->behavior = $8;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_TRIGGER;
n->objects = list_make1(lappend($7, makeString($5)));
n->arguments = NIL;
n->behavior = $8;
n->missing_ok = true;
$$ = (Node *) n;
}
@ -4247,9 +4258,9 @@ CreateAssertStmt:
DropAssertStmt:
DROP ASSERTION name opt_drop_behavior
{
DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = NULL;
n->property = $3;
DropStmt *n = makeNode(DropStmt);
n->objects = NIL;
n->arguments = NIL;
n->behavior = $4;
n->removeType = OBJECT_TRIGGER; /* XXX */
ereport(ERROR,
@ -4665,18 +4676,20 @@ opclass_drop:
DropOpClassStmt:
DROP OPERATOR CLASS any_name USING access_method opt_drop_behavior
{
RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
n->opclassname = $4;
n->amname = $6;
DropStmt *n = makeNode(DropStmt);
n->objects = list_make1($4);
n->arguments = list_make1(list_make1(makeString($6)));
n->removeType = OBJECT_OPCLASS;
n->behavior = $7;
n->missing_ok = false;
$$ = (Node *) n;
}
| DROP OPERATOR CLASS IF_P EXISTS any_name USING access_method opt_drop_behavior
{
RemoveOpClassStmt *n = makeNode(RemoveOpClassStmt);
n->opclassname = $6;
n->amname = $8;
DropStmt *n = makeNode(DropStmt);
n->objects = list_make1($6);
n->arguments = list_make1(list_make1(makeString($8)));
n->removeType = OBJECT_OPCLASS;
n->behavior = $9;
n->missing_ok = true;
$$ = (Node *) n;
@ -4686,18 +4699,20 @@ DropOpClassStmt:
DropOpFamilyStmt:
DROP OPERATOR FAMILY any_name USING access_method opt_drop_behavior
{
RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
n->opfamilyname = $4;
n->amname = $6;
DropStmt *n = makeNode(DropStmt);
n->objects = list_make1($4);
n->arguments = list_make1(list_make1(makeString($6)));
n->removeType = OBJECT_OPFAMILY;
n->behavior = $7;
n->missing_ok = false;
$$ = (Node *) n;
}
| DROP OPERATOR FAMILY IF_P EXISTS any_name USING access_method opt_drop_behavior
{
RemoveOpFamilyStmt *n = makeNode(RemoveOpFamilyStmt);
n->opfamilyname = $6;
n->amname = $8;
DropStmt *n = makeNode(DropStmt);
n->objects = list_make1($6);
n->arguments = list_make1(list_make1(makeString($8)));
n->removeType = OBJECT_OPFAMILY;
n->behavior = $9;
n->missing_ok = true;
$$ = (Node *) n;
@ -4748,6 +4763,7 @@ DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
n->removeType = $2;
n->missing_ok = TRUE;
n->objects = $5;
n->arguments = NIL;
n->behavior = $6;
$$ = (Node *)n;
}
@ -4757,6 +4773,7 @@ DropStmt: DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
n->removeType = $2;
n->missing_ok = FALSE;
n->objects = $3;
n->arguments = NIL;
n->behavior = $4;
$$ = (Node *)n;
}
@ -6173,20 +6190,20 @@ opt_restrict:
RemoveFuncStmt:
DROP FUNCTION func_name func_args opt_drop_behavior
{
RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->kind = OBJECT_FUNCTION;
n->name = $3;
n->args = extractArgTypes($4);
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_FUNCTION;
n->objects = list_make1($3);
n->arguments = list_make1(extractArgTypes($4));
n->behavior = $5;
n->missing_ok = false;
$$ = (Node *)n;
}
| DROP FUNCTION IF_P EXISTS func_name func_args opt_drop_behavior
{
RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->kind = OBJECT_FUNCTION;
n->name = $5;
n->args = extractArgTypes($6);
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_FUNCTION;
n->objects = list_make1($5);
n->arguments = list_make1(extractArgTypes($6));
n->behavior = $7;
n->missing_ok = true;
$$ = (Node *)n;
@ -6196,20 +6213,20 @@ RemoveFuncStmt:
RemoveAggrStmt:
DROP AGGREGATE func_name aggr_args opt_drop_behavior
{
RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->kind = OBJECT_AGGREGATE;
n->name = $3;
n->args = $4;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_AGGREGATE;
n->objects = list_make1($3);
n->arguments = list_make1($4);
n->behavior = $5;
n->missing_ok = false;
$$ = (Node *)n;
}
| DROP AGGREGATE IF_P EXISTS func_name aggr_args opt_drop_behavior
{
RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->kind = OBJECT_AGGREGATE;
n->name = $5;
n->args = $6;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_AGGREGATE;
n->objects = list_make1($5);
n->arguments = list_make1($6);
n->behavior = $7;
n->missing_ok = true;
$$ = (Node *)n;
@ -6219,20 +6236,20 @@ RemoveAggrStmt:
RemoveOperStmt:
DROP OPERATOR any_operator oper_argtypes opt_drop_behavior
{
RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->kind = OBJECT_OPERATOR;
n->name = $3;
n->args = $4;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_OPERATOR;
n->objects = list_make1($3);
n->arguments = list_make1($4);
n->behavior = $5;
n->missing_ok = false;
$$ = (Node *)n;
}
| DROP OPERATOR IF_P EXISTS any_operator oper_argtypes opt_drop_behavior
{
RemoveFuncStmt *n = makeNode(RemoveFuncStmt);
n->kind = OBJECT_OPERATOR;
n->name = $5;
n->args = $6;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_OPERATOR;
n->objects = list_make1($5);
n->arguments = list_make1($6);
n->behavior = $7;
n->missing_ok = true;
$$ = (Node *)n;
@ -6345,9 +6362,10 @@ cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; }
DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
{
DropCastStmt *n = makeNode(DropCastStmt);
n->sourcetype = $5;
n->targettype = $7;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_CAST;
n->objects = list_make1(list_make1($5));
n->arguments = list_make1(list_make1($7));
n->behavior = $9;
n->missing_ok = $3;
$$ = (Node *)n;
@ -7063,23 +7081,23 @@ opt_instead:
DropRuleStmt:
DROP RULE name ON qualified_name opt_drop_behavior
DROP RULE name ON any_name opt_drop_behavior
{
DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = $5;
n->property = $3;
n->behavior = $6;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_RULE;
n->objects = list_make1(lappend($5, makeString($3)));
n->arguments = NIL;
n->behavior = $6;
n->missing_ok = false;
$$ = (Node *) n;
}
| DROP RULE IF_P EXISTS name ON qualified_name opt_drop_behavior
| DROP RULE IF_P EXISTS name ON any_name opt_drop_behavior
{
DropPropertyStmt *n = makeNode(DropPropertyStmt);
n->relation = $7;
n->property = $5;
n->behavior = $8;
DropStmt *n = makeNode(DropStmt);
n->removeType = OBJECT_RULE;
n->objects = list_make1(lappend($7, makeString($5)));
n->arguments = NIL;
n->behavior = $8;
n->missing_ok = true;
$$ = (Node *) n;
}