1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

heap_fetch requires buffer pointer, must be released; heap_getnext

no longer returns buffer pointer, can be gotten from scan;
	descriptor; bootstrap can create multi-key indexes;
pg_procname index now is multi-key index; oidint2, oidint4, oidname
are gone (must be removed from regression tests); use System Cache
rather than sequential scan in many places; heap_modifytuple no
longer takes buffer parameter; remove unused buffer parameter in
a few other functions; oid8 is not index-able; remove some use of
single-character variable names; cleanup Buffer variables usage
and scan descriptor looping; cleaned up allocation and freeing of
tuples; 18k lines of diff;
This commit is contained in:
Bruce Momjian
1998-08-19 02:04:17 +00:00
parent 31de2c9461
commit 7971539020
123 changed files with 2139 additions and 3134 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.17 1998/08/18 00:48:58 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.18 1998/08/19 02:02:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -97,7 +97,7 @@ InsertRule(char *rulname,
eventrel = heap_openr(evobj);
if (eventrel == NULL)
elog(ERROR, "rules cannot be defined on relations not in schema");
eventrel_oid = RelationGetRelationId(eventrel);
eventrel_oid = RelationGetRelid(eventrel);
/*
* if the slotname is null, we know that this is a multi-attr rule
@ -201,7 +201,7 @@ DefineQueryRewrite(RuleStmt *stmt)
event_relation = heap_openr(event_obj->relname);
if (event_relation == NULL)
elog(ERROR, "virtual relations not supported yet");
ev_relid = RelationGetRelationId(event_relation);
ev_relid = RelationGetRelid(event_relation);
if (eslot_string == NULL)
{

View File

@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.18 1998/08/18 00:48:59 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.19 1998/08/19 02:02:30 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -1038,7 +1038,9 @@ CheckViewPerms(Relation view, List *rtable)
/*
* get the usename of the view's owner
*/
utup = SearchSysCacheTuple(USESYSID, view->rd_rel->relowner, 0, 0, 0);
utup = SearchSysCacheTuple(USESYSID,
ObjectIdGetDatum(view->rd_rel->relowner),
0, 0, 0);
if (!HeapTupleIsValid(utup))
{
elog(ERROR, "cache lookup for userid %d failed",

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.15 1998/07/27 19:38:08 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.16 1998/08/19 02:02:32 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -32,21 +32,23 @@
char *
RewriteGetRuleEventRel(char *rulename)
{
HeapTuple htp;
HeapTuple htup;
Oid eventrel;
htp = SearchSysCacheTuple(REWRITENAME, PointerGetDatum(rulename),
0, 0, 0);
if (!HeapTupleIsValid(htp))
htup = SearchSysCacheTuple(REWRITENAME,
PointerGetDatum(rulename),
0, 0, 0);
if (!HeapTupleIsValid(htup))
elog(ERROR, "RewriteGetRuleEventRel: rule \"%s\" not found",
rulename);
eventrel = ((Form_pg_rewrite) GETSTRUCT(htp))->ev_class;
htp = SearchSysCacheTuple(RELOID, PointerGetDatum(eventrel),
eventrel = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
htup = SearchSysCacheTuple(RELOID,
PointerGetDatum(eventrel),
0, 0, 0);
if (!HeapTupleIsValid(htp))
if (!HeapTupleIsValid(htup))
elog(ERROR, "RewriteGetRuleEventRel: class %d not found",
eventrel);
return ((Form_pg_class) GETSTRUCT(htp))->relname.data;
return ((Form_pg_class) GETSTRUCT(htup))->relname.data;
}
/* ----------------------------------------------------------------
@ -68,8 +70,6 @@ void
RemoveRewriteRule(char *ruleName)
{
Relation RewriteRelation = NULL;
HeapScanDesc scanDesc = NULL;
ScanKeyData scanKeyData;
HeapTuple tuple = NULL;
Oid ruleId = (Oid) 0;
Oid eventRelationOid = (Oid) NULL;
@ -84,13 +84,9 @@ RemoveRewriteRule(char *ruleName)
/*
* Scan the RuleRelation ('pg_rewrite') until we find a tuple
*/
ScanKeyEntryInitialize(&scanKeyData, 0, Anum_pg_rewrite_rulename,
F_NAMEEQ, NameGetDatum(ruleName));
scanDesc = heap_beginscan(RewriteRelation,
0, SnapshotNow, 1, &scanKeyData);
tuple = heap_getnext(scanDesc, 0, (Buffer *) NULL);
tuple = SearchSysCacheTupleCopy(REWRITENAME,
PointerGetDatum(ruleName),
0, 0, 0);
/*
* complain if no rule with such name existed
*/
@ -105,14 +101,14 @@ RemoveRewriteRule(char *ruleName)
* relation's OID
*/
ruleId = tuple->t_oid;
eventRelationOidDatum =
heap_getattr(tuple,
Anum_pg_rewrite_ev_class,
RelationGetTupleDescriptor(RewriteRelation),
&isNull);
eventRelationOidDatum = heap_getattr(tuple,
Anum_pg_rewrite_ev_class,
RelationGetTupleDescriptor(RewriteRelation),
&isNull);
if (isNull)
{
/* XXX strange!!! */
pfree(tuple);
elog(ERROR, "RemoveRewriteRule: null event target relation!");
}
eventRelationOid = DatumGetObjectId(eventRelationOidDatum);
@ -128,9 +124,10 @@ RemoveRewriteRule(char *ruleName)
/*
* Now delete the tuple...
*/
heap_delete(RewriteRelation, &(tuple->t_ctid));
heap_delete(RewriteRelation, &tuple->t_ctid);
pfree(tuple);
heap_close(RewriteRelation);
heap_endscan(scanDesc);
}
/*
@ -163,20 +160,8 @@ RelationRemoveRules(Oid relid)
scanDesc = heap_beginscan(RewriteRelation,
0, SnapshotNow, 1, &scanKeyData);
for (;;)
{
tuple = heap_getnext(scanDesc, 0, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple))
{
break; /* we're done */
}
/*
* delete the tuple...
*/
heap_delete(RewriteRelation, &(tuple->t_ctid));
}
while (HeapTupleIsValid(tuple = heap_getnext(scanDesc, 0)))
heap_delete(RewriteRelation, &tuple->t_ctid);
heap_endscan(scanDesc);
heap_close(RewriteRelation);

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.24 1998/07/27 19:38:09 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.25 1998/08/19 02:02:33 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -22,6 +22,7 @@
#include "nodes/parsenodes.h"
#include "nodes/pg_list.h"
#include "storage/buf.h" /* for InvalidBuffer */
#include "storage/bufmgr.h"
#include "utils/builtins.h" /* for textout */
#include "utils/catcache.h" /* for CacheContext */
#include "utils/mcxt.h" /* MemoryContext stuff */
@ -89,9 +90,7 @@ int
IsDefinedRewriteRule(char *ruleName)
{
Relation RewriteRelation = NULL;
HeapScanDesc scanDesc = NULL;
ScanKeyData scanKey;
HeapTuple tuple = NULL;
HeapTuple tuple;
/*
@ -99,21 +98,13 @@ IsDefinedRewriteRule(char *ruleName)
*/
RewriteRelation = heap_openr(RewriteRelationName);
/*
* Scan the RuleRelation ('pg_rewrite') until we find a tuple
*/
ScanKeyEntryInitialize(&scanKey, 0, Anum_pg_rewrite_rulename,
F_NAMEEQ, PointerGetDatum(ruleName));
scanDesc = heap_beginscan(RewriteRelation,
0, SnapshotNow, 1, &scanKey);
tuple = heap_getnext(scanDesc, 0, (Buffer *) NULL);
tuple = SearchSysCacheTuple(REWRITENAME,
PointerGetDatum(ruleName),
0, 0, 0);
/*
* return whether or not the rewrite rule existed
*/
heap_close(RewriteRelation);
heap_endscan(scanDesc);
return (HeapTupleIsValid(tuple));
}
@ -122,40 +113,28 @@ setRelhasrulesInRelation(Oid relationId, bool relhasrules)
{
Relation relationRelation;
HeapTuple tuple;
HeapTuple newTuple;
Relation idescs[Num_pg_class_indices];
Form_pg_class relp;
/*
* Lock a relation given its Oid. Go to the RelationRelation (i.e.
* pg_relation), find the appropriate tuple, and add the specified
* lock to it.
*/
tuple = SearchSysCacheTupleCopy(RELOID,
ObjectIdGetDatum(relationId),
0, 0, 0);
Assert(HeapTupleIsValid(tuple));
relationRelation = heap_openr(RelationRelationName);
tuple = ClassOidIndexScan(relationRelation, relationId);
/*
* Create a new tuple (i.e. a copy of the old tuple with its rule lock
* field changed and replace the old tuple in the RelationRelation
* NOTE: XXX ??? do we really need to make that copy ????
*/
newTuple = heap_copytuple(tuple);
relp = (Form_pg_class) GETSTRUCT(newTuple);
relp->relhasrules = relhasrules;
heap_replace(relationRelation, &(tuple->t_ctid), newTuple);
((Form_pg_class)GETSTRUCT(tuple))->relhasrules = relhasrules;
heap_replace(relationRelation, &tuple->t_ctid, tuple);
/* keep the catalog indices up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation,
newTuple);
CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
CatalogCloseIndices(Num_pg_class_indices, idescs);
/* be tidy */
pfree(tuple);
pfree(newTuple);
heap_close(relationRelation);
}