Fix crash if a DROP is attempted on an internally-dependent object.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Sep 2009 15:46:35 +0000 (15:46 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Sep 2009 15:46:35 +0000 (15:46 +0000)
Introduced in 8.4 rewrite of dependency.c.
Per bug #5072 from Amit Khandekar.

src/backend/catalog/dependency.c
src/test/regress/expected/rules.out
src/test/regress/sql/rules.sql

index dd2b29a43d799208138bed13c27ed1526fe29571..cb9a9c2675024e7879990e4d4dd2296a96971392 100644 (file)
@@ -559,7 +559,8 @@ findDependentObjects(const ObjectAddress *object,
                                {
                                        char       *otherObjDesc;
 
-                                       if (object_address_present(&otherObject, pendingObjects))
+                                       if (pendingObjects &&
+                                               object_address_present(&otherObject, pendingObjects))
                                        {
                                                systable_endscan(scan);
                                                /* need to release caller's lock; see notes below */
index 2667a13e44e03b372961e4bf9e64ddf4a978b0f3..9244376a3b98f2f0b1b813c9e9ac9d9ef445efce 100644 (file)
@@ -1424,10 +1424,10 @@ insert into rule_and_refint_t3 values (1, 12, 11, 'row3');
 insert into rule_and_refint_t3 values (1, 12, 12, 'row4');
 insert into rule_and_refint_t3 values (1, 11, 13, 'row5');
 ERROR:  insert or update on table "rule_and_refint_t3" violates foreign key constraint "rule_and_refint_t3_id3a_fkey1"
-DETAIL:  Key (id3a,id3c)=(1,13) is not present in table "rule_and_refint_t2".
+DETAIL:  Key (id3a, id3c)=(1, 13) is not present in table "rule_and_refint_t2".
 insert into rule_and_refint_t3 values (1, 13, 11, 'row6');
 ERROR:  insert or update on table "rule_and_refint_t3" violates foreign key constraint "rule_and_refint_t3_id3a_fkey"
-DETAIL:  Key (id3a,id3b)=(1,13) is not present in table "rule_and_refint_t1".
+DETAIL:  Key (id3a, id3b)=(1, 13) is not present in table "rule_and_refint_t1".
 create rule rule_and_refint_t3_ins as on insert to rule_and_refint_t3
        where (exists (select 1 from rule_and_refint_t3
                        where (((rule_and_refint_t3.id3a = new.id3a)
@@ -1439,10 +1439,18 @@ create rule rule_and_refint_t3_ins as on insert to rule_and_refint_t3
        and (rule_and_refint_t3.id3c = new.id3c));
 insert into rule_and_refint_t3 values (1, 11, 13, 'row7');
 ERROR:  insert or update on table "rule_and_refint_t3" violates foreign key constraint "rule_and_refint_t3_id3a_fkey1"
-DETAIL:  Key (id3a,id3c)=(1,13) is not present in table "rule_and_refint_t2".
+DETAIL:  Key (id3a, id3c)=(1, 13) is not present in table "rule_and_refint_t2".
 insert into rule_and_refint_t3 values (1, 13, 11, 'row8');
 ERROR:  insert or update on table "rule_and_refint_t3" violates foreign key constraint "rule_and_refint_t3_id3a_fkey"
-DETAIL:  Key (id3a,id3b)=(1,13) is not present in table "rule_and_refint_t1".
+DETAIL:  Key (id3a, id3b)=(1, 13) is not present in table "rule_and_refint_t1".
+--
+-- disallow dropping a view's rule (bug #5072)
+--
+create view fooview as select 'foo'::text;
+drop rule "_RETURN" on fooview;
+ERROR:  cannot drop rule _RETURN on view fooview because view fooview requires it
+HINT:  You can drop view fooview instead.
+drop view fooview;
 --
 -- check for planner problems with complex inherited UPDATES
 --
index a522d52d19909f7f23d9f680e55ae13478d41bb9..c7cf788b20ee4e8e7e6cd39f825b8a884c812864 100644 (file)
@@ -851,6 +851,14 @@ create rule rule_and_refint_t3_ins as on insert to rule_and_refint_t3
 insert into rule_and_refint_t3 values (1, 11, 13, 'row7');
 insert into rule_and_refint_t3 values (1, 13, 11, 'row8');
 
+--
+-- disallow dropping a view's rule (bug #5072)
+--
+
+create view fooview as select 'foo'::text;
+drop rule "_RETURN" on fooview;
+drop view fooview;
+
 --
 -- check for planner problems with complex inherited UPDATES
 --