1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* rewriteSupport.c
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-06-30 09:04:23 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.43 2000/06/30 07:04:23 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
|
|
|
|
#include "access/heapam.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "catalog/catname.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "catalog/indexing.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "rewrite/rewriteSupport.h"
|
1999-07-16 05:14:30 +02:00
|
|
|
#include "utils/catcache.h"
|
|
|
|
#include "utils/syscache.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
IsDefinedRewriteRule(char *ruleName)
|
|
|
|
{
|
1998-08-19 04:04:17 +02:00
|
|
|
HeapTuple tuple;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-11-22 18:56:41 +01:00
|
|
|
tuple = SearchSysCacheTuple(RULENAME,
|
1998-09-01 06:40:42 +02:00
|
|
|
PointerGetDatum(ruleName),
|
|
|
|
0, 0, 0);
|
1998-09-01 05:29:17 +02:00
|
|
|
return HeapTupleIsValid(tuple);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-30 09:04:23 +02:00
|
|
|
/*
|
|
|
|
* setRelhasrulesInRelation
|
|
|
|
* Set the value of the relation's relhasrules field in pg_class.
|
|
|
|
*
|
|
|
|
* NOTE: caller should be holding an appropriate lock on the relation.
|
|
|
|
*
|
|
|
|
* NOTE: an important side-effect of this operation is that an SI invalidation
|
|
|
|
* message is sent out to all backends --- including me --- causing relcache
|
|
|
|
* entries to be flushed or updated with the new set of rules for the table.
|
|
|
|
* Therefore, we execute the update even if relhasrules has the right value
|
|
|
|
* already. Possible future improvement: skip the disk update and just send
|
|
|
|
* an SI message in that case.
|
|
|
|
*/
|
|
|
|
void
|
1996-07-09 08:22:35 +02:00
|
|
|
setRelhasrulesInRelation(Oid relationId, bool relhasrules)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Relation relationRelation;
|
|
|
|
HeapTuple tuple;
|
|
|
|
Relation idescs[Num_pg_class_indices];
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
2000-06-30 09:04:23 +02:00
|
|
|
* Find the tuple to update in pg_class, using syscache for the lookup.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
1999-09-18 21:08:25 +02:00
|
|
|
relationRelation = heap_openr(RelationRelationName, RowExclusiveLock);
|
1998-08-19 04:04:17 +02:00
|
|
|
tuple = SearchSysCacheTupleCopy(RELOID,
|
1998-09-01 06:40:42 +02:00
|
|
|
ObjectIdGetDatum(relationId),
|
|
|
|
0, 0, 0);
|
1998-08-19 04:04:17 +02:00
|
|
|
Assert(HeapTupleIsValid(tuple));
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-30 09:04:23 +02:00
|
|
|
/* Do the update */
|
1998-09-01 06:40:42 +02:00
|
|
|
((Form_pg_class) GETSTRUCT(tuple))->relhasrules = relhasrules;
|
1999-11-24 01:44:37 +01:00
|
|
|
heap_update(relationRelation, &tuple->t_self, tuple, NULL);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-30 09:04:23 +02:00
|
|
|
/* Keep the catalog indices up to date */
|
1997-09-07 07:04:48 +02:00
|
|
|
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
|
1998-08-19 04:04:17 +02:00
|
|
|
CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
|
1997-09-07 07:04:48 +02:00
|
|
|
CatalogCloseIndices(Num_pg_class_indices, idescs);
|
|
|
|
|
1999-12-16 23:20:03 +01:00
|
|
|
heap_freetuple(tuple);
|
1999-09-18 21:08:25 +02:00
|
|
|
heap_close(relationRelation, RowExclusiveLock);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|