mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Remove dashes in comments that don't need them, rewrap with pgindent.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.70 2001/03/22 03:59:11 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.71 2001/03/22 06:16:06 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The old interface functions have been converted to macros
|
||||
@@ -246,9 +246,8 @@ nocachegetattr(HeapTuple tuple,
|
||||
* there's a null somewhere in the tuple
|
||||
*/
|
||||
|
||||
/* ----------------
|
||||
* check to see if desired att is null
|
||||
* ----------------
|
||||
/*
|
||||
* check to see if desired att is null
|
||||
*/
|
||||
|
||||
#ifdef IN_MACRO
|
||||
@@ -261,9 +260,8 @@ nocachegetattr(HeapTuple tuple,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* Now check to see if any preceding bits are null...
|
||||
* ----------------
|
||||
/*
|
||||
* Now check to see if any preceding bits are null...
|
||||
*/
|
||||
{
|
||||
int byte = attnum >> 3;
|
||||
@@ -658,9 +656,8 @@ heap_modifytuple(HeapTuple tuple,
|
||||
HeapTuple newTuple;
|
||||
uint8 infomask;
|
||||
|
||||
/* ----------------
|
||||
* sanity checks
|
||||
* ----------------
|
||||
/*
|
||||
* sanity checks
|
||||
*/
|
||||
Assert(HeapTupleIsValid(tuple));
|
||||
Assert(RelationIsValid(relation));
|
||||
@@ -670,10 +667,9 @@ heap_modifytuple(HeapTuple tuple,
|
||||
|
||||
numberOfAttributes = RelationGetForm(relation)->relnatts;
|
||||
|
||||
/* ----------------
|
||||
* allocate and fill *value and *nulls arrays from either
|
||||
* the tuple or the repl information, as appropriate.
|
||||
* ----------------
|
||||
/*
|
||||
* allocate and fill *value and *nulls arrays from either the tuple or
|
||||
* the repl information, as appropriate.
|
||||
*/
|
||||
value = (Datum *) palloc(numberOfAttributes * sizeof *value);
|
||||
nulls = (char *) palloc(numberOfAttributes * sizeof *nulls);
|
||||
@@ -701,17 +697,16 @@ heap_modifytuple(HeapTuple tuple,
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* create a new tuple from the *values and *nulls arrays
|
||||
* ----------------
|
||||
/*
|
||||
* create a new tuple from the *values and *nulls arrays
|
||||
*/
|
||||
newTuple = heap_formtuple(RelationGetDescr(relation),
|
||||
value,
|
||||
nulls);
|
||||
|
||||
/* ----------------
|
||||
* copy the header except for t_len, t_natts, t_hoff, t_bits, t_infomask
|
||||
* ----------------
|
||||
/*
|
||||
* copy the header except for t_len, t_natts, t_hoff, t_bits,
|
||||
* t_infomask
|
||||
*/
|
||||
infomask = newTuple->t_data->t_infomask;
|
||||
memmove((char *) &newTuple->t_data->t_oid, /* XXX */
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.53 2001/03/22 03:59:11 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.54 2001/03/22 06:16:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -165,9 +165,8 @@ index_formtuple(TupleDesc tupleDescriptor,
|
||||
|
||||
infomask |= size;
|
||||
|
||||
/* ----------------
|
||||
/*
|
||||
* initialize metadata
|
||||
* ----------------
|
||||
*/
|
||||
tuple->t_info = infomask;
|
||||
return tuple;
|
||||
@@ -205,9 +204,9 @@ nocache_index_getattr(IndexTuple tup,
|
||||
int data_off; /* tuple data offset */
|
||||
|
||||
(void) isnull; /* not used */
|
||||
/* ----------------
|
||||
* sanity checks
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* sanity checks
|
||||
*/
|
||||
|
||||
/* ----------------
|
||||
@@ -246,9 +245,9 @@ nocache_index_getattr(IndexTuple tup,
|
||||
}
|
||||
else
|
||||
{ /* there's a null somewhere in the tuple */
|
||||
/* ----------------
|
||||
* check to see if desired att is null
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* check to see if desired att is null
|
||||
*/
|
||||
|
||||
/* XXX "knows" t_bits are just after fixed tuple header! */
|
||||
@@ -264,9 +263,8 @@ nocache_index_getattr(IndexTuple tup,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* Now check to see if any preceding bits are null...
|
||||
* ----------------
|
||||
/*
|
||||
* Now check to see if any preceding bits are null...
|
||||
*/
|
||||
{
|
||||
int byte = attnum >> 3;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.58 2001/03/22 03:59:11 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.59 2001/03/22 06:16:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -155,16 +155,14 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
|
||||
if (myState->attrinfo != typeinfo || myState->nattrs != natts)
|
||||
printtup_prepare_info(myState, typeinfo, natts);
|
||||
|
||||
/* ----------------
|
||||
* tell the frontend to expect new tuple data (in ASCII style)
|
||||
* ----------------
|
||||
/*
|
||||
* tell the frontend to expect new tuple data (in ASCII style)
|
||||
*/
|
||||
pq_beginmessage(&buf);
|
||||
pq_sendbyte(&buf, 'D');
|
||||
|
||||
/* ----------------
|
||||
* send a bitmap of which attributes are not null
|
||||
* ----------------
|
||||
/*
|
||||
* send a bitmap of which attributes are not null
|
||||
*/
|
||||
j = 0;
|
||||
k = 1 << 7;
|
||||
@@ -183,9 +181,8 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
|
||||
if (k != (1 << 7)) /* flush last partial byte */
|
||||
pq_sendint(&buf, j, 1);
|
||||
|
||||
/* ----------------
|
||||
* send the attributes of this tuple
|
||||
* ----------------
|
||||
/*
|
||||
* send the attributes of this tuple
|
||||
*/
|
||||
for (i = 0; i < natts; ++i)
|
||||
{
|
||||
@@ -357,16 +354,14 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
|
||||
if (myState->attrinfo != typeinfo || myState->nattrs != natts)
|
||||
printtup_prepare_info(myState, typeinfo, natts);
|
||||
|
||||
/* ----------------
|
||||
* tell the frontend to expect new tuple data (in binary style)
|
||||
* ----------------
|
||||
/*
|
||||
* tell the frontend to expect new tuple data (in binary style)
|
||||
*/
|
||||
pq_beginmessage(&buf);
|
||||
pq_sendbyte(&buf, 'B');
|
||||
|
||||
/* ----------------
|
||||
* send a bitmap of which attributes are not null
|
||||
* ----------------
|
||||
/*
|
||||
* send a bitmap of which attributes are not null
|
||||
*/
|
||||
j = 0;
|
||||
k = 1 << 7;
|
||||
@@ -385,9 +380,8 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
|
||||
if (k != (1 << 7)) /* flush last partial byte */
|
||||
pq_sendint(&buf, j, 1);
|
||||
|
||||
/* ----------------
|
||||
* send the attributes of this tuple
|
||||
* ----------------
|
||||
/*
|
||||
* send the attributes of this tuple
|
||||
*/
|
||||
#ifdef IPORTAL_DEBUG
|
||||
fprintf(stderr, "sending tuple with %d atts\n", natts);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.72 2001/03/22 03:59:11 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.73 2001/03/22 06:16:06 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* some of the executor utility code such as "ExecTypeFromTL" should be
|
||||
@@ -37,17 +37,15 @@ CreateTemplateTupleDesc(int natts)
|
||||
uint32 size;
|
||||
TupleDesc desc;
|
||||
|
||||
/* ----------------
|
||||
* sanity checks
|
||||
* ----------------
|
||||
/*
|
||||
* sanity checks
|
||||
*/
|
||||
AssertArg(natts >= 1);
|
||||
|
||||
/* ----------------
|
||||
* allocate enough memory for the tuple descriptor and
|
||||
* zero it as TupleDescInitEntry assumes that the descriptor
|
||||
* is filled with NULL pointers.
|
||||
* ----------------
|
||||
/*
|
||||
* allocate enough memory for the tuple descriptor and zero it as
|
||||
* TupleDescInitEntry assumes that the descriptor is filled with NULL
|
||||
* pointers.
|
||||
*/
|
||||
size = natts * sizeof(Form_pg_attribute);
|
||||
desc = (TupleDesc) palloc(sizeof(struct tupleDesc));
|
||||
@@ -71,9 +69,8 @@ CreateTupleDesc(int natts, Form_pg_attribute *attrs)
|
||||
{
|
||||
TupleDesc desc;
|
||||
|
||||
/* ----------------
|
||||
* sanity checks
|
||||
* ----------------
|
||||
/*
|
||||
* sanity checks
|
||||
*/
|
||||
AssertArg(natts >= 1);
|
||||
|
||||
@@ -337,9 +334,8 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
Form_pg_type typeForm;
|
||||
Form_pg_attribute att;
|
||||
|
||||
/* ----------------
|
||||
* sanity checks
|
||||
* ----------------
|
||||
/*
|
||||
* sanity checks
|
||||
*/
|
||||
AssertArg(PointerIsValid(desc));
|
||||
AssertArg(attributeNumber >= 1);
|
||||
@@ -352,17 +348,15 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
|
||||
AssertArg(!PointerIsValid(desc->attrs[attributeNumber - 1]));
|
||||
|
||||
/* ----------------
|
||||
* allocate storage for this attribute
|
||||
* ----------------
|
||||
/*
|
||||
* allocate storage for this attribute
|
||||
*/
|
||||
|
||||
att = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
|
||||
desc->attrs[attributeNumber - 1] = att;
|
||||
|
||||
/* ----------------
|
||||
* initialize the attribute fields
|
||||
* ----------------
|
||||
/*
|
||||
* initialize the attribute fields
|
||||
*/
|
||||
att->attrelid = 0; /* dummy value */
|
||||
|
||||
@@ -404,10 +398,10 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
{
|
||||
/* ----------------
|
||||
* here type info does not exist yet so we just fill
|
||||
* the attribute with dummy information and return false.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* here type info does not exist yet so we just fill the attribute
|
||||
* with dummy information and return false.
|
||||
*/
|
||||
att->atttypid = InvalidOid;
|
||||
att->attlen = (int16) 0;
|
||||
@@ -417,32 +411,30 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* type info exists so we initialize our attribute
|
||||
* information from the type tuple we found..
|
||||
* ----------------
|
||||
/*
|
||||
* type info exists so we initialize our attribute information from
|
||||
* the type tuple we found..
|
||||
*/
|
||||
typeForm = (Form_pg_type) GETSTRUCT(tuple);
|
||||
|
||||
att->atttypid = tuple->t_data->t_oid;
|
||||
|
||||
/*------------------------
|
||||
/*
|
||||
* There are a couple of cases where we must override the information
|
||||
* stored in pg_type.
|
||||
*
|
||||
* First: if this attribute is a set, what is really stored in the
|
||||
* attribute is the OID of a tuple in the pg_proc catalog.
|
||||
* The pg_proc tuple contains the query string which defines
|
||||
* this set - i.e., the query to run to get the set.
|
||||
* So the atttypid (just assigned above) refers to the type returned
|
||||
* by this query, but the actual length of this attribute is the
|
||||
* length (size) of an OID.
|
||||
* attribute is the OID of a tuple in the pg_proc catalog. The pg_proc
|
||||
* tuple contains the query string which defines this set - i.e., the
|
||||
* query to run to get the set. So the atttypid (just assigned above)
|
||||
* refers to the type returned by this query, but the actual length of
|
||||
* this attribute is the length (size) of an OID.
|
||||
*
|
||||
* (Why not just make the atttypid point to the OID type, instead
|
||||
* of the type the query returns? Because the executor uses the atttypid
|
||||
* to tell the front end what type will be returned (in BeginCommand),
|
||||
* and in the end the type returned will be the result of the query, not
|
||||
* an OID.)
|
||||
* (Why not just make the atttypid point to the OID type, instead of the
|
||||
* type the query returns? Because the executor uses the atttypid to
|
||||
* tell the front end what type will be returned (in BeginCommand),
|
||||
* and in the end the type returned will be the result of the query,
|
||||
* not an OID.)
|
||||
*
|
||||
* (Why not wait until the return type of the set is known (i.e., the
|
||||
* recursive call to the executor to execute the set has returned)
|
||||
@@ -460,7 +452,6 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
*
|
||||
* A set of complex type is first and foremost a set, so its
|
||||
* representation is Oid not pointer. So, test that case first.
|
||||
*-----------------------------------------
|
||||
*/
|
||||
if (attisset)
|
||||
{
|
||||
@@ -550,9 +541,8 @@ BuildDescForRelation(List *schema, char *relname)
|
||||
int ndef = 0;
|
||||
bool attisset;
|
||||
|
||||
/* ----------------
|
||||
* allocate a new tuple descriptor
|
||||
* ----------------
|
||||
/*
|
||||
* allocate a new tuple descriptor
|
||||
*/
|
||||
natts = length(schema);
|
||||
desc = CreateTemplateTupleDesc(natts);
|
||||
@@ -565,11 +555,10 @@ BuildDescForRelation(List *schema, char *relname)
|
||||
ColumnDef *entry = lfirst(p);
|
||||
List *arry;
|
||||
|
||||
/* ----------------
|
||||
* for each entry in the list, get the name and type
|
||||
* information from the list and have TupleDescInitEntry
|
||||
* fill in the attribute information we need.
|
||||
* ----------------
|
||||
/*
|
||||
* for each entry in the list, get the name and type information
|
||||
* from the list and have TupleDescInitEntry fill in the attribute
|
||||
* information we need.
|
||||
*/
|
||||
attnum++;
|
||||
|
||||
@@ -595,12 +584,12 @@ BuildDescForRelation(List *schema, char *relname)
|
||||
typenameTypeId(typename),
|
||||
atttypmod, attdim, attisset))
|
||||
{
|
||||
/* ----------------
|
||||
* if TupleDescInitEntry() fails, it means there is
|
||||
* no type in the system catalogs. So now we check if
|
||||
* the type name equals the relation name. If so we
|
||||
* have a self reference, otherwise it's an error.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* if TupleDescInitEntry() fails, it means there is no type in
|
||||
* the system catalogs. So now we check if the type name
|
||||
* equals the relation name. If so we have a self reference,
|
||||
* otherwise it's an error.
|
||||
*/
|
||||
if (strcmp(typename, relname) == 0)
|
||||
TupleDescMakeSelfReference(desc, attnum, relname);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.111 2001/03/22 03:59:13 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.112 2001/03/22 06:16:07 momjian Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -116,20 +116,20 @@ initscan(HeapScanDesc scan,
|
||||
unsigned nkeys,
|
||||
ScanKey key)
|
||||
{
|
||||
/* ----------------
|
||||
* Make sure we have up-to-date idea of number of blocks in relation.
|
||||
* It is sufficient to do this once at scan start, since any tuples
|
||||
* added while the scan is in progress will be invisible to my
|
||||
* transaction anyway...
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* Make sure we have up-to-date idea of number of blocks in relation.
|
||||
* It is sufficient to do this once at scan start, since any tuples
|
||||
* added while the scan is in progress will be invisible to my
|
||||
* transaction anyway...
|
||||
*/
|
||||
relation->rd_nblocks = RelationGetNumberOfBlocks(relation);
|
||||
|
||||
if (relation->rd_nblocks == 0)
|
||||
{
|
||||
/* ----------------
|
||||
* relation is empty
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* relation is empty
|
||||
*/
|
||||
scan->rs_ntup.t_datamcxt = scan->rs_ctup.t_datamcxt =
|
||||
scan->rs_ptup.t_datamcxt = NULL;
|
||||
@@ -139,9 +139,9 @@ initscan(HeapScanDesc scan,
|
||||
}
|
||||
else if (atend)
|
||||
{
|
||||
/* ----------------
|
||||
* reverse scan
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* reverse scan
|
||||
*/
|
||||
scan->rs_ntup.t_datamcxt = scan->rs_ctup.t_datamcxt = NULL;
|
||||
scan->rs_ntup.t_data = scan->rs_ctup.t_data = NULL;
|
||||
@@ -152,9 +152,9 @@ initscan(HeapScanDesc scan,
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ----------------
|
||||
* forward scan
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* forward scan
|
||||
*/
|
||||
scan->rs_ctup.t_datamcxt = scan->rs_ptup.t_datamcxt = NULL;
|
||||
scan->rs_ctup.t_data = scan->rs_ptup.t_data = NULL;
|
||||
@@ -170,9 +170,8 @@ initscan(HeapScanDesc scan,
|
||||
ItemPointerSetInvalid(&(scan->rs_mntid));
|
||||
ItemPointerSetInvalid(&(scan->rs_mcd));
|
||||
|
||||
/* ----------------
|
||||
* copy the scan key, if appropriate
|
||||
* ----------------
|
||||
/*
|
||||
* copy the scan key, if appropriate
|
||||
*/
|
||||
if (key != NULL)
|
||||
memmove(scan->rs_key, key, nkeys * sizeof(ScanKeyData));
|
||||
@@ -188,11 +187,9 @@ unpinscan(HeapScanDesc scan)
|
||||
if (BufferIsValid(scan->rs_pbuf))
|
||||
ReleaseBuffer(scan->rs_pbuf);
|
||||
|
||||
/* ------------------------------------
|
||||
* Scan will pin buffer once for each non-NULL tuple pointer
|
||||
* (ptup, ctup, ntup), so they have to be unpinned multiple
|
||||
* times.
|
||||
* ------------------------------------
|
||||
/*
|
||||
* Scan will pin buffer once for each non-NULL tuple pointer (ptup,
|
||||
* ctup, ntup), so they have to be unpinned multiple times.
|
||||
*/
|
||||
if (BufferIsValid(scan->rs_cbuf))
|
||||
ReleaseBuffer(scan->rs_cbuf);
|
||||
@@ -251,19 +248,17 @@ heapgettup(Relation relation,
|
||||
ItemPointer tid = (tuple->t_data == NULL) ?
|
||||
(ItemPointer) NULL : &(tuple->t_self);
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_heapgettup);
|
||||
IncrHeapAccessStat(global_heapgettup);
|
||||
|
||||
/* ----------------
|
||||
* debugging stuff
|
||||
/*
|
||||
* debugging stuff
|
||||
*
|
||||
* check validity of arguments, here and for other functions too
|
||||
* Note: no locking manipulations needed--this is a local function
|
||||
* ----------------
|
||||
* check validity of arguments, here and for other functions too Note: no
|
||||
* locking manipulations needed--this is a local function
|
||||
*/
|
||||
#ifdef HEAPDEBUGALL
|
||||
if (ItemPointerIsValid(tid))
|
||||
@@ -289,9 +284,8 @@ heapgettup(Relation relation,
|
||||
|
||||
tuple->t_tableOid = relation->rd_id;
|
||||
|
||||
/* ----------------
|
||||
* return null immediately if relation is empty
|
||||
* ----------------
|
||||
/*
|
||||
* return null immediately if relation is empty
|
||||
*/
|
||||
if (!(pages = relation->rd_nblocks))
|
||||
{
|
||||
@@ -300,15 +294,14 @@ heapgettup(Relation relation,
|
||||
return;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* calculate next starting lineoff, given scan direction
|
||||
* ----------------
|
||||
/*
|
||||
* calculate next starting lineoff, given scan direction
|
||||
*/
|
||||
if (!dir)
|
||||
{
|
||||
/* ----------------
|
||||
|
||||
/*
|
||||
* ``no movement'' scan direction
|
||||
* ----------------
|
||||
*/
|
||||
/* assume it is a valid TID XXX */
|
||||
if (ItemPointerIsValid(tid) == false)
|
||||
@@ -340,9 +333,9 @@ heapgettup(Relation relation,
|
||||
}
|
||||
else if (dir < 0)
|
||||
{
|
||||
/* ----------------
|
||||
* reverse scan direction
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* reverse scan direction
|
||||
*/
|
||||
if (ItemPointerIsValid(tid) == false)
|
||||
tid = NULL;
|
||||
@@ -383,9 +376,9 @@ heapgettup(Relation relation,
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ----------------
|
||||
* forward scan direction
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* forward scan direction
|
||||
*/
|
||||
if (ItemPointerIsValid(tid) == false)
|
||||
{
|
||||
@@ -420,10 +413,9 @@ heapgettup(Relation relation,
|
||||
|
||||
/* 'dir' is now non-zero */
|
||||
|
||||
/* ----------------
|
||||
* calculate line pointer and number of remaining items
|
||||
* to check on this page.
|
||||
* ----------------
|
||||
/*
|
||||
* calculate line pointer and number of remaining items to check on
|
||||
* this page.
|
||||
*/
|
||||
lpp = PageGetItemId(dp, lineoff);
|
||||
if (dir < 0)
|
||||
@@ -431,10 +423,9 @@ heapgettup(Relation relation,
|
||||
else
|
||||
linesleft = lines - lineoff;
|
||||
|
||||
/* ----------------
|
||||
* advance the scan until we find a qualifying tuple or
|
||||
* run out of stuff to scan
|
||||
* ----------------
|
||||
/*
|
||||
* advance the scan until we find a qualifying tuple or run out of
|
||||
* stuff to scan
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
@@ -446,9 +437,9 @@ heapgettup(Relation relation,
|
||||
tuple->t_data = (HeapTupleHeader) PageGetItem((Page) dp, lpp);
|
||||
tuple->t_len = ItemIdGetLength(lpp);
|
||||
ItemPointerSet(&(tuple->t_self), page, lineoff);
|
||||
/* ----------------
|
||||
* if current tuple qualifies, return it.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* if current tuple qualifies, return it.
|
||||
*/
|
||||
HeapTupleSatisfies(tuple, relation, *buffer, (PageHeader) dp,
|
||||
snapshot, nkeys, key);
|
||||
@@ -459,9 +450,8 @@ heapgettup(Relation relation,
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* otherwise move to the next item on the page
|
||||
* ----------------
|
||||
/*
|
||||
* otherwise move to the next item on the page
|
||||
*/
|
||||
--linesleft;
|
||||
if (dir < 0)
|
||||
@@ -477,17 +467,15 @@ heapgettup(Relation relation,
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* if we get here, it means we've exhausted the items on
|
||||
* this page and it's time to move to the next..
|
||||
* ----------------
|
||||
/*
|
||||
* if we get here, it means we've exhausted the items on this page
|
||||
* and it's time to move to the next..
|
||||
*/
|
||||
LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
|
||||
page = nextpage(page, dir);
|
||||
|
||||
/* ----------------
|
||||
* return NULL if we've exhausted all the pages..
|
||||
* ----------------
|
||||
/*
|
||||
* return NULL if we've exhausted all the pages..
|
||||
*/
|
||||
if (page < 0 || page >= pages)
|
||||
{
|
||||
@@ -588,9 +576,8 @@ heap_open(Oid relationId, LOCKMODE lockmode)
|
||||
|
||||
Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_open);
|
||||
IncrHeapAccessStat(global_open);
|
||||
@@ -626,9 +613,8 @@ heap_openr(const char *relationName, LOCKMODE lockmode)
|
||||
|
||||
Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_openr);
|
||||
IncrHeapAccessStat(global_openr);
|
||||
@@ -663,9 +649,8 @@ heap_open_nofail(Oid relationId)
|
||||
{
|
||||
Relation r;
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_open);
|
||||
IncrHeapAccessStat(global_open);
|
||||
@@ -694,9 +679,8 @@ heap_openr_nofail(const char *relationName)
|
||||
{
|
||||
Relation r;
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_openr);
|
||||
IncrHeapAccessStat(global_openr);
|
||||
@@ -724,9 +708,8 @@ heap_close(Relation relation, LOCKMODE lockmode)
|
||||
{
|
||||
Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_close);
|
||||
IncrHeapAccessStat(global_close);
|
||||
@@ -752,27 +735,24 @@ heap_beginscan(Relation relation,
|
||||
{
|
||||
HeapScanDesc scan;
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_beginscan);
|
||||
IncrHeapAccessStat(global_beginscan);
|
||||
|
||||
/* ----------------
|
||||
* sanity checks
|
||||
* ----------------
|
||||
/*
|
||||
* sanity checks
|
||||
*/
|
||||
if (!RelationIsValid(relation))
|
||||
elog(ERROR, "heap_beginscan: !RelationIsValid(relation)");
|
||||
|
||||
/* ----------------
|
||||
* increment relation ref count while scanning relation
|
||||
/*
|
||||
* increment relation ref count while scanning relation
|
||||
*
|
||||
* This is just to make really sure the relcache entry won't go away
|
||||
* while the scan has a pointer to it. Caller should be holding the
|
||||
* rel open anyway, so this is redundant in all normal scenarios...
|
||||
* ----------------
|
||||
* This is just to make really sure the relcache entry won't go away
|
||||
* while the scan has a pointer to it. Caller should be holding the
|
||||
* rel open anyway, so this is redundant in all normal scenarios...
|
||||
*/
|
||||
RelationIncrementReferenceCount(relation);
|
||||
|
||||
@@ -780,9 +760,8 @@ heap_beginscan(Relation relation,
|
||||
if (relation->rd_rel->relkind == RELKIND_UNCATALOGED)
|
||||
snapshot = SnapshotSelf;
|
||||
|
||||
/* ----------------
|
||||
* allocate and initialize scan descriptor
|
||||
* ----------------
|
||||
/*
|
||||
* allocate and initialize scan descriptor
|
||||
*/
|
||||
scan = (HeapScanDesc) palloc(sizeof(HeapScanDescData));
|
||||
|
||||
@@ -814,22 +793,20 @@ heap_rescan(HeapScanDesc scan,
|
||||
bool scanFromEnd,
|
||||
ScanKey key)
|
||||
{
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_rescan);
|
||||
IncrHeapAccessStat(global_rescan);
|
||||
|
||||
/* ----------------
|
||||
* unpin scan buffers
|
||||
* ----------------
|
||||
/*
|
||||
* unpin scan buffers
|
||||
*/
|
||||
unpinscan(scan);
|
||||
|
||||
/* ----------------
|
||||
* reinitialize scan descriptor
|
||||
* ----------------
|
||||
/*
|
||||
* reinitialize scan descriptor
|
||||
*/
|
||||
scan->rs_atend = scanFromEnd;
|
||||
initscan(scan, scan->rs_rd, scanFromEnd, scan->rs_nkeys, key);
|
||||
@@ -845,24 +822,22 @@ heap_rescan(HeapScanDesc scan,
|
||||
void
|
||||
heap_endscan(HeapScanDesc scan)
|
||||
{
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_endscan);
|
||||
IncrHeapAccessStat(global_endscan);
|
||||
|
||||
/* Note: no locking manipulations needed */
|
||||
|
||||
/* ----------------
|
||||
* unpin scan buffers
|
||||
* ----------------
|
||||
/*
|
||||
* unpin scan buffers
|
||||
*/
|
||||
unpinscan(scan);
|
||||
|
||||
/* ----------------
|
||||
* decrement relation reference count and free scan descriptor storage
|
||||
* ----------------
|
||||
/*
|
||||
* decrement relation reference count and free scan descriptor storage
|
||||
*/
|
||||
RelationDecrementReferenceCount(scan->rs_rd);
|
||||
|
||||
@@ -919,34 +894,31 @@ heap_getnext(HeapScanDesc scandesc, int backw)
|
||||
{
|
||||
HeapScanDesc scan = scandesc;
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_getnext);
|
||||
IncrHeapAccessStat(global_getnext);
|
||||
|
||||
/* Note: no locking manipulations needed */
|
||||
|
||||
/* ----------------
|
||||
* argument checks
|
||||
* ----------------
|
||||
/*
|
||||
* argument checks
|
||||
*/
|
||||
if (scan == NULL)
|
||||
elog(ERROR, "heap_getnext: NULL relscan");
|
||||
|
||||
/* ----------------
|
||||
* initialize return buffer to InvalidBuffer
|
||||
* ----------------
|
||||
/*
|
||||
* initialize return buffer to InvalidBuffer
|
||||
*/
|
||||
|
||||
HEAPDEBUG_1; /* heap_getnext( info ) */
|
||||
|
||||
if (backw)
|
||||
{
|
||||
/* ----------------
|
||||
* handle reverse scan
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* handle reverse scan
|
||||
*/
|
||||
HEAPDEBUG_2; /* heap_getnext called with backw */
|
||||
|
||||
@@ -1020,9 +992,9 @@ heap_getnext(HeapScanDesc scandesc, int backw)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ----------------
|
||||
* handle forward scan
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* handle forward scan
|
||||
*/
|
||||
if (scan->rs_ctup.t_data == scan->rs_ntup.t_data &&
|
||||
BufferIsInvalid(scan->rs_nbuf))
|
||||
@@ -1097,10 +1069,9 @@ heap_getnext(HeapScanDesc scandesc, int backw)
|
||||
scan->rs_nbuf = UnknownBuffer;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* if we get here it means we have a new current scan tuple, so
|
||||
* point to the proper return buffer and return the tuple.
|
||||
* ----------------
|
||||
/*
|
||||
* if we get here it means we have a new current scan tuple, so point
|
||||
* to the proper return buffer and return the tuple.
|
||||
*/
|
||||
|
||||
HEAPDEBUG_7; /* heap_getnext returning tuple */
|
||||
@@ -1133,17 +1104,15 @@ heap_fetch(Relation relation,
|
||||
ItemPointer tid = &(tuple->t_self);
|
||||
OffsetNumber offnum;
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_fetch);
|
||||
IncrHeapAccessStat(global_fetch);
|
||||
|
||||
/* ----------------
|
||||
* get the buffer from the relation descriptor
|
||||
* Note that this does a buffer pin.
|
||||
* ----------------
|
||||
/*
|
||||
* get the buffer from the relation descriptor Note that this does a
|
||||
* buffer pin.
|
||||
*/
|
||||
|
||||
buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid));
|
||||
@@ -1154,17 +1123,15 @@ heap_fetch(Relation relation,
|
||||
|
||||
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
||||
|
||||
/* ----------------
|
||||
* get the item line pointer corresponding to the requested tid
|
||||
* ----------------
|
||||
/*
|
||||
* get the item line pointer corresponding to the requested tid
|
||||
*/
|
||||
dp = (PageHeader) BufferGetPage(buffer);
|
||||
offnum = ItemPointerGetOffsetNumber(tid);
|
||||
lp = PageGetItemId(dp, offnum);
|
||||
|
||||
/* ----------------
|
||||
* more sanity checks
|
||||
* ----------------
|
||||
/*
|
||||
* more sanity checks
|
||||
*/
|
||||
|
||||
if (!ItemIdIsUsed(lp))
|
||||
@@ -1182,9 +1149,8 @@ heap_fetch(Relation relation,
|
||||
tuple->t_len = ItemIdGetLength(lp);
|
||||
tuple->t_tableOid = relation->rd_id;
|
||||
|
||||
/* ----------------
|
||||
* check time qualification of tid
|
||||
* ----------------
|
||||
/*
|
||||
* check time qualification of tid
|
||||
*/
|
||||
|
||||
HeapTupleSatisfies(tuple, relation, buffer, dp,
|
||||
@@ -1229,10 +1195,9 @@ heap_get_latest_tid(Relation relation,
|
||||
bool invalidBlock,
|
||||
linkend;
|
||||
|
||||
/* ----------------
|
||||
* get the buffer from the relation descriptor
|
||||
* Note that this does a buffer pin.
|
||||
* ----------------
|
||||
/*
|
||||
* get the buffer from the relation descriptor Note that this does a
|
||||
* buffer pin.
|
||||
*/
|
||||
|
||||
buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid));
|
||||
@@ -1243,9 +1208,8 @@ heap_get_latest_tid(Relation relation,
|
||||
|
||||
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
||||
|
||||
/* ----------------
|
||||
* get the item line pointer corresponding to the requested tid
|
||||
* ----------------
|
||||
/*
|
||||
* get the item line pointer corresponding to the requested tid
|
||||
*/
|
||||
dp = (PageHeader) BufferGetPage(buffer);
|
||||
offnum = ItemPointerGetOffsetNumber(tid);
|
||||
@@ -1263,9 +1227,8 @@ heap_get_latest_tid(Relation relation,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* more sanity checks
|
||||
* ----------------
|
||||
/*
|
||||
* more sanity checks
|
||||
*/
|
||||
|
||||
tp.t_datamcxt = NULL;
|
||||
@@ -1274,9 +1237,8 @@ heap_get_latest_tid(Relation relation,
|
||||
tp.t_self = *tid;
|
||||
ctid = tp.t_data->t_ctid;
|
||||
|
||||
/* ----------------
|
||||
* check time qualification of tid
|
||||
* ----------------
|
||||
/*
|
||||
* check time qualification of tid
|
||||
*/
|
||||
|
||||
HeapTupleSatisfies(&tp, relation, buffer, dp,
|
||||
@@ -1323,15 +1285,13 @@ heap_insert(Relation relation, HeapTuple tup)
|
||||
IncrHeapAccessStat(local_insert);
|
||||
IncrHeapAccessStat(global_insert);
|
||||
|
||||
/* ----------------
|
||||
* If the object id of this tuple has already been assigned, trust
|
||||
* the caller. There are a couple of ways this can happen. At initial
|
||||
* db creation, the backend program sets oids for tuples. When we
|
||||
* define an index, we set the oid. Finally, in the future, we may
|
||||
* allow users to set their own object ids in order to support a
|
||||
* persistent object store (objects need to contain pointers to one
|
||||
* another).
|
||||
* ----------------
|
||||
/*
|
||||
* If the object id of this tuple has already been assigned, trust the
|
||||
* caller. There are a couple of ways this can happen. At initial db
|
||||
* creation, the backend program sets oids for tuples. When we define
|
||||
* an index, we set the oid. Finally, in the future, we may allow
|
||||
* users to set their own object ids in order to support a persistent
|
||||
* object store (objects need to contain pointers to one another).
|
||||
*/
|
||||
if (!OidIsValid(tup->t_data->t_oid))
|
||||
tup->t_data->t_oid = newoid();
|
||||
@@ -1346,10 +1306,10 @@ heap_insert(Relation relation, HeapTuple tup)
|
||||
tup->t_tableOid = relation->rd_id;
|
||||
|
||||
#ifdef TUPLE_TOASTER_ACTIVE
|
||||
/* ----------
|
||||
* If the new tuple is too big for storage or contains already
|
||||
* toasted attributes from some other relation, invoke the toaster.
|
||||
* ----------
|
||||
|
||||
/*
|
||||
* If the new tuple is too big for storage or contains already toasted
|
||||
* attributes from some other relation, invoke the toaster.
|
||||
*/
|
||||
if (HeapTupleHasExtended(tup) ||
|
||||
(MAXALIGN(tup->t_len) > TOAST_TUPLE_THRESHOLD))
|
||||
@@ -1540,12 +1500,12 @@ l1:
|
||||
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
|
||||
|
||||
#ifdef TUPLE_TOASTER_ACTIVE
|
||||
/* ----------
|
||||
* If the relation has toastable attributes, we need to delete
|
||||
* no longer needed items there too. We have to do this before
|
||||
|
||||
/*
|
||||
* If the relation has toastable attributes, we need to delete no
|
||||
* longer needed items there too. We have to do this before
|
||||
* WriteBuffer because we need to look at the contents of the tuple,
|
||||
* but it's OK to release the context lock on the buffer first.
|
||||
* ----------
|
||||
*/
|
||||
if (HeapTupleHasExtended(&tp))
|
||||
heap_tuple_toast_attrs(relation, NULL, &(tp));
|
||||
@@ -1977,9 +1937,8 @@ void
|
||||
heap_markpos(HeapScanDesc scan)
|
||||
{
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_markpos);
|
||||
IncrHeapAccessStat(global_markpos);
|
||||
@@ -2012,9 +1971,8 @@ heap_markpos(HeapScanDesc scan)
|
||||
scan->rs_key);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
/*
|
||||
* Should not unpin the buffer pages. They may still be in use.
|
||||
* ----------------
|
||||
*/
|
||||
if (scan->rs_ptup.t_data != NULL)
|
||||
scan->rs_mptid = scan->rs_ptup.t_self;
|
||||
@@ -2054,9 +2012,9 @@ heap_markpos(HeapScanDesc scan)
|
||||
void
|
||||
heap_restrpos(HeapScanDesc scan)
|
||||
{
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_restrpos);
|
||||
IncrHeapAccessStat(global_restrpos);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Id: hio.c,v 1.36 2001/03/22 03:59:13 momjian Exp $
|
||||
* $Id: hio.c,v 1.37 2001/03/22 06:16:07 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -37,9 +37,8 @@ RelationPutHeapTuple(Relation relation,
|
||||
ItemId itemId;
|
||||
Item item;
|
||||
|
||||
/* ----------------
|
||||
* increment access statistics
|
||||
* ----------------
|
||||
/*
|
||||
* increment access statistics
|
||||
*/
|
||||
IncrHeapAccessStat(local_RelationPutHeapTuple);
|
||||
IncrHeapAccessStat(global_RelationPutHeapTuple);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/Attic/stats.c,v 1.23 2001/01/24 19:42:48 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/Attic/stats.c,v 1.24 2001/03/22 06:16:07 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* initam should be moved someplace else.
|
||||
@@ -37,25 +37,22 @@ InitHeapAccessStatistics()
|
||||
MemoryContext oldContext;
|
||||
HeapAccessStatistics stats;
|
||||
|
||||
/* ----------------
|
||||
* make sure we don't initialize things twice
|
||||
* ----------------
|
||||
/*
|
||||
* make sure we don't initialize things twice
|
||||
*/
|
||||
if (heap_access_stats != NULL)
|
||||
return;
|
||||
|
||||
/* ----------------
|
||||
* allocate statistics structure from the top memory context
|
||||
* ----------------
|
||||
/*
|
||||
* allocate statistics structure from the top memory context
|
||||
*/
|
||||
oldContext = MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
stats = (HeapAccessStatistics)
|
||||
palloc(sizeof(HeapAccessStatisticsData));
|
||||
|
||||
/* ----------------
|
||||
* initialize fields to default values
|
||||
* ----------------
|
||||
/*
|
||||
* initialize fields to default values
|
||||
*/
|
||||
stats->global_open = 0;
|
||||
stats->global_openr = 0;
|
||||
@@ -103,17 +100,15 @@ InitHeapAccessStatistics()
|
||||
stats->local_RelationNameGetRelation = 0;
|
||||
stats->global_RelationNameGetRelation = 0;
|
||||
|
||||
/* ----------------
|
||||
* record init times
|
||||
* ----------------
|
||||
/*
|
||||
* record init times
|
||||
*/
|
||||
time(&stats->init_global_timestamp);
|
||||
time(&stats->local_reset_timestamp);
|
||||
time(&stats->last_request_timestamp);
|
||||
|
||||
/* ----------------
|
||||
* return to old memory context
|
||||
* ----------------
|
||||
/*
|
||||
* return to old memory context
|
||||
*/
|
||||
MemoryContextSwitchTo(oldContext);
|
||||
|
||||
@@ -130,18 +125,16 @@ ResetHeapAccessStatistics()
|
||||
{
|
||||
HeapAccessStatistics stats;
|
||||
|
||||
/* ----------------
|
||||
* do nothing if stats aren't initialized
|
||||
* ----------------
|
||||
/*
|
||||
* do nothing if stats aren't initialized
|
||||
*/
|
||||
if (heap_access_stats == NULL)
|
||||
return;
|
||||
|
||||
stats = heap_access_stats;
|
||||
|
||||
/* ----------------
|
||||
* reset local counts
|
||||
* ----------------
|
||||
/*
|
||||
* reset local counts
|
||||
*/
|
||||
stats->local_open = 0;
|
||||
stats->local_openr = 0;
|
||||
@@ -165,9 +158,8 @@ ResetHeapAccessStatistics()
|
||||
stats->local_RelationPutHeapTuple = 0;
|
||||
stats->local_RelationPutLongHeapTuple = 0;
|
||||
|
||||
/* ----------------
|
||||
* reset local timestamps
|
||||
* ----------------
|
||||
/*
|
||||
* reset local timestamps
|
||||
*/
|
||||
time(&stats->local_reset_timestamp);
|
||||
time(&stats->last_request_timestamp);
|
||||
@@ -185,22 +177,19 @@ GetHeapAccessStatistics()
|
||||
{
|
||||
HeapAccessStatistics stats;
|
||||
|
||||
/* ----------------
|
||||
* return nothing if stats aren't initialized
|
||||
* ----------------
|
||||
/*
|
||||
* return nothing if stats aren't initialized
|
||||
*/
|
||||
if (heap_access_stats == NULL)
|
||||
return NULL;
|
||||
|
||||
/* ----------------
|
||||
* record the current request time
|
||||
* ----------------
|
||||
/*
|
||||
* record the current request time
|
||||
*/
|
||||
time(&heap_access_stats->last_request_timestamp);
|
||||
|
||||
/* ----------------
|
||||
* allocate a copy of the stats and return it to the caller.
|
||||
* ----------------
|
||||
/*
|
||||
* allocate a copy of the stats and return it to the caller.
|
||||
*/
|
||||
stats = (HeapAccessStatistics)
|
||||
palloc(sizeof(HeapAccessStatisticsData));
|
||||
@@ -222,9 +211,9 @@ GetHeapAccessStatistics()
|
||||
void
|
||||
PrintHeapAccessStatistics(HeapAccessStatistics stats)
|
||||
{
|
||||
/* ----------------
|
||||
* return nothing if stats aren't valid
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* return nothing if stats aren't valid
|
||||
*/
|
||||
if (stats == NULL)
|
||||
return;
|
||||
@@ -342,9 +331,9 @@ PrintAndFreeHeapAccessStatistics(HeapAccessStatistics stats)
|
||||
void
|
||||
initam(void)
|
||||
{
|
||||
/* ----------------
|
||||
* initialize heap statistics.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* initialize heap statistics.
|
||||
*/
|
||||
InitHeapAccessStatistics();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.18 2001/03/22 03:59:13 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.19 2001/03/22 06:16:07 momjian Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -81,17 +81,18 @@ heap_tuple_fetch_attr(varattrib *attr)
|
||||
|
||||
if (VARATT_IS_EXTERNAL(attr))
|
||||
{
|
||||
/* ----------
|
||||
|
||||
/*
|
||||
* This is an external stored plain value
|
||||
* ----------
|
||||
*/
|
||||
result = toast_fetch_datum(attr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ----------
|
||||
* This is a plain value inside of the main tuple - why am I called?
|
||||
* ----------
|
||||
|
||||
/*
|
||||
* This is a plain value inside of the main tuple - why am I
|
||||
* called?
|
||||
*/
|
||||
result = attr;
|
||||
}
|
||||
@@ -134,18 +135,18 @@ heap_tuple_untoast_attr(varattrib *attr)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ----------
|
||||
|
||||
/*
|
||||
* This is an external stored plain value
|
||||
* ----------
|
||||
*/
|
||||
result = toast_fetch_datum(attr);
|
||||
}
|
||||
}
|
||||
else if (VARATT_IS_COMPRESSED(attr))
|
||||
{
|
||||
/* ----------
|
||||
|
||||
/*
|
||||
* This is a compressed value inside of the main tuple
|
||||
* ----------
|
||||
*/
|
||||
result = (varattrib *) palloc(attr->va_content.va_compressed.va_rawsize
|
||||
+ VARHDRSZ);
|
||||
@@ -154,9 +155,10 @@ heap_tuple_untoast_attr(varattrib *attr)
|
||||
pglz_decompress((PGLZ_Header *) attr, VARATT_DATA(result));
|
||||
}
|
||||
else
|
||||
/* ----------
|
||||
* This is a plain value inside of the main tuple - why am I called?
|
||||
* ----------
|
||||
|
||||
/*
|
||||
* This is a plain value inside of the main tuple - why am I
|
||||
* called?
|
||||
*/
|
||||
return attr;
|
||||
|
||||
@@ -180,19 +182,16 @@ toast_delete(Relation rel, HeapTuple oldtup)
|
||||
Datum value;
|
||||
bool isnull;
|
||||
|
||||
/* ----------
|
||||
* Get the tuple descriptor, the number of and attribute
|
||||
* descriptors.
|
||||
* ----------
|
||||
/*
|
||||
* Get the tuple descriptor, the number of and attribute descriptors.
|
||||
*/
|
||||
tupleDesc = rel->rd_att;
|
||||
numAttrs = tupleDesc->natts;
|
||||
att = tupleDesc->attrs;
|
||||
|
||||
/* ----------
|
||||
* Check for external stored attributes and delete them
|
||||
* from the secondary relation.
|
||||
* ----------
|
||||
/*
|
||||
* Check for external stored attributes and delete them from the
|
||||
* secondary relation.
|
||||
*/
|
||||
for (i = 0; i < numAttrs; i++)
|
||||
{
|
||||
@@ -237,10 +236,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
bool toast_free[MaxHeapAttributeNumber];
|
||||
bool toast_delold[MaxHeapAttributeNumber];
|
||||
|
||||
/* ----------
|
||||
* Get the tuple descriptor, the number of and attribute
|
||||
* descriptors and the location of the tuple values.
|
||||
* ----------
|
||||
/*
|
||||
* Get the tuple descriptor, the number of and attribute descriptors
|
||||
* and the location of the tuple values.
|
||||
*/
|
||||
tupleDesc = rel->rd_att;
|
||||
numAttrs = tupleDesc->natts;
|
||||
@@ -266,9 +264,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
|
||||
if (oldtup != NULL)
|
||||
{
|
||||
/* ----------
|
||||
|
||||
/*
|
||||
* For UPDATE get the old and new values of this attribute
|
||||
* ----------
|
||||
*/
|
||||
old_value = (varattrib *) DatumGetPointer(
|
||||
heap_getattr(oldtup, i + 1, tupleDesc, &old_isnull));
|
||||
@@ -276,10 +274,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
heap_getattr(newtup, i + 1, tupleDesc, &new_isnull);
|
||||
new_value = (varattrib *) DatumGetPointer(toast_values[i]);
|
||||
|
||||
/* ----------
|
||||
* If the old value is an external stored one, check if it
|
||||
* has changed so we have to delete it later.
|
||||
* ----------
|
||||
/*
|
||||
* If the old value is an external stored one, check if it has
|
||||
* changed so we have to delete it later.
|
||||
*/
|
||||
if (!old_isnull && att[i]->attlen == -1 &&
|
||||
VARATT_IS_EXTERNAL(old_value))
|
||||
@@ -290,21 +287,21 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
old_value->va_content.va_external.va_attno !=
|
||||
new_value->va_content.va_external.va_attno)
|
||||
{
|
||||
/* ----------
|
||||
* The old external store value isn't needed any
|
||||
* more after the update
|
||||
* ----------
|
||||
|
||||
/*
|
||||
* The old external store value isn't needed any more
|
||||
* after the update
|
||||
*/
|
||||
toast_delold[i] = true;
|
||||
need_delold = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ----------
|
||||
* This attribute isn't changed by this update
|
||||
* so we reuse the original reference to the old
|
||||
* value in the new tuple.
|
||||
* ----------
|
||||
|
||||
/*
|
||||
* This attribute isn't changed by this update so we
|
||||
* reuse the original reference to the old value in
|
||||
* the new tuple.
|
||||
*/
|
||||
toast_action[i] = 'p';
|
||||
toast_sizes[i] = VARATT_SIZE(toast_values[i]);
|
||||
@@ -314,17 +311,16 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ----------
|
||||
|
||||
/*
|
||||
* For INSERT simply get the new value
|
||||
* ----------
|
||||
*/
|
||||
toast_values[i] =
|
||||
heap_getattr(newtup, i + 1, tupleDesc, &new_isnull);
|
||||
}
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Handle NULL attributes
|
||||
* ----------
|
||||
*/
|
||||
if (new_isnull)
|
||||
{
|
||||
@@ -334,24 +330,22 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Now look at varsize attributes
|
||||
* ----------
|
||||
*/
|
||||
if (att[i]->attlen == -1)
|
||||
{
|
||||
/* ----------
|
||||
|
||||
/*
|
||||
* If the table's attribute says PLAIN always, force it so.
|
||||
* ----------
|
||||
*/
|
||||
if (att[i]->attstorage == 'p')
|
||||
toast_action[i] = 'p';
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* We took care of UPDATE above, so any external value we find
|
||||
* still in the tuple must be someone else's we cannot reuse.
|
||||
* Expand it to plain (and, probably, toast it again below).
|
||||
* ----------
|
||||
*/
|
||||
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
|
||||
{
|
||||
@@ -362,17 +356,16 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
need_free = true;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Remember the size of this attribute
|
||||
* ----------
|
||||
*/
|
||||
toast_sizes[i] = VARATT_SIZE(DatumGetPointer(toast_values[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ----------
|
||||
|
||||
/*
|
||||
* Not a variable size attribute, plain storage always
|
||||
* ----------
|
||||
*/
|
||||
toast_action[i] = 'p';
|
||||
toast_sizes[i] = att[i]->attlen;
|
||||
@@ -393,9 +386,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
maxDataLen += BITMAPLEN(numAttrs);
|
||||
maxDataLen = TOAST_TUPLE_TARGET - MAXALIGN(maxDataLen);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Look for attributes with attstorage 'x' to compress
|
||||
* ----------
|
||||
*/
|
||||
while (MAXALIGN(ComputeDataSize(tupleDesc, toast_values, toast_nulls)) >
|
||||
maxDataLen)
|
||||
@@ -405,9 +397,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
Datum old_value;
|
||||
Datum new_value;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Search for the biggest yet uncompressed internal attribute
|
||||
* ----------
|
||||
*/
|
||||
for (i = 0; i < numAttrs; i++)
|
||||
{
|
||||
@@ -427,9 +418,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
if (biggest_attno < 0)
|
||||
break;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Attempt to compress it inline
|
||||
* ----------
|
||||
*/
|
||||
i = biggest_attno;
|
||||
old_value = toast_values[i];
|
||||
@@ -457,10 +447,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* Second we look for attributes of attstorage 'x' or 'e' that
|
||||
* are still inline.
|
||||
* ----------
|
||||
/*
|
||||
* Second we look for attributes of attstorage 'x' or 'e' that are
|
||||
* still inline.
|
||||
*/
|
||||
while (MAXALIGN(ComputeDataSize(tupleDesc, toast_values, toast_nulls)) >
|
||||
maxDataLen && rel->rd_rel->reltoastrelid != InvalidOid)
|
||||
@@ -469,10 +458,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
int32 biggest_size = MAXALIGN(sizeof(varattrib));
|
||||
Datum old_value;
|
||||
|
||||
/* ----------
|
||||
* Search for the biggest yet inlined attribute with
|
||||
* attstorage = 'x' or 'e'
|
||||
* ----------
|
||||
/*
|
||||
* Search for the biggest yet inlined attribute with attstorage =
|
||||
* 'x' or 'e'
|
||||
*/
|
||||
for (i = 0; i < numAttrs; i++)
|
||||
{
|
||||
@@ -492,9 +480,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
if (biggest_attno < 0)
|
||||
break;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Store this external
|
||||
* ----------
|
||||
*/
|
||||
i = biggest_attno;
|
||||
old_value = toast_values[i];
|
||||
@@ -513,10 +500,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
need_free = true;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* Round 3 - this time we take attributes with storage
|
||||
* 'm' into compression
|
||||
* ----------
|
||||
/*
|
||||
* Round 3 - this time we take attributes with storage 'm' into
|
||||
* compression
|
||||
*/
|
||||
while (MAXALIGN(ComputeDataSize(tupleDesc, toast_values, toast_nulls)) >
|
||||
maxDataLen)
|
||||
@@ -526,9 +512,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
Datum old_value;
|
||||
Datum new_value;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Search for the biggest yet uncompressed internal attribute
|
||||
* ----------
|
||||
*/
|
||||
for (i = 0; i < numAttrs; i++)
|
||||
{
|
||||
@@ -548,9 +533,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
if (biggest_attno < 0)
|
||||
break;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Attempt to compress it inline
|
||||
* ----------
|
||||
*/
|
||||
i = biggest_attno;
|
||||
old_value = toast_values[i];
|
||||
@@ -578,9 +562,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Finally we store attributes of type 'm' external
|
||||
* ----------
|
||||
*/
|
||||
while (MAXALIGN(ComputeDataSize(tupleDesc, toast_values, toast_nulls)) >
|
||||
maxDataLen && rel->rd_rel->reltoastrelid != InvalidOid)
|
||||
@@ -589,10 +572,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
int32 biggest_size = MAXALIGN(sizeof(varattrib));
|
||||
Datum old_value;
|
||||
|
||||
/* ----------
|
||||
* Search for the biggest yet inlined attribute with
|
||||
* attstorage = 'm'
|
||||
* ----------
|
||||
/*
|
||||
* Search for the biggest yet inlined attribute with attstorage =
|
||||
* 'm'
|
||||
*/
|
||||
for (i = 0; i < numAttrs; i++)
|
||||
{
|
||||
@@ -612,9 +594,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
if (biggest_attno < 0)
|
||||
break;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Store this external
|
||||
* ----------
|
||||
*/
|
||||
i = biggest_attno;
|
||||
old_value = toast_values[i];
|
||||
@@ -633,10 +614,9 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
need_free = true;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* In the case we toasted any values, we need to build
|
||||
* a new heap tuple with the changed values.
|
||||
* ----------
|
||||
/*
|
||||
* In the case we toasted any values, we need to build a new heap
|
||||
* tuple with the changed values.
|
||||
*/
|
||||
if (need_change)
|
||||
{
|
||||
@@ -645,9 +625,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
MemoryContext oldcxt;
|
||||
HeapTupleHeader olddata;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Calculate the new size of the tuple
|
||||
* ----------
|
||||
*/
|
||||
new_len = offsetof(HeapTupleHeaderData, t_bits);
|
||||
if (has_nulls)
|
||||
@@ -655,19 +634,17 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
new_len = MAXALIGN(new_len);
|
||||
new_len += ComputeDataSize(tupleDesc, toast_values, toast_nulls);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Remember the old memory location of the tuple (for below),
|
||||
* switch to the memory context of the HeapTuple structure
|
||||
* and allocate the new tuple.
|
||||
* ----------
|
||||
* switch to the memory context of the HeapTuple structure and
|
||||
* allocate the new tuple.
|
||||
*/
|
||||
olddata = newtup->t_data;
|
||||
oldcxt = MemoryContextSwitchTo(newtup->t_datamcxt);
|
||||
new_data = palloc(new_len);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Put the tuple header and the changed values into place
|
||||
* ----------
|
||||
*/
|
||||
memcpy(new_data, newtup->t_data, newtup->t_data->t_hoff);
|
||||
newtup->t_data = (HeapTupleHeader) new_data;
|
||||
@@ -682,33 +659,29 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
|
||||
&(newtup->t_data->t_infomask),
|
||||
has_nulls ? newtup->t_data->t_bits : NULL);
|
||||
|
||||
/* ----------
|
||||
* In the case we modified a previously modified tuple again,
|
||||
* free the memory from the previous run
|
||||
* ----------
|
||||
/*
|
||||
* In the case we modified a previously modified tuple again, free
|
||||
* the memory from the previous run
|
||||
*/
|
||||
if ((char *) olddata != ((char *) newtup + HEAPTUPLESIZE))
|
||||
pfree(olddata);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Switch back to the old memory context
|
||||
* ----------
|
||||
*/
|
||||
MemoryContextSwitchTo(oldcxt);
|
||||
}
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Free allocated temp values
|
||||
* ----------
|
||||
*/
|
||||
if (need_free)
|
||||
for (i = 0; i < numAttrs; i++)
|
||||
if (toast_free[i])
|
||||
pfree(DatumGetPointer(toast_values[i]));
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Delete external values from the old tuple
|
||||
* ----------
|
||||
*/
|
||||
if (need_delold)
|
||||
for (i = 0; i < numAttrs; i++)
|
||||
@@ -776,9 +749,8 @@ toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
|
||||
char *data_p;
|
||||
int32 data_todo;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Create the varattrib reference
|
||||
* ----------
|
||||
*/
|
||||
result = (varattrib *) palloc(sizeof(varattrib));
|
||||
|
||||
@@ -802,9 +774,8 @@ toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
|
||||
result->va_content.va_external.va_rowid = mainoid;
|
||||
result->va_content.va_external.va_attno = attno;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Initialize constant parts of the tuple data
|
||||
* ----------
|
||||
*/
|
||||
t_values[0] = ObjectIdGetDatum(result->va_content.va_external.va_valueid);
|
||||
t_values[2] = PointerGetDatum(chunk_data);
|
||||
@@ -812,36 +783,32 @@ toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
|
||||
t_nulls[1] = ' ';
|
||||
t_nulls[2] = ' ';
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Get the data to process
|
||||
* ----------
|
||||
*/
|
||||
data_p = VARATT_DATA(value);
|
||||
data_todo = VARATT_SIZE(value) - VARHDRSZ;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Open the toast relation
|
||||
* ----------
|
||||
*/
|
||||
toastrel = heap_open(rel->rd_rel->reltoastrelid, RowExclusiveLock);
|
||||
toasttupDesc = toastrel->rd_att;
|
||||
toastidx = index_open(rel->rd_rel->reltoastidxid);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Split up the item into chunks
|
||||
* ----------
|
||||
*/
|
||||
while (data_todo > 0)
|
||||
{
|
||||
/* ----------
|
||||
|
||||
/*
|
||||
* Calculate the size of this chunk
|
||||
* ----------
|
||||
*/
|
||||
chunk_size = Min(TOAST_MAX_CHUNK_SIZE, data_todo);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Build a tuple
|
||||
* ----------
|
||||
*/
|
||||
t_values[1] = Int32GetDatum(chunk_seq++);
|
||||
VARATT_SIZEP(chunk_data) = chunk_size + VARHDRSZ;
|
||||
@@ -850,9 +817,8 @@ toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
|
||||
if (!HeapTupleIsValid(toasttup))
|
||||
elog(ERROR, "Failed to build TOAST tuple");
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Store it and create the index entry
|
||||
* ----------
|
||||
*/
|
||||
heap_insert(toastrel, toasttup);
|
||||
idxres = index_insert(toastidx, t_values, t_nulls,
|
||||
@@ -861,24 +827,21 @@ toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
|
||||
if (idxres == NULL)
|
||||
elog(ERROR, "Failed to insert index entry for TOAST tuple");
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Free memory
|
||||
* ----------
|
||||
*/
|
||||
heap_freetuple(toasttup);
|
||||
pfree(idxres);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Move on to next chunk
|
||||
* ----------
|
||||
*/
|
||||
data_todo -= chunk_size;
|
||||
data_p += chunk_size;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Done - close toast relation and return the reference
|
||||
* ----------
|
||||
*/
|
||||
index_close(toastidx);
|
||||
heap_close(toastrel, RowExclusiveLock);
|
||||
@@ -908,17 +871,15 @@ toast_delete_datum(Relation rel, Datum value)
|
||||
if (!VARATT_IS_EXTERNAL(attr))
|
||||
return;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Open the toast relation and it's index
|
||||
* ----------
|
||||
*/
|
||||
toastrel = heap_open(attr->va_content.va_external.va_toastrelid,
|
||||
RowExclusiveLock);
|
||||
toastidx = index_open(attr->va_content.va_external.va_toastidxid);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Setup a scan key to fetch from the index by va_valueid
|
||||
* ----------
|
||||
*/
|
||||
ScanKeyEntryInitialize(&toastkey,
|
||||
(bits16) 0,
|
||||
@@ -926,9 +887,8 @@ toast_delete_datum(Relation rel, Datum value)
|
||||
(RegProcedure) F_OIDEQ,
|
||||
ObjectIdGetDatum(attr->va_content.va_external.va_valueid));
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Read the chunks by index
|
||||
* ----------
|
||||
*/
|
||||
toastscan = index_beginscan(toastidx, false, 1, &toastkey);
|
||||
while ((indexRes = index_getnext(toastscan, ForwardScanDirection)) != NULL)
|
||||
@@ -940,18 +900,16 @@ toast_delete_datum(Relation rel, Datum value)
|
||||
if (!toasttup.t_data)
|
||||
continue;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Have a chunk, delete it
|
||||
* ----------
|
||||
*/
|
||||
simple_heap_delete(toastrel, &toasttup.t_self);
|
||||
|
||||
ReleaseBuffer(buffer);
|
||||
}
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* End scan and close relations
|
||||
* ----------
|
||||
*/
|
||||
index_endscan(toastscan);
|
||||
index_close(toastidx);
|
||||
@@ -1003,18 +961,16 @@ toast_fetch_datum(varattrib *attr)
|
||||
if (VARATT_IS_COMPRESSED(attr))
|
||||
VARATT_SIZEP(result) |= VARATT_FLAG_COMPRESSED;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Open the toast relation and it's index
|
||||
* ----------
|
||||
*/
|
||||
toastrel = heap_open(attr->va_content.va_external.va_toastrelid,
|
||||
AccessShareLock);
|
||||
toasttupDesc = toastrel->rd_att;
|
||||
toastidx = index_open(attr->va_content.va_external.va_toastidxid);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Setup a scan key to fetch from the index by va_valueid
|
||||
* ----------
|
||||
*/
|
||||
ScanKeyEntryInitialize(&toastkey,
|
||||
(bits16) 0,
|
||||
@@ -1022,11 +978,10 @@ toast_fetch_datum(varattrib *attr)
|
||||
(RegProcedure) F_OIDEQ,
|
||||
ObjectIdGetDatum(attr->va_content.va_external.va_valueid));
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Read the chunks by index
|
||||
*
|
||||
* Note we will not necessarily see the chunks in sequence-number order.
|
||||
* ----------
|
||||
*/
|
||||
toastscan = index_beginscan(toastidx, false, 1, &toastkey);
|
||||
while ((indexRes = index_getnext(toastscan, ForwardScanDirection)) != NULL)
|
||||
@@ -1039,9 +994,8 @@ toast_fetch_datum(varattrib *attr)
|
||||
continue;
|
||||
ttup = &toasttup;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Have a chunk, extract the sequence number and the data
|
||||
* ----------
|
||||
*/
|
||||
residx = DatumGetInt32(heap_getattr(ttup, 2, toasttupDesc, &isnull));
|
||||
Assert(!isnull);
|
||||
@@ -1049,9 +1003,8 @@ toast_fetch_datum(varattrib *attr)
|
||||
Assert(!isnull);
|
||||
chunksize = VARATT_SIZE(chunk) - VARHDRSZ;
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Some checks on the data we've found
|
||||
* ----------
|
||||
*/
|
||||
if (residx < 0 || residx >= numchunks)
|
||||
elog(ERROR, "unexpected chunk number %d for toast value %d",
|
||||
@@ -1076,9 +1029,8 @@ toast_fetch_datum(varattrib *attr)
|
||||
residx,
|
||||
attr->va_content.va_external.va_valueid);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Copy the data into proper place in our result
|
||||
* ----------
|
||||
*/
|
||||
memcpy(((char *) VARATT_DATA(result)) + residx * TOAST_MAX_CHUNK_SIZE,
|
||||
VARATT_DATA(chunk),
|
||||
@@ -1087,9 +1039,8 @@ toast_fetch_datum(varattrib *attr)
|
||||
ReleaseBuffer(buffer);
|
||||
}
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* Final checks that we successfully fetched the datum
|
||||
* ----------
|
||||
*/
|
||||
if (memcmp(chunks_found, chunks_expected, numchunks) != 0)
|
||||
elog(ERROR, "not all toast chunks found for value %d",
|
||||
@@ -1097,9 +1048,8 @@ toast_fetch_datum(varattrib *attr)
|
||||
pfree(chunks_expected);
|
||||
pfree(chunks_found);
|
||||
|
||||
/* ----------
|
||||
/*
|
||||
* End scan and close relations
|
||||
* ----------
|
||||
*/
|
||||
index_endscan(toastscan);
|
||||
index_close(toastidx);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.47 2001/01/24 19:42:48 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.48 2001/03/22 06:16:07 momjian Exp $
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
* index_open - open an index relation by relationId
|
||||
@@ -190,9 +190,8 @@ index_insert(Relation relation,
|
||||
RELATION_CHECKS;
|
||||
GET_REL_PROCEDURE(insert, aminsert);
|
||||
|
||||
/* ----------------
|
||||
* have the am's insert proc do all the work.
|
||||
* ----------------
|
||||
/*
|
||||
* have the am's insert proc do all the work.
|
||||
*/
|
||||
specificResult = (InsertIndexResult)
|
||||
DatumGetPointer(OidFunctionCall5(procedure,
|
||||
@@ -241,13 +240,12 @@ index_beginscan(Relation relation,
|
||||
|
||||
RelationIncrementReferenceCount(relation);
|
||||
|
||||
/* ----------------
|
||||
* Acquire AccessShareLock for the duration of the scan
|
||||
/*
|
||||
* Acquire AccessShareLock for the duration of the scan
|
||||
*
|
||||
* Note: we could get an SI inval message here and consequently have
|
||||
* to rebuild the relcache entry. The refcount increment above
|
||||
* ensures that we will rebuild it and not just flush it...
|
||||
* ----------------
|
||||
* Note: we could get an SI inval message here and consequently have to
|
||||
* rebuild the relcache entry. The refcount increment above ensures
|
||||
* that we will rebuild it and not just flush it...
|
||||
*/
|
||||
LockRelation(relation, AccessShareLock);
|
||||
|
||||
@@ -347,9 +345,8 @@ index_getnext(IndexScanDesc scan,
|
||||
|
||||
SCAN_CHECKS;
|
||||
|
||||
/* ----------------
|
||||
* Look up the access procedure only once per scan.
|
||||
* ----------------
|
||||
/*
|
||||
* Look up the access procedure only once per scan.
|
||||
*/
|
||||
if (scan->fn_getnext.fn_oid == InvalidOid)
|
||||
{
|
||||
@@ -359,9 +356,8 @@ index_getnext(IndexScanDesc scan,
|
||||
fmgr_info(procedure, &scan->fn_getnext);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* have the am's gettuple proc do all the work.
|
||||
* ----------------
|
||||
/*
|
||||
* have the am's gettuple proc do all the work.
|
||||
*/
|
||||
result = (RetrieveIndexResult)
|
||||
DatumGetPointer(FunctionCall2(&scan->fn_getnext,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.64 2001/03/22 03:59:15 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.65 2001/03/22 06:16:07 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -238,21 +238,19 @@ _bt_binsrch(Relation rel,
|
||||
high = mid;
|
||||
}
|
||||
|
||||
/*--------------------
|
||||
/*
|
||||
* At this point we have high == low, but be careful: they could point
|
||||
* past the last slot on the page.
|
||||
*
|
||||
* On a leaf page, we always return the first key >= scan key
|
||||
* (which could be the last slot + 1).
|
||||
*--------------------
|
||||
* On a leaf page, we always return the first key >= scan key (which
|
||||
* could be the last slot + 1).
|
||||
*/
|
||||
if (P_ISLEAF(opaque))
|
||||
return low;
|
||||
|
||||
/*--------------------
|
||||
* On a non-leaf page, return the last key < scan key.
|
||||
* There must be one if _bt_compare() is playing by the rules.
|
||||
*--------------------
|
||||
/*
|
||||
* On a non-leaf page, return the last key < scan key. There must be
|
||||
* one if _bt_compare() is playing by the rules.
|
||||
*/
|
||||
Assert(low > P_FIRSTDATAKEY(opaque));
|
||||
|
||||
@@ -584,21 +582,20 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
|
||||
|
||||
ItemPointerSet(current, blkno, offnum);
|
||||
|
||||
/*----------
|
||||
* At this point we are positioned at the first item >= scan key,
|
||||
* or possibly at the end of a page on which all the existing items
|
||||
* are < scan key and we know that everything on later pages is
|
||||
* >= scan key. We could step forward in the latter case, but that'd
|
||||
* be a waste of time if we want to scan backwards. So, it's now time to
|
||||
* examine the scan strategy to find the exact place to start the scan.
|
||||
/*
|
||||
* At this point we are positioned at the first item >= scan key, or
|
||||
* possibly at the end of a page on which all the existing items are <
|
||||
* scan key and we know that everything on later pages is >= scan key.
|
||||
* We could step forward in the latter case, but that'd be a waste of
|
||||
* time if we want to scan backwards. So, it's now time to examine
|
||||
* the scan strategy to find the exact place to start the scan.
|
||||
*
|
||||
* Note: if _bt_step fails (meaning we fell off the end of the index
|
||||
* in one direction or the other), we either return NULL (no matches) or
|
||||
* call _bt_endpoint() to set up a scan starting at that index endpoint,
|
||||
* as appropriate for the desired scan type.
|
||||
* Note: if _bt_step fails (meaning we fell off the end of the index in
|
||||
* one direction or the other), we either return NULL (no matches) or
|
||||
* call _bt_endpoint() to set up a scan starting at that index
|
||||
* endpoint, as appropriate for the desired scan type.
|
||||
*
|
||||
* it's yet other place to add some code later for is(not)null ...
|
||||
*----------
|
||||
*/
|
||||
|
||||
switch (strat_total)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.42 2001/03/22 03:59:17 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.43 2001/03/22 06:16:10 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This file contains the high level access-method interface to the
|
||||
@@ -124,30 +124,25 @@ TransactionLogTest(TransactionId transactionId, /* transaction id to test */
|
||||
XidStatus xidstatus; /* recorded status of xid */
|
||||
bool fail = false; /* success/failure */
|
||||
|
||||
/* ----------------
|
||||
* during initialization consider all transactions
|
||||
* as having been committed
|
||||
* ----------------
|
||||
/*
|
||||
* during initialization consider all transactions as having been
|
||||
* committed
|
||||
*/
|
||||
if (!RelationIsValid(LogRelation))
|
||||
return (bool) (status == XID_COMMIT);
|
||||
|
||||
/* ----------------
|
||||
* before going to the buffer manager, check our single
|
||||
* item cache to see if we didn't just check the transaction
|
||||
* status a moment ago.
|
||||
* ----------------
|
||||
/*
|
||||
* before going to the buffer manager, check our single item cache to
|
||||
* see if we didn't just check the transaction status a moment ago.
|
||||
*/
|
||||
if (TransactionIdEquals(transactionId, cachedTestXid))
|
||||
return (bool)
|
||||
(status == cachedTestXidStatus);
|
||||
|
||||
/* ----------------
|
||||
* compute the item pointer corresponding to the
|
||||
* page containing our transaction id. We save the item in
|
||||
* our cache to speed up things if we happen to ask for the
|
||||
* same xid's status more than once.
|
||||
* ----------------
|
||||
/*
|
||||
* compute the item pointer corresponding to the page containing our
|
||||
* transaction id. We save the item in our cache to speed up things
|
||||
* if we happen to ask for the same xid's status more than once.
|
||||
*/
|
||||
TransComputeBlockNumber(LogRelation, transactionId, &blockNumber);
|
||||
xidstatus = TransBlockNumberGetXidStatus(LogRelation,
|
||||
@@ -169,9 +164,8 @@ TransactionLogTest(TransactionId transactionId, /* transaction id to test */
|
||||
return (bool) (status == xidstatus);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* here the block didn't contain the information we wanted
|
||||
* ----------------
|
||||
/*
|
||||
* here the block didn't contain the information we wanted
|
||||
*/
|
||||
elog(ERROR, "TransactionLogTest: failed to get xidstatus");
|
||||
|
||||
@@ -192,16 +186,14 @@ TransactionLogUpdate(TransactionId transactionId, /* trans id to update */
|
||||
BlockNumber blockNumber;
|
||||
bool fail = false; /* success/failure */
|
||||
|
||||
/* ----------------
|
||||
* during initialization we don't record any updates.
|
||||
* ----------------
|
||||
/*
|
||||
* during initialization we don't record any updates.
|
||||
*/
|
||||
if (!RelationIsValid(LogRelation))
|
||||
return;
|
||||
|
||||
/* ----------------
|
||||
* update the log relation
|
||||
* ----------------
|
||||
/*
|
||||
* update the log relation
|
||||
*/
|
||||
TransComputeBlockNumber(LogRelation, transactionId, &blockNumber);
|
||||
TransBlockNumberSetXidStatus(LogRelation,
|
||||
@@ -292,43 +284,38 @@ static void
|
||||
TransRecover(Relation logRelation)
|
||||
{
|
||||
#ifdef NOT_USED
|
||||
/* ----------------
|
||||
* first get the last recorded transaction in the log.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* first get the last recorded transaction in the log.
|
||||
*/
|
||||
TransGetLastRecordedTransaction(logRelation, logLastXid, &fail);
|
||||
if (fail == true)
|
||||
elog(ERROR, "TransRecover: failed TransGetLastRecordedTransaction");
|
||||
|
||||
/* ----------------
|
||||
* next get the "last" and "next" variables
|
||||
* ----------------
|
||||
/*
|
||||
* next get the "last" and "next" variables
|
||||
*/
|
||||
VariableRelationGetLastXid(&varLastXid);
|
||||
VariableRelationGetNextXid(&varNextXid);
|
||||
|
||||
/* ----------------
|
||||
* intregity test (1)
|
||||
* ----------------
|
||||
/*
|
||||
* intregity test (1)
|
||||
*/
|
||||
if (TransactionIdIsLessThan(varNextXid, logLastXid))
|
||||
elog(ERROR, "TransRecover: varNextXid < logLastXid");
|
||||
|
||||
/* ----------------
|
||||
* intregity test (2)
|
||||
* ----------------
|
||||
/*
|
||||
* intregity test (2)
|
||||
*/
|
||||
|
||||
/* ----------------
|
||||
* intregity test (3)
|
||||
* ----------------
|
||||
/*
|
||||
* intregity test (3)
|
||||
*/
|
||||
|
||||
/* ----------------
|
||||
* here we have a valid "
|
||||
/*
|
||||
* here we have a valid "
|
||||
*
|
||||
* **** RESUME HERE ****
|
||||
* ----------------
|
||||
**** RESUME HERE ****
|
||||
*/
|
||||
varNextXid = TransactionIdDup(varLastXid);
|
||||
TransactionIdIncrement(&varNextXid);
|
||||
@@ -375,51 +362,45 @@ InitializeTransactionLog(void)
|
||||
Relation logRelation;
|
||||
MemoryContext oldContext;
|
||||
|
||||
/* ----------------
|
||||
* don't do anything during bootstrapping
|
||||
* ----------------
|
||||
/*
|
||||
* don't do anything during bootstrapping
|
||||
*/
|
||||
if (AMI_OVERRIDE)
|
||||
return;
|
||||
|
||||
/* ----------------
|
||||
* disable the transaction system so the access methods
|
||||
* don't interfere during initialization.
|
||||
* ----------------
|
||||
/*
|
||||
* disable the transaction system so the access methods don't
|
||||
* interfere during initialization.
|
||||
*/
|
||||
OverrideTransactionSystem(true);
|
||||
|
||||
/* ----------------
|
||||
* make sure allocations occur within the top memory context
|
||||
* so that our log management structures are protected from
|
||||
* garbage collection at the end of every transaction.
|
||||
* ----------------
|
||||
/*
|
||||
* make sure allocations occur within the top memory context so that
|
||||
* our log management structures are protected from garbage collection
|
||||
* at the end of every transaction.
|
||||
*/
|
||||
oldContext = MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
/* ----------------
|
||||
* first open the log and time relations
|
||||
* (these are created by amiint so they are guaranteed to exist)
|
||||
* ----------------
|
||||
/*
|
||||
* first open the log and time relations (these are created by amiint
|
||||
* so they are guaranteed to exist)
|
||||
*/
|
||||
logRelation = heap_openr(LogRelationName, NoLock);
|
||||
VariableRelation = heap_openr(VariableRelationName, NoLock);
|
||||
|
||||
/* ----------------
|
||||
* XXX TransactionLogUpdate requires that LogRelation
|
||||
* is valid so we temporarily set it so we can initialize
|
||||
* things properly. This could be done cleaner.
|
||||
* ----------------
|
||||
/*
|
||||
* XXX TransactionLogUpdate requires that LogRelation is valid so we
|
||||
* temporarily set it so we can initialize things properly. This could
|
||||
* be done cleaner.
|
||||
*/
|
||||
LogRelation = logRelation;
|
||||
|
||||
/* ----------------
|
||||
* if we have a virgin database, we initialize the log
|
||||
* relation by committing the AmiTransactionId (id 512) and we
|
||||
* initialize the variable relation by setting the next available
|
||||
* transaction id to FirstTransactionId (id 514). OID initialization
|
||||
* happens as a side effect of bootstrapping in varsup.c.
|
||||
* ----------------
|
||||
/*
|
||||
* if we have a virgin database, we initialize the log relation by
|
||||
* committing the AmiTransactionId (id 512) and we initialize the
|
||||
* variable relation by setting the next available transaction id to
|
||||
* FirstTransactionId (id 514). OID initialization happens as a side
|
||||
* effect of bootstrapping in varsup.c.
|
||||
*/
|
||||
SpinAcquire(OidGenLockId);
|
||||
if (!TransactionIdDidCommit(AmiTransactionId))
|
||||
@@ -433,33 +414,30 @@ InitializeTransactionLog(void)
|
||||
}
|
||||
else if (RecoveryCheckingEnabled())
|
||||
{
|
||||
/* ----------------
|
||||
* if we have a pre-initialized database and if the
|
||||
* perform recovery checking flag was passed then we
|
||||
* do our database integrity checking.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* if we have a pre-initialized database and if the perform
|
||||
* recovery checking flag was passed then we do our database
|
||||
* integrity checking.
|
||||
*/
|
||||
TransRecover(logRelation);
|
||||
}
|
||||
LogRelation = (Relation) NULL;
|
||||
SpinRelease(OidGenLockId);
|
||||
|
||||
/* ----------------
|
||||
* now re-enable the transaction system
|
||||
* ----------------
|
||||
/*
|
||||
* now re-enable the transaction system
|
||||
*/
|
||||
OverrideTransactionSystem(false);
|
||||
|
||||
/* ----------------
|
||||
* instantiate the global variables
|
||||
* ----------------
|
||||
/*
|
||||
* instantiate the global variables
|
||||
*/
|
||||
LogRelation = logRelation;
|
||||
|
||||
/* ----------------
|
||||
* restore the memory context to the previous context
|
||||
* before we return from initialization.
|
||||
* ----------------
|
||||
/*
|
||||
* restore the memory context to the previous context before we return
|
||||
* from initialization.
|
||||
*/
|
||||
MemoryContextSwitchTo(oldContext);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.29 2001/03/22 03:59:17 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.30 2001/03/22 06:16:10 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This file contains support functions for the high
|
||||
@@ -56,11 +56,9 @@ TransComputeBlockNumber(Relation relation, /* relation to test */
|
||||
{
|
||||
long itemsPerBlock = 0;
|
||||
|
||||
/* ----------------
|
||||
* we calculate the block number of our transaction
|
||||
* by dividing the transaction id by the number of
|
||||
* transaction things per block.
|
||||
* ----------------
|
||||
/*
|
||||
* we calculate the block number of our transaction by dividing the
|
||||
* transaction id by the number of transaction things per block.
|
||||
*/
|
||||
if (relation == LogRelation)
|
||||
itemsPerBlock = TP_NumXidStatusPerBlock;
|
||||
@@ -109,18 +107,16 @@ TransBlockGetLastTransactionIdStatus(Block tblock,
|
||||
BitIndex offset;
|
||||
XidStatus xstatus;
|
||||
|
||||
/* ----------------
|
||||
* sanity check
|
||||
* ----------------
|
||||
/*
|
||||
* sanity check
|
||||
*/
|
||||
Assert((tblock != NULL));
|
||||
|
||||
/* ----------------
|
||||
* search downward from the top of the block data, looking
|
||||
* for the first Non-in progress transaction status. Since we
|
||||
* are scanning backward, this will be last recorded transaction
|
||||
* status on the block.
|
||||
* ----------------
|
||||
/*
|
||||
* search downward from the top of the block data, looking for the
|
||||
* first Non-in progress transaction status. Since we are scanning
|
||||
* backward, this will be last recorded transaction status on the
|
||||
* block.
|
||||
*/
|
||||
maxIndex = TP_NumXidStatusPerBlock;
|
||||
for (index = maxIndex; index > 0; index--)
|
||||
@@ -131,11 +127,10 @@ TransBlockGetLastTransactionIdStatus(Block tblock,
|
||||
|
||||
xstatus = (bit1 | bit2);
|
||||
|
||||
/* ----------------
|
||||
* here we have the status of some transaction, so test
|
||||
* if the status is recorded as "in progress". If so, then
|
||||
* we save the transaction id in the place specified by the caller.
|
||||
* ----------------
|
||||
/*
|
||||
* here we have the status of some transaction, so test if the
|
||||
* status is recorded as "in progress". If so, then we save the
|
||||
* transaction id in the place specified by the caller.
|
||||
*/
|
||||
if (xstatus != XID_INPROGRESS)
|
||||
{
|
||||
@@ -148,12 +143,11 @@ TransBlockGetLastTransactionIdStatus(Block tblock,
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* if we get here and index is 0 it means we couldn't find
|
||||
* a non-inprogress transaction on the block. For now we just
|
||||
* return this info to the user. They can check if the return
|
||||
* status is "in progress" to know this condition has arisen.
|
||||
* ----------------
|
||||
/*
|
||||
* if we get here and index is 0 it means we couldn't find a
|
||||
* non-inprogress transaction on the block. For now we just return
|
||||
* this info to the user. They can check if the return status is "in
|
||||
* progress" to know this condition has arisen.
|
||||
*/
|
||||
if (index == 0)
|
||||
{
|
||||
@@ -161,9 +155,8 @@ TransBlockGetLastTransactionIdStatus(Block tblock,
|
||||
TransactionIdStore(baseXid, returnXidP);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* return the status to the user
|
||||
* ----------------
|
||||
/*
|
||||
* return the status to the user
|
||||
*/
|
||||
return xstatus;
|
||||
}
|
||||
@@ -200,17 +193,15 @@ TransBlockGetXidStatus(Block tblock,
|
||||
*/
|
||||
index = transactionId % TP_NumXidStatusPerBlock;
|
||||
|
||||
/* ----------------
|
||||
* get the data at the specified index
|
||||
* ----------------
|
||||
/*
|
||||
* get the data at the specified index
|
||||
*/
|
||||
offset = BitIndexOf(index);
|
||||
bit1 = ((bits8) BitArrayBitIsSet((BitArray) tblock, offset++)) << 1;
|
||||
bit2 = (bits8) BitArrayBitIsSet((BitArray) tblock, offset);
|
||||
|
||||
/* ----------------
|
||||
* return the transaction status to the caller
|
||||
* ----------------
|
||||
/*
|
||||
* return the transaction status to the caller
|
||||
*/
|
||||
return (XidStatus) (bit1 | bit2);
|
||||
}
|
||||
@@ -245,9 +236,8 @@ TransBlockSetXidStatus(Block tblock,
|
||||
|
||||
offset = BitIndexOf(index);
|
||||
|
||||
/* ----------------
|
||||
* store the transaction value at the specified offset
|
||||
* ----------------
|
||||
/*
|
||||
* store the transaction value at the specified offset
|
||||
*/
|
||||
switch (xstatus)
|
||||
{
|
||||
@@ -291,18 +281,16 @@ TransBlockNumberGetXidStatus(Relation relation,
|
||||
XidStatus xstatus; /* recorded status of xid */
|
||||
bool localfail; /* bool used if failP = NULL */
|
||||
|
||||
/* ----------------
|
||||
* get the page containing the transaction information
|
||||
* ----------------
|
||||
/*
|
||||
* get the page containing the transaction information
|
||||
*/
|
||||
buffer = ReadBuffer(relation, blockNumber);
|
||||
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
||||
block = BufferGetBlock(buffer);
|
||||
|
||||
/* ----------------
|
||||
* get the status from the block. note, for now we always
|
||||
* return false in failP.
|
||||
* ----------------
|
||||
/*
|
||||
* get the status from the block. note, for now we always return
|
||||
* false in failP.
|
||||
*/
|
||||
if (failP == NULL)
|
||||
failP = &localfail;
|
||||
@@ -310,9 +298,8 @@ TransBlockNumberGetXidStatus(Relation relation,
|
||||
|
||||
xstatus = TransBlockGetXidStatus(block, xid);
|
||||
|
||||
/* ----------------
|
||||
* release the buffer and return the status
|
||||
* ----------------
|
||||
/*
|
||||
* release the buffer and return the status
|
||||
*/
|
||||
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
|
||||
ReleaseBuffer(buffer);
|
||||
@@ -335,19 +322,17 @@ TransBlockNumberSetXidStatus(Relation relation,
|
||||
Block block; /* block containing xstatus */
|
||||
bool localfail; /* bool used if failP = NULL */
|
||||
|
||||
/* ----------------
|
||||
* get the block containing the transaction status
|
||||
* ----------------
|
||||
/*
|
||||
* get the block containing the transaction status
|
||||
*/
|
||||
buffer = ReadBuffer(relation, blockNumber);
|
||||
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
|
||||
block = BufferGetBlock(buffer);
|
||||
|
||||
/* ----------------
|
||||
* attempt to update the status of the transaction on the block.
|
||||
* if we are successful, write the block. otherwise release the buffer.
|
||||
* note, for now we always return false in failP.
|
||||
* ----------------
|
||||
/*
|
||||
* attempt to update the status of the transaction on the block. if we
|
||||
* are successful, write the block. otherwise release the buffer.
|
||||
* note, for now we always return false in failP.
|
||||
*/
|
||||
if (failP == NULL)
|
||||
failP = &localfail;
|
||||
@@ -381,22 +366,20 @@ TransGetLastRecordedTransaction(Relation relation,
|
||||
|
||||
(*failP) = false;
|
||||
|
||||
/* ----------------
|
||||
* SOMEDAY gain exclusive access to the log relation
|
||||
/*
|
||||
* SOMEDAY gain exclusive access to the log relation
|
||||
*
|
||||
* That someday is today 5 Aug. 1991 -mer
|
||||
* It looks to me like we only need to set a read lock here, despite
|
||||
* the above comment about exclusive access. The block is never
|
||||
* actually written into, we only check status bits.
|
||||
* ----------------
|
||||
* That someday is today 5 Aug. 1991 -mer It looks to me like we only
|
||||
* need to set a read lock here, despite the above comment about
|
||||
* exclusive access. The block is never actually written into, we
|
||||
* only check status bits.
|
||||
*/
|
||||
RelationSetLockForRead(relation);
|
||||
|
||||
/* ----------------
|
||||
* we assume the last block of the log contains the last
|
||||
* recorded transaction. If the relation is empty we return
|
||||
* failure to the user.
|
||||
* ----------------
|
||||
/*
|
||||
* we assume the last block of the log contains the last recorded
|
||||
* transaction. If the relation is empty we return failure to the
|
||||
* user.
|
||||
*/
|
||||
n = RelationGetNumberOfBlocks(relation);
|
||||
if (n == 0)
|
||||
@@ -405,17 +388,15 @@ TransGetLastRecordedTransaction(Relation relation,
|
||||
return;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* get the block containing the transaction information
|
||||
* ----------------
|
||||
/*
|
||||
* get the block containing the transaction information
|
||||
*/
|
||||
blockNumber = n - 1;
|
||||
buffer = ReadBuffer(relation, blockNumber);
|
||||
block = BufferGetBlock(buffer);
|
||||
|
||||
/* ----------------
|
||||
* get the last xid on the block
|
||||
* ----------------
|
||||
/*
|
||||
* get the last xid on the block
|
||||
*/
|
||||
baseXid = blockNumber * TP_NumXidStatusPerBlock;
|
||||
|
||||
@@ -424,9 +405,8 @@ TransGetLastRecordedTransaction(Relation relation,
|
||||
|
||||
ReleaseBuffer(buffer);
|
||||
|
||||
/* ----------------
|
||||
* SOMEDAY release our lock on the log relation
|
||||
* ----------------
|
||||
/*
|
||||
* SOMEDAY release our lock on the log relation
|
||||
*/
|
||||
RelationUnsetLockForRead(relation);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.100 2001/03/22 03:59:18 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.101 2001/03/22 06:16:10 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
@@ -396,17 +396,15 @@ GetCurrentTransactionId(void)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
|
||||
/* ----------------
|
||||
* if the transaction system is disabled, we return
|
||||
* the special "disabled" transaction id.
|
||||
* ----------------
|
||||
/*
|
||||
* if the transaction system is disabled, we return the special
|
||||
* "disabled" transaction id.
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return (TransactionId) DisabledTransactionId;
|
||||
|
||||
/* ----------------
|
||||
* otherwise return the current transaction id.
|
||||
* ----------------
|
||||
/*
|
||||
* otherwise return the current transaction id.
|
||||
*/
|
||||
return (TransactionId) s->transactionIdData;
|
||||
}
|
||||
@@ -421,10 +419,9 @@ GetCurrentCommandId(void)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
|
||||
/* ----------------
|
||||
* if the transaction system is disabled, we return
|
||||
* the special "disabled" command id.
|
||||
* ----------------
|
||||
/*
|
||||
* if the transaction system is disabled, we return the special
|
||||
* "disabled" command id.
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return (CommandId) DisabledCommandId;
|
||||
@@ -437,10 +434,9 @@ GetScanCommandId(void)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
|
||||
/* ----------------
|
||||
* if the transaction system is disabled, we return
|
||||
* the special "disabled" command id.
|
||||
* ----------------
|
||||
/*
|
||||
* if the transaction system is disabled, we return the special
|
||||
* "disabled" command id.
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return (CommandId) DisabledCommandId;
|
||||
@@ -458,10 +454,9 @@ GetCurrentTransactionStartTime(void)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
|
||||
/* ----------------
|
||||
* if the transaction system is disabled, we return
|
||||
* the special "disabled" starting time.
|
||||
* ----------------
|
||||
/*
|
||||
* if the transaction system is disabled, we return the special
|
||||
* "disabled" starting time.
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return (AbsoluteTime) DisabledStartTime;
|
||||
@@ -608,16 +603,15 @@ AtStart_Locks(void)
|
||||
static void
|
||||
AtStart_Memory(void)
|
||||
{
|
||||
/* ----------------
|
||||
* We shouldn't have any transaction contexts already.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* We shouldn't have any transaction contexts already.
|
||||
*/
|
||||
Assert(TopTransactionContext == NULL);
|
||||
Assert(TransactionCommandContext == NULL);
|
||||
|
||||
/* ----------------
|
||||
* Create a toplevel context for the transaction.
|
||||
* ----------------
|
||||
/*
|
||||
* Create a toplevel context for the transaction.
|
||||
*/
|
||||
TopTransactionContext =
|
||||
AllocSetContextCreate(TopMemoryContext,
|
||||
@@ -626,9 +620,8 @@ AtStart_Memory(void)
|
||||
ALLOCSET_DEFAULT_INITSIZE,
|
||||
ALLOCSET_DEFAULT_MAXSIZE);
|
||||
|
||||
/* ----------------
|
||||
* Create a statement-level context and make it active.
|
||||
* ----------------
|
||||
/*
|
||||
* Create a statement-level context and make it active.
|
||||
*/
|
||||
TransactionCommandContext =
|
||||
AllocSetContextCreate(TopTransactionContext,
|
||||
@@ -732,9 +725,9 @@ RecordTransactionCommit()
|
||||
static void
|
||||
AtCommit_Cache(void)
|
||||
{
|
||||
/* ----------------
|
||||
|
||||
/*
|
||||
* Make catalog changes visible to all backend.
|
||||
* ----------------
|
||||
*/
|
||||
RegisterInvalid(true);
|
||||
}
|
||||
@@ -746,9 +739,9 @@ AtCommit_Cache(void)
|
||||
static void
|
||||
AtCommit_LocalCache(void)
|
||||
{
|
||||
/* ----------------
|
||||
|
||||
/*
|
||||
* Make catalog changes visible to me for the next command.
|
||||
* ----------------
|
||||
*/
|
||||
ImmediateLocalInvalidation(true);
|
||||
}
|
||||
@@ -760,11 +753,11 @@ AtCommit_LocalCache(void)
|
||||
static void
|
||||
AtCommit_Locks(void)
|
||||
{
|
||||
/* ----------------
|
||||
* XXX What if ProcReleaseLocks fails? (race condition?)
|
||||
|
||||
/*
|
||||
* XXX What if ProcReleaseLocks fails? (race condition?)
|
||||
*
|
||||
* Then you're up a creek! -mer 5/24/92
|
||||
* ----------------
|
||||
* Then you're up a creek! -mer 5/24/92
|
||||
*/
|
||||
ProcReleaseLocks(true);
|
||||
}
|
||||
@@ -776,17 +769,16 @@ AtCommit_Locks(void)
|
||||
static void
|
||||
AtCommit_Memory(void)
|
||||
{
|
||||
/* ----------------
|
||||
* Now that we're "out" of a transaction, have the
|
||||
* system allocate things in the top memory context instead
|
||||
* of per-transaction contexts.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* Now that we're "out" of a transaction, have the system allocate
|
||||
* things in the top memory context instead of per-transaction
|
||||
* contexts.
|
||||
*/
|
||||
MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
/* ----------------
|
||||
* Release all transaction-local memory.
|
||||
* ----------------
|
||||
/*
|
||||
* Release all transaction-local memory.
|
||||
*/
|
||||
Assert(TopTransactionContext != NULL);
|
||||
MemoryContextDelete(TopTransactionContext);
|
||||
@@ -862,11 +854,11 @@ AtAbort_Cache(void)
|
||||
static void
|
||||
AtAbort_Locks(void)
|
||||
{
|
||||
/* ----------------
|
||||
* XXX What if ProcReleaseLocks() fails? (race condition?)
|
||||
|
||||
/*
|
||||
* XXX What if ProcReleaseLocks() fails? (race condition?)
|
||||
*
|
||||
* Then you're up a creek without a paddle! -mer
|
||||
* ----------------
|
||||
* Then you're up a creek without a paddle! -mer
|
||||
*/
|
||||
ProcReleaseLocks(false);
|
||||
}
|
||||
@@ -879,21 +871,20 @@ AtAbort_Locks(void)
|
||||
static void
|
||||
AtAbort_Memory(void)
|
||||
{
|
||||
/* ----------------
|
||||
* Make sure we are in a valid context (not a child of
|
||||
* TransactionCommandContext...). Note that it is possible
|
||||
* for this code to be called when we aren't in a transaction
|
||||
* at all; go directly to TopMemoryContext in that case.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* Make sure we are in a valid context (not a child of
|
||||
* TransactionCommandContext...). Note that it is possible for this
|
||||
* code to be called when we aren't in a transaction at all; go
|
||||
* directly to TopMemoryContext in that case.
|
||||
*/
|
||||
if (TransactionCommandContext != NULL)
|
||||
{
|
||||
MemoryContextSwitchTo(TransactionCommandContext);
|
||||
|
||||
/* ----------------
|
||||
* We do not want to destroy transaction contexts yet,
|
||||
* but it should be OK to delete any command-local memory.
|
||||
* ----------------
|
||||
/*
|
||||
* We do not want to destroy transaction contexts yet, but it
|
||||
* should be OK to delete any command-local memory.
|
||||
*/
|
||||
MemoryContextResetAndDeleteChildren(TransactionCommandContext);
|
||||
}
|
||||
@@ -914,17 +905,16 @@ AtAbort_Memory(void)
|
||||
static void
|
||||
AtCleanup_Memory(void)
|
||||
{
|
||||
/* ----------------
|
||||
* Now that we're "out" of a transaction, have the
|
||||
* system allocate things in the top memory context instead
|
||||
* of per-transaction contexts.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* Now that we're "out" of a transaction, have the system allocate
|
||||
* things in the top memory context instead of per-transaction
|
||||
* contexts.
|
||||
*/
|
||||
MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
/* ----------------
|
||||
* Release all transaction-local memory.
|
||||
* ----------------
|
||||
/*
|
||||
* Release all transaction-local memory.
|
||||
*/
|
||||
if (TopTransactionContext != NULL)
|
||||
MemoryContextDelete(TopTransactionContext);
|
||||
@@ -951,61 +941,54 @@ StartTransaction(void)
|
||||
FreeXactSnapshot();
|
||||
XactIsoLevel = DefaultXactIsoLevel;
|
||||
|
||||
/* ----------------
|
||||
* Check the current transaction state. If the transaction system
|
||||
* is switched off, or if we're already in a transaction, do nothing.
|
||||
* We're already in a transaction when the monitor sends a null
|
||||
* command to the backend to flush the comm channel. This is a
|
||||
* hacky fix to a communications problem, and we keep having to
|
||||
* deal with it here. We should fix the comm channel code. mao 080891
|
||||
* ----------------
|
||||
/*
|
||||
* Check the current transaction state. If the transaction system is
|
||||
* switched off, or if we're already in a transaction, do nothing.
|
||||
* We're already in a transaction when the monitor sends a null
|
||||
* command to the backend to flush the comm channel. This is a hacky
|
||||
* fix to a communications problem, and we keep having to deal with it
|
||||
* here. We should fix the comm channel code. mao 080891
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED || s->state == TRANS_INPROGRESS)
|
||||
return;
|
||||
|
||||
/* ----------------
|
||||
* set the current transaction state information
|
||||
* appropriately during start processing
|
||||
* ----------------
|
||||
/*
|
||||
* set the current transaction state information appropriately during
|
||||
* start processing
|
||||
*/
|
||||
s->state = TRANS_START;
|
||||
|
||||
SetReindexProcessing(false);
|
||||
|
||||
/* ----------------
|
||||
* generate a new transaction id
|
||||
* ----------------
|
||||
/*
|
||||
* generate a new transaction id
|
||||
*/
|
||||
GetNewTransactionId(&(s->transactionIdData));
|
||||
|
||||
XactLockTableInsert(s->transactionIdData);
|
||||
|
||||
/* ----------------
|
||||
* initialize current transaction state fields
|
||||
* ----------------
|
||||
/*
|
||||
* initialize current transaction state fields
|
||||
*/
|
||||
s->commandId = FirstCommandId;
|
||||
s->scanCommandId = FirstCommandId;
|
||||
s->startTime = GetCurrentAbsoluteTime();
|
||||
|
||||
/* ----------------
|
||||
* initialize the various transaction subsystems
|
||||
* ----------------
|
||||
/*
|
||||
* initialize the various transaction subsystems
|
||||
*/
|
||||
AtStart_Memory();
|
||||
AtStart_Cache();
|
||||
AtStart_Locks();
|
||||
|
||||
/* ----------------
|
||||
* Tell the trigger manager to we're starting a transaction
|
||||
* ----------------
|
||||
/*
|
||||
* Tell the trigger manager to we're starting a transaction
|
||||
*/
|
||||
DeferredTriggerBeginXact();
|
||||
|
||||
/* ----------------
|
||||
* done with start processing, set current transaction
|
||||
* state to "in progress"
|
||||
* ----------------
|
||||
/*
|
||||
* done with start processing, set current transaction state to "in
|
||||
* progress"
|
||||
*/
|
||||
s->state = TRANS_INPROGRESS;
|
||||
|
||||
@@ -1034,9 +1017,8 @@ CommitTransaction(void)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
|
||||
/* ----------------
|
||||
* check the current transaction state
|
||||
* ----------------
|
||||
/*
|
||||
* check the current transaction state
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return;
|
||||
@@ -1047,24 +1029,21 @@ CommitTransaction(void)
|
||||
/* Prevent cancel/die interrupt while cleaning up */
|
||||
HOLD_INTERRUPTS();
|
||||
|
||||
/* ----------------
|
||||
* Tell the trigger manager that this transaction is about to be
|
||||
* committed. He'll invoke all trigger deferred until XACT before
|
||||
* we really start on committing the transaction.
|
||||
* ----------------
|
||||
/*
|
||||
* Tell the trigger manager that this transaction is about to be
|
||||
* committed. He'll invoke all trigger deferred until XACT before we
|
||||
* really start on committing the transaction.
|
||||
*/
|
||||
DeferredTriggerEndXact();
|
||||
|
||||
/* ----------------
|
||||
* set the current transaction state information
|
||||
* appropriately during the abort processing
|
||||
* ----------------
|
||||
/*
|
||||
* set the current transaction state information appropriately during
|
||||
* the abort processing
|
||||
*/
|
||||
s->state = TRANS_COMMIT;
|
||||
|
||||
/* ----------------
|
||||
* do commit processing
|
||||
* ----------------
|
||||
/*
|
||||
* do commit processing
|
||||
*/
|
||||
|
||||
/* handle commit for large objects [ PA, 7/17/98 ] */
|
||||
@@ -1109,10 +1088,9 @@ CommitTransaction(void)
|
||||
|
||||
SharedBufferChanged = false;/* safest place to do it */
|
||||
|
||||
/* ----------------
|
||||
* done with commit processing, set current transaction
|
||||
* state back to default
|
||||
* ----------------
|
||||
/*
|
||||
* done with commit processing, set current transaction state back to
|
||||
* default
|
||||
*/
|
||||
s->state = TRANS_DEFAULT;
|
||||
|
||||
@@ -1157,9 +1135,8 @@ AbortTransaction(void)
|
||||
*/
|
||||
LockWaitCancel();
|
||||
|
||||
/* ----------------
|
||||
* check the current transaction state
|
||||
* ----------------
|
||||
/*
|
||||
* check the current transaction state
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
{
|
||||
@@ -1170,10 +1147,9 @@ AbortTransaction(void)
|
||||
if (s->state != TRANS_INPROGRESS)
|
||||
elog(NOTICE, "AbortTransaction and not in in-progress state");
|
||||
|
||||
/* ----------------
|
||||
* set the current transaction state information
|
||||
* appropriately during the abort processing
|
||||
* ----------------
|
||||
/*
|
||||
* set the current transaction state information appropriately during
|
||||
* the abort processing
|
||||
*/
|
||||
s->state = TRANS_ABORT;
|
||||
|
||||
@@ -1182,9 +1158,8 @@ AbortTransaction(void)
|
||||
*/
|
||||
SetUserId(GetSessionUserId());
|
||||
|
||||
/* ----------------
|
||||
* do abort processing
|
||||
* ----------------
|
||||
/*
|
||||
* do abort processing
|
||||
*/
|
||||
DeferredTriggerAbortXact();
|
||||
lo_commit(false); /* 'false' means it's abort */
|
||||
@@ -1207,9 +1182,8 @@ AbortTransaction(void)
|
||||
|
||||
SharedBufferChanged = false;/* safest place to do it */
|
||||
|
||||
/* ----------------
|
||||
* State remains TRANS_ABORT until CleanupTransaction().
|
||||
* ----------------
|
||||
/*
|
||||
* State remains TRANS_ABORT until CleanupTransaction().
|
||||
*/
|
||||
RESUME_INTERRUPTS();
|
||||
}
|
||||
@@ -1227,23 +1201,20 @@ CleanupTransaction(void)
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return;
|
||||
|
||||
/* ----------------
|
||||
* State should still be TRANS_ABORT from AbortTransaction().
|
||||
* ----------------
|
||||
/*
|
||||
* State should still be TRANS_ABORT from AbortTransaction().
|
||||
*/
|
||||
if (s->state != TRANS_ABORT)
|
||||
elog(FATAL, "CleanupTransaction and not in abort state");
|
||||
|
||||
/* ----------------
|
||||
* do abort cleanup processing
|
||||
* ----------------
|
||||
/*
|
||||
* do abort cleanup processing
|
||||
*/
|
||||
AtCleanup_Memory();
|
||||
|
||||
/* ----------------
|
||||
* done with abort processing, set current transaction
|
||||
* state back to default
|
||||
* ----------------
|
||||
/*
|
||||
* done with abort processing, set current transaction state back to
|
||||
* default
|
||||
*/
|
||||
s->state = TRANS_DEFAULT;
|
||||
}
|
||||
@@ -1259,44 +1230,41 @@ StartTransactionCommand(void)
|
||||
|
||||
switch (s->blockState)
|
||||
{
|
||||
/* ----------------
|
||||
* if we aren't in a transaction block, we
|
||||
* just do our usual start transaction.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* if we aren't in a transaction block, we just do our usual
|
||||
* start transaction.
|
||||
*/
|
||||
case TBLOCK_DEFAULT:
|
||||
StartTransaction();
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* We should never experience this -- if we do it
|
||||
* means the BEGIN state was not changed in the previous
|
||||
* CommitTransactionCommand(). If we get it, we print
|
||||
* a warning and change to the in-progress state.
|
||||
* ----------------
|
||||
/*
|
||||
* We should never experience this -- if we do it means the
|
||||
* BEGIN state was not changed in the previous
|
||||
* CommitTransactionCommand(). If we get it, we print a
|
||||
* warning and change to the in-progress state.
|
||||
*/
|
||||
case TBLOCK_BEGIN:
|
||||
elog(NOTICE, "StartTransactionCommand: unexpected TBLOCK_BEGIN");
|
||||
s->blockState = TBLOCK_INPROGRESS;
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* This is the case when are somewhere in a transaction
|
||||
* block and about to start a new command. For now we
|
||||
* do nothing but someday we may do command-local resource
|
||||
* initialization.
|
||||
* ----------------
|
||||
/*
|
||||
* This is the case when are somewhere in a transaction block
|
||||
* and about to start a new command. For now we do nothing
|
||||
* but someday we may do command-local resource
|
||||
* initialization.
|
||||
*/
|
||||
case TBLOCK_INPROGRESS:
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* As with BEGIN, we should never experience this
|
||||
* if we do it means the END state was not changed in the
|
||||
* previous CommitTransactionCommand(). If we get it, we
|
||||
* print a warning, commit the transaction, start a new
|
||||
* transaction and change to the default state.
|
||||
* ----------------
|
||||
/*
|
||||
* As with BEGIN, we should never experience this if we do it
|
||||
* means the END state was not changed in the previous
|
||||
* CommitTransactionCommand(). If we get it, we print a
|
||||
* warning, commit the transaction, start a new transaction
|
||||
* and change to the default state.
|
||||
*/
|
||||
case TBLOCK_END:
|
||||
elog(NOTICE, "StartTransactionCommand: unexpected TBLOCK_END");
|
||||
@@ -1305,23 +1273,21 @@ StartTransactionCommand(void)
|
||||
StartTransaction();
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* Here we are in the middle of a transaction block but
|
||||
* one of the commands caused an abort so we do nothing
|
||||
* but remain in the abort state. Eventually we will get
|
||||
* to the "END TRANSACTION" which will set things straight.
|
||||
* ----------------
|
||||
/*
|
||||
* Here we are in the middle of a transaction block but one of
|
||||
* the commands caused an abort so we do nothing but remain in
|
||||
* the abort state. Eventually we will get to the "END
|
||||
* TRANSACTION" which will set things straight.
|
||||
*/
|
||||
case TBLOCK_ABORT:
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* This means we somehow aborted and the last call to
|
||||
* CommitTransactionCommand() didn't clear the state so
|
||||
* we remain in the ENDABORT state and maybe next time
|
||||
* we get to CommitTransactionCommand() the state will
|
||||
* get reset to default.
|
||||
* ----------------
|
||||
/*
|
||||
* This means we somehow aborted and the last call to
|
||||
* CommitTransactionCommand() didn't clear the state so we
|
||||
* remain in the ENDABORT state and maybe next time we get to
|
||||
* CommitTransactionCommand() the state will get reset to
|
||||
* default.
|
||||
*/
|
||||
case TBLOCK_ENDABORT:
|
||||
elog(NOTICE, "StartTransactionCommand: unexpected TBLOCK_ENDABORT");
|
||||
@@ -1347,68 +1313,62 @@ CommitTransactionCommand(void)
|
||||
|
||||
switch (s->blockState)
|
||||
{
|
||||
/* ----------------
|
||||
* if we aren't in a transaction block, we
|
||||
* just do our usual transaction commit
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* if we aren't in a transaction block, we just do our usual
|
||||
* transaction commit
|
||||
*/
|
||||
case TBLOCK_DEFAULT:
|
||||
CommitTransaction();
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* This is the case right after we get a "BEGIN TRANSACTION"
|
||||
* command, but the user hasn't done anything else yet, so
|
||||
* we change to the "transaction block in progress" state
|
||||
* and return.
|
||||
* ----------------
|
||||
/*
|
||||
* This is the case right after we get a "BEGIN TRANSACTION"
|
||||
* command, but the user hasn't done anything else yet, so we
|
||||
* change to the "transaction block in progress" state and
|
||||
* return.
|
||||
*/
|
||||
case TBLOCK_BEGIN:
|
||||
s->blockState = TBLOCK_INPROGRESS;
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* This is the case when we have finished executing a command
|
||||
* someplace within a transaction block. We increment the
|
||||
* command counter and return. Someday we may free resources
|
||||
* local to the command.
|
||||
/*
|
||||
* This is the case when we have finished executing a command
|
||||
* someplace within a transaction block. We increment the
|
||||
* command counter and return. Someday we may free resources
|
||||
* local to the command.
|
||||
*
|
||||
* That someday is today, at least for memory allocated in
|
||||
* TransactionCommandContext.
|
||||
* - vadim 03/25/97
|
||||
* ----------------
|
||||
* That someday is today, at least for memory allocated in
|
||||
* TransactionCommandContext. - vadim 03/25/97
|
||||
*/
|
||||
case TBLOCK_INPROGRESS:
|
||||
CommandCounterIncrement();
|
||||
MemoryContextResetAndDeleteChildren(TransactionCommandContext);
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* This is the case when we just got the "END TRANSACTION"
|
||||
* statement, so we commit the transaction and go back to
|
||||
* the default state.
|
||||
* ----------------
|
||||
/*
|
||||
* This is the case when we just got the "END TRANSACTION"
|
||||
* statement, so we commit the transaction and go back to the
|
||||
* default state.
|
||||
*/
|
||||
case TBLOCK_END:
|
||||
CommitTransaction();
|
||||
s->blockState = TBLOCK_DEFAULT;
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* Here we are in the middle of a transaction block but
|
||||
* one of the commands caused an abort so we do nothing
|
||||
* but remain in the abort state. Eventually we will get
|
||||
* to the "END TRANSACTION" which will set things straight.
|
||||
* ----------------
|
||||
/*
|
||||
* Here we are in the middle of a transaction block but one of
|
||||
* the commands caused an abort so we do nothing but remain in
|
||||
* the abort state. Eventually we will get to the "END
|
||||
* TRANSACTION" which will set things straight.
|
||||
*/
|
||||
case TBLOCK_ABORT:
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* Here we were in an aborted transaction block which
|
||||
* just processed the "END TRANSACTION" command from the
|
||||
* user, so clean up and return to the default state.
|
||||
* ----------------
|
||||
/*
|
||||
* Here we were in an aborted transaction block which just
|
||||
* processed the "END TRANSACTION" command from the user, so
|
||||
* clean up and return to the default state.
|
||||
*/
|
||||
case TBLOCK_ENDABORT:
|
||||
CleanupTransaction();
|
||||
@@ -1428,22 +1388,21 @@ AbortCurrentTransaction(void)
|
||||
|
||||
switch (s->blockState)
|
||||
{
|
||||
/* ----------------
|
||||
* if we aren't in a transaction block, we
|
||||
* just do the basic abort & cleanup transaction.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* if we aren't in a transaction block, we just do the basic
|
||||
* abort & cleanup transaction.
|
||||
*/
|
||||
case TBLOCK_DEFAULT:
|
||||
AbortTransaction();
|
||||
CleanupTransaction();
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* If we are in the TBLOCK_BEGIN it means something
|
||||
* screwed up right after reading "BEGIN TRANSACTION"
|
||||
* so we enter the abort state. Eventually an "END
|
||||
* TRANSACTION" will fix things.
|
||||
* ----------------
|
||||
/*
|
||||
* If we are in the TBLOCK_BEGIN it means something screwed up
|
||||
* right after reading "BEGIN TRANSACTION" so we enter the
|
||||
* abort state. Eventually an "END TRANSACTION" will fix
|
||||
* things.
|
||||
*/
|
||||
case TBLOCK_BEGIN:
|
||||
s->blockState = TBLOCK_ABORT;
|
||||
@@ -1451,12 +1410,11 @@ AbortCurrentTransaction(void)
|
||||
/* CleanupTransaction happens when we exit TBLOCK_ABORT */
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* This is the case when are somewhere in a transaction
|
||||
* block which aborted so we abort the transaction and
|
||||
* set the ABORT state. Eventually an "END TRANSACTION"
|
||||
* will fix things and restore us to a normal state.
|
||||
* ----------------
|
||||
/*
|
||||
* This is the case when are somewhere in a transaction block
|
||||
* which aborted so we abort the transaction and set the ABORT
|
||||
* state. Eventually an "END TRANSACTION" will fix things and
|
||||
* restore us to a normal state.
|
||||
*/
|
||||
case TBLOCK_INPROGRESS:
|
||||
s->blockState = TBLOCK_ABORT;
|
||||
@@ -1464,12 +1422,10 @@ AbortCurrentTransaction(void)
|
||||
/* CleanupTransaction happens when we exit TBLOCK_ABORT */
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* Here, the system was fouled up just after the
|
||||
* user wanted to end the transaction block so we
|
||||
* abort the transaction and put us back into the
|
||||
* default state.
|
||||
* ----------------
|
||||
/*
|
||||
* Here, the system was fouled up just after the user wanted
|
||||
* to end the transaction block so we abort the transaction
|
||||
* and put us back into the default state.
|
||||
*/
|
||||
case TBLOCK_END:
|
||||
s->blockState = TBLOCK_DEFAULT;
|
||||
@@ -1477,22 +1433,20 @@ AbortCurrentTransaction(void)
|
||||
CleanupTransaction();
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* Here, we are already in an aborted transaction
|
||||
* state and are waiting for an "END TRANSACTION" to
|
||||
* come along and lo and behold, we abort again!
|
||||
* So we just remain in the abort state.
|
||||
* ----------------
|
||||
/*
|
||||
* Here, we are already in an aborted transaction state and
|
||||
* are waiting for an "END TRANSACTION" to come along and lo
|
||||
* and behold, we abort again! So we just remain in the abort
|
||||
* state.
|
||||
*/
|
||||
case TBLOCK_ABORT:
|
||||
break;
|
||||
|
||||
/* ----------------
|
||||
* Here we were in an aborted transaction block which
|
||||
* just processed the "END TRANSACTION" command but somehow
|
||||
* aborted again.. since we must have done the abort
|
||||
* processing, we clean up and return to the default state.
|
||||
* ----------------
|
||||
/*
|
||||
* Here we were in an aborted transaction block which just
|
||||
* processed the "END TRANSACTION" command but somehow aborted
|
||||
* again.. since we must have done the abort processing, we
|
||||
* clean up and return to the default state.
|
||||
*/
|
||||
case TBLOCK_ENDABORT:
|
||||
CleanupTransaction();
|
||||
@@ -1514,9 +1468,8 @@ BeginTransactionBlock(void)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
|
||||
/* ----------------
|
||||
* check the current transaction state
|
||||
* ----------------
|
||||
/*
|
||||
* check the current transaction state
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return;
|
||||
@@ -1524,21 +1477,18 @@ BeginTransactionBlock(void)
|
||||
if (s->blockState != TBLOCK_DEFAULT)
|
||||
elog(NOTICE, "BEGIN: already a transaction in progress");
|
||||
|
||||
/* ----------------
|
||||
* set the current transaction block state information
|
||||
* appropriately during begin processing
|
||||
* ----------------
|
||||
/*
|
||||
* set the current transaction block state information appropriately
|
||||
* during begin processing
|
||||
*/
|
||||
s->blockState = TBLOCK_BEGIN;
|
||||
|
||||
/* ----------------
|
||||
* do begin processing
|
||||
* ----------------
|
||||
/*
|
||||
* do begin processing
|
||||
*/
|
||||
|
||||
/* ----------------
|
||||
* done with begin processing, set block state to inprogress
|
||||
* ----------------
|
||||
/*
|
||||
* done with begin processing, set block state to inprogress
|
||||
*/
|
||||
s->blockState = TBLOCK_INPROGRESS;
|
||||
}
|
||||
@@ -1552,22 +1502,20 @@ EndTransactionBlock(void)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
|
||||
/* ----------------
|
||||
* check the current transaction state
|
||||
* ----------------
|
||||
/*
|
||||
* check the current transaction state
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return;
|
||||
|
||||
if (s->blockState == TBLOCK_INPROGRESS)
|
||||
{
|
||||
/* ----------------
|
||||
* here we are in a transaction block which should commit
|
||||
* when we get to the upcoming CommitTransactionCommand()
|
||||
* so we set the state to "END". CommitTransactionCommand()
|
||||
* will recognize this and commit the transaction and return
|
||||
* us to the default state
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* here we are in a transaction block which should commit when we
|
||||
* get to the upcoming CommitTransactionCommand() so we set the
|
||||
* state to "END". CommitTransactionCommand() will recognize this
|
||||
* and commit the transaction and return us to the default state
|
||||
*/
|
||||
s->blockState = TBLOCK_END;
|
||||
return;
|
||||
@@ -1575,25 +1523,23 @@ EndTransactionBlock(void)
|
||||
|
||||
if (s->blockState == TBLOCK_ABORT)
|
||||
{
|
||||
/* ----------------
|
||||
* here, we are in a transaction block which aborted
|
||||
* and since the AbortTransaction() was already done,
|
||||
* we do whatever is needed and change to the special
|
||||
* "END ABORT" state. The upcoming CommitTransactionCommand()
|
||||
* will recognise this and then put us back in the default
|
||||
* state.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* here, we are in a transaction block which aborted and since the
|
||||
* AbortTransaction() was already done, we do whatever is needed
|
||||
* and change to the special "END ABORT" state. The upcoming
|
||||
* CommitTransactionCommand() will recognise this and then put us
|
||||
* back in the default state.
|
||||
*/
|
||||
s->blockState = TBLOCK_ENDABORT;
|
||||
return;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* here, the user issued COMMIT when not inside a transaction.
|
||||
* Issue a notice and go to abort state. The upcoming call to
|
||||
* CommitTransactionCommand() will then put us back into the
|
||||
* default state.
|
||||
* ----------------
|
||||
/*
|
||||
* here, the user issued COMMIT when not inside a transaction. Issue a
|
||||
* notice and go to abort state. The upcoming call to
|
||||
* CommitTransactionCommand() will then put us back into the default
|
||||
* state.
|
||||
*/
|
||||
elog(NOTICE, "COMMIT: no transaction in progress");
|
||||
AbortTransaction();
|
||||
@@ -1610,34 +1556,31 @@ AbortTransactionBlock(void)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
|
||||
/* ----------------
|
||||
* check the current transaction state
|
||||
* ----------------
|
||||
/*
|
||||
* check the current transaction state
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return;
|
||||
|
||||
if (s->blockState == TBLOCK_INPROGRESS)
|
||||
{
|
||||
/* ----------------
|
||||
* here we were inside a transaction block something
|
||||
* screwed up inside the system so we enter the abort state,
|
||||
* do the abort processing and then return.
|
||||
* We remain in the abort state until we see an
|
||||
* END TRANSACTION command.
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* here we were inside a transaction block something screwed up
|
||||
* inside the system so we enter the abort state, do the abort
|
||||
* processing and then return. We remain in the abort state until
|
||||
* we see an END TRANSACTION command.
|
||||
*/
|
||||
s->blockState = TBLOCK_ABORT;
|
||||
AbortTransaction();
|
||||
return;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* here, the user issued ABORT when not inside a transaction.
|
||||
* Issue a notice and go to abort state. The upcoming call to
|
||||
* CommitTransactionCommand() will then put us back into the
|
||||
* default state.
|
||||
* ----------------
|
||||
/*
|
||||
* here, the user issued ABORT when not inside a transaction. Issue a
|
||||
* notice and go to abort state. The upcoming call to
|
||||
* CommitTransactionCommand() will then put us back into the default
|
||||
* state.
|
||||
*/
|
||||
elog(NOTICE, "ROLLBACK: no transaction in progress");
|
||||
AbortTransaction();
|
||||
@@ -1655,9 +1598,8 @@ UserAbortTransactionBlock(void)
|
||||
{
|
||||
TransactionState s = CurrentTransactionState;
|
||||
|
||||
/* ----------------
|
||||
* check the current transaction state
|
||||
* ----------------
|
||||
/*
|
||||
* check the current transaction state
|
||||
*/
|
||||
if (s->state == TRANS_DISABLED)
|
||||
return;
|
||||
@@ -1675,14 +1617,13 @@ UserAbortTransactionBlock(void)
|
||||
|
||||
if (s->blockState == TBLOCK_INPROGRESS)
|
||||
{
|
||||
/* ----------------
|
||||
* here we were inside a transaction block and we
|
||||
* got an abort command from the user, so we move to
|
||||
* the abort state, do the abort processing and
|
||||
* then change to the ENDABORT state so we will end up
|
||||
* in the default state after the upcoming
|
||||
* CommitTransactionCommand().
|
||||
* ----------------
|
||||
|
||||
/*
|
||||
* here we were inside a transaction block and we got an abort
|
||||
* command from the user, so we move to the abort state, do the
|
||||
* abort processing and then change to the ENDABORT state so we
|
||||
* will end up in the default state after the upcoming
|
||||
* CommitTransactionCommand().
|
||||
*/
|
||||
s->blockState = TBLOCK_ABORT;
|
||||
AbortTransaction();
|
||||
@@ -1690,12 +1631,11 @@ UserAbortTransactionBlock(void)
|
||||
return;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* here, the user issued ABORT when not inside a transaction.
|
||||
* Issue a notice and go to abort state. The upcoming call to
|
||||
* CommitTransactionCommand() will then put us back into the
|
||||
* default state.
|
||||
* ----------------
|
||||
/*
|
||||
* here, the user issued ABORT when not inside a transaction. Issue a
|
||||
* notice and go to abort state. The upcoming call to
|
||||
* CommitTransactionCommand() will then put us back into the default
|
||||
* state.
|
||||
*/
|
||||
elog(NOTICE, "ROLLBACK: no transaction in progress");
|
||||
AbortTransaction();
|
||||
|
||||
Reference in New Issue
Block a user