aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-11-02 17:15:19 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2010-11-02 17:15:19 -0400
commit5ab15b521f42833875a53b885ff7ab8cf0a655a3 (patch)
tree80a95547b4f601454436e1c835ae75211d80d270 /src/backend/utils/adt/ruleutils.c
parentf44b6fc9f1334e3f52ed3c5430e008637af59a12 (diff)
downloadpostgresql-5ab15b521f42833875a53b885ff7ab8cf0a655a3.tar.gz
postgresql-5ab15b521f42833875a53b885ff7ab8cf0a655a3.zip
Ensure an index that uses a whole-row Var still depends on its table.
We failed to record any dependency on the underlying table for an index declared like "create index i on t (foo(t.*))". This would create trouble if the table were dropped without previously dropping the index. To fix, simplify some overly-cute code in index_create(), accepting the possibility that sometimes the whole-table dependency will be redundant. Also document this hazard in dependency.c. Per report from Kevin Grittner. In passing, prevent a core dump in pg_get_indexdef() if the index's table can't be found. I came across this while experimenting with Kevin's example. Not sure it's a real issue when the catalogs aren't corrupt, but might as well be cautious. Back-patch to all supported versions.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index f93f47b0675..4b564362cae 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -217,6 +217,7 @@ static void get_opclass_name(Oid opclass, Oid actual_datatype,
static Node *processIndirection(Node *node, deparse_context *context,
bool printit);
static void printSubscripts(ArrayRef *aref, deparse_context *context);
+static char *get_relation_name(Oid relid);
static char *generate_relation_name(Oid relid, List *namespaces);
static char *generate_function_name(Oid funcid, int nargs, Oid *argtypes,
bool *is_variadic);
@@ -731,7 +732,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, bool showTblSpc,
indexpr_item = list_head(indexprs);
- context = deparse_context_for(get_rel_name(indrelid), indrelid);
+ context = deparse_context_for(get_relation_name(indrelid), indrelid);
/*
* Start the index definition. Note that the index's name should never be
@@ -1123,7 +1124,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
if (conForm->conrelid != InvalidOid)
{
/* relation constraint */
- context = deparse_context_for(get_rel_name(conForm->conrelid),
+ context = deparse_context_for(get_relation_name(conForm->conrelid),
conForm->conrelid);
}
else
@@ -5827,7 +5828,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
gavealias = true;
}
else if (rte->rtekind == RTE_RELATION &&
- strcmp(rte->eref->aliasname, get_rel_name(rte->relid)) != 0)
+ strcmp(rte->eref->aliasname, get_relation_name(rte->relid)) != 0)
{
/*
* Apparently the rel has been renamed since the rule was made.
@@ -6328,6 +6329,23 @@ quote_qualified_identifier(const char *namespace,
}
/*
+ * get_relation_name
+ * Get the unqualified name of a relation specified by OID
+ *
+ * This differs from the underlying get_rel_name() function in that it will
+ * throw error instead of silently returning NULL if the OID is bad.
+ */
+static char *
+get_relation_name(Oid relid)
+{
+ char *relname = get_rel_name(relid);
+
+ if (!relname)
+ elog(ERROR, "cache lookup failed for relation %u", relid);
+ return relname;
+}
+
+/*
* generate_relation_name
* Compute the name to display for a relation specified by OID
*