aboutsummaryrefslogtreecommitdiff
path: root/src/backend/rewrite/rewriteHandler.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-04-17 00:32:58 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-04-17 00:32:58 +0000
commitc273e8b13c30832954490f88b64c704d5c841c8a (patch)
treee4b56ee46a0c4ccc068a906c4d260688f664fb37 /src/backend/rewrite/rewriteHandler.c
parentcdcaec5c53b290cc5e51a520980a97ac9eb4d5e3 (diff)
downloadpostgresql-c273e8b13c30832954490f88b64c704d5c841c8a.tar.gz
postgresql-c273e8b13c30832954490f88b64c704d5c841c8a.zip
Add some defenses to guard against case where a rule refers to a table
or view that's been dropped and then recreated with the same name (but, perhaps, different columns). Eventually we'd like to support this but for now all we can do is fail cleanly, rather than possibly coredumping if we proceed using the obsolete rule.
Diffstat (limited to 'src/backend/rewrite/rewriteHandler.c')
-rw-r--r--src/backend/rewrite/rewriteHandler.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index 889351067db..9bc112de200 100644
--- a/src/backend/rewrite/rewriteHandler.c
+++ b/src/backend/rewrite/rewriteHandler.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.91 2001/03/22 06:16:16 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.92 2001/04/17 00:32:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -486,16 +486,25 @@ fireRIRrules(Query *parsetree)
rel = heap_openr(rte->relname, lockmode);
+ /*
+ * Check to see if relation's OID matches the RTE. If not, the RTE
+ * actually refers to an older relation that had the same name.
+ * Eventually we might want to reparse the referencing rule, but
+ * for now all we can do is punt.
+ */
+ if (RelationGetRelid(rel) != rte->relid)
+ elog(ERROR, "Relation \"%s\" with OID %u no longer exists",
+ rte->relname, rte->relid);
+
+ /*
+ * Collect the RIR rules that we must apply
+ */
rules = rel->rd_rules;
if (rules == NULL)
{
heap_close(rel, NoLock);
continue;
}
-
- /*
- * Collect the RIR rules that we must apply
- */
locks = NIL;
for (i = 0; i < rules->numLocks; i++)
{
@@ -776,6 +785,19 @@ RewriteQuery(Query *parsetree, bool *instead_flag, List **qual_products)
*/
rt_entry_relation = heap_openr(rt_entry->relname, RowExclusiveLock);
+ /*
+ * Check to see if relation's OID matches the RTE. If not, the RTE
+ * actually refers to an older relation that had the same name.
+ * Eventually we might want to reparse the referencing rule, but
+ * for now all we can do is punt.
+ */
+ if (RelationGetRelid(rt_entry_relation) != rt_entry->relid)
+ elog(ERROR, "Relation \"%s\" with OID %u no longer exists",
+ rt_entry->relname, rt_entry->relid);
+
+ /*
+ * Collect and apply the appropriate rules.
+ */
rt_entry_locks = rt_entry_relation->rd_rules;
if (rt_entry_locks != NULL)