mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +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:
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.13 1998/06/15 19:28:17 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.14 1998/08/19 02:01:58 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* At the point the version is defined, 2 physical relations are created
|
||||
@@ -185,26 +185,26 @@ VersionCreate(char *vname, char *bname)
|
||||
static void
|
||||
setAttrList(char *bname)
|
||||
{
|
||||
Relation rdesc;
|
||||
Relation rel;
|
||||
int i = 0;
|
||||
int maxattrs = 0;
|
||||
char *attrname;
|
||||
char temp_buf[512];
|
||||
int notfirst = 0;
|
||||
|
||||
rdesc = heap_openr(bname);
|
||||
if (rdesc == NULL)
|
||||
rel = heap_openr(bname);
|
||||
if (rel == NULL)
|
||||
{
|
||||
elog(ERROR, "Unable to expand all -- amopenr failed ");
|
||||
return;
|
||||
}
|
||||
maxattrs = RelationGetNumberOfAttributes(rdesc);
|
||||
maxattrs = RelationGetNumberOfAttributes(rel);
|
||||
|
||||
attr_list[0] = '\0';
|
||||
|
||||
for (i = maxattrs - 1; i > -1; --i)
|
||||
{
|
||||
attrname = (rdesc->rd_att->attrs[i]->attname).data;
|
||||
attrname = (rel->rd_att->attrs[i]->attname).data;
|
||||
|
||||
if (notfirst == 1)
|
||||
sprintf(temp_buf, ", %s = new.%s", attrname, attrname);
|
||||
@@ -216,7 +216,7 @@ setAttrList(char *bname)
|
||||
strcat(attr_list, temp_buf);
|
||||
}
|
||||
|
||||
heap_close(rdesc);
|
||||
heap_close(rel);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.36 1998/07/27 19:37:50 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.37 1998/08/19 02:01:39 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -172,7 +172,6 @@ Async_Notify(char *relname)
|
||||
HeapScanDesc sRel;
|
||||
TupleDesc tdesc;
|
||||
ScanKeyData key;
|
||||
Buffer b;
|
||||
Datum d,
|
||||
value[3];
|
||||
bool isnull;
|
||||
@@ -211,16 +210,14 @@ Async_Notify(char *relname)
|
||||
value[0] = value[1] = value[2] = (Datum) 0;
|
||||
value[Anum_pg_listener_notify - 1] = Int32GetDatum(1);
|
||||
|
||||
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0, &b)))
|
||||
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0)))
|
||||
{
|
||||
d = heap_getattr(lTuple, Anum_pg_listener_notify,
|
||||
tdesc, &isnull);
|
||||
d = heap_getattr(lTuple, Anum_pg_listener_notify, tdesc, &isnull);
|
||||
if (!DatumGetInt32(d))
|
||||
{
|
||||
rTuple = heap_modifytuple(lTuple, b, lRel, value, nulls, repl);
|
||||
rTuple = heap_modifytuple(lTuple, lRel, value, nulls, repl);
|
||||
heap_replace(lRel, &lTuple->t_ctid, rTuple);
|
||||
}
|
||||
ReleaseBuffer(b);
|
||||
}
|
||||
heap_endscan(sRel);
|
||||
RelationUnsetLockForWrite(lRel);
|
||||
@@ -260,7 +257,6 @@ Async_NotifyAtCommit()
|
||||
ScanKeyData key;
|
||||
Datum d;
|
||||
bool isnull;
|
||||
Buffer b;
|
||||
extern TransactionState CurrentTransactionState;
|
||||
|
||||
if (!pendingNotifies)
|
||||
@@ -286,7 +282,7 @@ Async_NotifyAtCommit()
|
||||
sRel = heap_beginscan(lRel, 0, SnapshotNow, 1, &key);
|
||||
tdesc = RelationGetTupleDescriptor(lRel);
|
||||
|
||||
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0, &b)))
|
||||
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0)))
|
||||
{
|
||||
d = heap_getattr(lTuple, Anum_pg_listener_relname,
|
||||
tdesc, &isnull);
|
||||
@@ -317,7 +313,6 @@ Async_NotifyAtCommit()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
ReleaseBuffer(b);
|
||||
}
|
||||
heap_endscan(sRel);
|
||||
RelationUnsetLockForWrite(lRel);
|
||||
@@ -400,11 +395,10 @@ Async_Listen(char *relname, int pid)
|
||||
Datum values[Natts_pg_listener];
|
||||
char nulls[Natts_pg_listener];
|
||||
TupleDesc tdesc;
|
||||
HeapScanDesc s;
|
||||
HeapTuple htup,
|
||||
tup;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tuple,
|
||||
newtup;
|
||||
Relation lDesc;
|
||||
Buffer b;
|
||||
Datum d;
|
||||
int i;
|
||||
bool isnull;
|
||||
@@ -431,22 +425,21 @@ Async_Listen(char *relname, int pid)
|
||||
|
||||
/* is someone already listening. One listener per relation */
|
||||
tdesc = RelationGetTupleDescriptor(lDesc);
|
||||
s = heap_beginscan(lDesc, 0, SnapshotNow, 0, (ScanKey) NULL);
|
||||
while (HeapTupleIsValid(htup = heap_getnext(s, 0, &b)))
|
||||
scan = heap_beginscan(lDesc, 0, SnapshotNow, 0, (ScanKey) NULL);
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
|
||||
{
|
||||
d = heap_getattr(htup, Anum_pg_listener_relname, tdesc,
|
||||
d = heap_getattr(tuple, Anum_pg_listener_relname, tdesc,
|
||||
&isnull);
|
||||
relnamei = DatumGetPointer(d);
|
||||
if (!strncmp(relnamei, relname, NAMEDATALEN))
|
||||
{
|
||||
d = heap_getattr(htup, Anum_pg_listener_pid, tdesc, &isnull);
|
||||
d = heap_getattr(tuple, Anum_pg_listener_pid, tdesc, &isnull);
|
||||
pid = DatumGetInt32(d);
|
||||
if (pid == MyProcPid)
|
||||
alreadyListener = 1;
|
||||
}
|
||||
ReleaseBuffer(b);
|
||||
}
|
||||
heap_endscan(s);
|
||||
heap_endscan(scan);
|
||||
|
||||
if (alreadyListener)
|
||||
{
|
||||
@@ -456,12 +449,12 @@ Async_Listen(char *relname, int pid)
|
||||
}
|
||||
|
||||
tupDesc = lDesc->rd_att;
|
||||
tup = heap_formtuple(tupDesc,
|
||||
newtup = heap_formtuple(tupDesc,
|
||||
values,
|
||||
nulls);
|
||||
heap_insert(lDesc, tup);
|
||||
heap_insert(lDesc, newtup);
|
||||
|
||||
pfree(tup);
|
||||
pfree(newtup);
|
||||
|
||||
/*
|
||||
* if (alreadyListener) { elog(NOTICE,"Async_Listen: already one
|
||||
@@ -504,7 +497,8 @@ Async_Unlisten(char *relname, int pid)
|
||||
Relation lDesc;
|
||||
HeapTuple lTuple;
|
||||
|
||||
lTuple = SearchSysCacheTuple(LISTENREL, PointerGetDatum(relname),
|
||||
lTuple = SearchSysCacheTuple(LISTENREL,
|
||||
PointerGetDatum(relname),
|
||||
Int32GetDatum(pid),
|
||||
0, 0);
|
||||
lDesc = heap_openr(ListenerRelationName);
|
||||
@@ -556,7 +550,6 @@ Async_NotifyFrontEnd()
|
||||
value[3];
|
||||
char repl[3],
|
||||
nulls[3];
|
||||
Buffer b;
|
||||
bool isnull;
|
||||
|
||||
notifyFrontEndPending = 0;
|
||||
@@ -585,11 +578,10 @@ Async_NotifyFrontEnd()
|
||||
value[0] = value[1] = value[2] = (Datum) 0;
|
||||
value[Anum_pg_listener_notify - 1] = Int32GetDatum(0);
|
||||
|
||||
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0, &b)))
|
||||
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0)))
|
||||
{
|
||||
d = heap_getattr(lTuple, Anum_pg_listener_relname,
|
||||
tdesc, &isnull);
|
||||
rTuple = heap_modifytuple(lTuple, b, lRel, value, nulls, repl);
|
||||
d = heap_getattr(lTuple, Anum_pg_listener_relname, tdesc, &isnull);
|
||||
rTuple = heap_modifytuple(lTuple, lRel, value, nulls, repl);
|
||||
heap_replace(lRel, &lTuple->t_ctid, rTuple);
|
||||
|
||||
/* notifying the front end */
|
||||
@@ -603,8 +595,9 @@ Async_NotifyFrontEnd()
|
||||
}
|
||||
else
|
||||
elog(NOTICE, "Async_NotifyFrontEnd: no asynchronous notification to frontend on interactive sessions");
|
||||
ReleaseBuffer(b);
|
||||
}
|
||||
heap_endscan(sRel);
|
||||
heap_close(lRel);
|
||||
CommitTransactionCommand();
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.27 1998/08/06 05:12:22 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.28 1998/08/19 02:01:41 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -128,7 +128,7 @@ cluster(char oldrelname[], char oldindexname[])
|
||||
elog(ERROR, "cluster: unknown relation: \"%s\"",
|
||||
oldrelname);
|
||||
}
|
||||
OIDOldHeap = OldHeap->rd_id;/* Get OID for the index scan */
|
||||
OIDOldHeap = RelationGetRelid(OldHeap);/* Get OID for the index scan */
|
||||
|
||||
OldIndex = index_openr(oldindexname); /* Open old index relation */
|
||||
if (!RelationIsValid(OldIndex))
|
||||
@@ -136,7 +136,7 @@ cluster(char oldrelname[], char oldindexname[])
|
||||
elog(ERROR, "cluster: unknown index: \"%s\"",
|
||||
oldindexname);
|
||||
}
|
||||
OIDOldIndex = OldIndex->rd_id; /* OID for the index scan */
|
||||
OIDOldIndex = RelationGetRelid(OldIndex); /* OID for the index scan */
|
||||
|
||||
heap_close(OldHeap);
|
||||
index_close(OldIndex);
|
||||
@@ -150,7 +150,7 @@ cluster(char oldrelname[], char oldindexname[])
|
||||
* with a pg_vlock.
|
||||
*/
|
||||
NewHeap = copy_heap(OIDOldHeap);
|
||||
OIDNewHeap = NewHeap->rd_id;
|
||||
OIDNewHeap = RelationGetRelid(NewHeap);
|
||||
strcpy(NewHeapName, NewHeap->rd_rel->relname.data);
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap)
|
||||
*/
|
||||
Old_pg_index_Tuple =
|
||||
SearchSysCacheTuple(INDEXRELID,
|
||||
ObjectIdGetDatum(OldIndex->rd_id),
|
||||
ObjectIdGetDatum(RelationGetRelid(OldIndex)),
|
||||
0, 0, 0);
|
||||
|
||||
Assert(Old_pg_index_Tuple);
|
||||
@@ -265,7 +265,7 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap)
|
||||
|
||||
Old_pg_index_relation_Tuple =
|
||||
SearchSysCacheTuple(RELOID,
|
||||
ObjectIdGetDatum(OldIndex->rd_id),
|
||||
ObjectIdGetDatum(RelationGetRelid(OldIndex)),
|
||||
0, 0, 0);
|
||||
|
||||
Assert(Old_pg_index_relation_Tuple);
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.29 1998/07/27 19:37:51 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.30 1998/08/19 02:01:42 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The PortalExecutorHeapMemory crap needs to be eliminated
|
||||
@@ -272,7 +272,6 @@ PerformAddAttribute(char *relationName,
|
||||
{
|
||||
Relation relrdesc,
|
||||
attrdesc;
|
||||
HeapScanDesc attsdesc;
|
||||
HeapTuple reltup;
|
||||
HeapTuple attributeTuple;
|
||||
AttributeTupleForm attribute;
|
||||
@@ -281,8 +280,6 @@ PerformAddAttribute(char *relationName,
|
||||
int minattnum,
|
||||
maxatts;
|
||||
HeapTuple tup;
|
||||
ScanKeyData key[2];
|
||||
ItemPointerData oldTID;
|
||||
Relation idescs[Num_pg_attr_indices];
|
||||
Relation ridescs[Num_pg_class_indices];
|
||||
bool hasindex;
|
||||
@@ -334,7 +331,7 @@ PerformAddAttribute(char *relationName,
|
||||
elog(ERROR, "PerformAddAttribute: unknown relation: \"%s\"",
|
||||
relationName);
|
||||
}
|
||||
myrelid = relrdesc->rd_id;
|
||||
myrelid = RelationGetRelid(relrdesc);
|
||||
heap_close(relrdesc);
|
||||
|
||||
/* this routine is actually in the planner */
|
||||
@@ -364,9 +361,12 @@ PerformAddAttribute(char *relationName,
|
||||
}
|
||||
|
||||
relrdesc = heap_openr(RelationRelationName);
|
||||
reltup = ClassNameIndexScan(relrdesc, relationName);
|
||||
|
||||
if (!PointerIsValid(reltup))
|
||||
reltup = SearchSysCacheTupleCopy(RELNAME,
|
||||
PointerGetDatum(relationName),
|
||||
0, 0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(reltup))
|
||||
{
|
||||
heap_close(relrdesc);
|
||||
elog(ERROR, "PerformAddAttribute: relation \"%s\" not found",
|
||||
@@ -387,11 +387,10 @@ PerformAddAttribute(char *relationName,
|
||||
maxatts = minattnum + 1;
|
||||
if (maxatts > MaxHeapAttributeNumber)
|
||||
{
|
||||
pfree(reltup); /* XXX temp */
|
||||
heap_close(relrdesc); /* XXX temp */
|
||||
pfree(reltup);
|
||||
heap_close(relrdesc);
|
||||
elog(ERROR, "PerformAddAttribute: relations limited to %d attributes",
|
||||
MaxHeapAttributeNumber);
|
||||
return;
|
||||
}
|
||||
|
||||
attrdesc = heap_openr(AttributeRelationName);
|
||||
@@ -406,18 +405,6 @@ PerformAddAttribute(char *relationName,
|
||||
if (hasindex)
|
||||
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
|
||||
|
||||
ScanKeyEntryInitialize(&key[0],
|
||||
(bits16) NULL,
|
||||
(AttrNumber) Anum_pg_attribute_attrelid,
|
||||
(RegProcedure) F_OIDEQ,
|
||||
(Datum) reltup->t_oid);
|
||||
|
||||
ScanKeyEntryInitialize(&key[1],
|
||||
(bits16) NULL,
|
||||
(AttrNumber) Anum_pg_attribute_attname,
|
||||
(RegProcedure) F_NAMEEQ,
|
||||
(Datum) NULL);
|
||||
|
||||
attributeD.attrelid = reltup->t_oid;
|
||||
|
||||
attributeTuple = heap_addheader(Natts_pg_attribute,
|
||||
@@ -431,53 +418,44 @@ PerformAddAttribute(char *relationName,
|
||||
{
|
||||
HeapTuple typeTuple;
|
||||
TypeTupleForm form;
|
||||
char *p;
|
||||
char *typename;
|
||||
int attnelems;
|
||||
|
||||
/*
|
||||
* XXX use syscache here as an optimization
|
||||
*/
|
||||
key[1].sk_argument = (Datum) colDef->colname;
|
||||
attsdesc = heap_beginscan(attrdesc, 0, SnapshotNow, 2, key);
|
||||
tup = SearchSysCacheTuple(ATTNAME,
|
||||
ObjectIdGetDatum(reltup->t_oid),
|
||||
PointerGetDatum(colDef->colname),
|
||||
0, 0);
|
||||
|
||||
|
||||
tup = heap_getnext(attsdesc, 0, (Buffer *) NULL);
|
||||
if (HeapTupleIsValid(tup))
|
||||
{
|
||||
pfree(reltup); /* XXX temp */
|
||||
heap_endscan(attsdesc); /* XXX temp */
|
||||
heap_close(attrdesc); /* XXX temp */
|
||||
heap_close(relrdesc); /* XXX temp */
|
||||
heap_close(attrdesc);
|
||||
heap_close(relrdesc);
|
||||
elog(ERROR, "PerformAddAttribute: attribute \"%s\" already exists in class \"%s\"",
|
||||
key[1].sk_argument,
|
||||
relationName);
|
||||
return;
|
||||
colDef->colname, relationName);
|
||||
}
|
||||
heap_endscan(attsdesc);
|
||||
|
||||
/*
|
||||
* check to see if it is an array attribute.
|
||||
*/
|
||||
|
||||
p = colDef->typename->name;
|
||||
typename = colDef->typename->name;
|
||||
|
||||
if (colDef->typename->arrayBounds)
|
||||
{
|
||||
attnelems = length(colDef->typename->arrayBounds);
|
||||
p = makeArrayTypeName(colDef->typename->name);
|
||||
typename = makeArrayTypeName(colDef->typename->name);
|
||||
}
|
||||
else
|
||||
attnelems = 0;
|
||||
|
||||
typeTuple = SearchSysCacheTuple(TYPNAME,
|
||||
PointerGetDatum(p),
|
||||
PointerGetDatum(typename),
|
||||
0, 0, 0);
|
||||
form = (TypeTupleForm) GETSTRUCT(typeTuple);
|
||||
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "Add: type \"%s\" nonexistent", p);
|
||||
namestrcpy(&(attribute->attname), (char *) key[1].sk_argument);
|
||||
|
||||
elog(ERROR, "Add: type \"%s\" nonexistent", typename);
|
||||
namestrcpy(&(attribute->attname), colDef->colname);
|
||||
attribute->atttypid = typeTuple->t_oid;
|
||||
attribute->attlen = form->typlen;
|
||||
attributeD.attdisbursion = 0;
|
||||
@@ -504,8 +482,7 @@ PerformAddAttribute(char *relationName,
|
||||
heap_close(attrdesc);
|
||||
|
||||
((Form_pg_class) GETSTRUCT(reltup))->relnatts = maxatts;
|
||||
oldTID = reltup->t_ctid;
|
||||
heap_replace(relrdesc, &oldTID, reltup);
|
||||
heap_replace(relrdesc, &reltup->t_ctid, reltup);
|
||||
|
||||
/* keep catalog indices current */
|
||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.52 1998/07/27 19:37:51 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.53 1998/08/19 02:01:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -257,9 +257,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
fwrite(&ntuples, sizeof(int32), 1, fp);
|
||||
}
|
||||
|
||||
for (tuple = heap_getnext(scandesc, 0, NULL);
|
||||
tuple != NULL;
|
||||
tuple = heap_getnext(scandesc, 0, NULL))
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scandesc, 0)))
|
||||
{
|
||||
|
||||
if (oids && !binary)
|
||||
@@ -417,7 +415,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
|
||||
if (rel->rd_rel->relhasindex)
|
||||
{
|
||||
GetIndexRelations(rel->rd_id, &n_indices, &index_rels);
|
||||
GetIndexRelations(RelationGetRelid(rel), &n_indices, &index_rels);
|
||||
if (n_indices > 0)
|
||||
{
|
||||
has_index = true;
|
||||
@@ -435,7 +433,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
itupdescArr[i] = RelationGetTupleDescriptor(index_rels[i]);
|
||||
pgIndexTup =
|
||||
SearchSysCacheTuple(INDEXRELID,
|
||||
ObjectIdGetDatum(index_rels[i]->rd_id),
|
||||
ObjectIdGetDatum(RelationGetRelid(index_rels[i])),
|
||||
0, 0, 0);
|
||||
Assert(pgIndexTup);
|
||||
pgIndexP[i] = (IndexTupleForm) GETSTRUCT(pgIndexTup);
|
||||
@@ -758,7 +756,6 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
(AttrNumber *) &(pgIndexP[i]->indkey[0]),
|
||||
tuple,
|
||||
tupDesc,
|
||||
InvalidBuffer,
|
||||
idatum,
|
||||
index_nulls,
|
||||
finfoP[i]);
|
||||
@@ -833,7 +830,6 @@ GetTypeElement(Oid type)
|
||||
ObjectIdGetDatum(type),
|
||||
0, 0, 0);
|
||||
|
||||
|
||||
if (HeapTupleIsValid(typeTuple))
|
||||
return ((int) ((TypeTupleForm) GETSTRUCT(typeTuple))->typelem);
|
||||
|
||||
@@ -913,9 +909,7 @@ GetIndexRelations(Oid main_relation_oid,
|
||||
scan = head;
|
||||
head->next = NULL;
|
||||
|
||||
for (tuple = heap_getnext(scandesc, 0, NULL);
|
||||
tuple != NULL;
|
||||
tuple = heap_getnext(scandesc, 0, NULL))
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scandesc, 0)))
|
||||
{
|
||||
|
||||
index_relation_oid =
|
||||
@@ -1168,10 +1162,9 @@ CountTuples(Relation relation)
|
||||
|
||||
scandesc = heap_beginscan(relation, 0, SnapshotNow, 0, NULL);
|
||||
|
||||
for (tuple = heap_getnext(scandesc, 0, NULL), i = 0;
|
||||
tuple != NULL;
|
||||
tuple = heap_getnext(scandesc, 0, NULL), i++)
|
||||
;
|
||||
i = 0;
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scandesc, 0)))
|
||||
i++;
|
||||
heap_endscan(scandesc);
|
||||
return (i);
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.31 1998/08/06 05:12:24 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.32 1998/08/19 02:01:45 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -404,7 +404,7 @@ StoreCatalogInheritance(Oid relationId, List *supers)
|
||||
char nullarr[Natts_pg_inherits];
|
||||
|
||||
tuple = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(strVal(lfirst(entry))),
|
||||
PointerGetDatum(strVal(lfirst(entry))),
|
||||
0, 0, 0);
|
||||
AssertArg(HeapTupleIsValid(tuple));
|
||||
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.19 1998/08/11 18:28:13 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.20 1998/08/19 02:01:46 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -148,7 +148,6 @@ get_pg_dbtup(char *command, char *dbname, Relation dbrel)
|
||||
{
|
||||
HeapTuple dbtup;
|
||||
HeapTuple tup;
|
||||
Buffer buf;
|
||||
HeapScanDesc scan;
|
||||
ScanKeyData scanKey;
|
||||
|
||||
@@ -163,13 +162,10 @@ get_pg_dbtup(char *command, char *dbname, Relation dbrel)
|
||||
* since we want to return the tuple out of this proc, and we're going
|
||||
* to close the relation, copy the tuple and return the copy.
|
||||
*/
|
||||
tup = heap_getnext(scan, 0, &buf);
|
||||
tup = heap_getnext(scan, 0);
|
||||
|
||||
if (HeapTupleIsValid(tup))
|
||||
{
|
||||
dbtup = heap_copytuple(tup);
|
||||
ReleaseBuffer(buf);
|
||||
}
|
||||
else
|
||||
dbtup = tup;
|
||||
|
||||
@@ -205,8 +201,9 @@ check_permissions(char *command,
|
||||
char path[MAXPGPATH + 1];
|
||||
|
||||
userName = GetPgUserName();
|
||||
utup = SearchSysCacheTuple(USENAME, PointerGetDatum(userName),
|
||||
0, 0, 0);
|
||||
utup = SearchSysCacheTuple(USENAME,
|
||||
PointerGetDatum(userName),
|
||||
0, 0, 0);
|
||||
*userIdP = ((Form_pg_shadow) GETSTRUCT(utup))->usesysid;
|
||||
use_super = ((Form_pg_shadow) GETSTRUCT(utup))->usesuper;
|
||||
use_createdb = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb;
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.21 1998/06/15 19:28:15 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.22 1998/08/19 02:01:48 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -118,7 +118,8 @@ DefineIndex(char *heapRelationName,
|
||||
/*
|
||||
* compute access method id
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(AMNAME, PointerGetDatum(accessMethodName),
|
||||
tuple = SearchSysCacheTuple(AMNAME,
|
||||
PointerGetDatum(accessMethodName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
@@ -244,7 +245,8 @@ ExtendIndex(char *indexRelationName, Expr *predicate, List *rangetable)
|
||||
/*
|
||||
* compute index relation id and access method id
|
||||
*/
|
||||
tuple = SearchSysCacheTuple(RELNAME, PointerGetDatum(indexRelationName),
|
||||
tuple = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(indexRelationName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
|
@@ -53,7 +53,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
Oid typev[8];
|
||||
char nulls[Natts_pg_language];
|
||||
Datum values[Natts_pg_language];
|
||||
Relation rdesc;
|
||||
Relation rel;
|
||||
HeapTuple tup;
|
||||
TupleDesc tupDesc;
|
||||
|
||||
@@ -90,7 +90,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
memset(typev, 0, sizeof(typev));
|
||||
procTup = SearchSysCacheTuple(PRONAME,
|
||||
PointerGetDatum(stmt->plhandler),
|
||||
UInt16GetDatum(0),
|
||||
Int32GetDatum(0),
|
||||
PointerGetDatum(typev),
|
||||
0);
|
||||
if (!HeapTupleIsValid(procTup))
|
||||
@@ -121,14 +121,14 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
values[i++] = ObjectIdGetDatum(procTup->t_oid);
|
||||
values[i++] = (Datum) fmgr(F_TEXTIN, stmt->plcompiler);
|
||||
|
||||
rdesc = heap_openr(LanguageRelationName);
|
||||
rel = heap_openr(LanguageRelationName);
|
||||
|
||||
tupDesc = rdesc->rd_att;
|
||||
tupDesc = rel->rd_att;
|
||||
tup = heap_formtuple(tupDesc, values, nulls);
|
||||
|
||||
heap_insert(rdesc, tup);
|
||||
heap_insert(rel, tup);
|
||||
|
||||
heap_close(rdesc);
|
||||
heap_close(rel);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -142,11 +142,7 @@ DropProceduralLanguage(DropPLangStmt *stmt)
|
||||
{
|
||||
char languageName[NAMEDATALEN];
|
||||
HeapTuple langTup;
|
||||
|
||||
Relation rdesc;
|
||||
HeapScanDesc scanDesc;
|
||||
ScanKeyData scanKeyData;
|
||||
HeapTuple tup;
|
||||
Relation rel;
|
||||
|
||||
/* ----------------
|
||||
* Check permission
|
||||
@@ -165,7 +161,7 @@ DropProceduralLanguage(DropPLangStmt *stmt)
|
||||
*/
|
||||
case_translate_language_name(stmt->plname, languageName);
|
||||
|
||||
langTup = SearchSysCacheTuple(LANNAME,
|
||||
langTup = SearchSysCacheTupleCopy(LANNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(langTup))
|
||||
@@ -177,24 +173,9 @@ DropProceduralLanguage(DropPLangStmt *stmt)
|
||||
languageName);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* Now scan pg_language and delete the PL tuple
|
||||
* ----------------
|
||||
*/
|
||||
rdesc = heap_openr(LanguageRelationName);
|
||||
rel = heap_openr(LanguageRelationName);
|
||||
heap_delete(rel, &langTup->t_ctid);
|
||||
|
||||
ScanKeyEntryInitialize(&scanKeyData, 0, Anum_pg_language_lanname,
|
||||
F_NAMEEQ, PointerGetDatum(languageName));
|
||||
|
||||
scanDesc = heap_beginscan(rdesc, 0, SnapshotNow, 1, &scanKeyData);
|
||||
|
||||
tup = heap_getnext(scanDesc, 0, (Buffer *) NULL);
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "Language with name '%s' not found", languageName);
|
||||
|
||||
heap_delete(rdesc, &(tup->t_ctid));
|
||||
|
||||
heap_endscan(scanDesc);
|
||||
heap_close(rdesc);
|
||||
pfree(langTup);
|
||||
heap_close(rel);
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.26 1998/07/27 19:37:53 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.27 1998/08/19 02:01:50 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -51,16 +51,13 @@ RemoveOperator(char *operatorName, /* operator name */
|
||||
char *typeName2) /* optional second type name */
|
||||
{
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tup;
|
||||
Oid typeId1 = InvalidOid;
|
||||
Oid typeId2 = InvalidOid;
|
||||
bool defined;
|
||||
ItemPointerData itemPointerData;
|
||||
Buffer buffer;
|
||||
ScanKeyData operatorKey[3];
|
||||
char *userName;
|
||||
|
||||
char oprtype;
|
||||
|
||||
if (typeName1)
|
||||
{
|
||||
typeId1 = TypeGet(typeName1, &defined);
|
||||
@@ -81,24 +78,20 @@ RemoveOperator(char *operatorName, /* operator name */
|
||||
}
|
||||
}
|
||||
|
||||
ScanKeyEntryInitialize(&operatorKey[0], 0x0,
|
||||
Anum_pg_operator_oprname,
|
||||
F_NAMEEQ,
|
||||
PointerGetDatum(operatorName));
|
||||
|
||||
ScanKeyEntryInitialize(&operatorKey[1], 0x0,
|
||||
Anum_pg_operator_oprleft,
|
||||
F_OIDEQ,
|
||||
ObjectIdGetDatum(typeId1));
|
||||
|
||||
ScanKeyEntryInitialize(&operatorKey[2], 0x0,
|
||||
Anum_pg_operator_oprright,
|
||||
F_OIDEQ,
|
||||
ObjectIdGetDatum(typeId2));
|
||||
if (OidIsValid(typeId1) && OidIsValid(typeId2))
|
||||
oprtype = 'b';
|
||||
else if (OidIsValid(typeId1))
|
||||
oprtype = 'l';
|
||||
else
|
||||
oprtype = 'r';
|
||||
|
||||
tup = SearchSysCacheTupleCopy(OPRNAME,
|
||||
PointerGetDatum(operatorName),
|
||||
ObjectIdGetDatum(typeId1),
|
||||
ObjectIdGetDatum(typeId2),
|
||||
CharGetDatum(oprtype));
|
||||
|
||||
relation = heap_openr(OperatorRelationName);
|
||||
scan = heap_beginscan(relation, 0, SnapshotNow, 3, operatorKey);
|
||||
tup = heap_getnext(scan, 0, &buffer);
|
||||
if (HeapTupleIsValid(tup))
|
||||
{
|
||||
#ifndef NO_SECURITY
|
||||
@@ -109,8 +102,7 @@ RemoveOperator(char *operatorName, /* operator name */
|
||||
elog(ERROR, "RemoveOperator: operator '%s': permission denied",
|
||||
operatorName);
|
||||
#endif
|
||||
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
|
||||
heap_delete(relation, &itemPointerData);
|
||||
heap_delete(relation, &tup->t_ctid);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -134,7 +126,7 @@ RemoveOperator(char *operatorName, /* operator name */
|
||||
typeName2);
|
||||
}
|
||||
}
|
||||
heap_endscan(scan);
|
||||
pfree(tup);
|
||||
heap_close(relation);
|
||||
}
|
||||
|
||||
@@ -150,31 +142,25 @@ RemoveOperator(char *operatorName, /* operator name */
|
||||
static void
|
||||
SingleOpOperatorRemove(Oid typeOid)
|
||||
{
|
||||
Relation rdesc;
|
||||
Relation rel;
|
||||
ScanKeyData key[3];
|
||||
HeapScanDesc sdesc;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tup;
|
||||
ItemPointerData itemPointerData;
|
||||
Buffer buffer;
|
||||
static attnums[3] = {7, 8, 9}; /* left, right, return */
|
||||
int i;
|
||||
|
||||
ScanKeyEntryInitialize(&key[0],
|
||||
0, 0, F_OIDEQ, (Datum) typeOid);
|
||||
rdesc = heap_openr(OperatorRelationName);
|
||||
rel = heap_openr(OperatorRelationName);
|
||||
for (i = 0; i < 3; ++i)
|
||||
{
|
||||
key[0].sk_attno = attnums[i];
|
||||
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 1, key);
|
||||
while (PointerIsValid(tup = heap_getnext(sdesc, 0, &buffer)))
|
||||
{
|
||||
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
|
||||
/* XXX LOCK not being passed */
|
||||
heap_delete(rdesc, &itemPointerData);
|
||||
}
|
||||
heap_endscan(sdesc);
|
||||
scan = heap_beginscan(rel, 0, SnapshotNow, 1, key);
|
||||
while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
|
||||
heap_delete(rel, &tup->t_ctid);
|
||||
heap_endscan(scan);
|
||||
}
|
||||
heap_close(rdesc);
|
||||
heap_close(rel);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -193,12 +179,10 @@ AttributeAndRelationRemove(Oid typeOid)
|
||||
};
|
||||
struct oidlist *oidptr,
|
||||
*optr;
|
||||
Relation rdesc;
|
||||
Relation rel;
|
||||
ScanKeyData key[1];
|
||||
HeapScanDesc sdesc;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tup;
|
||||
ItemPointerData itemPointerData;
|
||||
Buffer buffer;
|
||||
|
||||
/*
|
||||
* Get the oid's of the relations to be removed by scanning the entire
|
||||
@@ -213,31 +197,30 @@ AttributeAndRelationRemove(Oid typeOid)
|
||||
oidptr = (struct oidlist *) palloc(sizeof(*oidptr));
|
||||
oidptr->next = NULL;
|
||||
optr = oidptr;
|
||||
rdesc = heap_openr(AttributeRelationName);
|
||||
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 1, key);
|
||||
while (PointerIsValid(tup = heap_getnext(sdesc, 0, &buffer)))
|
||||
rel = heap_openr(AttributeRelationName);
|
||||
scan = heap_beginscan(rel, 0, SnapshotNow, 1, key);
|
||||
while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
|
||||
{
|
||||
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
|
||||
optr->reloid = ((AttributeTupleForm) GETSTRUCT(tup))->attrelid;
|
||||
optr->next = (struct oidlist *) palloc(sizeof(*oidptr));
|
||||
optr = optr->next;
|
||||
}
|
||||
optr->next = NULL;
|
||||
heap_endscan(sdesc);
|
||||
heap_close(rdesc);
|
||||
heap_endscan(scan);
|
||||
heap_close(rel);
|
||||
|
||||
|
||||
ScanKeyEntryInitialize(&key[0], 0,
|
||||
ObjectIdAttributeNumber,
|
||||
F_OIDEQ, (Datum) 0);
|
||||
optr = oidptr;
|
||||
rdesc = heap_openr(RelationRelationName);
|
||||
rel = heap_openr(RelationRelationName);
|
||||
while (PointerIsValid((char *) optr->next))
|
||||
{
|
||||
key[0].sk_argument = (Datum) (optr++)->reloid;
|
||||
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 1, key);
|
||||
tup = heap_getnext(sdesc, 0, &buffer);
|
||||
if (PointerIsValid(tup))
|
||||
scan = heap_beginscan(rel, 0, SnapshotNow, 1, key);
|
||||
tup = heap_getnext(scan, 0);
|
||||
if (HeapTupleIsValid(tup))
|
||||
{
|
||||
char *name;
|
||||
|
||||
@@ -245,11 +228,11 @@ AttributeAndRelationRemove(Oid typeOid)
|
||||
heap_destroy_with_catalog(name);
|
||||
}
|
||||
}
|
||||
heap_endscan(sdesc);
|
||||
heap_close(rdesc);
|
||||
heap_endscan(scan);
|
||||
heap_close(rel);
|
||||
}
|
||||
|
||||
#endif /* NOTYET */
|
||||
#endif /* NOTYET */
|
||||
|
||||
/*
|
||||
* TypeRemove
|
||||
@@ -260,13 +243,8 @@ void
|
||||
RemoveType(char *typeName) /* type name to be removed */
|
||||
{
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tup;
|
||||
Oid typeOid;
|
||||
ItemPointerData itemPointerData;
|
||||
static ScanKeyData typeKey[1] = {
|
||||
{0, Anum_pg_type_typname, F_NAMEEQ}
|
||||
};
|
||||
char *shadow_type;
|
||||
char *userName;
|
||||
|
||||
@@ -278,44 +256,33 @@ RemoveType(char *typeName) /* type name to be removed */
|
||||
#endif
|
||||
|
||||
relation = heap_openr(TypeRelationName);
|
||||
fmgr_info(typeKey[0].sk_procedure, &typeKey[0].sk_func);
|
||||
typeKey[0].sk_nargs = typeKey[0].sk_func.fn_nargs;
|
||||
tup = SearchSysCacheTuple(TYPNAME,
|
||||
PointerGetDatum(typeName),
|
||||
0, 0, 0);
|
||||
|
||||
/* Delete the primary type */
|
||||
|
||||
typeKey[0].sk_argument = PointerGetDatum(typeName);
|
||||
|
||||
scan = heap_beginscan(relation, 0, SnapshotNow, 1, typeKey);
|
||||
tup = heap_getnext(scan, 0, (Buffer *) 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
{
|
||||
heap_endscan(scan);
|
||||
heap_close(relation);
|
||||
elog(ERROR, "RemoveType: type '%s' does not exist",
|
||||
typeName);
|
||||
elog(ERROR, "RemoveType: type '%s' does not exist", typeName);
|
||||
}
|
||||
|
||||
relation = heap_openr(TypeRelationName);
|
||||
typeOid = tup->t_oid;
|
||||
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
|
||||
heap_delete(relation, &itemPointerData);
|
||||
heap_endscan(scan);
|
||||
heap_delete(relation, &tup->t_ctid);
|
||||
|
||||
/* Now, Delete the "array of" that type */
|
||||
shadow_type = makeArrayTypeName(typeName);
|
||||
typeKey[0].sk_argument = NameGetDatum(shadow_type);
|
||||
|
||||
scan = heap_beginscan(relation, 0, SnapshotNow,
|
||||
1, (ScanKey) typeKey);
|
||||
tup = heap_getnext(scan, 0, (Buffer *) 0);
|
||||
|
||||
tup = SearchSysCacheTuple(TYPNAME,
|
||||
PointerGetDatum(shadow_type),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
{
|
||||
elog(ERROR, "RemoveType: type '%s': array stub not found",
|
||||
typeName);
|
||||
heap_close(relation);
|
||||
elog(ERROR, "RemoveType: type '%s' does not exist", typeName);
|
||||
}
|
||||
|
||||
typeOid = tup->t_oid;
|
||||
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
|
||||
heap_delete(relation, &itemPointerData);
|
||||
heap_endscan(scan);
|
||||
heap_delete(relation, &tup->t_ctid);
|
||||
|
||||
heap_close(relation);
|
||||
}
|
||||
@@ -335,24 +302,16 @@ RemoveFunction(char *functionName, /* function name to be removed */
|
||||
List *argNameList /* list of TypeNames */ )
|
||||
{
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tup;
|
||||
Buffer buffer = InvalidBuffer;
|
||||
bool bufferUsed = FALSE;
|
||||
Oid argList[8];
|
||||
Form_pg_proc the_proc = NULL;
|
||||
ItemPointerData itemPointerData;
|
||||
static ScanKeyData key[3] = {
|
||||
{0, Anum_pg_proc_proname, F_NAMEEQ}
|
||||
};
|
||||
char *userName;
|
||||
char *typename;
|
||||
int i;
|
||||
|
||||
|
||||
MemSet(argList, 0, 8 * sizeof(Oid));
|
||||
for (i = 0; i < nargs; i++)
|
||||
{
|
||||
/* typename = ((TypeName*)(lfirst(argNameList)))->name; */
|
||||
typename = strVal(lfirst(argNameList));
|
||||
argNameList = lnext(argNameList);
|
||||
|
||||
@@ -360,7 +319,8 @@ RemoveFunction(char *functionName, /* function name to be removed */
|
||||
argList[i] = 0;
|
||||
else
|
||||
{
|
||||
tup = SearchSysCacheTuple(TYPNAME, PointerGetDatum(typename),
|
||||
tup = SearchSysCacheTuple(TYPNAME,
|
||||
PointerGetDatum(typename),
|
||||
0, 0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
@@ -369,12 +329,6 @@ RemoveFunction(char *functionName, /* function name to be removed */
|
||||
}
|
||||
}
|
||||
|
||||
tup = SearchSysCacheTuple(PRONAME, PointerGetDatum(functionName),
|
||||
Int32GetDatum(nargs),
|
||||
PointerGetDatum(argList), 0);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
func_error("RemoveFunction", functionName, nargs, argList, NULL);
|
||||
|
||||
#ifndef NO_SECURITY
|
||||
userName = GetPgUserName();
|
||||
if (!pg_func_ownercheck(userName, functionName, nargs, argList))
|
||||
@@ -384,48 +338,27 @@ RemoveFunction(char *functionName, /* function name to be removed */
|
||||
}
|
||||
#endif
|
||||
|
||||
key[0].sk_argument = PointerGetDatum(functionName);
|
||||
|
||||
fmgr_info(key[0].sk_procedure, &key[0].sk_func);
|
||||
key[0].sk_nargs = key[0].sk_func.fn_nargs;
|
||||
|
||||
relation = heap_openr(ProcedureRelationName);
|
||||
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key);
|
||||
tup = SearchSysCacheTuple(PRONAME,
|
||||
PointerGetDatum(functionName),
|
||||
Int32GetDatum(nargs),
|
||||
PointerGetDatum(argList),
|
||||
0);
|
||||
|
||||
do
|
||||
{ /* hope this is ok because it's indexed */
|
||||
if (bufferUsed)
|
||||
{
|
||||
ReleaseBuffer(buffer);
|
||||
bufferUsed = FALSE;
|
||||
}
|
||||
tup = heap_getnext(scan, 0, (Buffer *) &buffer);
|
||||
if (!HeapTupleIsValid(tup))
|
||||
break;
|
||||
bufferUsed = TRUE;
|
||||
the_proc = (Form_pg_proc) GETSTRUCT(tup);
|
||||
} while ((namestrcmp(&(the_proc->proname), functionName) == 0) &&
|
||||
(the_proc->pronargs != nargs ||
|
||||
!oid8eq(&(the_proc->proargtypes[0]), &argList[0])));
|
||||
|
||||
|
||||
if (!HeapTupleIsValid(tup) || namestrcmp(&(the_proc->proname),
|
||||
functionName) != 0)
|
||||
if (!HeapTupleIsValid(tup))
|
||||
{
|
||||
heap_endscan(scan);
|
||||
heap_close(relation);
|
||||
func_error("RemoveFunction", functionName, nargs, argList, NULL);
|
||||
}
|
||||
|
||||
/* ok, function has been found */
|
||||
if ((((Form_pg_proc) GETSTRUCT(tup))->prolang) == INTERNALlanguageId)
|
||||
{
|
||||
heap_close(relation);
|
||||
elog(ERROR, "RemoveFunction: function \"%s\" is built-in",functionName);
|
||||
}
|
||||
|
||||
if (the_proc->prolang == INTERNALlanguageId)
|
||||
elog(ERROR, "RemoveFunction: function \"%s\" is built-in",
|
||||
functionName);
|
||||
heap_delete(relation, &tup->t_ctid);
|
||||
|
||||
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
|
||||
heap_delete(relation, &itemPointerData);
|
||||
heap_endscan(scan);
|
||||
heap_close(relation);
|
||||
}
|
||||
|
||||
@@ -433,13 +366,10 @@ void
|
||||
RemoveAggregate(char *aggName, char *aggType)
|
||||
{
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tup;
|
||||
ItemPointerData itemPointerData;
|
||||
char *userName;
|
||||
Oid basetypeID = InvalidOid;
|
||||
bool defined;
|
||||
ScanKeyData aggregateKey[3];
|
||||
|
||||
|
||||
/*
|
||||
@@ -461,9 +391,7 @@ RemoveAggregate(char *aggName, char *aggType)
|
||||
else
|
||||
basetypeID = 0;
|
||||
|
||||
/*
|
||||
#ifndef NO_SECURITY
|
||||
*/
|
||||
userName = GetPgUserName();
|
||||
if (!pg_aggr_ownercheck(userName, aggName, basetypeID))
|
||||
{
|
||||
@@ -478,26 +406,16 @@ RemoveAggregate(char *aggName, char *aggType)
|
||||
aggName);
|
||||
}
|
||||
}
|
||||
/*
|
||||
#endif
|
||||
*/
|
||||
|
||||
ScanKeyEntryInitialize(&aggregateKey[0], 0x0,
|
||||
Anum_pg_aggregate_aggname,
|
||||
F_NAMEEQ,
|
||||
PointerGetDatum(aggName));
|
||||
|
||||
ScanKeyEntryInitialize(&aggregateKey[1], 0x0,
|
||||
Anum_pg_aggregate_aggbasetype,
|
||||
F_OIDEQ,
|
||||
ObjectIdGetDatum(basetypeID));
|
||||
|
||||
relation = heap_openr(AggregateRelationName);
|
||||
scan = heap_beginscan(relation, 0, SnapshotNow, 2, aggregateKey);
|
||||
tup = heap_getnext(scan, 0, (Buffer *) 0);
|
||||
tup = SearchSysCacheTuple(AGGNAME,
|
||||
PointerGetDatum(aggName),
|
||||
ObjectIdGetDatum(basetypeID),
|
||||
0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
{
|
||||
heap_endscan(scan);
|
||||
heap_close(relation);
|
||||
if (aggType)
|
||||
{
|
||||
@@ -510,8 +428,7 @@ RemoveAggregate(char *aggName, char *aggType)
|
||||
aggName);
|
||||
}
|
||||
}
|
||||
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
|
||||
heap_delete(relation, &itemPointerData);
|
||||
heap_endscan(scan);
|
||||
heap_delete(relation, &tup->t_ctid);
|
||||
|
||||
heap_close(relation);
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.13 1998/07/26 04:30:24 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.14 1998/08/19 02:01:52 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <utils/portal.h>
|
||||
#include <tcop/dest.h>
|
||||
#include <commands/command.h>
|
||||
#include <storage/bufmgr.h>
|
||||
#include <utils/excid.h>
|
||||
#include <utils/mcxt.h>
|
||||
#include <catalog/pg_proc.h>
|
||||
@@ -52,7 +53,7 @@
|
||||
* Attname attribute is changed in attribute catalog.
|
||||
* No record of the previous attname is kept (correct?).
|
||||
*
|
||||
* get proper reldesc from relation catalog (if not arg)
|
||||
* get proper relrelation from relation catalog (if not arg)
|
||||
* scan attribute catalog
|
||||
* for name conflict (within rel)
|
||||
* for original attribute (if not arg)
|
||||
@@ -70,14 +71,13 @@ renameatt(char *relname,
|
||||
char *userName,
|
||||
int recurse)
|
||||
{
|
||||
Relation relrdesc,
|
||||
attrdesc;
|
||||
Relation attrelation;
|
||||
HeapTuple reltup,
|
||||
oldatttup,
|
||||
newatttup;
|
||||
ItemPointerData oldTID;
|
||||
Relation idescs[Num_pg_attr_indices];
|
||||
|
||||
Relation irelations[Num_pg_attr_indices];
|
||||
Oid relid;
|
||||
|
||||
/*
|
||||
* permissions checking. this would normally be done in utility.c,
|
||||
* but this particular routine is recursive.
|
||||
@@ -110,19 +110,20 @@ renameatt(char *relname,
|
||||
List *child,
|
||||
*children;
|
||||
|
||||
relrdesc = heap_openr(relname);
|
||||
if (!RelationIsValid(relrdesc))
|
||||
{
|
||||
elog(ERROR, "renameatt: unknown relation: \"%s\"",
|
||||
relname);
|
||||
}
|
||||
myrelid = relrdesc->rd_id;
|
||||
heap_close(relrdesc);
|
||||
reltup = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(relname),
|
||||
0, 0, 0);
|
||||
|
||||
if (!HeapTupleIsValid(reltup))
|
||||
{
|
||||
elog(ERROR, "renameatt: unknown relation: \"%s\"", relname);
|
||||
}
|
||||
|
||||
myrelid = reltup->t_oid;
|
||||
|
||||
/* this routine is actually in the planner */
|
||||
children = find_all_inheritors(lconsi(myrelid, NIL), NIL);
|
||||
|
||||
|
||||
/*
|
||||
* find_all_inheritors does the recursive search of the
|
||||
* inheritance hierarchy, so all we have to do is process all of
|
||||
@@ -130,72 +131,70 @@ renameatt(char *relname,
|
||||
*/
|
||||
foreach(child, children)
|
||||
{
|
||||
char *childname;
|
||||
char childname[NAMEDATALEN];
|
||||
|
||||
childrelid = lfirsti(child);
|
||||
if (childrelid == myrelid)
|
||||
continue;
|
||||
relrdesc = heap_open(childrelid);
|
||||
if (!RelationIsValid(relrdesc))
|
||||
reltup = SearchSysCacheTuple(RELOID,
|
||||
ObjectIdGetDatum(childrelid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(reltup))
|
||||
{
|
||||
elog(ERROR, "renameatt: can't find catalog entry for inheriting class with oid %d",
|
||||
childrelid);
|
||||
}
|
||||
childname = (relrdesc->rd_rel->relname).data;
|
||||
heap_close(relrdesc);
|
||||
renameatt(childname, oldattname, newattname,
|
||||
userName, 0); /* no more recursion! */
|
||||
/* make copy of cache value, could disappear in call */
|
||||
StrNCpy(childname,
|
||||
((Form_pg_class) GETSTRUCT(reltup))->relname.data,
|
||||
NAMEDATALEN);
|
||||
/* no more recursion! */
|
||||
renameatt(childname, oldattname, newattname, userName, 0);
|
||||
}
|
||||
}
|
||||
|
||||
relrdesc = heap_openr(RelationRelationName);
|
||||
reltup = ClassNameIndexScan(relrdesc, relname);
|
||||
if (!PointerIsValid(reltup))
|
||||
{
|
||||
heap_close(relrdesc);
|
||||
elog(ERROR, "renameatt: relation \"%s\" nonexistent",
|
||||
relname);
|
||||
return;
|
||||
}
|
||||
heap_close(relrdesc);
|
||||
reltup = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(relname),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(reltup))
|
||||
elog(ERROR, "renameatt: relation \"%s\" nonexistent", relname);
|
||||
|
||||
relid = reltup->t_oid;
|
||||
|
||||
oldatttup = SearchSysCacheTupleCopy(ATTNAME,
|
||||
ObjectIdGetDatum(relid),
|
||||
PointerGetDatum(oldattname),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(oldatttup))
|
||||
elog(ERROR, "renameatt: attribute \"%s\" nonexistent", oldattname);
|
||||
|
||||
attrdesc = heap_openr(AttributeRelationName);
|
||||
oldatttup = AttributeNameIndexScan(attrdesc, reltup->t_oid, oldattname);
|
||||
if (!PointerIsValid(oldatttup))
|
||||
{
|
||||
heap_close(attrdesc);
|
||||
elog(ERROR, "renameatt: attribute \"%s\" nonexistent",
|
||||
oldattname);
|
||||
}
|
||||
if (((AttributeTupleForm) GETSTRUCT(oldatttup))->attnum < 0)
|
||||
{
|
||||
elog(ERROR, "renameatt: system attribute \"%s\" not renamed",
|
||||
oldattname);
|
||||
}
|
||||
elog(ERROR, "renameatt: system attribute \"%s\" not renamed", oldattname);
|
||||
|
||||
newatttup = AttributeNameIndexScan(attrdesc, reltup->t_oid, newattname);
|
||||
if (PointerIsValid(newatttup))
|
||||
newatttup = SearchSysCacheTuple(ATTNAME,
|
||||
ObjectIdGetDatum(relid),
|
||||
PointerGetDatum(newattname),
|
||||
0, 0);
|
||||
/* should not already exist */
|
||||
if (HeapTupleIsValid(newatttup))
|
||||
{
|
||||
pfree(oldatttup);
|
||||
heap_close(attrdesc);
|
||||
elog(ERROR, "renameatt: attribute \"%s\" exists",
|
||||
newattname);
|
||||
elog(ERROR, "renameatt: attribute \"%s\" exists", newattname);
|
||||
}
|
||||
|
||||
namestrcpy(&(((AttributeTupleForm) (GETSTRUCT(oldatttup)))->attname),
|
||||
newattname);
|
||||
oldTID = oldatttup->t_ctid;
|
||||
StrNCpy((((AttributeTupleForm) (GETSTRUCT(oldatttup)))->attname.data),
|
||||
newattname, NAMEDATALEN);
|
||||
|
||||
/* insert "fixed" tuple */
|
||||
heap_replace(attrdesc, &oldTID, oldatttup);
|
||||
attrelation = heap_openr(AttributeRelationName);
|
||||
heap_replace(attrelation, &oldatttup->t_ctid, oldatttup);
|
||||
|
||||
/* keep system catalog indices current */
|
||||
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
|
||||
CatalogIndexInsert(idescs, Num_pg_attr_indices, attrdesc, oldatttup);
|
||||
CatalogCloseIndices(Num_pg_attr_indices, idescs);
|
||||
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
|
||||
CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, oldatttup);
|
||||
CatalogCloseIndices(Num_pg_attr_indices, irelations);
|
||||
|
||||
heap_close(attrdesc);
|
||||
pfree(oldatttup);
|
||||
heap_close(attrelation);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -215,67 +214,52 @@ renameatt(char *relname,
|
||||
* properly replace the new relation tuple.
|
||||
*/
|
||||
void
|
||||
renamerel(char oldrelname[], char newrelname[])
|
||||
renamerel(char *oldrelname, char *newrelname)
|
||||
{
|
||||
Relation relrdesc; /* for RELATION relation */
|
||||
Relation relrelation; /* for RELATION relation */
|
||||
HeapTuple oldreltup,
|
||||
newreltup;
|
||||
ItemPointerData oldTID;
|
||||
char oldpath[MAXPGPATH],
|
||||
newpath[MAXPGPATH];
|
||||
Relation idescs[Num_pg_class_indices];
|
||||
|
||||
Relation irelations[Num_pg_class_indices];
|
||||
|
||||
if (IsSystemRelationName(oldrelname))
|
||||
{
|
||||
elog(ERROR, "renamerel: system relation \"%s\" not renamed",
|
||||
oldrelname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsSystemRelationName(newrelname))
|
||||
{
|
||||
elog(ERROR, "renamerel: Illegal class name: \"%s\" -- pg_ is reserved for system catalogs",
|
||||
newrelname);
|
||||
return;
|
||||
}
|
||||
|
||||
relrdesc = heap_openr(RelationRelationName);
|
||||
oldreltup = ClassNameIndexScan(relrdesc, oldrelname);
|
||||
oldreltup = SearchSysCacheTupleCopy(RELNAME,
|
||||
PointerGetDatum(oldrelname),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(oldreltup))
|
||||
elog(ERROR, "renamerel: relation \"%s\" does not exist", oldrelname);
|
||||
|
||||
if (!PointerIsValid(oldreltup))
|
||||
{
|
||||
heap_close(relrdesc);
|
||||
elog(ERROR, "renamerel: relation \"%s\" does not exist",
|
||||
oldrelname);
|
||||
}
|
||||
newreltup = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(newrelname),
|
||||
0, 0, 0);
|
||||
if (HeapTupleIsValid(newreltup))
|
||||
elog(ERROR, "renamerel: relation \"%s\" exists", newrelname);
|
||||
|
||||
newreltup = ClassNameIndexScan(relrdesc, newrelname);
|
||||
if (PointerIsValid(newreltup))
|
||||
{
|
||||
pfree(oldreltup);
|
||||
heap_close(relrdesc);
|
||||
elog(ERROR, "renamerel: relation \"%s\" exists",
|
||||
newrelname);
|
||||
}
|
||||
|
||||
/* rename the directory first, so if this fails the rename's not done */
|
||||
/* rename the path first, so if this fails the rename's not done */
|
||||
strcpy(oldpath, relpath(oldrelname));
|
||||
strcpy(newpath, relpath(newrelname));
|
||||
if (rename(oldpath, newpath) < 0)
|
||||
elog(ERROR, "renamerel: unable to rename file: %m");
|
||||
elog(ERROR, "renamerel: unable to rename file: %s", oldpath);
|
||||
|
||||
memmove((char *) (((Form_pg_class) GETSTRUCT(oldreltup))->relname.data),
|
||||
newrelname,
|
||||
NAMEDATALEN);
|
||||
oldTID = oldreltup->t_ctid;
|
||||
StrNCpy((((Form_pg_class) GETSTRUCT(oldreltup))->relname.data),
|
||||
newrelname, NAMEDATALEN);
|
||||
|
||||
/* insert fixed rel tuple */
|
||||
heap_replace(relrdesc, &oldTID, oldreltup);
|
||||
relrelation = heap_openr(RelationRelationName);
|
||||
heap_replace(relrelation, &oldreltup->t_ctid, oldreltup);
|
||||
|
||||
/* keep the system catalog indices current */
|
||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
|
||||
CatalogIndexInsert(idescs, Num_pg_class_indices, relrdesc, oldreltup);
|
||||
CatalogCloseIndices(Num_pg_class_indices, idescs);
|
||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, irelations);
|
||||
CatalogIndexInsert(irelations, Num_pg_class_indices, relrelation, oldreltup);
|
||||
CatalogCloseIndices(Num_pg_class_indices, irelations);
|
||||
|
||||
pfree(oldreltup);
|
||||
heap_close(relrdesc);
|
||||
heap_close(relrelation);
|
||||
}
|
||||
|
@@ -395,18 +395,18 @@ init_sequence(char *caller, char *name)
|
||||
|
||||
if (elm != (SeqTable) NULL) /* we opened sequence from our */
|
||||
{ /* SeqTable - check relid ! */
|
||||
if (RelationGetRelationId(elm->rel) != elm->relid)
|
||||
if (RelationGetRelid(elm->rel) != elm->relid)
|
||||
{
|
||||
elog(NOTICE, "%s.%s: sequence was re-created",
|
||||
name, caller, name);
|
||||
elm->cached = elm->last = elm->increment = 0;
|
||||
elm->relid = RelationGetRelationId(elm->rel);
|
||||
elm->relid = RelationGetRelid(elm->rel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
elm = temp;
|
||||
elm->relid = RelationGetRelationId(elm->rel);
|
||||
elm->relid = RelationGetRelid(elm->rel);
|
||||
if (seqtab == (SeqTable) NULL)
|
||||
seqtab = elm;
|
||||
else
|
||||
|
@@ -59,7 +59,6 @@ CreateTrigger(CreateTrigStmt *stmt)
|
||||
ScanKeyData key;
|
||||
Relation relrdesc;
|
||||
HeapTuple tuple;
|
||||
ItemPointerData oldTID;
|
||||
Relation idescs[Num_pg_trigger_indices];
|
||||
Relation ridescs[Num_pg_class_indices];
|
||||
MemoryContext oldcxt;
|
||||
@@ -118,9 +117,9 @@ CreateTrigger(CreateTrigStmt *stmt)
|
||||
tgrel = heap_openr(TriggerRelationName);
|
||||
RelationSetLockForWrite(tgrel);
|
||||
ScanKeyEntryInitialize(&key, 0, Anum_pg_trigger_tgrelid,
|
||||
F_OIDEQ, rel->rd_id);
|
||||
F_OIDEQ, RelationGetRelid(rel));
|
||||
tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key);
|
||||
while (tuple = heap_getnext(tgscan, 0, (Buffer *) NULL), PointerIsValid(tuple))
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(tgscan, 0)))
|
||||
{
|
||||
Form_pg_trigger pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple);
|
||||
|
||||
@@ -135,7 +134,9 @@ CreateTrigger(CreateTrigStmt *stmt)
|
||||
MemSet(fargtypes, 0, 8 * sizeof(Oid));
|
||||
tuple = SearchSysCacheTuple(PRONAME,
|
||||
PointerGetDatum(stmt->funcname),
|
||||
0, PointerGetDatum(fargtypes), 0);
|
||||
Int32GetDatum(0),
|
||||
PointerGetDatum(fargtypes),
|
||||
0);
|
||||
if (!HeapTupleIsValid(tuple) ||
|
||||
((Form_pg_proc) GETSTRUCT(tuple))->prorettype != 0 ||
|
||||
((Form_pg_proc) GETSTRUCT(tuple))->pronargs != 0)
|
||||
@@ -157,7 +158,7 @@ CreateTrigger(CreateTrigStmt *stmt)
|
||||
|
||||
MemSet(nulls, ' ', Natts_pg_trigger * sizeof(char));
|
||||
|
||||
values[Anum_pg_trigger_tgrelid - 1] = ObjectIdGetDatum(rel->rd_id);
|
||||
values[Anum_pg_trigger_tgrelid - 1] = ObjectIdGetDatum(RelationGetRelid(rel));
|
||||
values[Anum_pg_trigger_tgname - 1] = NameGetDatum(namein(stmt->trigname));
|
||||
values[Anum_pg_trigger_tgfoid - 1] = ObjectIdGetDatum(tuple->t_oid);
|
||||
values[Anum_pg_trigger_tgtype - 1] = Int16GetDatum(tgtype);
|
||||
@@ -218,17 +219,16 @@ CreateTrigger(CreateTrigStmt *stmt)
|
||||
pfree(DatumGetPointer(values[Anum_pg_trigger_tgargs - 1]));
|
||||
|
||||
/* update pg_class */
|
||||
relrdesc = heap_openr(RelationRelationName);
|
||||
tuple = ClassNameIndexScan(relrdesc, stmt->relname);
|
||||
if (!PointerIsValid(tuple))
|
||||
{
|
||||
heap_close(relrdesc);
|
||||
tuple = SearchSysCacheTupleCopy(RELNAME,
|
||||
PointerGetDatum(stmt->relname),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "CreateTrigger: relation %s not found in pg_class", stmt->relname);
|
||||
}
|
||||
|
||||
relrdesc = heap_openr(RelationRelationName);
|
||||
((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found + 1;
|
||||
RelationInvalidateHeapTuple(relrdesc, tuple);
|
||||
oldTID = tuple->t_ctid;
|
||||
heap_replace(relrdesc, &oldTID, tuple);
|
||||
heap_replace(relrdesc, &tuple->t_ctid, tuple);
|
||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
|
||||
CatalogIndexInsert(ridescs, Num_pg_class_indices, relrdesc, tuple);
|
||||
CatalogCloseIndices(Num_pg_class_indices, ridescs);
|
||||
@@ -254,12 +254,11 @@ DropTrigger(DropTrigStmt *stmt)
|
||||
ScanKeyData key;
|
||||
Relation relrdesc;
|
||||
HeapTuple tuple;
|
||||
ItemPointerData oldTID;
|
||||
Relation ridescs[Num_pg_class_indices];
|
||||
MemoryContext oldcxt;
|
||||
int found = 0;
|
||||
int tgfound = 0;
|
||||
|
||||
|
||||
#ifndef NO_SECURITY
|
||||
if (!pg_ownercheck(GetPgUserName(), stmt->relname, RELNAME))
|
||||
elog(ERROR, "%s: %s", stmt->relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
|
||||
@@ -274,9 +273,9 @@ DropTrigger(DropTrigStmt *stmt)
|
||||
tgrel = heap_openr(TriggerRelationName);
|
||||
RelationSetLockForWrite(tgrel);
|
||||
ScanKeyEntryInitialize(&key, 0, Anum_pg_trigger_tgrelid,
|
||||
F_OIDEQ, rel->rd_id);
|
||||
F_OIDEQ, RelationGetRelid(rel));
|
||||
tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key);
|
||||
while (tuple = heap_getnext(tgscan, 0, (Buffer *) NULL), PointerIsValid(tuple))
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(tgscan, 0)))
|
||||
{
|
||||
Form_pg_trigger pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple);
|
||||
|
||||
@@ -298,18 +297,17 @@ DropTrigger(DropTrigStmt *stmt)
|
||||
RelationUnsetLockForWrite(tgrel);
|
||||
heap_close(tgrel);
|
||||
|
||||
tuple = SearchSysCacheTupleCopy(RELNAME,
|
||||
PointerGetDatum(stmt->relname),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "DropTrigger: relation %s not found in pg_class", stmt->relname);
|
||||
|
||||
/* update pg_class */
|
||||
relrdesc = heap_openr(RelationRelationName);
|
||||
tuple = ClassNameIndexScan(relrdesc, stmt->relname);
|
||||
if (!PointerIsValid(tuple))
|
||||
{
|
||||
heap_close(relrdesc);
|
||||
elog(ERROR, "DropTrigger: relation %s not found in pg_class", stmt->relname);
|
||||
}
|
||||
((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found;
|
||||
RelationInvalidateHeapTuple(relrdesc, tuple);
|
||||
oldTID = tuple->t_ctid;
|
||||
heap_replace(relrdesc, &oldTID, tuple);
|
||||
heap_replace(relrdesc, &tuple->t_ctid, tuple);
|
||||
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
|
||||
CatalogIndexInsert(ridescs, Num_pg_class_indices, relrdesc, tuple);
|
||||
CatalogCloseIndices(Num_pg_class_indices, ridescs);
|
||||
@@ -338,11 +336,11 @@ RelationRemoveTriggers(Relation rel)
|
||||
tgrel = heap_openr(TriggerRelationName);
|
||||
RelationSetLockForWrite(tgrel);
|
||||
ScanKeyEntryInitialize(&key, 0, Anum_pg_trigger_tgrelid,
|
||||
F_OIDEQ, rel->rd_id);
|
||||
F_OIDEQ, RelationGetRelid(rel));
|
||||
|
||||
tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key);
|
||||
|
||||
while (tup = heap_getnext(tgscan, 0, (Buffer *) NULL), PointerIsValid(tup))
|
||||
while (HeapTupleIsValid(tup = heap_getnext(tgscan, 0)))
|
||||
heap_delete(tgrel, &tup->t_ctid);
|
||||
|
||||
heap_endscan(tgscan);
|
||||
@@ -377,7 +375,7 @@ RelationBuildTriggers(Relation relation)
|
||||
(bits16) 0x0,
|
||||
(AttrNumber) 1,
|
||||
(RegProcedure) F_OIDEQ,
|
||||
ObjectIdGetDatum(relation->rd_id));
|
||||
ObjectIdGetDatum(RelationGetRelid(relation)));
|
||||
|
||||
tgrel = heap_openr(TriggerRelationName);
|
||||
RelationSetLockForRead(tgrel);
|
||||
|
@@ -95,7 +95,6 @@ DefineUser(CreateUserStmt *stmt)
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tuple;
|
||||
Datum datum;
|
||||
Buffer buffer;
|
||||
char sql[512];
|
||||
char *sql_end;
|
||||
bool exists = false,
|
||||
@@ -135,7 +134,7 @@ DefineUser(CreateUserStmt *stmt)
|
||||
RelationSetLockForWrite(pg_shadow_rel);
|
||||
|
||||
scan = heap_beginscan(pg_shadow_rel, false, SnapshotNow, 0, NULL);
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer)))
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
|
||||
{
|
||||
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_shadow_dsc, &n);
|
||||
|
||||
@@ -145,8 +144,6 @@ DefineUser(CreateUserStmt *stmt)
|
||||
datum = heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_shadow_dsc, &n);
|
||||
if ((int) datum > max_id)
|
||||
max_id = (int) datum;
|
||||
|
||||
ReleaseBuffer(buffer);
|
||||
}
|
||||
heap_endscan(scan);
|
||||
|
||||
@@ -223,15 +220,10 @@ AlterUser(AlterUserStmt *stmt)
|
||||
char *pg_shadow;
|
||||
Relation pg_shadow_rel;
|
||||
TupleDesc pg_shadow_dsc;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tuple;
|
||||
Datum datum;
|
||||
Buffer buffer;
|
||||
char sql[512];
|
||||
char *sql_end;
|
||||
bool exists = false,
|
||||
n,
|
||||
inblock;
|
||||
bool inblock;
|
||||
|
||||
if (stmt->password)
|
||||
CheckPgUserAclNotNull();
|
||||
@@ -264,25 +256,14 @@ AlterUser(AlterUserStmt *stmt)
|
||||
*/
|
||||
RelationSetLockForWrite(pg_shadow_rel);
|
||||
|
||||
scan = heap_beginscan(pg_shadow_rel, false, SnapshotNow, 0, NULL);
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer)))
|
||||
{
|
||||
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_shadow_dsc, &n);
|
||||
|
||||
if (!strncmp((char *) datum, stmt->user, strlen(stmt->user)))
|
||||
{
|
||||
exists = true;
|
||||
ReleaseBuffer(buffer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
heap_endscan(scan);
|
||||
|
||||
if (!exists)
|
||||
tuple = SearchSysCacheTuple(USENAME,
|
||||
PointerGetDatum(stmt->user),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
RelationUnsetLockForWrite(pg_shadow_rel);
|
||||
heap_close(pg_shadow_rel);
|
||||
UserAbortTransactionBlock();
|
||||
UserAbortTransactionBlock(); /* needed? */
|
||||
elog(ERROR, "alterUser: user \"%s\" does not exist", stmt->user);
|
||||
return;
|
||||
}
|
||||
@@ -354,12 +335,11 @@ RemoveUser(char *user)
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tuple;
|
||||
Datum datum;
|
||||
Buffer buffer;
|
||||
char sql[512];
|
||||
bool n,
|
||||
inblock;
|
||||
int usesysid = -1,
|
||||
ndbase = 0;
|
||||
int32 usesysid;
|
||||
int ndbase = 0;
|
||||
char **dbase = NULL;
|
||||
|
||||
if (!(inblock = IsTransactionBlock()))
|
||||
@@ -375,7 +355,6 @@ RemoveUser(char *user)
|
||||
UserAbortTransactionBlock();
|
||||
elog(ERROR, "removeUser: user \"%s\" does not have SELECT and DELETE privilege for \"%s\"",
|
||||
pg_shadow, ShadowRelationName);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -393,30 +372,19 @@ RemoveUser(char *user)
|
||||
*/
|
||||
RelationSetLockForWrite(pg_shadow_rel);
|
||||
|
||||
scan = heap_beginscan(pg_shadow_rel, false, SnapshotNow, 0, NULL);
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer)))
|
||||
{
|
||||
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_dsc, &n);
|
||||
|
||||
if (!strncmp((char *) datum, user, strlen(user)))
|
||||
{
|
||||
usesysid = (int) heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_dsc, &n);
|
||||
ReleaseBuffer(buffer);
|
||||
break;
|
||||
}
|
||||
ReleaseBuffer(buffer);
|
||||
}
|
||||
heap_endscan(scan);
|
||||
|
||||
if (usesysid == -1)
|
||||
tuple = SearchSysCacheTuple(USENAME,
|
||||
PointerGetDatum(user),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
RelationUnsetLockForWrite(pg_shadow_rel);
|
||||
heap_close(pg_shadow_rel);
|
||||
UserAbortTransactionBlock();
|
||||
elog(ERROR, "removeUser: user \"%s\" does not exist", user);
|
||||
return;
|
||||
}
|
||||
|
||||
usesysid = (int32) heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_dsc, &n);
|
||||
|
||||
/*
|
||||
* Perform a scan of the pg_database relation to find the databases
|
||||
* owned by usesysid. Then drop them.
|
||||
@@ -425,7 +393,7 @@ RemoveUser(char *user)
|
||||
pg_dsc = RelationGetTupleDescriptor(pg_rel);
|
||||
|
||||
scan = heap_beginscan(pg_rel, false, SnapshotNow, 0, NULL);
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer)))
|
||||
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
|
||||
{
|
||||
datum = heap_getattr(tuple, Anum_pg_database_datdba, pg_dsc, &n);
|
||||
|
||||
@@ -440,7 +408,6 @@ RemoveUser(char *user)
|
||||
dbase[ndbase++][NAMEDATALEN] = '\0';
|
||||
}
|
||||
}
|
||||
ReleaseBuffer(buffer);
|
||||
}
|
||||
heap_endscan(scan);
|
||||
heap_close(pg_rel);
|
||||
@@ -496,17 +463,18 @@ RemoveUser(char *user)
|
||||
static void
|
||||
CheckPgUserAclNotNull()
|
||||
{
|
||||
HeapTuple htp;
|
||||
HeapTuple htup;
|
||||
|
||||
htp = SearchSysCacheTuple(RELNAME, PointerGetDatum(ShadowRelationName),
|
||||
htup = SearchSysCacheTuple(RELNAME,
|
||||
PointerGetDatum(ShadowRelationName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(htp))
|
||||
if (!HeapTupleIsValid(htup))
|
||||
{
|
||||
elog(ERROR, "IsPgUserAclNull: class \"%s\" not found",
|
||||
ShadowRelationName);
|
||||
}
|
||||
|
||||
if (heap_attisnull(htp, Anum_pg_class_relacl))
|
||||
if (heap_attisnull(htup, Anum_pg_class_relacl))
|
||||
{
|
||||
elog(NOTICE, "To use passwords, you have to revoke permissions on pg_shadow");
|
||||
elog(NOTICE, "so normal users can not read the passwords.");
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.69 1998/07/27 19:37:53 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.70 1998/08/19 02:01:56 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
/* #include <port-protos.h> *//* Why? */
|
||||
|
||||
extern int BlowawayRelationBuffers(Relation rdesc, BlockNumber block);
|
||||
extern int BlowawayRelationBuffers(Relation rel, BlockNumber block);
|
||||
|
||||
bool VacuumRunning = false;
|
||||
|
||||
@@ -84,7 +84,7 @@ static void vc_vacheap(VRelStats *vacrelstats, Relation onerel, VPageList vpl);
|
||||
static void vc_vacpage(Page page, VPageDescr vpd);
|
||||
static void vc_vaconeind(VPageList vpl, Relation indrel, int nhtups);
|
||||
static void vc_scanoneind(Relation indrel, int nhtups);
|
||||
static void vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup);
|
||||
static void vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple tuple);
|
||||
static void vc_bucketcpy(AttributeTupleForm attr, Datum value, Datum *bucket, int16 *bucket_len);
|
||||
static void vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelstats);
|
||||
static void vc_delhilowstats(Oid relid, int attcnt, int *attnums);
|
||||
@@ -261,7 +261,6 @@ vc_getrels(NameData *VacRelP)
|
||||
TupleDesc pgcdesc;
|
||||
HeapScanDesc pgcscan;
|
||||
HeapTuple pgctup;
|
||||
Buffer buf;
|
||||
PortalVariableMemory portalmem;
|
||||
MemoryContext old;
|
||||
VRelList vrl,
|
||||
@@ -270,8 +269,8 @@ vc_getrels(NameData *VacRelP)
|
||||
char *rname;
|
||||
char rkind;
|
||||
bool n;
|
||||
ScanKeyData pgckey;
|
||||
bool found = false;
|
||||
ScanKeyData pgckey;
|
||||
|
||||
StartTransactionCommand();
|
||||
|
||||
@@ -295,9 +294,8 @@ vc_getrels(NameData *VacRelP)
|
||||
|
||||
pgcscan = heap_beginscan(pgclass, false, SnapshotNow, 1, &pgckey);
|
||||
|
||||
while (HeapTupleIsValid(pgctup = heap_getnext(pgcscan, 0, &buf)))
|
||||
while (HeapTupleIsValid(pgctup = heap_getnext(pgcscan, 0)))
|
||||
{
|
||||
|
||||
found = true;
|
||||
|
||||
d = heap_getattr(pgctup, Anum_pg_class_relname, pgcdesc, &n);
|
||||
@@ -314,7 +312,6 @@ vc_getrels(NameData *VacRelP)
|
||||
{
|
||||
elog(NOTICE, "Rel %s: can't vacuum LargeObjects now",
|
||||
rname);
|
||||
ReleaseBuffer(buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -325,7 +322,6 @@ vc_getrels(NameData *VacRelP)
|
||||
/* skip system relations */
|
||||
if (rkind != 'r')
|
||||
{
|
||||
ReleaseBuffer(buf);
|
||||
elog(NOTICE, "Vacuum: can not process index and certain system tables");
|
||||
continue;
|
||||
}
|
||||
@@ -343,9 +339,6 @@ vc_getrels(NameData *VacRelP)
|
||||
|
||||
cur->vrl_relid = pgctup->t_oid;
|
||||
cur->vrl_next = (VRelList) NULL;
|
||||
|
||||
/* wei hates it if you forget to do this */
|
||||
ReleaseBuffer(buf);
|
||||
}
|
||||
if (found == false)
|
||||
elog(NOTICE, "Vacuum: table not found");
|
||||
@@ -378,10 +371,7 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
|
||||
TupleDesc pgcdesc;
|
||||
HeapTuple pgctup,
|
||||
pgttup;
|
||||
Buffer pgcbuf;
|
||||
HeapScanDesc pgcscan;
|
||||
Relation onerel;
|
||||
ScanKeyData pgckey;
|
||||
VPageListData Vvpl; /* List of pages to vacuum and/or clean
|
||||
* indices */
|
||||
VPageListData Fvpl; /* List of pages with space enough for
|
||||
@@ -394,22 +384,18 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
|
||||
|
||||
StartTransactionCommand();
|
||||
|
||||
ScanKeyEntryInitialize(&pgckey, 0x0, ObjectIdAttributeNumber,
|
||||
F_OIDEQ,
|
||||
ObjectIdGetDatum(relid));
|
||||
|
||||
pgclass = heap_openr(RelationRelationName);
|
||||
pgcdesc = RelationGetTupleDescriptor(pgclass);
|
||||
pgcscan = heap_beginscan(pgclass, false, SnapshotNow, 1, &pgckey);
|
||||
|
||||
/*
|
||||
* Race condition -- if the pg_class tuple has gone away since the
|
||||
* last time we saw it, we don't need to vacuum it.
|
||||
*/
|
||||
|
||||
if (!HeapTupleIsValid(pgctup = heap_getnext(pgcscan, 0, &pgcbuf)))
|
||||
pgctup = SearchSysCacheTuple(RELOID,
|
||||
ObjectIdGetDatum(relid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(pgctup))
|
||||
{
|
||||
heap_endscan(pgcscan);
|
||||
heap_close(pgclass);
|
||||
CommitTransactionCommand();
|
||||
return;
|
||||
@@ -508,7 +494,7 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
|
||||
stats->f_cmpgt.fn_addr = NULL;
|
||||
|
||||
pgttup = SearchSysCacheTuple(TYPOID,
|
||||
ObjectIdGetDatum(stats->attr->atttypid),
|
||||
ObjectIdGetDatum(stats->attr->atttypid),
|
||||
0, 0, 0);
|
||||
if (HeapTupleIsValid(pgttup))
|
||||
stats->outfunc = ((TypeTupleForm) GETSTRUCT(pgttup))->typoutput;
|
||||
@@ -581,7 +567,6 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
|
||||
|
||||
/* all done with this class */
|
||||
heap_close(onerel);
|
||||
heap_endscan(pgcscan);
|
||||
heap_close(pgclass);
|
||||
|
||||
/* update statistics in pg_class */
|
||||
@@ -610,8 +595,8 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
|
||||
blkno;
|
||||
ItemId itemid;
|
||||
ItemPointer itemptr;
|
||||
HeapTuple htup;
|
||||
Buffer buf;
|
||||
HeapTuple tuple;
|
||||
Page page,
|
||||
tempPage = NULL;
|
||||
OffsetNumber offnum,
|
||||
@@ -706,23 +691,23 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
|
||||
continue;
|
||||
}
|
||||
|
||||
htup = (HeapTuple) PageGetItem(page, itemid);
|
||||
tuple = (HeapTuple) PageGetItem(page, itemid);
|
||||
tupgone = false;
|
||||
|
||||
if (!(htup->t_infomask & HEAP_XMIN_COMMITTED))
|
||||
if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED))
|
||||
{
|
||||
if (htup->t_infomask & HEAP_XMIN_INVALID)
|
||||
if (tuple->t_infomask & HEAP_XMIN_INVALID)
|
||||
tupgone = true;
|
||||
else
|
||||
{
|
||||
if (TransactionIdDidAbort(htup->t_xmin))
|
||||
if (TransactionIdDidAbort(tuple->t_xmin))
|
||||
tupgone = true;
|
||||
else if (TransactionIdDidCommit(htup->t_xmin))
|
||||
else if (TransactionIdDidCommit(tuple->t_xmin))
|
||||
{
|
||||
htup->t_infomask |= HEAP_XMIN_COMMITTED;
|
||||
tuple->t_infomask |= HEAP_XMIN_COMMITTED;
|
||||
pgchanged = true;
|
||||
}
|
||||
else if (!TransactionIdIsInProgress(htup->t_xmin))
|
||||
else if (!TransactionIdIsInProgress(tuple->t_xmin))
|
||||
{
|
||||
|
||||
/*
|
||||
@@ -735,7 +720,7 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
|
||||
else
|
||||
{
|
||||
elog(NOTICE, "Rel %s: TID %u/%u: InsertTransactionInProgress %u - can't shrink relation",
|
||||
relname, blkno, offnum, htup->t_xmin);
|
||||
relname, blkno, offnum, tuple->t_xmin);
|
||||
do_shrinking = false;
|
||||
}
|
||||
}
|
||||
@@ -745,32 +730,32 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
|
||||
* here we are concerned about tuples with xmin committed and
|
||||
* xmax unknown or committed
|
||||
*/
|
||||
if (htup->t_infomask & HEAP_XMIN_COMMITTED &&
|
||||
!(htup->t_infomask & HEAP_XMAX_INVALID))
|
||||
if (tuple->t_infomask & HEAP_XMIN_COMMITTED &&
|
||||
!(tuple->t_infomask & HEAP_XMAX_INVALID))
|
||||
{
|
||||
if (htup->t_infomask & HEAP_XMAX_COMMITTED)
|
||||
if (tuple->t_infomask & HEAP_XMAX_COMMITTED)
|
||||
tupgone = true;
|
||||
else if (TransactionIdDidAbort(htup->t_xmax))
|
||||
else if (TransactionIdDidAbort(tuple->t_xmax))
|
||||
{
|
||||
htup->t_infomask |= HEAP_XMAX_INVALID;
|
||||
tuple->t_infomask |= HEAP_XMAX_INVALID;
|
||||
pgchanged = true;
|
||||
}
|
||||
else if (TransactionIdDidCommit(htup->t_xmax))
|
||||
else if (TransactionIdDidCommit(tuple->t_xmax))
|
||||
tupgone = true;
|
||||
else if (!TransactionIdIsInProgress(htup->t_xmax))
|
||||
else if (!TransactionIdIsInProgress(tuple->t_xmax))
|
||||
{
|
||||
|
||||
/*
|
||||
* Not Aborted, Not Committed, Not in Progress - so it
|
||||
* from crashed process. - vadim 06/02/97
|
||||
*/
|
||||
htup->t_infomask |= HEAP_XMAX_INVALID;;
|
||||
tuple->t_infomask |= HEAP_XMAX_INVALID;;
|
||||
pgchanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(NOTICE, "Rel %s: TID %u/%u: DeleteTransactionInProgress %u - can't shrink relation",
|
||||
relname, blkno, offnum, htup->t_xmax);
|
||||
relname, blkno, offnum, tuple->t_xmax);
|
||||
do_shrinking = false;
|
||||
}
|
||||
}
|
||||
@@ -779,7 +764,7 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
|
||||
* It's possibly! But from where it comes ? And should we fix
|
||||
* it ? - vadim 11/28/96
|
||||
*/
|
||||
itemptr = &(htup->t_ctid);
|
||||
itemptr = &(tuple->t_ctid);
|
||||
if (!ItemPointerIsValid(itemptr) ||
|
||||
BlockIdGetBlockNumber(&(itemptr->ip_blkid)) != blkno)
|
||||
{
|
||||
@@ -792,13 +777,13 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
|
||||
/*
|
||||
* Other checks...
|
||||
*/
|
||||
if (htup->t_len != itemid->lp_len)
|
||||
if (tuple->t_len != itemid->lp_len)
|
||||
{
|
||||
elog(NOTICE, "Rel %s: TID %u/%u: TUPLE_LEN IN PAGEHEADER %u IS NOT THE SAME AS IN TUPLEHEADER %u. TUPGONE %d.",
|
||||
relname, blkno, offnum,
|
||||
itemid->lp_len, htup->t_len, tupgone);
|
||||
itemid->lp_len, tuple->t_len, tupgone);
|
||||
}
|
||||
if (!OidIsValid(htup->t_oid))
|
||||
if (!OidIsValid(tuple->t_oid))
|
||||
{
|
||||
elog(NOTICE, "Rel %s: TID %u/%u: OID IS INVALID. TUPGONE %d.",
|
||||
relname, blkno, offnum, tupgone);
|
||||
@@ -830,11 +815,11 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
|
||||
{
|
||||
ntups++;
|
||||
notup = false;
|
||||
if (htup->t_len < min_tlen)
|
||||
min_tlen = htup->t_len;
|
||||
if (htup->t_len > max_tlen)
|
||||
max_tlen = htup->t_len;
|
||||
vc_attrstats(onerel, vacrelstats, htup);
|
||||
if (tuple->t_len < min_tlen)
|
||||
min_tlen = tuple->t_len;
|
||||
if (tuple->t_len > max_tlen)
|
||||
max_tlen = tuple->t_len;
|
||||
vc_attrstats(onerel, vacrelstats, tuple);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -947,7 +932,7 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
|
||||
moff;
|
||||
ItemId itemid,
|
||||
newitemid;
|
||||
HeapTuple htup,
|
||||
HeapTuple tuple,
|
||||
newtup;
|
||||
TupleDesc tupdesc = NULL;
|
||||
Datum *idatum = NULL;
|
||||
@@ -1064,8 +1049,8 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
|
||||
if (!ItemIdIsUsed(itemid))
|
||||
continue;
|
||||
|
||||
htup = (HeapTuple) PageGetItem(page, itemid);
|
||||
tlen = htup->t_len;
|
||||
tuple = (HeapTuple) PageGetItem(page, itemid);
|
||||
tlen = tuple->t_len;
|
||||
|
||||
/* try to find new page for this tuple */
|
||||
if (ToBuf == InvalidBuffer ||
|
||||
@@ -1112,7 +1097,7 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
|
||||
|
||||
/* copy tuple */
|
||||
newtup = (HeapTuple) palloc(tlen);
|
||||
memmove((char *) newtup, (char *) htup, tlen);
|
||||
memmove((char *) newtup, (char *) tuple, tlen);
|
||||
|
||||
/* store transaction information */
|
||||
TransactionIdStore(myXID, &(newtup->t_xmin));
|
||||
@@ -1138,10 +1123,10 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
|
||||
ItemPointerSet(&(newtup->t_ctid), ToVpd->vpd_blkno, newoff);
|
||||
|
||||
/* now logically delete end-tuple */
|
||||
TransactionIdStore(myXID, &(htup->t_xmax));
|
||||
htup->t_cmax = myCID;
|
||||
TransactionIdStore(myXID, &(tuple->t_xmax));
|
||||
tuple->t_cmax = myCID;
|
||||
/* set xmax to unknown */
|
||||
htup->t_infomask &= ~(HEAP_XMAX_INVALID | HEAP_XMAX_COMMITTED);
|
||||
tuple->t_infomask &= ~(HEAP_XMAX_INVALID | HEAP_XMAX_COMMITTED);
|
||||
|
||||
ToVpd->vpd_nusd++;
|
||||
nmoved++;
|
||||
@@ -1158,7 +1143,6 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
|
||||
(AttrNumber *) &(idcur->tform->indkey[0]),
|
||||
newtup,
|
||||
tupdesc,
|
||||
InvalidBuffer,
|
||||
idatum,
|
||||
inulls,
|
||||
idcur->finfoP);
|
||||
@@ -1244,10 +1228,10 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
|
||||
itemid = PageGetItemId(page, newoff);
|
||||
if (!ItemIdIsUsed(itemid))
|
||||
continue;
|
||||
htup = (HeapTuple) PageGetItem(page, itemid);
|
||||
if (TransactionIdEquals((TransactionId) htup->t_xmin, myXID))
|
||||
tuple = (HeapTuple) PageGetItem(page, itemid);
|
||||
if (TransactionIdEquals((TransactionId) tuple->t_xmin, myXID))
|
||||
{
|
||||
htup->t_infomask |= HEAP_XMIN_COMMITTED;
|
||||
tuple->t_infomask |= HEAP_XMIN_COMMITTED;
|
||||
ntups++;
|
||||
}
|
||||
}
|
||||
@@ -1307,8 +1291,8 @@ Elapsed %u/%u sec.",
|
||||
itemid = PageGetItemId(page, offnum);
|
||||
if (!ItemIdIsUsed(itemid))
|
||||
continue;
|
||||
htup = (HeapTuple) PageGetItem(page, itemid);
|
||||
Assert(TransactionIdEquals((TransactionId) htup->t_xmax, myXID));
|
||||
tuple = (HeapTuple) PageGetItem(page, itemid);
|
||||
Assert(TransactionIdEquals((TransactionId) tuple->t_xmax, myXID));
|
||||
itemid->lp_flags &= ~LP_USED;
|
||||
ntups++;
|
||||
}
|
||||
@@ -1453,7 +1437,7 @@ vc_scanoneind(Relation indrel, int nhtups)
|
||||
|
||||
/* now update statistics in pg_class */
|
||||
nipages = RelationGetNumberOfBlocks(indrel);
|
||||
vc_updstats(indrel->rd_id, nipages, nitups, false, NULL);
|
||||
vc_updstats(RelationGetRelid(indrel), nipages, nitups, false, NULL);
|
||||
|
||||
getrusage(RUSAGE_SELF, &ru1);
|
||||
|
||||
@@ -1526,7 +1510,6 @@ vc_vaconeind(VPageList vpl, Relation indrel, int nhtups)
|
||||
else
|
||||
nitups++;
|
||||
|
||||
/* be tidy */
|
||||
pfree(res);
|
||||
}
|
||||
|
||||
@@ -1534,7 +1517,7 @@ vc_vaconeind(VPageList vpl, Relation indrel, int nhtups)
|
||||
|
||||
/* now update statistics in pg_class */
|
||||
nipages = RelationGetNumberOfBlocks(indrel);
|
||||
vc_updstats(indrel->rd_id, nipages, nitups, false, NULL);
|
||||
vc_updstats(RelationGetRelid(indrel), nipages, nitups, false, NULL);
|
||||
|
||||
getrusage(RUSAGE_SELF, &ru1);
|
||||
|
||||
@@ -1615,7 +1598,7 @@ vc_tidreapped(ItemPointer itemptr, VPageList vpl)
|
||||
*
|
||||
*/
|
||||
static void
|
||||
vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup)
|
||||
vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple tuple)
|
||||
{
|
||||
int i,
|
||||
attr_cnt = vacrelstats->va_natts;
|
||||
@@ -1629,7 +1612,7 @@ vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup)
|
||||
VacAttrStats *stats = &vacattrstats[i];
|
||||
bool value_hit = true;
|
||||
|
||||
value = heap_getattr(htup,
|
||||
value = heap_getattr(tuple,
|
||||
stats->attr->attnum, tupDesc, &isnull);
|
||||
|
||||
if (!VacAttrStatsEqValid(stats))
|
||||
@@ -1751,35 +1734,28 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
|
||||
Relation rd,
|
||||
ad,
|
||||
sd;
|
||||
HeapScanDesc rsdesc,
|
||||
asdesc;
|
||||
TupleDesc sdesc;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple rtup,
|
||||
atup,
|
||||
stup;
|
||||
Buffer rbuf,
|
||||
abuf;
|
||||
Form_pg_class pgcform;
|
||||
ScanKeyData rskey,
|
||||
askey;
|
||||
ScanKeyData askey;
|
||||
AttributeTupleForm attp;
|
||||
|
||||
/*
|
||||
* update number of tuples and number of pages in pg_class
|
||||
*/
|
||||
ScanKeyEntryInitialize(&rskey, 0x0, ObjectIdAttributeNumber,
|
||||
F_OIDEQ,
|
||||
ObjectIdGetDatum(relid));
|
||||
rtup = SearchSysCacheTupleCopy(RELOID,
|
||||
ObjectIdGetDatum(relid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(rtup))
|
||||
elog(ERROR, "pg_class entry for relid %d vanished during vacuuming",
|
||||
relid);
|
||||
|
||||
rd = heap_openr(RelationRelationName);
|
||||
rsdesc = heap_beginscan(rd, false, SnapshotNow, 1, &rskey);
|
||||
|
||||
if (!HeapTupleIsValid(rtup = heap_getnext(rsdesc, 0, &rbuf)))
|
||||
elog(ERROR, "pg_class entry for relid %d vanished during vacuuming",
|
||||
relid);
|
||||
|
||||
/* overwrite the existing statistics in the tuple */
|
||||
vc_setpagelock(rd, BufferGetBlockNumber(rbuf));
|
||||
vc_setpagelock(rd, ItemPointerGetBlockNumber(&rtup->t_ctid));
|
||||
pgcform = (Form_pg_class) GETSTRUCT(rtup);
|
||||
pgcform->reltuples = ntups;
|
||||
pgcform->relpages = npages;
|
||||
@@ -1795,9 +1771,9 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
|
||||
ScanKeyEntryInitialize(&askey, 0, Anum_pg_attribute_attrelid,
|
||||
F_INT4EQ, relid);
|
||||
|
||||
asdesc = heap_beginscan(ad, false, SnapshotNow, 1, &askey);
|
||||
scan = heap_beginscan(ad, false, SnapshotNow, 1, &askey);
|
||||
|
||||
while (HeapTupleIsValid(atup = heap_getnext(asdesc, 0, &abuf)))
|
||||
while (HeapTupleIsValid(atup = heap_getnext(scan, 0)))
|
||||
{
|
||||
int i;
|
||||
float32data selratio; /* average ratio of rows selected
|
||||
@@ -1824,7 +1800,7 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
|
||||
if (VacAttrStatsEqValid(stats))
|
||||
{
|
||||
|
||||
vc_setpagelock(ad, BufferGetBlockNumber(abuf));
|
||||
vc_setpagelock(ad, ItemPointerGetBlockNumber(&atup->t_ctid));
|
||||
|
||||
if (stats->nonnull_cnt + stats->null_cnt == 0 ||
|
||||
(stats->null_cnt <= 1 && stats->best_cnt == 1))
|
||||
@@ -1853,7 +1829,7 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
|
||||
if (selratio > 1.0)
|
||||
selratio = 1.0;
|
||||
attp->attdisbursion = selratio;
|
||||
WriteNoReleaseBuffer(abuf);
|
||||
WriteNoReleaseBuffer(ItemPointerGetBlockNumber(&atup->t_ctid));
|
||||
|
||||
/* DO PG_STATISTIC INSERTS */
|
||||
|
||||
@@ -1888,9 +1864,7 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
|
||||
values[i++] = (Datum) fmgr(F_TEXTIN, out_string);
|
||||
pfree(out_string);
|
||||
|
||||
sdesc = sd->rd_att;
|
||||
|
||||
stup = heap_formtuple(sdesc, values, nulls);
|
||||
stup = heap_formtuple(sd->rd_att, values, nulls);
|
||||
|
||||
/* ----------------
|
||||
* insert the tuple in the relation and get the tuple's oid.
|
||||
@@ -1903,13 +1877,15 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
|
||||
}
|
||||
}
|
||||
}
|
||||
heap_endscan(asdesc);
|
||||
heap_endscan(scan);
|
||||
heap_close(ad);
|
||||
heap_close(sd);
|
||||
}
|
||||
|
||||
/* XXX -- after write, should invalidate relcache in other backends */
|
||||
WriteNoReleaseBuffer(rbuf); /* heap_endscan release scan' buffers ? */
|
||||
#ifdef NOT_USED
|
||||
WriteNoReleaseBuffer(&rtup->t_ctid); /* heap_endscan release scan' buffers ? */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* invalidating system relations confuses the function cache of
|
||||
@@ -1918,8 +1894,7 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
|
||||
if (!IsSystemRelationName(pgcform->relname.data))
|
||||
RelationInvalidateHeapTuple(rd, rtup);
|
||||
|
||||
/* that's all, folks */
|
||||
heap_endscan(rsdesc);
|
||||
pfree(rtup);
|
||||
heap_close(rd);
|
||||
}
|
||||
|
||||
@@ -1947,7 +1922,7 @@ vc_delhilowstats(Oid relid, int attcnt, int *attnums)
|
||||
else
|
||||
pgsscan = heap_beginscan(pgstatistic, false, SnapshotNow, 0, NULL);
|
||||
|
||||
while (HeapTupleIsValid(pgstup = heap_getnext(pgsscan, 0, NULL)))
|
||||
while (HeapTupleIsValid(pgstup = heap_getnext(pgsscan, 0)))
|
||||
{
|
||||
if (attcnt > 0)
|
||||
{
|
||||
@@ -2156,7 +2131,7 @@ vc_getindices(Oid relid, int *nindices, Relation **Irel)
|
||||
|
||||
pgiscan = heap_beginscan(pgindex, false, SnapshotNow, 1, &pgikey);
|
||||
|
||||
while (HeapTupleIsValid(pgitup = heap_getnext(pgiscan, 0, NULL)))
|
||||
while (HeapTupleIsValid(pgitup = heap_getnext(pgiscan, 0)))
|
||||
{
|
||||
d = heap_getattr(pgitup, Anum_pg_index_indexrelid,
|
||||
pgidesc, &n);
|
||||
@@ -2233,7 +2208,7 @@ vc_mkindesc(Relation onerel, int nindices, Relation *Irel, IndDesc **Idesc)
|
||||
{
|
||||
pgIndexTup =
|
||||
SearchSysCacheTuple(INDEXRELID,
|
||||
ObjectIdGetDatum(Irel[i]->rd_id),
|
||||
ObjectIdGetDatum(RelationGetRelid(Irel[i])),
|
||||
0, 0, 0);
|
||||
Assert(pgIndexTup);
|
||||
idcur->tform = (IndexTupleForm) GETSTRUCT(pgIndexTup);
|
||||
|
Reference in New Issue
Block a user