summaryrefslogtreecommitdiff
path: root/src/backend/catalog/dependency.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-11-02 17:15:13 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2010-11-02 17:15:13 -0400
commite84bf651216a80c1d0c0d14901dea244c6a333ab (patch)
tree54fc20f4e9aca3ae25f8298373454afafb382f93 /src/backend/catalog/dependency.c
parent77459eba8cb32aa0e1e1736a3f3b08b8e8dde181 (diff)
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/catalog/dependency.c')
-rw-r--r--src/backend/catalog/dependency.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index 491c402a03b..eb32a1706fd 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1235,6 +1235,12 @@ recordDependencyOnExpr(const ObjectAddress *depender,
* range table. An additional frammish is that dependencies on that
* relation (or its component columns) will be marked with 'self_behavior',
* whereas 'behavior' is used for everything else.
+ *
+ * NOTE: the caller should ensure that a whole-table dependency on the
+ * specified relation is created separately, if one is needed. In particular,
+ * a whole-row Var "relation.*" will not cause this routine to emit any
+ * dependency item. This is appropriate behavior for subexpressions of an
+ * ordinary query, so other cases need to cope as necessary.
*/
void
recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
@@ -1347,7 +1353,14 @@ find_expr_references_walker(Node *node,
/*
* A whole-row Var references no specific columns, so adds no new
- * dependency.
+ * dependency. (We assume that there is a whole-table dependency
+ * arising from each underlying rangetable entry. While we could
+ * record such a dependency when finding a whole-row Var that
+ * references a relation directly, it's quite unclear how to extend
+ * that to whole-row Vars for JOINs, so it seems better to leave the
+ * responsibility with the range table. Note that this poses some
+ * risks for identifying dependencies of stand-alone expressions:
+ * whole-table references may need to be created separately.)
*/
if (var->varattno == InvalidAttrNumber)
return false;