88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.135 2009/01/22 17:27:54 petere Exp $
11+ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.136 2009/01/27 12:40:15 petere Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
1515#include "postgres.h"
1616
1717#include "access/heapam.h"
18- #include "access/xact.h"
1918#include "catalog/dependency.h"
2019#include "catalog/indexing.h"
2120#include "catalog/namespace.h"
2625#include "parser/parse_utilcmd.h"
2726#include "rewrite/rewriteDefine.h"
2827#include "rewrite/rewriteManip.h"
29- #include "rewrite/rewriteRemove.h"
3028#include "rewrite/rewriteSupport.h"
3129#include "utils/acl.h"
3230#include "utils/builtins.h"
@@ -41,7 +39,6 @@ static void checkRuleResultList(List *targetList, TupleDesc resultDesc,
4139bool isSelect );
4240static bool setRuleCheckAsUser_walker (Node * node ,Oid * context );
4341static void setRuleCheckAsUser_Query (Query * qry ,Oid userid );
44- static const char * rule_event_string (CmdType evtype );
4542
4643
4744/*
@@ -55,7 +52,6 @@ InsertRule(char *rulname,
5552Oid eventrel_oid ,
5653AttrNumber evslot_index ,
5754bool evinstead ,
58- bool is_auto ,
5955Node * event_qual ,
6056List * action ,
6157bool replace )
@@ -88,7 +84,6 @@ InsertRule(char *rulname,
8884values [i ++ ]= CharGetDatum (evtype + '0' );/* ev_type */
8985values [i ++ ]= CharGetDatum (RULE_FIRES_ON_ORIGIN );/* ev_enabled */
9086values [i ++ ]= BoolGetDatum (evinstead );/* is_instead */
91- values [i ++ ]= BoolGetDatum (is_auto );/* is_auto */
9287values [i ++ ]= CStringGetTextDatum (evqual );/* ev_qual */
9388values [i ++ ]= CStringGetTextDatum (actiontree );/* ev_action */
9489
@@ -107,11 +102,7 @@ InsertRule(char *rulname,
107102
108103if (HeapTupleIsValid (oldtup ))
109104{
110- /*
111- * If REPLACE was not used we still check if the old rule is
112- * automatic: Then we replace it anyway.
113- */
114- if (!replace && !((Form_pg_rewrite )GETSTRUCT (oldtup ))-> is_auto )
105+ if (!replace )
115106ereport (ERROR ,
116107(errcode (ERRCODE_DUPLICATE_OBJECT ),
117108errmsg ("rule \"%s\" for relation \"%s\" already exists" ,
@@ -124,7 +115,6 @@ InsertRule(char *rulname,
124115replaces [Anum_pg_rewrite_ev_attr - 1 ]= true;
125116replaces [Anum_pg_rewrite_ev_type - 1 ]= true;
126117replaces [Anum_pg_rewrite_is_instead - 1 ]= true;
127- replaces [Anum_pg_rewrite_is_auto - 1 ]= true;
128118replaces [Anum_pg_rewrite_ev_qual - 1 ]= true;
129119replaces [Anum_pg_rewrite_ev_action - 1 ]= true;
130120
@@ -215,7 +205,6 @@ DefineRule(RuleStmt *stmt, const char *queryString)
215205whereClause ,
216206stmt -> event ,
217207stmt -> instead ,
218- false,/* not is_auto */
219208stmt -> replace ,
220209actions );
221210}
@@ -234,7 +223,6 @@ DefineQueryRewrite(char *rulename,
234223Node * event_qual ,
235224CmdType event_type ,
236225bool is_instead ,
237- bool is_auto ,
238226bool replace ,
239227List * action )
240228{
@@ -458,42 +446,6 @@ DefineQueryRewrite(char *rulename,
458446RelationGetDescr (event_relation ),
459447false);
460448}
461-
462- /*
463- * If defining a non-automatic DO INSTEAD rule, drop all
464- * automatic rules on the same event.
465- */
466- if (!is_auto && is_instead )
467- {
468- RemoveAutomaticRulesOnEvent (event_relation ,event_type );
469- CommandCounterIncrement ();
470- }
471-
472- /*
473- * If defining an automatic rule and there is a manual rule on
474- * the same event, warn and don't do it.
475- */
476- if (is_auto && event_relation -> rd_rules != NULL )
477- {
478- int i ;
479-
480- for (i = 0 ;i < event_relation -> rd_rules -> numLocks ;i ++ )
481- {
482- RewriteRule * rule = event_relation -> rd_rules -> rules [i ];
483-
484- if (rule -> event == event_type && !rule -> is_auto && rule -> isInstead == is_instead )
485- {
486- ereport (WARNING ,
487- (errmsg ("automatic %s rule not created because manually created %s rule exists" ,
488- rule_event_string (event_type ),rule_event_string (event_type )),
489- errhint ("If you prefer to have the automatic rule, drop the manually created rule and run CREATE OR REPLACE VIEW again." )));
490-
491- heap_close (event_relation ,NoLock );
492- return ;
493- }
494- }
495- }
496-
497449}
498450
499451/*
@@ -509,7 +461,6 @@ DefineQueryRewrite(char *rulename,
509461event_relid ,
510462event_attno ,
511463is_instead ,
512- is_auto ,
513464event_qual ,
514465action ,
515466replace );
@@ -803,16 +754,3 @@ RenameRewriteRule(Oid owningRel, const char *oldName,
803754}
804755
805756#endif
806-
807-
808- static const char *
809- rule_event_string (CmdType type )
810- {
811- if (type == CMD_INSERT )
812- return "INSERT" ;
813- if (type == CMD_UPDATE )
814- return "UPDATE" ;
815- if (type == CMD_DELETE )
816- return "DELETE" ;
817- return "???" ;
818- }