diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-11-02 17:15:29 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-11-02 17:15:29 -0400 |
commit | 6b1952b07176723b98d8ca0ce3d913bf1360c8af (patch) | |
tree | 40ecd0d2e67b82e507c57d9f64259545af4097d0 /src/backend/catalog/index.c | |
parent | 2487e8d8c8ca0014d9c02de16d0bdce62da64ad7 (diff) | |
download | postgresql-6b1952b07176723b98d8ca0ce3d913bf1360c8af.tar.gz postgresql-6b1952b07176723b98d8ca0ce3d913bf1360c8af.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/catalog/index.c')
-rw-r--r-- | src/backend/catalog/index.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 624135e508a..e57809427af 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -42,7 +42,6 @@ #include "executor/executor.h" #include "miscadmin.h" #include "optimizer/clauses.h" -#include "optimizer/var.h" #include "parser/parse_expr.h" #include "storage/procarray.h" #include "storage/smgr.h" @@ -712,16 +711,12 @@ index_create(Oid heapRelationId, } /* - * It's possible for an index to not depend on any columns of - * the table at all, in which case we need to give it a dependency - * on the table as a whole; else it won't get dropped when the - * table is dropped. This edge case is not totally useless; - * for example, a unique index on a constant expression can serve - * to prevent a table from containing more than one row. + * If there are no simply-referenced columns, give the index an + * auto dependency on the whole table. In most cases, this will + * be redundant, but it might not be if the index expressions and + * predicate contain no Vars or only whole-row Vars. */ - if (!have_simple_col && - !contain_vars_of_level((Node *) indexInfo->ii_Expressions, 0) && - !contain_vars_of_level((Node *) indexInfo->ii_Predicate, 0)) + if (!have_simple_col) { referenced.classId = RelationRelationId; referenced.objectId = heapRelationId; |