mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Change SearchSysCache coding conventions so that a reference count is
maintained for each cache entry. A cache entry will not be freed until the matching ReleaseSysCache call has been executed. This eliminates worries about cache entries getting dropped while still in use. See my posting to pg-hackers of even date for more info.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.8 2000/10/16 17:08:05 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.9 2000/11/16 22:30:19 tgl Exp $
|
||||
*
|
||||
|
||||
*-------------------------------------------------------------------------
|
||||
@@ -58,8 +58,7 @@ static void del_stats(Oid relid, int attcnt, int *attnums);
|
||||
void
|
||||
analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL)
|
||||
{
|
||||
HeapTuple tuple,
|
||||
typetuple;
|
||||
HeapTuple tuple;
|
||||
Relation onerel;
|
||||
int32 i;
|
||||
int attr_cnt,
|
||||
@@ -81,20 +80,26 @@ analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL)
|
||||
* Race condition -- if the pg_class tuple has gone away since the
|
||||
* last time we saw it, we don't need to vacuum it.
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(RELOID,
|
||||
ObjectIdGetDatum(relid),
|
||||
0, 0, 0);
|
||||
/*
|
||||
* We can VACUUM ANALYZE any table except pg_statistic.
|
||||
* see update_relstats
|
||||
*/
|
||||
if (!HeapTupleIsValid(tuple) ||
|
||||
strcmp(NameStr(((Form_pg_class) GETSTRUCT(tuple))->relname),
|
||||
StatisticRelationName) == 0)
|
||||
tuple = SearchSysCache(RELOID,
|
||||
ObjectIdGetDatum(relid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
CommitTransactionCommand();
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* We can VACUUM ANALYZE any table except pg_statistic.
|
||||
* see update_relstats
|
||||
*/
|
||||
if (strcmp(NameStr(((Form_pg_class) GETSTRUCT(tuple))->relname),
|
||||
StatisticRelationName) == 0)
|
||||
{
|
||||
ReleaseSysCache(tuple);
|
||||
CommitTransactionCommand();
|
||||
return;
|
||||
}
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
onerel = heap_open(relid, AccessShareLock);
|
||||
|
||||
@@ -168,6 +173,7 @@ analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL)
|
||||
{
|
||||
pgopform = (Form_pg_operator) GETSTRUCT(func_operator);
|
||||
fmgr_info(pgopform->oprcode, &(stats->f_cmpeq));
|
||||
ReleaseSysCache(func_operator);
|
||||
}
|
||||
else
|
||||
stats->f_cmpeq.fn_addr = NULL;
|
||||
@@ -178,6 +184,7 @@ analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL)
|
||||
pgopform = (Form_pg_operator) GETSTRUCT(func_operator);
|
||||
fmgr_info(pgopform->oprcode, &(stats->f_cmplt));
|
||||
stats->op_cmplt = oprid(func_operator);
|
||||
ReleaseSysCache(func_operator);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -190,17 +197,19 @@ analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL)
|
||||
{
|
||||
pgopform = (Form_pg_operator) GETSTRUCT(func_operator);
|
||||
fmgr_info(pgopform->oprcode, &(stats->f_cmpgt));
|
||||
ReleaseSysCache(func_operator);
|
||||
}
|
||||
else
|
||||
stats->f_cmpgt.fn_addr = NULL;
|
||||
|
||||
typetuple = SearchSysCacheTuple(TYPEOID,
|
||||
ObjectIdGetDatum(stats->attr->atttypid),
|
||||
0, 0, 0);
|
||||
if (HeapTupleIsValid(typetuple))
|
||||
tuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(stats->attr->atttypid),
|
||||
0, 0, 0);
|
||||
if (HeapTupleIsValid(tuple))
|
||||
{
|
||||
stats->outfunc = ((Form_pg_type) GETSTRUCT(typetuple))->typoutput;
|
||||
stats->typelem = ((Form_pg_type) GETSTRUCT(typetuple))->typelem;
|
||||
stats->outfunc = ((Form_pg_type) GETSTRUCT(tuple))->typoutput;
|
||||
stats->typelem = ((Form_pg_type) GETSTRUCT(tuple))->typelem;
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.70 2000/10/03 03:11:13 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.71 2000/11/16 22:30:18 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -193,9 +193,7 @@ void
|
||||
Async_Listen(char *relname, int pid)
|
||||
{
|
||||
Relation lRel;
|
||||
TupleDesc tdesc;
|
||||
HeapTuple tuple,
|
||||
newtup;
|
||||
HeapTuple tuple;
|
||||
Datum values[Natts_pg_listener];
|
||||
char nulls[Natts_pg_listener];
|
||||
int i;
|
||||
@@ -205,13 +203,12 @@ Async_Listen(char *relname, int pid)
|
||||
elog(DEBUG, "Async_Listen: %s", relname);
|
||||
|
||||
lRel = heap_openr(ListenerRelationName, AccessExclusiveLock);
|
||||
tdesc = RelationGetDescr(lRel);
|
||||
|
||||
/* Detect whether we are already listening on this relname */
|
||||
tuple = SearchSysCacheTuple(LISTENREL, Int32GetDatum(pid),
|
||||
PointerGetDatum(relname),
|
||||
0, 0);
|
||||
if (tuple != NULL)
|
||||
if (SearchSysCacheExists(LISTENREL,
|
||||
Int32GetDatum(pid),
|
||||
PointerGetDatum(relname),
|
||||
0, 0))
|
||||
{
|
||||
/* No need to scan the rest of the table */
|
||||
heap_close(lRel, AccessExclusiveLock);
|
||||
@@ -235,18 +232,18 @@ Async_Listen(char *relname, int pid)
|
||||
values[i++] = (Datum) 0; /* no notifies pending */
|
||||
|
||||
tupDesc = lRel->rd_att;
|
||||
newtup = heap_formtuple(tupDesc, values, nulls);
|
||||
heap_insert(lRel, newtup);
|
||||
tuple = heap_formtuple(tupDesc, values, nulls);
|
||||
heap_insert(lRel, tuple);
|
||||
if (RelationGetForm(lRel)->relhasindex)
|
||||
{
|
||||
Relation idescs[Num_pg_listener_indices];
|
||||
|
||||
CatalogOpenIndices(Num_pg_listener_indices, Name_pg_listener_indices, idescs);
|
||||
CatalogIndexInsert(idescs, Num_pg_listener_indices, lRel, newtup);
|
||||
CatalogIndexInsert(idescs, Num_pg_listener_indices, lRel, tuple);
|
||||
CatalogCloseIndices(Num_pg_listener_indices, idescs);
|
||||
}
|
||||
|
||||
heap_freetuple(newtup);
|
||||
heap_freetuple(tuple);
|
||||
|
||||
heap_close(lRel, AccessExclusiveLock);
|
||||
|
||||
@@ -296,11 +293,15 @@ Async_Unlisten(char *relname, int pid)
|
||||
|
||||
lRel = heap_openr(ListenerRelationName, AccessExclusiveLock);
|
||||
/* Note we assume there can be only one matching tuple. */
|
||||
lTuple = SearchSysCacheTuple(LISTENREL, Int32GetDatum(pid),
|
||||
PointerGetDatum(relname),
|
||||
0, 0);
|
||||
if (lTuple != NULL)
|
||||
lTuple = SearchSysCache(LISTENREL,
|
||||
Int32GetDatum(pid),
|
||||
PointerGetDatum(relname),
|
||||
0, 0);
|
||||
if (HeapTupleIsValid(lTuple))
|
||||
{
|
||||
heap_delete(lRel, &lTuple->t_self, NULL);
|
||||
ReleaseSysCache(lTuple);
|
||||
}
|
||||
heap_close(lRel, AccessExclusiveLock);
|
||||
|
||||
/*
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.59 2000/11/08 22:09:57 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.60 2000/11/16 22:30:18 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -84,15 +84,16 @@ cluster(char *oldrelname, char *oldindexname)
|
||||
/*
|
||||
* Check that index is in fact an index on the given relation
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(INDEXRELID,
|
||||
ObjectIdGetDatum(OIDOldIndex),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(INDEXRELID,
|
||||
ObjectIdGetDatum(OIDOldIndex),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "CLUSTER: no pg_index entry for index %u",
|
||||
OIDOldIndex);
|
||||
if (((Form_pg_index) GETSTRUCT(tuple))->indrelid != OIDOldHeap)
|
||||
elog(ERROR, "CLUSTER: \"%s\" is not an index for table \"%s\"",
|
||||
saveoldindexname, saveoldrelname);
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
/* Drop relcache refcnts, but do NOT give up the locks */
|
||||
heap_close(OldHeap, NoLock);
|
||||
@@ -184,17 +185,17 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName)
|
||||
* To do this I get the info from pg_index, and add a new index with
|
||||
* a temporary name.
|
||||
*/
|
||||
Old_pg_index_Tuple = SearchSysCacheTupleCopy(INDEXRELID,
|
||||
ObjectIdGetDatum(OIDOldIndex),
|
||||
0, 0, 0);
|
||||
Old_pg_index_Tuple = SearchSysCache(INDEXRELID,
|
||||
ObjectIdGetDatum(OIDOldIndex),
|
||||
0, 0, 0);
|
||||
Assert(Old_pg_index_Tuple);
|
||||
Old_pg_index_Form = (Form_pg_index) GETSTRUCT(Old_pg_index_Tuple);
|
||||
|
||||
indexInfo = BuildIndexInfo(Old_pg_index_Tuple);
|
||||
|
||||
Old_pg_index_relation_Tuple = SearchSysCacheTupleCopy(RELOID,
|
||||
ObjectIdGetDatum(OIDOldIndex),
|
||||
0, 0, 0);
|
||||
Old_pg_index_relation_Tuple = SearchSysCache(RELOID,
|
||||
ObjectIdGetDatum(OIDOldIndex),
|
||||
0, 0, 0);
|
||||
Assert(Old_pg_index_relation_Tuple);
|
||||
Old_pg_index_relation_Form = (Form_pg_class) GETSTRUCT(Old_pg_index_relation_Tuple);
|
||||
|
||||
@@ -209,6 +210,9 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName)
|
||||
|
||||
setRelhasindex(OIDNewHeap, true);
|
||||
|
||||
ReleaseSysCache(Old_pg_index_Tuple);
|
||||
ReleaseSysCache(Old_pg_index_relation_Tuple);
|
||||
|
||||
index_close(OldIndex);
|
||||
heap_close(NewHeap, NoLock);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.111 2000/11/14 01:57:30 inoue Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.112 2000/11/16 22:30:19 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The PerformAddAttribute() code, like most of the relation
|
||||
@@ -274,13 +274,13 @@ AlterTableAddColumn(const char *relationName,
|
||||
attrdesc;
|
||||
Oid myrelid;
|
||||
HeapTuple reltup;
|
||||
HeapTuple newreltup;
|
||||
HeapTuple attributeTuple;
|
||||
Form_pg_attribute attribute;
|
||||
FormData_pg_attribute attributeD;
|
||||
int i;
|
||||
int minattnum,
|
||||
maxatts;
|
||||
HeapTuple tup;
|
||||
Relation idescs[Num_pg_attr_indices];
|
||||
Relation ridescs[Num_pg_class_indices];
|
||||
bool hasindex;
|
||||
@@ -359,9 +359,9 @@ AlterTableAddColumn(const char *relationName,
|
||||
|
||||
rel = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
|
||||
reltup = SearchSysCacheTupleCopy(RELNAME,
|
||||
PointerGetDatum(relationName),
|
||||
0, 0, 0);
|
||||
reltup = SearchSysCache(RELNAME,
|
||||
PointerGetDatum(relationName),
|
||||
0, 0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(reltup))
|
||||
elog(ERROR, "ALTER TABLE: relation \"%s\" not found",
|
||||
@@ -371,10 +371,8 @@ AlterTableAddColumn(const char *relationName,
|
||||
* XXX is the following check sufficient?
|
||||
*/
|
||||
if (((Form_pg_class) GETSTRUCT(reltup))->relkind != RELKIND_RELATION)
|
||||
{
|
||||
elog(ERROR, "ALTER TABLE: relation \"%s\" is not a table",
|
||||
relationName);
|
||||
}
|
||||
|
||||
minattnum = ((Form_pg_class) GETSTRUCT(reltup))->relnatts;
|
||||
maxatts = minattnum + 1;
|
||||
@@ -407,12 +405,10 @@ AlterTableAddColumn(const char *relationName,
|
||||
char *typename;
|
||||
int attnelems;
|
||||
|
||||
tup = SearchSysCacheTuple(ATTNAME,
|
||||
ObjectIdGetDatum(reltup->t_data->t_oid),
|
||||
PointerGetDatum(colDef->colname),
|
||||
0, 0);
|
||||
|
||||
if (HeapTupleIsValid(tup))
|
||||
if (SearchSysCacheExists(ATTNAME,
|
||||
ObjectIdGetDatum(reltup->t_data->t_oid),
|
||||
PointerGetDatum(colDef->colname),
|
||||
0, 0))
|
||||
elog(ERROR, "ALTER TABLE: column name \"%s\" already exists in table \"%s\"",
|
||||
colDef->colname, relationName);
|
||||
|
||||
@@ -430,13 +426,13 @@ AlterTableAddColumn(const char *relationName,
|
||||
else
|
||||
attnelems = 0;
|
||||
|
||||
typeTuple = SearchSysCacheTuple(TYPENAME,
|
||||
PointerGetDatum(typename),
|
||||
0, 0, 0);
|
||||
tform = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
|
||||
typeTuple = SearchSysCache(TYPENAME,
|
||||
PointerGetDatum(typename),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "ALTER TABLE: type \"%s\" does not exist", typename);
|
||||
tform = (Form_pg_type) GETSTRUCT(typeTuple);
|
||||
|
||||
namestrcpy(&(attribute->attname), colDef->colname);
|
||||
attribute->atttypid = typeTuple->t_data->t_oid;
|
||||
attribute->attlen = tform->typlen;
|
||||
@@ -453,6 +449,8 @@ AlterTableAddColumn(const char *relationName,
|
||||
attribute->atthasdef = (colDef->raw_default != NULL ||
|
||||
colDef->cooked_default != NULL);
|
||||
|
||||
ReleaseSysCache(typeTuple);
|
||||
|
||||
heap_insert(attrdesc, attributeTuple);
|
||||
if (hasindex)
|
||||
CatalogIndexInsert(idescs,
|
||||
@@ -466,15 +464,21 @@ AlterTableAddColumn(const char *relationName,
|
||||
|
||||
heap_close(attrdesc, RowExclusiveLock);
|
||||
|
||||
((Form_pg_class) GETSTRUCT(reltup))->relnatts = maxatts;
|
||||
heap_update(rel, &reltup->t_self, reltup, NULL);
|
||||
/*
|
||||
* Update number of attributes in pg_class tuple
|
||||
*/
|
||||
newreltup = heap_copytuple(reltup);
|
||||
|
||||
((Form_pg_class) GETSTRUCT(newreltup))->relnatts = maxatts;
|
||||
heap_update(rel, &newreltup->t_self, newreltup, NULL);
|
||||
|
||||
/* keep catalog indices current */
|
||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
|
||||
CatalogIndexInsert(ridescs, Num_pg_class_indices, rel, reltup);
|
||||
CatalogIndexInsert(ridescs, Num_pg_class_indices, rel, newreltup);
|
||||
CatalogCloseIndices(Num_pg_class_indices, ridescs);
|
||||
|
||||
heap_freetuple(reltup);
|
||||
heap_freetuple(newreltup);
|
||||
ReleaseSysCache(reltup);
|
||||
|
||||
heap_close(rel, NoLock);
|
||||
|
||||
@@ -555,11 +559,10 @@ AlterTableAlterColumn(const char *relationName,
|
||||
/*
|
||||
* get the number of the attribute
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(ATTNAME,
|
||||
ObjectIdGetDatum(myrelid),
|
||||
PointerGetDatum(colName),
|
||||
0, 0);
|
||||
|
||||
tuple = SearchSysCache(ATTNAME,
|
||||
ObjectIdGetDatum(myrelid),
|
||||
PointerGetDatum(colName),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
heap_close(rel, AccessExclusiveLock);
|
||||
@@ -568,6 +571,7 @@ AlterTableAlterColumn(const char *relationName,
|
||||
}
|
||||
|
||||
attnum = ((Form_pg_attribute) GETSTRUCT(tuple))->attnum;
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
if (newDefault) /* SET DEFAULT */
|
||||
{
|
||||
@@ -595,7 +599,6 @@ AlterTableAlterColumn(const char *relationName,
|
||||
Relation attr_rel;
|
||||
ScanKeyData scankeys[3];
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tuple;
|
||||
|
||||
attr_rel = heap_openr(AttributeRelationName, AccessExclusiveLock);
|
||||
ScanKeyEntryInitialize(&scankeys[0], 0x0,
|
||||
@@ -867,10 +870,11 @@ RemoveColumnReferences(Oid reloid, int attnum, bool checkonly, HeapTuple reltup)
|
||||
}
|
||||
else
|
||||
{
|
||||
htup = SearchSysCacheTuple(RELOID,
|
||||
ObjectIdGetDatum(index->indexrelid),
|
||||
0, 0, 0);
|
||||
htup = SearchSysCache(RELOID,
|
||||
ObjectIdGetDatum(index->indexrelid),
|
||||
0, 0, 0);
|
||||
RemoveIndex(NameStr(((Form_pg_class) GETSTRUCT(htup))->relname));
|
||||
ReleaseSysCache(htup);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -941,18 +945,19 @@ AlterTableDropColumn(const char *relationName,
|
||||
if (length(find_all_inheritors(myrelid)) > 1)
|
||||
elog(ERROR, "ALTER TABLE: cannot drop a column on table that is inherited from");
|
||||
|
||||
|
||||
/*
|
||||
* lock the pg_class tuple for update
|
||||
*/
|
||||
reltup = SearchSysCacheTuple(RELNAME, PointerGetDatum(relationName),
|
||||
0, 0, 0);
|
||||
|
||||
rel = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
reltup = SearchSysCache(RELNAME,
|
||||
PointerGetDatum(relationName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(reltup))
|
||||
elog(ERROR, "ALTER TABLE: relation \"%s\" not found",
|
||||
relationName);
|
||||
rel = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
classtuple.t_self = reltup->t_self;
|
||||
ReleaseSysCache(reltup);
|
||||
|
||||
switch (heap_mark4update(rel, &classtuple, &buffer))
|
||||
{
|
||||
case HeapTupleSelfUpdated:
|
||||
@@ -976,19 +981,21 @@ AlterTableDropColumn(const char *relationName,
|
||||
attrdesc = heap_openr(AttributeRelationName, RowExclusiveLock);
|
||||
|
||||
/*
|
||||
* Get the target pg_attribute tuple
|
||||
* Get the target pg_attribute tuple and make a modifiable copy
|
||||
*/
|
||||
tup = SearchSysCacheTupleCopy(ATTNAME,
|
||||
ObjectIdGetDatum(reltup->t_data->t_oid),
|
||||
PointerGetDatum(colName), 0, 0);
|
||||
tup = SearchSysCacheCopy(ATTNAME,
|
||||
ObjectIdGetDatum(reltup->t_data->t_oid),
|
||||
PointerGetDatum(colName),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "ALTER TABLE: column name \"%s\" doesn't exist in table \"%s\"",
|
||||
colName, relationName);
|
||||
|
||||
attribute = (Form_pg_attribute) GETSTRUCT(tup);
|
||||
if (attribute->attnum <= 0)
|
||||
elog(ERROR, "ALTER TABLE: column name \"%s\" was already dropped", colName);
|
||||
attnum = attribute->attnum;
|
||||
if (attnum <= 0)
|
||||
elog(ERROR, "ALTER TABLE: column name \"%s\" was already dropped",
|
||||
colName);
|
||||
attoid = tup->t_data->t_oid;
|
||||
|
||||
/*
|
||||
@@ -1226,10 +1233,9 @@ AlterTableAddConstraint(char *relationName,
|
||||
int count;
|
||||
List *indexoidlist,
|
||||
*indexoidscan;
|
||||
Form_pg_index indexStruct = NULL;
|
||||
Form_pg_attribute *rel_attrs = NULL;
|
||||
int i;
|
||||
int found=0;
|
||||
int i;
|
||||
bool found = false;
|
||||
|
||||
if (get_temp_rel_by_username(fkconstraint->pktable_name)!=NULL &&
|
||||
get_temp_rel_by_username(relationName)==NULL) {
|
||||
@@ -1264,42 +1270,50 @@ AlterTableAddConstraint(char *relationName,
|
||||
indexoidlist = RelationGetIndexList(pkrel);
|
||||
|
||||
foreach(indexoidscan, indexoidlist)
|
||||
{
|
||||
Oid indexoid = lfirsti(indexoidscan);
|
||||
HeapTuple indexTuple;
|
||||
List *attrl;
|
||||
indexTuple = SearchSysCacheTuple(INDEXRELID,
|
||||
ObjectIdGetDatum(indexoid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(indexTuple))
|
||||
elog(ERROR, "transformFkeyGetPrimaryKey: index %u not found",
|
||||
indexoid);
|
||||
indexStruct = (Form_pg_index) GETSTRUCT(indexTuple);
|
||||
{
|
||||
Oid indexoid = lfirsti(indexoidscan);
|
||||
HeapTuple indexTuple;
|
||||
Form_pg_index indexStruct;
|
||||
|
||||
if (indexStruct->indisunique) {
|
||||
/* go through the fkconstraint->pk_attrs list */
|
||||
foreach(attrl, fkconstraint->pk_attrs) {
|
||||
Ident *attr=lfirst(attrl);
|
||||
found=0;
|
||||
for (i = 0; i < INDEX_MAX_KEYS && indexStruct->indkey[i] != 0; i++)
|
||||
indexTuple = SearchSysCache(INDEXRELID,
|
||||
ObjectIdGetDatum(indexoid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(indexTuple))
|
||||
elog(ERROR, "transformFkeyGetPrimaryKey: index %u not found",
|
||||
indexoid);
|
||||
indexStruct = (Form_pg_index) GETSTRUCT(indexTuple);
|
||||
|
||||
if (indexStruct->indisunique)
|
||||
{
|
||||
List *attrl;
|
||||
|
||||
/* go through the fkconstraint->pk_attrs list */
|
||||
foreach(attrl, fkconstraint->pk_attrs)
|
||||
{
|
||||
Ident *attr=lfirst(attrl);
|
||||
found = false;
|
||||
for (i = 0; i < INDEX_MAX_KEYS && indexStruct->indkey[i] != 0; i++)
|
||||
{
|
||||
int pkattno = indexStruct->indkey[i];
|
||||
if (pkattno>0)
|
||||
{
|
||||
int pkattno = indexStruct->indkey[i];
|
||||
if (pkattno>0) {
|
||||
char *name = NameStr(rel_attrs[pkattno-1]->attname);
|
||||
if (strcmp(name, attr->name)==0) {
|
||||
found=1;
|
||||
break;
|
||||
}
|
||||
char *name = NameStr(rel_attrs[pkattno-1]->attname);
|
||||
if (strcmp(name, attr->name)==0)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
break;
|
||||
}
|
||||
if (found)
|
||||
break;
|
||||
indexStruct = NULL;
|
||||
}
|
||||
ReleaseSysCache(indexTuple);
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
elog(ERROR, "UNIQUE constraint matching given keys for referenced table \"%s\" not found",
|
||||
fkconstraint->pktable_name);
|
||||
@@ -1309,17 +1323,18 @@ AlterTableAddConstraint(char *relationName,
|
||||
|
||||
rel_attrs = rel->rd_att->attrs;
|
||||
if (fkconstraint->fk_attrs!=NIL) {
|
||||
int found=0;
|
||||
List *fkattrs;
|
||||
Ident *fkattr;
|
||||
|
||||
found = false;
|
||||
foreach(fkattrs, fkconstraint->fk_attrs) {
|
||||
int count=0;
|
||||
found=0;
|
||||
int count;
|
||||
found = false;
|
||||
fkattr=lfirst(fkattrs);
|
||||
for (; count < rel->rd_att->natts; count++) {
|
||||
for (count = 0; count < rel->rd_att->natts; count++) {
|
||||
char *name = NameStr(rel->rd_att->attrs[count]->attname);
|
||||
if (strcmp(name, fkattr->name)==0) {
|
||||
found=1;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1441,20 +1456,22 @@ AlterTableOwner(const char *relationName, const char *newOwnerName)
|
||||
/*
|
||||
* look up the new owner in pg_shadow and get the sysid
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(SHADOWNAME, PointerGetDatum(newOwnerName),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(SHADOWNAME,
|
||||
PointerGetDatum(newOwnerName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "ALTER TABLE: user \"%s\" not found", newOwnerName);
|
||||
|
||||
newOwnerSysid = ((Form_pg_shadow) GETSTRUCT(tuple))->usesysid;
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
/*
|
||||
* find the table's entry in pg_class and lock it for writing
|
||||
* find the table's entry in pg_class and make a modifiable copy
|
||||
*/
|
||||
class_rel = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
|
||||
tuple = SearchSysCacheTupleCopy(RELNAME, PointerGetDatum(relationName),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCacheCopy(RELNAME,
|
||||
PointerGetDatum(relationName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "ALTER TABLE: relation \"%s\" not found",
|
||||
relationName);
|
||||
@@ -1525,13 +1542,15 @@ AlterTableCreateToastTable(const char *relationName, bool silent)
|
||||
*/
|
||||
class_rel = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
|
||||
reltup = SearchSysCacheTuple(RELNAME, PointerGetDatum(relationName),
|
||||
0, 0, 0);
|
||||
reltup = SearchSysCache(RELNAME,
|
||||
PointerGetDatum(relationName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(reltup))
|
||||
elog(ERROR, "ALTER TABLE: relation \"%s\" not found",
|
||||
relationName);
|
||||
|
||||
classtuple.t_self = reltup->t_self;
|
||||
ReleaseSysCache(reltup);
|
||||
|
||||
switch (heap_mark4update(class_rel, &classtuple, &buffer))
|
||||
{
|
||||
case HeapTupleSelfUpdated:
|
||||
|
||||
@@ -276,7 +276,6 @@ DeleteComments(Oid oid)
|
||||
static void
|
||||
CommentRelation(int reltype, char *relname, char *comment)
|
||||
{
|
||||
|
||||
HeapTuple reltuple;
|
||||
Oid oid;
|
||||
char relkind;
|
||||
@@ -288,17 +287,20 @@ CommentRelation(int reltype, char *relname, char *comment)
|
||||
|
||||
/*** Now, attempt to find the oid in the cached version of pg_class ***/
|
||||
|
||||
reltuple = SearchSysCacheTuple(RELNAME, PointerGetDatum(relname),
|
||||
0, 0, 0);
|
||||
reltuple = SearchSysCache(RELNAME,
|
||||
PointerGetDatum(relname),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(reltuple))
|
||||
elog(ERROR, "relation '%s' does not exist", relname);
|
||||
|
||||
oid = reltuple->t_data->t_oid;
|
||||
|
||||
/*** Next, verify that the relation type matches the intent ***/
|
||||
|
||||
relkind = ((Form_pg_class) GETSTRUCT(reltuple))->relkind;
|
||||
|
||||
ReleaseSysCache(reltuple);
|
||||
|
||||
/*** Next, verify that the relation type matches the intent ***/
|
||||
|
||||
switch (reltype)
|
||||
{
|
||||
case (INDEX):
|
||||
@@ -322,7 +324,6 @@ CommentRelation(int reltype, char *relname, char *comment)
|
||||
/*** Create the comments using the tuple's oid ***/
|
||||
|
||||
CreateComments(oid, comment);
|
||||
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
@@ -340,9 +341,7 @@ CommentRelation(int reltype, char *relname, char *comment)
|
||||
static void
|
||||
CommentAttribute(char *relname, char *attrname, char *comment)
|
||||
{
|
||||
|
||||
Relation relation;
|
||||
HeapTuple attrtuple;
|
||||
Oid oid;
|
||||
|
||||
/*** First, check object security ***/
|
||||
@@ -350,15 +349,19 @@ CommentAttribute(char *relname, char *attrname, char *comment)
|
||||
if (!pg_ownercheck(GetUserId(), relname, RELNAME))
|
||||
elog(ERROR, "you are not permitted to comment on class '%s\'", relname);
|
||||
|
||||
/*** Now, fetch the attribute oid from the system cache ***/
|
||||
/* Open the containing relation to ensure it won't go away meanwhile */
|
||||
|
||||
relation = heap_openr(relname, AccessShareLock);
|
||||
attrtuple = SearchSysCacheTuple(ATTNAME, ObjectIdGetDatum(relation->rd_id),
|
||||
PointerGetDatum(attrname), 0, 0);
|
||||
if (!HeapTupleIsValid(attrtuple))
|
||||
|
||||
/*** Now, fetch the attribute oid from the system cache ***/
|
||||
|
||||
oid = GetSysCacheOid(ATTNAME,
|
||||
ObjectIdGetDatum(relation->rd_id),
|
||||
PointerGetDatum(attrname),
|
||||
0, 0);
|
||||
if (!OidIsValid(oid))
|
||||
elog(ERROR, "'%s' is not an attribute of class '%s'",
|
||||
attrname, relname);
|
||||
oid = attrtuple->t_data->t_oid;
|
||||
|
||||
/*** Call CreateComments() to create/drop the comments ***/
|
||||
|
||||
@@ -412,11 +415,13 @@ CommentDatabase(char *database, char *comment)
|
||||
/*** Now, fetch user information ***/
|
||||
|
||||
userid = GetUserId();
|
||||
usertuple = SearchSysCacheTuple(SHADOWSYSID, ObjectIdGetDatum(userid),
|
||||
0, 0, 0);
|
||||
usertuple = SearchSysCache(SHADOWSYSID,
|
||||
ObjectIdGetDatum(userid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(usertuple))
|
||||
elog(ERROR, "invalid user id %u", (unsigned) userid);
|
||||
superuser = ((Form_pg_shadow) GETSTRUCT(usertuple))->usesuper;
|
||||
ReleaseSysCache(usertuple);
|
||||
|
||||
/*** Allow if the userid matches the database dba or is a superuser ***/
|
||||
|
||||
@@ -452,8 +457,6 @@ CommentDatabase(char *database, char *comment)
|
||||
static void
|
||||
CommentRewrite(char *rule, char *comment)
|
||||
{
|
||||
|
||||
HeapTuple rewritetuple;
|
||||
Oid oid;
|
||||
char *relation;
|
||||
int aclcheck;
|
||||
@@ -472,17 +475,15 @@ CommentRewrite(char *rule, char *comment)
|
||||
|
||||
/*** Next, find the rule's oid ***/
|
||||
|
||||
rewritetuple = SearchSysCacheTuple(RULENAME, PointerGetDatum(rule),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(rewritetuple))
|
||||
oid = GetSysCacheOid(RULENAME,
|
||||
PointerGetDatum(rule),
|
||||
0, 0, 0);
|
||||
if (!OidIsValid(oid))
|
||||
elog(ERROR, "rule '%s' does not exist", rule);
|
||||
|
||||
oid = rewritetuple->t_data->t_oid;
|
||||
|
||||
/*** Call CreateComments() to create/drop the comments ***/
|
||||
|
||||
CreateComments(oid, comment);
|
||||
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
@@ -499,8 +500,6 @@ CommentRewrite(char *rule, char *comment)
|
||||
static void
|
||||
CommentType(char *type, char *comment)
|
||||
{
|
||||
|
||||
HeapTuple typetuple;
|
||||
Oid oid;
|
||||
|
||||
/*** First, validate user ***/
|
||||
@@ -515,17 +514,15 @@ CommentType(char *type, char *comment)
|
||||
|
||||
/*** Next, find the type's oid ***/
|
||||
|
||||
typetuple = SearchSysCacheTuple(TYPENAME, PointerGetDatum(type),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typetuple))
|
||||
oid = GetSysCacheOid(TYPENAME,
|
||||
PointerGetDatum(type),
|
||||
0, 0, 0);
|
||||
if (!OidIsValid(oid))
|
||||
elog(ERROR, "type '%s' does not exist", type);
|
||||
|
||||
oid = typetuple->t_data->t_oid;
|
||||
|
||||
/*** Call CreateComments() to create/drop the comments ***/
|
||||
|
||||
CreateComments(oid, comment);
|
||||
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
@@ -543,7 +540,6 @@ CommentAggregate(char *aggregate, List *arguments, char *comment)
|
||||
{
|
||||
TypeName *aggtype = (TypeName *) lfirst(arguments);
|
||||
char *aggtypename = NULL;
|
||||
HeapTuple aggtuple;
|
||||
Oid baseoid,
|
||||
oid;
|
||||
bool defined;
|
||||
@@ -580,9 +576,11 @@ CommentAggregate(char *aggregate, List *arguments, char *comment)
|
||||
|
||||
/*** Now, attempt to find the actual tuple in pg_aggregate ***/
|
||||
|
||||
aggtuple = SearchSysCacheTuple(AGGNAME, PointerGetDatum(aggregate),
|
||||
ObjectIdGetDatum(baseoid), 0, 0);
|
||||
if (!HeapTupleIsValid(aggtuple))
|
||||
oid = GetSysCacheOid(AGGNAME,
|
||||
PointerGetDatum(aggregate),
|
||||
ObjectIdGetDatum(baseoid),
|
||||
0, 0);
|
||||
if (!OidIsValid(oid))
|
||||
{
|
||||
if (aggtypename)
|
||||
{
|
||||
@@ -593,12 +591,9 @@ CommentAggregate(char *aggregate, List *arguments, char *comment)
|
||||
elog(ERROR, "aggregate '%s' does not exist", aggregate);
|
||||
}
|
||||
|
||||
oid = aggtuple->t_data->t_oid;
|
||||
|
||||
/*** Call CreateComments() to create/drop the comments ***/
|
||||
|
||||
CreateComments(oid, comment);
|
||||
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
@@ -615,8 +610,6 @@ CommentAggregate(char *aggregate, List *arguments, char *comment)
|
||||
static void
|
||||
CommentProc(char *function, List *arguments, char *comment)
|
||||
{
|
||||
HeapTuple argtuple,
|
||||
functuple;
|
||||
Oid oid,
|
||||
argoids[FUNC_MAX_ARGS];
|
||||
int i,
|
||||
@@ -640,12 +633,11 @@ CommentProc(char *function, List *arguments, char *comment)
|
||||
argoids[i] = InvalidOid;
|
||||
else
|
||||
{
|
||||
argtuple = SearchSysCacheTuple(TYPENAME,
|
||||
PointerGetDatum(typnam),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(argtuple))
|
||||
argoids[i] = GetSysCacheOid(TYPENAME,
|
||||
PointerGetDatum(typnam),
|
||||
0, 0, 0);
|
||||
if (!OidIsValid(argoids[i]))
|
||||
elog(ERROR, "CommentProc: type '%s' not found", typnam);
|
||||
argoids[i] = argtuple->t_data->t_oid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,14 +651,14 @@ CommentProc(char *function, List *arguments, char *comment)
|
||||
|
||||
/*** Now, find the corresponding oid for this procedure ***/
|
||||
|
||||
functuple = SearchSysCacheTuple(PROCNAME, PointerGetDatum(function),
|
||||
Int32GetDatum(argcount),
|
||||
PointerGetDatum(argoids), 0);
|
||||
if (!HeapTupleIsValid(functuple))
|
||||
oid = GetSysCacheOid(PROCNAME,
|
||||
PointerGetDatum(function),
|
||||
Int32GetDatum(argcount),
|
||||
PointerGetDatum(argoids),
|
||||
0);
|
||||
if (!OidIsValid(oid))
|
||||
func_error("CommentProc", function, argcount, argoids, NULL);
|
||||
|
||||
oid = functuple->t_data->t_oid;
|
||||
|
||||
/*** Call CreateComments() to create/drop the comments ***/
|
||||
|
||||
CreateComments(oid, comment);
|
||||
@@ -738,10 +730,11 @@ CommentOperator(char *opername, List *arguments, char *comment)
|
||||
|
||||
/*** Attempt to fetch the operator oid ***/
|
||||
|
||||
optuple = SearchSysCacheTupleCopy(OPERNAME, PointerGetDatum(opername),
|
||||
ObjectIdGetDatum(leftoid),
|
||||
ObjectIdGetDatum(rightoid),
|
||||
CharGetDatum(oprtype));
|
||||
optuple = SearchSysCache(OPERNAME,
|
||||
PointerGetDatum(opername),
|
||||
ObjectIdGetDatum(leftoid),
|
||||
ObjectIdGetDatum(rightoid),
|
||||
CharGetDatum(oprtype));
|
||||
if (!HeapTupleIsValid(optuple))
|
||||
elog(ERROR, "operator '%s' does not exist", opername);
|
||||
|
||||
@@ -764,6 +757,8 @@ CommentOperator(char *opername, List *arguments, char *comment)
|
||||
if (oid == InvalidOid)
|
||||
elog(ERROR, "operator '%s' does not have an underlying function", opername);
|
||||
|
||||
ReleaseSysCache(optuple);
|
||||
|
||||
/*** Call CreateComments() to create/drop the comments ***/
|
||||
|
||||
CreateComments(oid, comment);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.123 2000/11/12 00:36:56 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.124 2000/11/16 22:30:19 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -48,9 +48,9 @@
|
||||
static void CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_print);
|
||||
static void CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_print);
|
||||
static Oid GetOutputFunction(Oid type);
|
||||
static Oid GetTypeElement(Oid type);
|
||||
static Oid GetInputFunction(Oid type);
|
||||
static Oid IsTypeByVal(Oid type);
|
||||
static Oid GetTypeElement(Oid type);
|
||||
static bool IsTypeByVal(Oid type);
|
||||
static void CopyReadNewline(FILE *fp, int *newline);
|
||||
static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_print);
|
||||
|
||||
@@ -669,7 +669,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
|
||||
continue;
|
||||
}
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
byval[i] = (bool) IsTypeByVal(attr[i]->atttypid);
|
||||
byval[i] = IsTypeByVal(attr[i]->atttypid);
|
||||
}
|
||||
|
||||
lineno = 0;
|
||||
@@ -893,65 +893,64 @@ static Oid
|
||||
GetOutputFunction(Oid type)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
Oid result;
|
||||
|
||||
typeTuple = SearchSysCacheTuple(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
|
||||
if (HeapTupleIsValid(typeTuple))
|
||||
return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typoutput;
|
||||
|
||||
elog(ERROR, "GetOutputFunction: Cache lookup of type %u failed", type);
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
static Oid
|
||||
GetTypeElement(Oid type)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
|
||||
typeTuple = SearchSysCacheTuple(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
|
||||
if (HeapTupleIsValid(typeTuple))
|
||||
return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typelem;
|
||||
|
||||
elog(ERROR, "GetOutputFunction: Cache lookup of type %u failed", type);
|
||||
return InvalidOid;
|
||||
typeTuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "GetOutputFunction: Cache lookup of type %u failed", type);
|
||||
result = ((Form_pg_type) GETSTRUCT(typeTuple))->typoutput;
|
||||
ReleaseSysCache(typeTuple);
|
||||
return result;
|
||||
}
|
||||
|
||||
static Oid
|
||||
GetInputFunction(Oid type)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
Oid result;
|
||||
|
||||
typeTuple = SearchSysCacheTuple(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
|
||||
if (HeapTupleIsValid(typeTuple))
|
||||
return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typinput;
|
||||
|
||||
elog(ERROR, "GetInputFunction: Cache lookup of type %u failed", type);
|
||||
return InvalidOid;
|
||||
typeTuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "GetInputFunction: Cache lookup of type %u failed", type);
|
||||
result = ((Form_pg_type) GETSTRUCT(typeTuple))->typinput;
|
||||
ReleaseSysCache(typeTuple);
|
||||
return result;
|
||||
}
|
||||
|
||||
static Oid
|
||||
GetTypeElement(Oid type)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
Oid result;
|
||||
|
||||
typeTuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "GetTypeElement: Cache lookup of type %u failed", type);
|
||||
result = ((Form_pg_type) GETSTRUCT(typeTuple))->typelem;
|
||||
ReleaseSysCache(typeTuple);
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool
|
||||
IsTypeByVal(Oid type)
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
bool result;
|
||||
|
||||
typeTuple = SearchSysCacheTuple(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
|
||||
if (HeapTupleIsValid(typeTuple))
|
||||
return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typbyval;
|
||||
|
||||
elog(ERROR, "GetInputFunction: Cache lookup of type %u failed", type);
|
||||
|
||||
return InvalidOid;
|
||||
typeTuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "IsTypeByVal: Cache lookup of type %u failed", type);
|
||||
result = ((Form_pg_type) GETSTRUCT(typeTuple))->typbyval;
|
||||
ReleaseSysCache(typeTuple);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.66 2000/11/13 09:16:55 inoue Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.67 2000/11/16 22:30:18 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -408,11 +408,14 @@ MergeAttributes(List *schema, List *supers, List **supconstr)
|
||||
* form name, type and constraints
|
||||
*/
|
||||
attributeName = NameStr(attribute->attname);
|
||||
tuple = SearchSysCacheTuple(TYPEOID,
|
||||
tuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(attribute->atttypid),
|
||||
0, 0, 0);
|
||||
Assert(HeapTupleIsValid(tuple));
|
||||
attributeType = NameStr(((Form_pg_type) GETSTRUCT(tuple))->typname);
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "CREATE TABLE: cache lookup failed for type %u",
|
||||
attribute->atttypid);
|
||||
attributeType = pstrdup(NameStr(((Form_pg_type) GETSTRUCT(tuple))->typname));
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
/*
|
||||
* check validity
|
||||
@@ -554,22 +557,25 @@ StoreCatalogInheritance(Oid relationId, List *supers)
|
||||
idList = NIL;
|
||||
foreach(entry, supers)
|
||||
{
|
||||
Oid entryOid;
|
||||
Datum datum[Natts_pg_inherits];
|
||||
char nullarr[Natts_pg_inherits];
|
||||
|
||||
tuple = SearchSysCacheTuple(RELNAME,
|
||||
entryOid = GetSysCacheOid(RELNAME,
|
||||
PointerGetDatum(strVal(lfirst(entry))),
|
||||
0, 0, 0);
|
||||
AssertArg(HeapTupleIsValid(tuple));
|
||||
0, 0, 0);
|
||||
if (!OidIsValid(entryOid))
|
||||
elog(ERROR, "StoreCatalogInheritance: cache lookup failed for relation \"%s\"",
|
||||
strVal(lfirst(entry)));
|
||||
|
||||
/*
|
||||
* build idList for use below
|
||||
*/
|
||||
idList = lappendi(idList, tuple->t_data->t_oid);
|
||||
idList = lappendi(idList, entryOid);
|
||||
|
||||
datum[0] = ObjectIdGetDatum(relationId); /* inhrel */
|
||||
datum[1] = ObjectIdGetDatum(tuple->t_data->t_oid); /* inhparent */
|
||||
datum[2] = Int16GetDatum(seqNumber); /* inhseqno */
|
||||
datum[0] = ObjectIdGetDatum(relationId); /* inhrel */
|
||||
datum[1] = ObjectIdGetDatum(entryOid); /* inhparent */
|
||||
datum[2] = Int16GetDatum(seqNumber); /* inhseqno */
|
||||
|
||||
nullarr[0] = ' ';
|
||||
nullarr[1] = ' ';
|
||||
@@ -624,11 +630,10 @@ StoreCatalogInheritance(Oid relationId, List *supers)
|
||||
|
||||
for (number = 1;; number += 1)
|
||||
{
|
||||
tuple = SearchSysCacheTuple(INHRELID,
|
||||
ObjectIdGetDatum(id),
|
||||
Int16GetDatum(number),
|
||||
0, 0);
|
||||
|
||||
tuple = SearchSysCache(INHRELID,
|
||||
ObjectIdGetDatum(id),
|
||||
Int16GetDatum(number),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
break;
|
||||
|
||||
@@ -636,6 +641,8 @@ StoreCatalogInheritance(Oid relationId, List *supers)
|
||||
GETSTRUCT(tuple))->inhparent,
|
||||
NIL);
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
current = lnext(current);
|
||||
}
|
||||
lnext(current) = next;
|
||||
@@ -746,35 +753,28 @@ checkAttrExists(const char *attributeName, const char *attributeType, List *sche
|
||||
static void
|
||||
setRelhassubclassInRelation(Oid relationId, bool relhassubclass)
|
||||
{
|
||||
Relation relationRelation;
|
||||
HeapTuple tuple;
|
||||
Relation idescs[Num_pg_class_indices];
|
||||
Relation relationRelation;
|
||||
HeapTuple tuple;
|
||||
Relation idescs[Num_pg_class_indices];
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
relationRelation = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
tuple = SearchSysCacheTupleCopy(RELOID,
|
||||
ObjectIdGetDatum(relationId),
|
||||
0, 0, 0)
|
||||
;
|
||||
Assert(HeapTupleIsValid(tuple));
|
||||
/*
|
||||
* Fetch a modifiable copy of the tuple, modify it, update pg_class.
|
||||
*/
|
||||
relationRelation = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
tuple = SearchSysCacheCopy(RELOID,
|
||||
ObjectIdGetDatum(relationId),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "setRelhassubclassInRelation: cache lookup failed for relation %u", relationId);
|
||||
|
||||
((Form_pg_class) GETSTRUCT(tuple))->relhassubclass = relhassubclass;
|
||||
heap_update(relationRelation, &tuple->t_self, tuple, NULL);
|
||||
((Form_pg_class) GETSTRUCT(tuple))->relhassubclass = relhassubclass;
|
||||
heap_update(relationRelation, &tuple->t_self, tuple, NULL);
|
||||
|
||||
/* keep the catalog indices up to date */
|
||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
|
||||
CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple
|
||||
);
|
||||
CatalogCloseIndices(Num_pg_class_indices, idescs);
|
||||
/* keep the catalog indices up to date */
|
||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
|
||||
CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
|
||||
CatalogCloseIndices(Num_pg_class_indices, idescs);
|
||||
|
||||
heap_freetuple(tuple);
|
||||
heap_close(relationRelation, RowExclusiveLock);
|
||||
heap_close(relationRelation, RowExclusiveLock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.67 2000/11/14 18:37:41 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.68 2000/11/16 22:30:18 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -445,9 +445,9 @@ get_user_info(Oid use_sysid, bool *use_super, bool *use_createdb)
|
||||
{
|
||||
HeapTuple utup;
|
||||
|
||||
utup = SearchSysCacheTuple(SHADOWSYSID,
|
||||
ObjectIdGetDatum(use_sysid),
|
||||
0, 0, 0);
|
||||
utup = SearchSysCache(SHADOWSYSID,
|
||||
ObjectIdGetDatum(use_sysid),
|
||||
0, 0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(utup))
|
||||
return false;
|
||||
@@ -457,6 +457,8 @@ get_user_info(Oid use_sysid, bool *use_super, bool *use_createdb)
|
||||
if (use_createdb)
|
||||
*use_createdb = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb;
|
||||
|
||||
ReleaseSysCache(utup);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.47 2000/10/07 00:58:16 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.48 2000/11/16 22:30:18 tgl Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The "DefineFoo" routines take the parse tree and pick out the
|
||||
@@ -277,10 +277,9 @@ CreateFunction(ProcedureStmt *stmt, CommandDest dest)
|
||||
Form_pg_language languageStruct;
|
||||
|
||||
/* Lookup the language in the system cache */
|
||||
languageTuple = SearchSysCacheTuple(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
|
||||
languageTuple = SearchSysCache(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(languageTuple))
|
||||
elog(ERROR,
|
||||
"Unrecognized language specified in a CREATE FUNCTION: "
|
||||
@@ -299,12 +298,12 @@ CreateFunction(ProcedureStmt *stmt, CommandDest dest)
|
||||
* be defined by postgres superusers only
|
||||
*/
|
||||
if (!languageStruct->lanpltrusted && !superuser())
|
||||
{
|
||||
elog(ERROR, "Only users with Postgres superuser privilege "
|
||||
"are permitted to create a function in the '%s' "
|
||||
"language.",
|
||||
languageName);
|
||||
}
|
||||
|
||||
ReleaseSysCache(languageTuple);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.40 2000/11/08 22:09:57 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.41 2000/11/16 22:30:18 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -86,7 +86,6 @@ DefineIndex(char *heapRelationName,
|
||||
Oid relationId;
|
||||
IndexInfo *indexInfo;
|
||||
int numberOfAttributes;
|
||||
HeapTuple tuple;
|
||||
List *cnfPred = NIL;
|
||||
bool lossy = false;
|
||||
List *pl;
|
||||
@@ -111,13 +110,12 @@ DefineIndex(char *heapRelationName,
|
||||
/*
|
||||
* compute access method id
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(AMNAME,
|
||||
PointerGetDatum(accessMethodName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
accessMethodId = GetSysCacheOid(AMNAME,
|
||||
PointerGetDatum(accessMethodName),
|
||||
0, 0, 0);
|
||||
if (!OidIsValid(accessMethodId))
|
||||
elog(ERROR, "DefineIndex: access method \"%s\" not found",
|
||||
accessMethodName);
|
||||
accessMethodId = tuple->t_data->t_oid;
|
||||
|
||||
/*
|
||||
* XXX Hardwired hacks to check for limitations on supported index types.
|
||||
@@ -239,21 +237,22 @@ ExtendIndex(char *indexRelationName, Expr *predicate, List *rangetable)
|
||||
/*
|
||||
* Get index's relation id and access method id from pg_class
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(indexRelationName),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(RELNAME,
|
||||
PointerGetDatum(indexRelationName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "ExtendIndex: index \"%s\" not found",
|
||||
indexRelationName);
|
||||
indexId = tuple->t_data->t_oid;
|
||||
accessMethodId = ((Form_pg_class) GETSTRUCT(tuple))->relam;
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
/*
|
||||
* Extract info from the pg_index tuple for the index
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(INDEXRELID,
|
||||
ObjectIdGetDatum(indexId),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(INDEXRELID,
|
||||
ObjectIdGetDatum(indexId),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "ExtendIndex: relation \"%s\" is not an index",
|
||||
indexRelationName);
|
||||
@@ -262,6 +261,7 @@ ExtendIndex(char *indexRelationName, Expr *predicate, List *rangetable)
|
||||
relationId = index->indrelid;
|
||||
indexInfo = BuildIndexInfo(tuple);
|
||||
oldPred = indexInfo->ii_Predicate;
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
if (oldPred == NULL)
|
||||
elog(ERROR, "ExtendIndex: \"%s\" is not a partial index",
|
||||
@@ -391,16 +391,16 @@ FuncIndexArgs(IndexInfo *indexInfo,
|
||||
HeapTuple tuple;
|
||||
Form_pg_attribute att;
|
||||
|
||||
tuple = SearchSysCacheTuple(ATTNAME,
|
||||
ObjectIdGetDatum(relId),
|
||||
PointerGetDatum(arg),
|
||||
0, 0);
|
||||
tuple = SearchSysCache(ATTNAME,
|
||||
ObjectIdGetDatum(relId),
|
||||
PointerGetDatum(arg),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "DefineIndex: attribute \"%s\" not found", arg);
|
||||
att = (Form_pg_attribute) GETSTRUCT(tuple);
|
||||
|
||||
indexInfo->ii_KeyAttrNumbers[nargs] = att->attnum;
|
||||
argTypes[nargs] = att->atttypid;
|
||||
ReleaseSysCache(tuple);
|
||||
nargs++;
|
||||
}
|
||||
|
||||
@@ -465,10 +465,10 @@ NormIndexAttrs(IndexInfo *indexInfo,
|
||||
if (attribute->name == NULL)
|
||||
elog(ERROR, "missing attribute for define index");
|
||||
|
||||
atttuple = SearchSysCacheTupleCopy(ATTNAME,
|
||||
ObjectIdGetDatum(relId),
|
||||
PointerGetDatum(attribute->name),
|
||||
0, 0);
|
||||
atttuple = SearchSysCache(ATTNAME,
|
||||
ObjectIdGetDatum(relId),
|
||||
PointerGetDatum(attribute->name),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(atttuple))
|
||||
elog(ERROR, "DefineIndex: attribute \"%s\" not found",
|
||||
attribute->name);
|
||||
@@ -479,7 +479,7 @@ NormIndexAttrs(IndexInfo *indexInfo,
|
||||
classOidP[attn] = GetAttrOpClass(attribute, attform->atttypid,
|
||||
accessMethodName, accessMethodId);
|
||||
|
||||
heap_freetuple(atttuple);
|
||||
ReleaseSysCache(atttuple);
|
||||
attn++;
|
||||
}
|
||||
}
|
||||
@@ -507,13 +507,12 @@ GetAttrOpClass(IndexElem *attribute, Oid attrType,
|
||||
doTypeCheck = false;
|
||||
}
|
||||
|
||||
tuple = SearchSysCacheTuple(CLANAME,
|
||||
PointerGetDatum(attribute->class),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
opClassId = GetSysCacheOid(CLANAME,
|
||||
PointerGetDatum(attribute->class),
|
||||
0, 0, 0);
|
||||
if (!OidIsValid(opClassId))
|
||||
elog(ERROR, "DefineIndex: opclass \"%s\" not found",
|
||||
attribute->class);
|
||||
opClassId = tuple->t_data->t_oid;
|
||||
|
||||
/*
|
||||
* Assume the opclass is supported by this index access method
|
||||
@@ -532,10 +531,8 @@ GetAttrOpClass(IndexElem *attribute, Oid attrType,
|
||||
scan = heap_beginscan(relation, false, SnapshotNow, 2, entry);
|
||||
|
||||
if (! HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
|
||||
{
|
||||
elog(ERROR, "DefineIndex: opclass \"%s\" not supported by access method \"%s\"",
|
||||
attribute->class, accessMethodName);
|
||||
}
|
||||
|
||||
oprId = ((Form_pg_amop) GETSTRUCT(tuple))->amopopr;
|
||||
|
||||
@@ -557,9 +554,9 @@ GetAttrOpClass(IndexElem *attribute, Oid attrType,
|
||||
*/
|
||||
if (doTypeCheck)
|
||||
{
|
||||
tuple = SearchSysCacheTuple(OPEROID,
|
||||
ObjectIdGetDatum(oprId),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(oprId),
|
||||
0, 0, 0);
|
||||
if (HeapTupleIsValid(tuple))
|
||||
{
|
||||
Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tuple);
|
||||
@@ -570,6 +567,7 @@ GetAttrOpClass(IndexElem *attribute, Oid attrType,
|
||||
! IS_BINARY_COMPATIBLE(attrType, opInputType))
|
||||
elog(ERROR, "DefineIndex: opclass \"%s\" does not accept datatype \"%s\"",
|
||||
attribute->class, typeidTypeName(attrType));
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,15 +578,18 @@ static char *
|
||||
GetDefaultOpClass(Oid atttypid)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
char *result;
|
||||
|
||||
tuple = SearchSysCacheTuple(CLADEFTYPE,
|
||||
ObjectIdGetDatum(atttypid),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(CLADEFTYPE,
|
||||
ObjectIdGetDatum(atttypid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
return NULL;
|
||||
|
||||
return DatumGetCString(DirectFunctionCall1(nameout,
|
||||
NameGetDatum(&((Form_pg_opclass) GETSTRUCT(tuple))->opcname)));
|
||||
result = pstrdup(NameStr(((Form_pg_opclass) GETSTRUCT(tuple))->opcname));
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -605,21 +606,19 @@ RemoveIndex(char *name)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
|
||||
tuple = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(name),
|
||||
0, 0, 0);
|
||||
|
||||
tuple = SearchSysCache(RELNAME,
|
||||
PointerGetDatum(name),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "index \"%s\" does not exist", name);
|
||||
|
||||
if (((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_INDEX)
|
||||
{
|
||||
elog(ERROR, "relation \"%s\" is of type \"%c\"",
|
||||
name,
|
||||
((Form_pg_class) GETSTRUCT(tuple))->relkind);
|
||||
}
|
||||
name, ((Form_pg_class) GETSTRUCT(tuple))->relkind);
|
||||
|
||||
index_drop(tuple->t_data->t_oid);
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -644,22 +643,20 @@ ReindexIndex(const char *name, bool force /* currently unused */ )
|
||||
if (IsTransactionBlock())
|
||||
elog(ERROR, "REINDEX cannot run inside a BEGIN/END block");
|
||||
|
||||
tuple = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(name),
|
||||
0, 0, 0);
|
||||
|
||||
tuple = SearchSysCache(RELNAME,
|
||||
PointerGetDatum(name),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "index \"%s\" does not exist", name);
|
||||
|
||||
if (((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_INDEX)
|
||||
{
|
||||
elog(ERROR, "relation \"%s\" is of type \"%c\"",
|
||||
name,
|
||||
((Form_pg_class) GETSTRUCT(tuple))->relkind);
|
||||
}
|
||||
name, ((Form_pg_class) GETSTRUCT(tuple))->relkind);
|
||||
|
||||
if (!reindex_index(tuple->t_data->t_oid, force))
|
||||
elog(NOTICE, "index \"%s\" wasn't reindexed", name);
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -684,22 +681,20 @@ ReindexTable(const char *name, bool force)
|
||||
if (IsTransactionBlock())
|
||||
elog(ERROR, "REINDEX cannot run inside a BEGIN/END block");
|
||||
|
||||
tuple = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(name),
|
||||
0, 0, 0);
|
||||
|
||||
tuple = SearchSysCache(RELNAME,
|
||||
PointerGetDatum(name),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "table \"%s\" does not exist", name);
|
||||
|
||||
if (((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_RELATION)
|
||||
{
|
||||
elog(ERROR, "relation \"%s\" is of type \"%c\"",
|
||||
name,
|
||||
((Form_pg_class) GETSTRUCT(tuple))->relkind);
|
||||
}
|
||||
name, ((Form_pg_class) GETSTRUCT(tuple))->relkind);
|
||||
|
||||
if (!reindex_relation(tuple->t_data->t_oid, force))
|
||||
elog(NOTICE, "table \"%s\" wasn't reindexed", name);
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -48,7 +48,6 @@ void
|
||||
CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
{
|
||||
char languageName[NAMEDATALEN];
|
||||
HeapTuple langTup;
|
||||
HeapTuple procTup;
|
||||
|
||||
Oid typev[FUNC_MAX_ARGS];
|
||||
@@ -77,10 +76,9 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
*/
|
||||
case_translate_language_name(stmt->plname, languageName);
|
||||
|
||||
langTup = SearchSysCacheTuple(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
if (HeapTupleIsValid(langTup))
|
||||
if (SearchSysCacheExists(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0))
|
||||
elog(ERROR, "Language %s already exists", languageName);
|
||||
|
||||
/* ----------------
|
||||
@@ -89,21 +87,17 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
* ----------------
|
||||
*/
|
||||
memset(typev, 0, sizeof(typev));
|
||||
procTup = SearchSysCacheTuple(PROCNAME,
|
||||
PointerGetDatum(stmt->plhandler),
|
||||
Int32GetDatum(0),
|
||||
PointerGetDatum(typev),
|
||||
0);
|
||||
procTup = SearchSysCache(PROCNAME,
|
||||
PointerGetDatum(stmt->plhandler),
|
||||
Int32GetDatum(0),
|
||||
PointerGetDatum(typev),
|
||||
0);
|
||||
if (!HeapTupleIsValid(procTup))
|
||||
{
|
||||
elog(ERROR, "PL handler function %s() doesn't exist",
|
||||
stmt->plhandler);
|
||||
}
|
||||
if (((Form_pg_proc) GETSTRUCT(procTup))->prorettype != InvalidOid)
|
||||
{
|
||||
elog(ERROR, "PL handler function %s() isn't of return type Opaque",
|
||||
stmt->plhandler);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* Insert the new language into pg_language
|
||||
@@ -123,6 +117,8 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
values[i++] = DirectFunctionCall1(textin,
|
||||
CStringGetDatum(stmt->plcompiler));
|
||||
|
||||
ReleaseSysCache(procTup);
|
||||
|
||||
rel = heap_openr(LanguageRelationName, RowExclusiveLock);
|
||||
|
||||
tupDesc = rel->rd_att;
|
||||
@@ -173,9 +169,9 @@ DropProceduralLanguage(DropPLangStmt *stmt)
|
||||
|
||||
rel = heap_openr(LanguageRelationName, RowExclusiveLock);
|
||||
|
||||
langTup = SearchSysCacheTupleCopy(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
langTup = SearchSysCacheCopy(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(langTup))
|
||||
elog(ERROR, "Language %s doesn't exist", languageName);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.54 2000/10/16 17:08:05 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.55 2000/11/16 22:30:18 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -73,11 +73,11 @@ RemoveOperator(char *operatorName, /* operator name */
|
||||
|
||||
relation = heap_openr(OperatorRelationName, RowExclusiveLock);
|
||||
|
||||
tup = SearchSysCacheTupleCopy(OPERNAME,
|
||||
PointerGetDatum(operatorName),
|
||||
ObjectIdGetDatum(typeId1),
|
||||
ObjectIdGetDatum(typeId2),
|
||||
CharGetDatum(oprtype));
|
||||
tup = SearchSysCacheCopy(OPERNAME,
|
||||
PointerGetDatum(operatorName),
|
||||
ObjectIdGetDatum(typeId1),
|
||||
ObjectIdGetDatum(typeId2),
|
||||
CharGetDatum(oprtype));
|
||||
|
||||
if (HeapTupleIsValid(tup))
|
||||
{
|
||||
@@ -254,14 +254,11 @@ RemoveType(char *typeName) /* type name to be removed */
|
||||
|
||||
relation = heap_openr(TypeRelationName, RowExclusiveLock);
|
||||
|
||||
tup = SearchSysCacheTuple(TYPENAME,
|
||||
PointerGetDatum(typeName),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache(TYPENAME,
|
||||
PointerGetDatum(typeName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
{
|
||||
heap_close(relation, RowExclusiveLock);
|
||||
elog(ERROR, "RemoveType: type '%s' does not exist", typeName);
|
||||
}
|
||||
|
||||
typeOid = tup->t_data->t_oid;
|
||||
|
||||
@@ -271,19 +268,20 @@ RemoveType(char *typeName) /* type name to be removed */
|
||||
|
||||
heap_delete(relation, &tup->t_self, NULL);
|
||||
|
||||
/* Now, Delete the "array of" that type */
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
/* Also, delete the "array of" that type */
|
||||
shadow_type = makeArrayTypeName(typeName);
|
||||
tup = SearchSysCacheTuple(TYPENAME,
|
||||
PointerGetDatum(shadow_type),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache(TYPENAME,
|
||||
PointerGetDatum(shadow_type),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
{
|
||||
heap_close(relation, RowExclusiveLock);
|
||||
elog(ERROR, "RemoveType: type '%s' does not exist", shadow_type);
|
||||
}
|
||||
|
||||
heap_delete(relation, &tup->t_self, NULL);
|
||||
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
heap_close(relation, RowExclusiveLock);
|
||||
}
|
||||
|
||||
@@ -321,12 +319,11 @@ RemoveFunction(char *functionName, /* function name to be removed */
|
||||
argList[i] = InvalidOid;
|
||||
else
|
||||
{
|
||||
tup = SearchSysCacheTuple(TYPENAME,
|
||||
PointerGetDatum(typnam),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
argList[i] = GetSysCacheOid(TYPENAME,
|
||||
PointerGetDatum(typnam),
|
||||
0, 0, 0);
|
||||
if (!OidIsValid(argList[i]))
|
||||
elog(ERROR, "RemoveFunction: type '%s' not found", typnam);
|
||||
argList[i] = tup->t_data->t_oid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,11 +334,12 @@ RemoveFunction(char *functionName, /* function name to be removed */
|
||||
}
|
||||
|
||||
relation = heap_openr(ProcedureRelationName, RowExclusiveLock);
|
||||
tup = SearchSysCacheTuple(PROCNAME,
|
||||
PointerGetDatum(functionName),
|
||||
Int32GetDatum(nargs),
|
||||
PointerGetDatum(argList),
|
||||
0);
|
||||
|
||||
tup = SearchSysCache(PROCNAME,
|
||||
PointerGetDatum(functionName),
|
||||
Int32GetDatum(nargs),
|
||||
PointerGetDatum(argList),
|
||||
0);
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
func_error("RemoveFunction", functionName, nargs, argList, NULL);
|
||||
@@ -359,6 +357,8 @@ RemoveFunction(char *functionName, /* function name to be removed */
|
||||
|
||||
heap_delete(relation, &tup->t_self, NULL);
|
||||
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
heap_close(relation, RowExclusiveLock);
|
||||
}
|
||||
|
||||
@@ -370,7 +370,6 @@ RemoveAggregate(char *aggName, char *aggType)
|
||||
Oid basetypeID = InvalidOid;
|
||||
bool defined;
|
||||
|
||||
|
||||
/*
|
||||
* if a basetype is passed in, then attempt to find an aggregate for
|
||||
* that specific type.
|
||||
@@ -405,10 +404,11 @@ RemoveAggregate(char *aggName, char *aggType)
|
||||
}
|
||||
|
||||
relation = heap_openr(AggregateRelationName, RowExclusiveLock);
|
||||
tup = SearchSysCacheTuple(AGGNAME,
|
||||
PointerGetDatum(aggName),
|
||||
ObjectIdGetDatum(basetypeID),
|
||||
0, 0);
|
||||
|
||||
tup = SearchSysCache(AGGNAME,
|
||||
PointerGetDatum(aggName),
|
||||
ObjectIdGetDatum(basetypeID),
|
||||
0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
{
|
||||
@@ -431,5 +431,7 @@ RemoveAggregate(char *aggName, char *aggType)
|
||||
|
||||
heap_delete(relation, &tup->t_self, NULL);
|
||||
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
heap_close(relation, RowExclusiveLock);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.52 2000/11/08 22:09:57 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.53 2000/11/16 22:30:18 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -58,8 +58,7 @@ renameatt(char *relname,
|
||||
Relation targetrelation;
|
||||
Relation attrelation;
|
||||
HeapTuple reltup,
|
||||
oldatttup,
|
||||
newatttup;
|
||||
atttup;
|
||||
Oid relid;
|
||||
|
||||
/*
|
||||
@@ -113,9 +112,9 @@ renameatt(char *relname,
|
||||
|
||||
if (childrelid == relid)
|
||||
continue;
|
||||
reltup = SearchSysCacheTuple(RELOID,
|
||||
ObjectIdGetDatum(childrelid),
|
||||
0, 0, 0);
|
||||
reltup = SearchSysCache(RELOID,
|
||||
ObjectIdGetDatum(childrelid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(reltup))
|
||||
{
|
||||
elog(ERROR, "renameatt: can't find catalog entry for inheriting class with oid %u",
|
||||
@@ -125,6 +124,7 @@ renameatt(char *relname,
|
||||
StrNCpy(childname,
|
||||
NameStr(((Form_pg_class) GETSTRUCT(reltup))->relname),
|
||||
NAMEDATALEN);
|
||||
ReleaseSysCache(reltup);
|
||||
/* note we need not recurse again! */
|
||||
renameatt(childname, oldattname, newattname, 0);
|
||||
}
|
||||
@@ -132,42 +132,38 @@ renameatt(char *relname,
|
||||
|
||||
attrelation = heap_openr(AttributeRelationName, RowExclusiveLock);
|
||||
|
||||
oldatttup = SearchSysCacheTupleCopy(ATTNAME,
|
||||
ObjectIdGetDatum(relid),
|
||||
PointerGetDatum(oldattname),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(oldatttup))
|
||||
atttup = SearchSysCacheCopy(ATTNAME,
|
||||
ObjectIdGetDatum(relid),
|
||||
PointerGetDatum(oldattname),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(atttup))
|
||||
elog(ERROR, "renameatt: attribute \"%s\" does not exist", oldattname);
|
||||
|
||||
if (((Form_pg_attribute) GETSTRUCT(oldatttup))->attnum < 0)
|
||||
if (((Form_pg_attribute) GETSTRUCT(atttup))->attnum < 0)
|
||||
elog(ERROR, "renameatt: system attribute \"%s\" not renamed", oldattname);
|
||||
|
||||
newatttup = SearchSysCacheTuple(ATTNAME,
|
||||
ObjectIdGetDatum(relid),
|
||||
PointerGetDatum(newattname),
|
||||
0, 0);
|
||||
/* should not already exist */
|
||||
if (HeapTupleIsValid(newatttup))
|
||||
{
|
||||
heap_freetuple(oldatttup);
|
||||
if (SearchSysCacheExists(ATTNAME,
|
||||
ObjectIdGetDatum(relid),
|
||||
PointerGetDatum(newattname),
|
||||
0, 0))
|
||||
elog(ERROR, "renameatt: attribute \"%s\" exists", newattname);
|
||||
}
|
||||
|
||||
StrNCpy(NameStr(((Form_pg_attribute) GETSTRUCT(oldatttup))->attname),
|
||||
StrNCpy(NameStr(((Form_pg_attribute) GETSTRUCT(atttup))->attname),
|
||||
newattname, NAMEDATALEN);
|
||||
|
||||
heap_update(attrelation, &oldatttup->t_self, oldatttup, NULL);
|
||||
heap_update(attrelation, &atttup->t_self, atttup, NULL);
|
||||
|
||||
/* keep system catalog indices current */
|
||||
{
|
||||
Relation irelations[Num_pg_attr_indices];
|
||||
|
||||
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
|
||||
CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, oldatttup);
|
||||
CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, atttup);
|
||||
CatalogCloseIndices(Num_pg_attr_indices, irelations);
|
||||
}
|
||||
|
||||
heap_freetuple(oldatttup);
|
||||
heap_freetuple(atttup);
|
||||
heap_close(attrelation, RowExclusiveLock);
|
||||
}
|
||||
|
||||
@@ -179,7 +175,7 @@ renamerel(const char *oldrelname, const char *newrelname)
|
||||
{
|
||||
Relation targetrelation;
|
||||
Relation relrelation; /* for RELATION relation */
|
||||
HeapTuple oldreltup;
|
||||
HeapTuple reltup;
|
||||
Oid reloid;
|
||||
char relkind;
|
||||
Relation irelations[Num_pg_class_indices];
|
||||
@@ -238,27 +234,27 @@ renamerel(const char *oldrelname, const char *newrelname)
|
||||
*/
|
||||
relrelation = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
|
||||
oldreltup = SearchSysCacheTupleCopy(RELNAME,
|
||||
PointerGetDatum(oldrelname),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(oldreltup))
|
||||
reltup = SearchSysCacheCopy(RELNAME,
|
||||
PointerGetDatum(oldrelname),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(reltup))
|
||||
elog(ERROR, "renamerel: relation \"%s\" does not exist", oldrelname);
|
||||
|
||||
if (RelnameFindRelid(newrelname) != InvalidOid)
|
||||
elog(ERROR, "renamerel: relation \"%s\" exists", newrelname);
|
||||
|
||||
/*
|
||||
* Update pg_class tuple with new relname. (Scribbling on oldreltup
|
||||
* Update pg_class tuple with new relname. (Scribbling on reltup
|
||||
* is OK because it's a copy...)
|
||||
*/
|
||||
StrNCpy(NameStr(((Form_pg_class) GETSTRUCT(oldreltup))->relname),
|
||||
StrNCpy(NameStr(((Form_pg_class) GETSTRUCT(reltup))->relname),
|
||||
newrelname, NAMEDATALEN);
|
||||
|
||||
heap_update(relrelation, &oldreltup->t_self, oldreltup, NULL);
|
||||
heap_update(relrelation, &reltup->t_self, reltup, NULL);
|
||||
|
||||
/* keep the system catalog indices current */
|
||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, irelations);
|
||||
CatalogIndexInsert(irelations, Num_pg_class_indices, relrelation, oldreltup);
|
||||
CatalogIndexInsert(irelations, Num_pg_class_indices, relrelation, reltup);
|
||||
CatalogCloseIndices(Num_pg_class_indices, irelations);
|
||||
|
||||
heap_close(relrelation, NoLock);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.79 2000/11/08 22:09:57 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.80 2000/11/16 22:30:18 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -154,11 +154,11 @@ CreateTrigger(CreateTrigStmt *stmt)
|
||||
* Find and validate the trigger function.
|
||||
*/
|
||||
MemSet(fargtypes, 0, FUNC_MAX_ARGS * sizeof(Oid));
|
||||
tuple = SearchSysCacheTuple(PROCNAME,
|
||||
PointerGetDatum(stmt->funcname),
|
||||
Int32GetDatum(0),
|
||||
PointerGetDatum(fargtypes),
|
||||
0);
|
||||
tuple = SearchSysCache(PROCNAME,
|
||||
PointerGetDatum(stmt->funcname),
|
||||
Int32GetDatum(0),
|
||||
PointerGetDatum(fargtypes),
|
||||
0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "CreateTrigger: function %s() does not exist",
|
||||
stmt->funcname);
|
||||
@@ -167,6 +167,8 @@ CreateTrigger(CreateTrigStmt *stmt)
|
||||
stmt->funcname);
|
||||
funcoid = tuple->t_data->t_oid;
|
||||
funclang = ((Form_pg_proc) GETSTRUCT(tuple))->prolang;
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
if (funclang != ClanguageId &&
|
||||
funclang != NEWClanguageId &&
|
||||
funclang != INTERNALlanguageId &&
|
||||
@@ -174,14 +176,15 @@ CreateTrigger(CreateTrigStmt *stmt)
|
||||
{
|
||||
HeapTuple langTup;
|
||||
|
||||
langTup = SearchSysCacheTuple(LANGOID,
|
||||
ObjectIdGetDatum(funclang),
|
||||
0, 0, 0);
|
||||
langTup = SearchSysCache(LANGOID,
|
||||
ObjectIdGetDatum(funclang),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(langTup))
|
||||
elog(ERROR, "CreateTrigger: cache lookup for PL %u failed",
|
||||
funclang);
|
||||
if (((Form_pg_language) GETSTRUCT(langTup))->lanispl == false)
|
||||
elog(ERROR, "CreateTrigger: only builtin, C and PL functions are supported");
|
||||
ReleaseSysCache(langTup);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -268,9 +271,9 @@ CreateTrigger(CreateTrigStmt *stmt)
|
||||
* rebuild relcache entries.
|
||||
*/
|
||||
pgrel = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
tuple = SearchSysCacheTupleCopy(RELNAME,
|
||||
PointerGetDatum(stmt->relname),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCacheCopy(RELNAME,
|
||||
PointerGetDatum(stmt->relname),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "CreateTrigger: relation %s not found in pg_class",
|
||||
stmt->relname);
|
||||
@@ -353,9 +356,9 @@ DropTrigger(DropTrigStmt *stmt)
|
||||
* rebuild relcache entries.
|
||||
*/
|
||||
pgrel = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
tuple = SearchSysCacheTupleCopy(RELNAME,
|
||||
PointerGetDatum(stmt->relname),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCacheCopy(RELNAME,
|
||||
PointerGetDatum(stmt->relname),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "DropTrigger: relation %s not found in pg_class",
|
||||
stmt->relname);
|
||||
@@ -426,9 +429,9 @@ RelationRemoveTriggers(Relation rel)
|
||||
Relation ridescs[Num_pg_class_indices];
|
||||
|
||||
pgrel = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
tup = SearchSysCacheTupleCopy(RELOID,
|
||||
RelationGetRelid(rel),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCacheCopy(RELOID,
|
||||
RelationGetRelid(rel),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "RelationRemoveTriggers: relation %u not found in pg_class",
|
||||
RelationGetRelid(rel));
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.69 2000/10/19 03:55:51 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.70 2000/11/16 22:30:19 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -363,9 +363,9 @@ AlterUser(AlterUserStmt *stmt)
|
||||
pg_shadow_rel = heap_openr(ShadowRelationName, AccessExclusiveLock);
|
||||
pg_shadow_dsc = RelationGetDescr(pg_shadow_rel);
|
||||
|
||||
tuple = SearchSysCacheTuple(SHADOWNAME,
|
||||
PointerGetDatum(stmt->user),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(SHADOWNAME,
|
||||
PointerGetDatum(stmt->user),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
heap_close(pg_shadow_rel, AccessExclusiveLock);
|
||||
@@ -470,10 +470,13 @@ AlterUser(AlterUserStmt *stmt)
|
||||
CatalogOpenIndices(Num_pg_shadow_indices,
|
||||
Name_pg_shadow_indices, idescs);
|
||||
CatalogIndexInsert(idescs, Num_pg_shadow_indices, pg_shadow_rel,
|
||||
tuple);
|
||||
new_tuple);
|
||||
CatalogCloseIndices(Num_pg_shadow_indices, idescs);
|
||||
}
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
heap_freetuple(new_tuple);
|
||||
|
||||
/*
|
||||
* Write the updated pg_shadow data to the flat password file.
|
||||
*/
|
||||
@@ -525,9 +528,9 @@ DropUser(DropUserStmt *stmt)
|
||||
int32 usesysid;
|
||||
const char *user = strVal(lfirst(item));
|
||||
|
||||
tuple = SearchSysCacheTuple(SHADOWNAME,
|
||||
PointerGetDatum(user),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(SHADOWNAME,
|
||||
PointerGetDatum(user),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
heap_close(pg_shadow_rel, AccessExclusiveLock);
|
||||
@@ -579,6 +582,8 @@ DropUser(DropUserStmt *stmt)
|
||||
*/
|
||||
heap_delete(pg_shadow_rel, &tuple->t_self, NULL);
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
/*
|
||||
* Remove user from groups
|
||||
*
|
||||
@@ -633,24 +638,21 @@ CheckPgUserAclNotNull()
|
||||
{
|
||||
HeapTuple htup;
|
||||
|
||||
htup = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(ShadowRelationName),
|
||||
0, 0, 0);
|
||||
htup = SearchSysCache(RELNAME,
|
||||
PointerGetDatum(ShadowRelationName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(htup))
|
||||
{
|
||||
/* BIG problem */
|
||||
elog(ERROR, "IsPgUserAclNull: \"%s\" not found",
|
||||
elog(ERROR, "CheckPgUserAclNotNull: \"%s\" not found",
|
||||
ShadowRelationName);
|
||||
}
|
||||
|
||||
if (heap_attisnull(htup, Anum_pg_class_relacl))
|
||||
{
|
||||
elog(ERROR,
|
||||
"To use passwords, you have to revoke permissions on %s "
|
||||
"so normal users cannot read the passwords. "
|
||||
"Try 'REVOKE ALL ON \"%s\" FROM PUBLIC'.",
|
||||
ShadowRelationName, ShadowRelationName);
|
||||
}
|
||||
|
||||
ReleaseSysCache(htup);
|
||||
}
|
||||
|
||||
|
||||
@@ -716,24 +718,21 @@ CreateGroup(CreateGroupStmt *stmt)
|
||||
/*
|
||||
* Translate the given user names to ids
|
||||
*/
|
||||
|
||||
foreach(item, stmt->initUsers)
|
||||
{
|
||||
const char *groupuser = strVal(lfirst(item));
|
||||
Value *v;
|
||||
|
||||
tuple = SearchSysCacheTuple(SHADOWNAME,
|
||||
PointerGetDatum(groupuser),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(SHADOWNAME,
|
||||
PointerGetDatum(groupuser),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
heap_close(pg_group_rel, AccessExclusiveLock);
|
||||
elog(ERROR, "CREATE GROUP: user \"%s\" does not exist", groupuser);
|
||||
}
|
||||
|
||||
v = makeInteger(((Form_pg_shadow) GETSTRUCT(tuple))->usesysid);
|
||||
if (!member(v, newlist))
|
||||
newlist = lcons(v, newlist);
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
|
||||
/* build an array to insert */
|
||||
@@ -817,20 +816,19 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
|
||||
pg_group_dsc = RelationGetDescr(pg_group_rel);
|
||||
|
||||
/*
|
||||
* Verify that group exists. If we find a tuple, will take that the
|
||||
* rest of the way and make our modifications on it.
|
||||
* Fetch existing tuple for group.
|
||||
*/
|
||||
if (!HeapTupleIsValid(group_tuple = SearchSysCacheTupleCopy(GRONAME, PointerGetDatum(stmt->name), 0, 0, 0)))
|
||||
{
|
||||
heap_close(pg_group_rel, AccessExclusiveLock);
|
||||
group_tuple = SearchSysCache(GRONAME,
|
||||
PointerGetDatum(stmt->name),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(group_tuple))
|
||||
elog(ERROR, "%s: group \"%s\" does not exist", tag, stmt->name);
|
||||
}
|
||||
|
||||
AssertState(stmt->action == +1 || stmt->action == -1);
|
||||
|
||||
/*
|
||||
* Now decide what to do.
|
||||
*/
|
||||
AssertState(stmt->action == +1 || stmt->action == -1);
|
||||
|
||||
if (stmt->action == +1) /* add users, might also be invoked by
|
||||
* create user */
|
||||
{
|
||||
@@ -876,15 +874,14 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
|
||||
if (strcmp(tag, "ALTER GROUP") == 0)
|
||||
{
|
||||
/* Get the uid of the proposed user to add. */
|
||||
tuple = SearchSysCacheTuple(SHADOWNAME,
|
||||
PointerGetDatum(strVal(lfirst(item))),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(SHADOWNAME,
|
||||
PointerGetDatum(strVal(lfirst(item))),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
heap_close(pg_group_rel, AccessExclusiveLock);
|
||||
elog(ERROR, "%s: user \"%s\" does not exist", tag, strVal(lfirst(item)));
|
||||
}
|
||||
elog(ERROR, "%s: user \"%s\" does not exist",
|
||||
tag, strVal(lfirst(item)));
|
||||
v = makeInteger(((Form_pg_shadow) GETSTRUCT(tuple))->usesysid);
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
else if (strcmp(tag, "CREATE USER") == 0)
|
||||
{
|
||||
@@ -999,15 +996,13 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
|
||||
if (!is_dropuser)
|
||||
{
|
||||
/* Get the uid of the proposed user to drop. */
|
||||
tuple = SearchSysCacheTuple(SHADOWNAME,
|
||||
PointerGetDatum(strVal(lfirst(item))),
|
||||
0, 0, 0);
|
||||
tuple = SearchSysCache(SHADOWNAME,
|
||||
PointerGetDatum(strVal(lfirst(item))),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
heap_close(pg_group_rel, AccessExclusiveLock);
|
||||
elog(ERROR, "ALTER GROUP: user \"%s\" does not exist", strVal(lfirst(item)));
|
||||
}
|
||||
v = makeInteger(((Form_pg_shadow) GETSTRUCT(tuple))->usesysid);
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1056,9 +1051,9 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
|
||||
} /* endif group not null */
|
||||
} /* endif alter group drop user */
|
||||
|
||||
heap_close(pg_group_rel, AccessExclusiveLock);
|
||||
ReleaseSysCache(group_tuple);
|
||||
|
||||
pfree(group_tuple);
|
||||
heap_close(pg_group_rel, AccessExclusiveLock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.172 2000/11/16 05:50:59 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.173 2000/11/16 22:30:19 tgl Exp $
|
||||
*
|
||||
|
||||
*-------------------------------------------------------------------------
|
||||
@@ -356,7 +356,6 @@ getrels(NameData *VacRelP)
|
||||
static void
|
||||
vacuum_rel(Oid relid, bool analyze, bool is_toastrel)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
Relation onerel;
|
||||
VacPageListData vacuum_pages; /* List of pages to vacuum and/or clean
|
||||
* indices */
|
||||
@@ -384,10 +383,9 @@ vacuum_rel(Oid relid, bool analyze, bool is_toastrel)
|
||||
* Race condition -- if the pg_class tuple has gone away since the
|
||||
* last time we saw it, we don't need to vacuum it.
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(RELOID,
|
||||
ObjectIdGetDatum(relid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
if (!SearchSysCacheExists(RELOID,
|
||||
ObjectIdGetDatum(relid),
|
||||
0, 0, 0))
|
||||
{
|
||||
if (!is_toastrel)
|
||||
CommitTransactionCommand();
|
||||
@@ -2237,17 +2235,17 @@ update_relstats(Oid relid, int num_pages, int num_tuples, bool hasindex,
|
||||
*/
|
||||
rd = heap_openr(RelationRelationName, RowExclusiveLock);
|
||||
|
||||
ctup = SearchSysCacheTupleCopy(RELOID,
|
||||
ObjectIdGetDatum(relid),
|
||||
0, 0, 0);
|
||||
ctup = SearchSysCache(RELOID,
|
||||
ObjectIdGetDatum(relid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(ctup))
|
||||
elog(ERROR, "pg_class entry for relid %u vanished during vacuuming",
|
||||
relid);
|
||||
|
||||
/* get the buffer cache tuple */
|
||||
rtup.t_self = ctup->t_self;
|
||||
ReleaseSysCache(ctup);
|
||||
heap_fetch(rd, SnapshotNow, &rtup, &buffer);
|
||||
heap_freetuple(ctup);
|
||||
|
||||
/* overwrite the existing statistics in the tuple */
|
||||
pgcform = (Form_pg_class) GETSTRUCT(&rtup);
|
||||
@@ -2481,13 +2479,14 @@ get_index_desc(Relation onerel, int nindices, Relation *Irel)
|
||||
|
||||
for (i = 0; i < nindices; i++)
|
||||
{
|
||||
cachetuple = SearchSysCacheTuple(INDEXRELID,
|
||||
cachetuple = SearchSysCache(INDEXRELID,
|
||||
ObjectIdGetDatum(RelationGetRelid(Irel[i])),
|
||||
0, 0, 0);
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(cachetuple))
|
||||
elog(ERROR, "get_index_desc: index %u not found",
|
||||
RelationGetRelid(Irel[i]));
|
||||
indexInfo[i] = BuildIndexInfo(cachetuple);
|
||||
ReleaseSysCache(cachetuple);
|
||||
}
|
||||
|
||||
return indexInfo;
|
||||
|
||||
Reference in New Issue
Block a user