mirror of
https://github.com/postgres/postgres.git
synced 2025-10-29 22:49:41 +03:00
Eliminate pg_rewrite.ev_attr column and related dead code.
Commit 95ef6a3448 removed the
ability to create rules on an individual column as of 7.3, but
left some residual code which has since been useless. This cleans
up that dead code without any change in behavior other than
dropping the useless column from the catalog.
This commit is contained in:
@@ -58,7 +58,6 @@ static Oid
|
||||
InsertRule(char *rulname,
|
||||
int evtype,
|
||||
Oid eventrel_oid,
|
||||
AttrNumber evslot_index,
|
||||
bool evinstead,
|
||||
Node *event_qual,
|
||||
List *action,
|
||||
@@ -86,7 +85,6 @@ InsertRule(char *rulname,
|
||||
namestrcpy(&rname, rulname);
|
||||
values[Anum_pg_rewrite_rulename - 1] = NameGetDatum(&rname);
|
||||
values[Anum_pg_rewrite_ev_class - 1] = ObjectIdGetDatum(eventrel_oid);
|
||||
values[Anum_pg_rewrite_ev_attr - 1] = Int16GetDatum(evslot_index);
|
||||
values[Anum_pg_rewrite_ev_type - 1] = CharGetDatum(evtype + '0');
|
||||
values[Anum_pg_rewrite_ev_enabled - 1] = CharGetDatum(RULE_FIRES_ON_ORIGIN);
|
||||
values[Anum_pg_rewrite_is_instead - 1] = BoolGetDatum(evinstead);
|
||||
@@ -117,7 +115,6 @@ InsertRule(char *rulname,
|
||||
* When replacing, we don't need to replace every attribute
|
||||
*/
|
||||
MemSet(replaces, false, sizeof(replaces));
|
||||
replaces[Anum_pg_rewrite_ev_attr - 1] = true;
|
||||
replaces[Anum_pg_rewrite_ev_type - 1] = true;
|
||||
replaces[Anum_pg_rewrite_is_instead - 1] = true;
|
||||
replaces[Anum_pg_rewrite_ev_qual - 1] = true;
|
||||
@@ -238,7 +235,6 @@ DefineQueryRewrite(char *rulename,
|
||||
List *action)
|
||||
{
|
||||
Relation event_relation;
|
||||
int event_attno;
|
||||
ListCell *l;
|
||||
Query *query;
|
||||
bool RelisBecomingView = false;
|
||||
@@ -495,7 +491,6 @@ DefineQueryRewrite(char *rulename,
|
||||
/*
|
||||
* This rule is allowed - prepare to install it.
|
||||
*/
|
||||
event_attno = -1;
|
||||
|
||||
/* discard rule if it's null action and not INSTEAD; it's a no-op */
|
||||
if (action != NIL || is_instead)
|
||||
@@ -503,7 +498,6 @@ DefineQueryRewrite(char *rulename,
|
||||
ruleId = InsertRule(rulename,
|
||||
event_type,
|
||||
event_relid,
|
||||
event_attno,
|
||||
is_instead,
|
||||
event_qual,
|
||||
action,
|
||||
|
||||
@@ -1276,10 +1276,7 @@ matchLocks(CmdType event,
|
||||
if (oneLock->event == event)
|
||||
{
|
||||
if (parsetree->commandType != CMD_SELECT ||
|
||||
(oneLock->attrno == -1 ?
|
||||
rangeTableEntry_used((Node *) parsetree, varno, 0) :
|
||||
attribute_used((Node *) parsetree,
|
||||
varno, oneLock->attrno, 0)))
|
||||
rangeTableEntry_used((Node *) parsetree, varno, 0))
|
||||
matching_locks = lappend(matching_locks, oneLock);
|
||||
}
|
||||
}
|
||||
@@ -1295,7 +1292,6 @@ static Query *
|
||||
ApplyRetrieveRule(Query *parsetree,
|
||||
RewriteRule *rule,
|
||||
int rt_index,
|
||||
bool relation_level,
|
||||
Relation relation,
|
||||
List *activeRIRs,
|
||||
bool forUpdatePushedDown)
|
||||
@@ -1309,8 +1305,6 @@ ApplyRetrieveRule(Query *parsetree,
|
||||
elog(ERROR, "expected just one rule action");
|
||||
if (rule->qual != NULL)
|
||||
elog(ERROR, "cannot handle qualified ON SELECT rule");
|
||||
if (!relation_level)
|
||||
elog(ERROR, "cannot handle per-attribute ON SELECT rule");
|
||||
|
||||
if (rt_index == parsetree->resultRelation)
|
||||
{
|
||||
@@ -1632,14 +1626,6 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
|
||||
if (rule->event != CMD_SELECT)
|
||||
continue;
|
||||
|
||||
if (rule->attrno > 0)
|
||||
{
|
||||
/* per-attr rule; do we need it? */
|
||||
if (!attribute_used((Node *) parsetree, rt_index,
|
||||
rule->attrno, 0))
|
||||
continue;
|
||||
}
|
||||
|
||||
locks = lappend(locks, rule);
|
||||
}
|
||||
|
||||
@@ -1664,7 +1650,6 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
|
||||
parsetree = ApplyRetrieveRule(parsetree,
|
||||
rule,
|
||||
rt_index,
|
||||
rule->attrno == -1,
|
||||
rel,
|
||||
activeRIRs,
|
||||
forUpdatePushedDown);
|
||||
|
||||
@@ -857,70 +857,6 @@ rangeTableEntry_used(Node *node, int rt_index, int sublevels_up)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* attribute_used -
|
||||
* Check if a specific attribute number of a RTE is used
|
||||
* somewhere in the query or expression.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int rt_index;
|
||||
int attno;
|
||||
int sublevels_up;
|
||||
} attribute_used_context;
|
||||
|
||||
static bool
|
||||
attribute_used_walker(Node *node,
|
||||
attribute_used_context *context)
|
||||
{
|
||||
if (node == NULL)
|
||||
return false;
|
||||
if (IsA(node, Var))
|
||||
{
|
||||
Var *var = (Var *) node;
|
||||
|
||||
if (var->varlevelsup == context->sublevels_up &&
|
||||
var->varno == context->rt_index &&
|
||||
var->varattno == context->attno)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (IsA(node, Query))
|
||||
{
|
||||
/* Recurse into subselects */
|
||||
bool result;
|
||||
|
||||
context->sublevels_up++;
|
||||
result = query_tree_walker((Query *) node, attribute_used_walker,
|
||||
(void *) context, 0);
|
||||
context->sublevels_up--;
|
||||
return result;
|
||||
}
|
||||
return expression_tree_walker(node, attribute_used_walker,
|
||||
(void *) context);
|
||||
}
|
||||
|
||||
bool
|
||||
attribute_used(Node *node, int rt_index, int attno, int sublevels_up)
|
||||
{
|
||||
attribute_used_context context;
|
||||
|
||||
context.rt_index = rt_index;
|
||||
context.attno = attno;
|
||||
context.sublevels_up = sublevels_up;
|
||||
|
||||
/*
|
||||
* Must be prepared to start with a Query or a bare expression tree; if
|
||||
* it's a Query, we don't want to increment sublevels_up.
|
||||
*/
|
||||
return query_or_expression_tree_walker(node,
|
||||
attribute_used_walker,
|
||||
(void *) &context,
|
||||
0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* If the given Query is an INSERT ... SELECT construct, extract and
|
||||
* return the sub-Query node that represents the SELECT part. Otherwise
|
||||
|
||||
Reference in New Issue
Block a user