8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
15
15
#include "postgres.h"
16
16
17
17
#include "access/heapam.h"
18
- #include "access/xact.h"
19
18
#include "catalog/dependency.h"
20
19
#include "catalog/indexing.h"
21
20
#include "catalog/namespace.h"
26
25
#include "parser/parse_utilcmd.h"
27
26
#include "rewrite/rewriteDefine.h"
28
27
#include "rewrite/rewriteManip.h"
29
- #include "rewrite/rewriteRemove.h"
30
28
#include "rewrite/rewriteSupport.h"
31
29
#include "utils/acl.h"
32
30
#include "utils/builtins.h"
@@ -41,7 +39,6 @@ static void checkRuleResultList(List *targetList, TupleDesc resultDesc,
41
39
bool isSelect );
42
40
static bool setRuleCheckAsUser_walker (Node * node ,Oid * context );
43
41
static void setRuleCheckAsUser_Query (Query * qry ,Oid userid );
44
- static const char * rule_event_string (CmdType evtype );
45
42
46
43
47
44
/*
@@ -55,7 +52,6 @@ InsertRule(char *rulname,
55
52
Oid eventrel_oid ,
56
53
AttrNumber evslot_index ,
57
54
bool evinstead ,
58
- bool is_auto ,
59
55
Node * event_qual ,
60
56
List * action ,
61
57
bool replace )
@@ -88,7 +84,6 @@ InsertRule(char *rulname,
88
84
values [i ++ ]= CharGetDatum (evtype + '0' );/* ev_type */
89
85
values [i ++ ]= CharGetDatum (RULE_FIRES_ON_ORIGIN );/* ev_enabled */
90
86
values [i ++ ]= BoolGetDatum (evinstead );/* is_instead */
91
- values [i ++ ]= BoolGetDatum (is_auto );/* is_auto */
92
87
values [i ++ ]= CStringGetTextDatum (evqual );/* ev_qual */
93
88
values [i ++ ]= CStringGetTextDatum (actiontree );/* ev_action */
94
89
@@ -107,11 +102,7 @@ InsertRule(char *rulname,
107
102
108
103
if (HeapTupleIsValid (oldtup ))
109
104
{
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 )
115
106
ereport (ERROR ,
116
107
(errcode (ERRCODE_DUPLICATE_OBJECT ),
117
108
errmsg ("rule \"%s\" for relation \"%s\" already exists" ,
@@ -124,7 +115,6 @@ InsertRule(char *rulname,
124
115
replaces [Anum_pg_rewrite_ev_attr - 1 ]= true;
125
116
replaces [Anum_pg_rewrite_ev_type - 1 ]= true;
126
117
replaces [Anum_pg_rewrite_is_instead - 1 ]= true;
127
- replaces [Anum_pg_rewrite_is_auto - 1 ]= true;
128
118
replaces [Anum_pg_rewrite_ev_qual - 1 ]= true;
129
119
replaces [Anum_pg_rewrite_ev_action - 1 ]= true;
130
120
@@ -215,7 +205,6 @@ DefineRule(RuleStmt *stmt, const char *queryString)
215
205
whereClause ,
216
206
stmt -> event ,
217
207
stmt -> instead ,
218
- false,/* not is_auto */
219
208
stmt -> replace ,
220
209
actions );
221
210
}
@@ -234,7 +223,6 @@ DefineQueryRewrite(char *rulename,
234
223
Node * event_qual ,
235
224
CmdType event_type ,
236
225
bool is_instead ,
237
- bool is_auto ,
238
226
bool replace ,
239
227
List * action )
240
228
{
@@ -458,42 +446,6 @@ DefineQueryRewrite(char *rulename,
458
446
RelationGetDescr (event_relation ),
459
447
false);
460
448
}
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
-
497
449
}
498
450
499
451
/*
@@ -509,7 +461,6 @@ DefineQueryRewrite(char *rulename,
509
461
event_relid ,
510
462
event_attno ,
511
463
is_instead ,
512
- is_auto ,
513
464
event_qual ,
514
465
action ,
515
466
replace );
@@ -803,16 +754,3 @@ RenameRewriteRule(Oid owningRel, const char *oldName,
803
754
}
804
755
805
756
#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
- }