Header And Logo

| The world's most advanced open source database.

Data Structures | Defines | Typedefs | Functions | Variables

combocid.c File Reference

#include "postgres.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "utils/combocid.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
Include dependency graph for combocid.c:

Go to the source code of this file.

Data Structures

struct  ComboCidKeyData
struct  ComboCidEntryData


#define CCID_HASH_SIZE   100
#define CCID_ARRAY_SIZE   100


typedef ComboCidKeyDataComboCidKey
typedef ComboCidEntryDataComboCidEntry


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)


static HTABcomboHash = NULL
static ComboCidKey comboCids = NULL
static int usedComboCids = 0
static int sizeComboCids = 0

Define Documentation

#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 Documentation

Definition at line 69 of file combocid.c.

Definition at line 61 of file combocid.c.

Function Documentation

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;

static CommandId GetComboCommandId ( CommandId  cmin,
CommandId  cmax 
) [static]

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",
                                HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT);

        comboCids = (ComboCidKeyData *)
                               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,

    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;

    entry->combocid = combocid;

    return combocid;

static CommandId GetRealCmax ( CommandId  combocid  )  [static]

Definition at line 277 of file combocid.c.

References Assert, ComboCidKeyData::cmax, and usedComboCids.

Referenced by HeapTupleHeaderGetCmax().

    Assert(combocid < usedComboCids);
    return comboCids[combocid].cmax;

static CommandId GetRealCmin ( CommandId  combocid  )  [static]

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) &&
        CommandId   cmin = HeapTupleHeaderGetCmin(tup);

        *cmax = GetComboCommandId(cmin, *cmax);
        *iscombo = true;
        *iscombo = false;

CommandId HeapTupleHeaderGetCmax ( HeapTupleHeader  tup  ) 
CommandId HeapTupleHeaderGetCmin ( HeapTupleHeader  tup  ) 

Variable Documentation

ComboCidKey comboCids = NULL [static]

Definition at line 79 of file combocid.c.

HTAB* comboHash = NULL [static]

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().