#include "postgres.h"#include "access/htup_details.h"#include "access/xact.h"#include "utils/combocid.h"#include "utils/hsearch.h"#include "utils/memutils.h"
Go to the source code of this file.
Data Structures | |
| struct | ComboCidKeyData |
| struct | ComboCidEntryData |
Defines | |
| #define | CCID_HASH_SIZE 100 |
| #define | CCID_ARRAY_SIZE 100 |
Typedefs | |
| typedef ComboCidKeyData * | ComboCidKey |
| typedef ComboCidEntryData * | ComboCidEntry |
Functions | |
| static CommandId | GetComboCommandId (CommandId cmin, CommandId cmax) |
| static CommandId | GetRealCmin (CommandId combocid) |
| static CommandId | GetRealCmax (CommandId combocid) |
| CommandId | HeapTupleHeaderGetCmin (HeapTupleHeader tup) |
| CommandId | HeapTupleHeaderGetCmax (HeapTupleHeader tup) |
| void | HeapTupleHeaderAdjustCmax (HeapTupleHeader tup, CommandId *cmax, bool *iscombo) |
| void | AtEOXact_ComboCid (void) |
Variables | |
| static HTAB * | comboHash = NULL |
| static ComboCidKey | comboCids = NULL |
| static int | usedComboCids = 0 |
| static int | sizeComboCids = 0 |
| #define CCID_ARRAY_SIZE 100 |
Definition at line 84 of file combocid.c.
| #define CCID_HASH_SIZE 100 |
Definition at line 72 of file combocid.c.
Referenced by GetComboCommandId().
| typedef ComboCidEntryData* ComboCidEntry |
Definition at line 69 of file combocid.c.
| typedef ComboCidKeyData* ComboCidKey |
Definition at line 61 of file combocid.c.
| void AtEOXact_ComboCid | ( | void | ) |
Definition at line 173 of file combocid.c.
References sizeComboCids, and usedComboCids.
Referenced by AbortTransaction(), CommitTransaction(), and PrepareTransaction().
{
/*
* Don't bother to pfree. These are allocated in TopTransactionContext, so
* they're going to go away at the end of transaction anyway.
*/
comboHash = NULL;
comboCids = NULL;
usedComboCids = 0;
sizeComboCids = 0;
}
Definition at line 195 of file combocid.c.
References CCID_HASH_SIZE, ComboCidKeyData::cmax, ComboCidKeyData::cmin, ComboCidEntryData::combocid, HASHCTL::entrysize, HASHCTL::hash, HASH_CONTEXT, hash_create(), HASH_ELEM, HASH_FUNCTION, hash_search(), HASHCTL::hcxt, HASHCTL::keysize, MemoryContextAlloc(), NULL, repalloc(), sizeComboCids, TopTransactionContext, and usedComboCids.
Referenced by HeapTupleHeaderAdjustCmax().
{
CommandId combocid;
ComboCidKeyData key;
ComboCidEntry entry;
bool found;
/*
* Create the hash table and array the first time we need to use combo
* cids in the transaction.
*/
if (comboHash == NULL)
{
HASHCTL hash_ctl;
memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(ComboCidKeyData);
hash_ctl.entrysize = sizeof(ComboCidEntryData);
hash_ctl.hash = tag_hash;
hash_ctl.hcxt = TopTransactionContext;
comboHash = hash_create("Combo CIDs",
CCID_HASH_SIZE,
&hash_ctl,
HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT);
comboCids = (ComboCidKeyData *)
MemoryContextAlloc(TopTransactionContext,
sizeof(ComboCidKeyData) * CCID_ARRAY_SIZE);
sizeComboCids = CCID_ARRAY_SIZE;
usedComboCids = 0;
}
/* Lookup or create a hash entry with the desired cmin/cmax */
/* We assume there is no struct padding in ComboCidKeyData! */
key.cmin = cmin;
key.cmax = cmax;
entry = (ComboCidEntry) hash_search(comboHash,
(void *) &key,
HASH_ENTER,
&found);
if (found)
{
/* Reuse an existing combo cid */
return entry->combocid;
}
/*
* We have to create a new combo cid. Check that there's room for it in
* the array, and grow it if there isn't.
*/
if (usedComboCids >= sizeComboCids)
{
/* We need to grow the array */
int newsize = sizeComboCids * 2;
comboCids = (ComboCidKeyData *)
repalloc(comboCids, sizeof(ComboCidKeyData) * newsize);
sizeComboCids = newsize;
}
combocid = usedComboCids;
comboCids[combocid].cmin = cmin;
comboCids[combocid].cmax = cmax;
usedComboCids++;
entry->combocid = combocid;
return combocid;
}
Definition at line 277 of file combocid.c.
References Assert, ComboCidKeyData::cmax, and usedComboCids.
Referenced by HeapTupleHeaderGetCmax().
{
Assert(combocid < usedComboCids);
return comboCids[combocid].cmax;
}
Definition at line 270 of file combocid.c.
References Assert, ComboCidKeyData::cmin, and usedComboCids.
Referenced by HeapTupleHeaderGetCmin().
{
Assert(combocid < usedComboCids);
return comboCids[combocid].cmin;
}
| void HeapTupleHeaderAdjustCmax | ( | HeapTupleHeader | tup, | |
| CommandId * | cmax, | |||
| bool * | iscombo | |||
| ) |
Definition at line 144 of file combocid.c.
References GetComboCommandId(), HEAP_XMIN_COMMITTED, HeapTupleHeaderGetCmin(), HeapTupleHeaderGetXmin, HeapTupleHeaderData::t_infomask, and TransactionIdIsCurrentTransactionId().
Referenced by heap_delete(), and heap_update().
{
/*
* If we're marking a tuple deleted that was inserted by (any
* subtransaction of) our transaction, we need to use a combo command id.
* Test for HEAP_XMIN_COMMITTED first, because it's cheaper than a
* TransactionIdIsCurrentTransactionId call.
*/
if (!(tup->t_infomask & HEAP_XMIN_COMMITTED) &&
TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tup)))
{
CommandId cmin = HeapTupleHeaderGetCmin(tup);
*cmax = GetComboCommandId(cmin, *cmax);
*iscombo = true;
}
else
{
*iscombo = false;
}
}
| CommandId HeapTupleHeaderGetCmax | ( | HeapTupleHeader | tup | ) |
Definition at line 117 of file combocid.c.
References Assert, GetRealCmax(), HEAP_COMBOCID, HEAP_MOVED, HeapTupleHeaderGetRawCommandId, HeapTupleHeaderGetUpdateXid, HeapTupleHeaderData::t_infomask, and TransactionIdIsCurrentTransactionId().
Referenced by heap_delete(), heap_lock_tuple(), heap_update(), HeapTupleSatisfiesMVCC(), HeapTupleSatisfiesNow(), and HeapTupleSatisfiesUpdate().
{
CommandId cid = HeapTupleHeaderGetRawCommandId(tup);
Assert(!(tup->t_infomask & HEAP_MOVED));
Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetUpdateXid(tup)));
if (tup->t_infomask & HEAP_COMBOCID)
return GetRealCmax(cid);
else
return cid;
}
| CommandId HeapTupleHeaderGetCmin | ( | HeapTupleHeader | tup | ) |
Definition at line 103 of file combocid.c.
References Assert, GetRealCmin(), HEAP_COMBOCID, HEAP_MOVED, HeapTupleHeaderGetRawCommandId, HeapTupleHeaderGetXmin, HeapTupleHeaderData::t_infomask, and TransactionIdIsCurrentTransactionId().
Referenced by EvalPlanQualFetch(), HeapTupleHeaderAdjustCmax(), HeapTupleSatisfiesMVCC(), HeapTupleSatisfiesNow(), and HeapTupleSatisfiesUpdate().
{
CommandId cid = HeapTupleHeaderGetRawCommandId(tup);
Assert(!(tup->t_infomask & HEAP_MOVED));
Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tup)));
if (tup->t_infomask & HEAP_COMBOCID)
return GetRealCmin(cid);
else
return cid;
}
ComboCidKey comboCids = NULL [static] |
Definition at line 79 of file combocid.c.
Definition at line 52 of file combocid.c.
int sizeComboCids = 0 [static] |
Definition at line 81 of file combocid.c.
Referenced by AtEOXact_ComboCid(), and GetComboCommandId().
int usedComboCids = 0 [static] |
Definition at line 80 of file combocid.c.
Referenced by AtEOXact_ComboCid(), GetComboCommandId(), GetRealCmax(), and GetRealCmin().
1.7.1