Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Functions

xid.c File Reference

#include "postgres.h"
#include <limits.h>
#include "access/transam.h"
#include "access/xact.h"
#include "libpq/pqformat.h"
#include "utils/builtins.h"
Include dependency graph for xid.c:

Go to the source code of this file.

Defines

#define PG_GETARG_TRANSACTIONID(n)   DatumGetTransactionId(PG_GETARG_DATUM(n))
#define PG_RETURN_TRANSACTIONID(x)   return TransactionIdGetDatum(x)
#define PG_GETARG_COMMANDID(n)   DatumGetCommandId(PG_GETARG_DATUM(n))
#define PG_RETURN_COMMANDID(x)   return CommandIdGetDatum(x)

Functions

Datum xidin (PG_FUNCTION_ARGS)
Datum xidout (PG_FUNCTION_ARGS)
Datum xidrecv (PG_FUNCTION_ARGS)
Datum xidsend (PG_FUNCTION_ARGS)
Datum xideq (PG_FUNCTION_ARGS)
Datum xid_age (PG_FUNCTION_ARGS)
int xidComparator (const void *arg1, const void *arg2)
Datum cidin (PG_FUNCTION_ARGS)
Datum cidout (PG_FUNCTION_ARGS)
Datum cidrecv (PG_FUNCTION_ARGS)
Datum cidsend (PG_FUNCTION_ARGS)
Datum cideq (PG_FUNCTION_ARGS)

Define Documentation

#define PG_GETARG_COMMANDID (   n  )     DatumGetCommandId(PG_GETARG_DATUM(n))

Definition at line 27 of file xid.c.

Referenced by cideq(), cidout(), and cidsend().

#define PG_GETARG_TRANSACTIONID (   n  )     DatumGetTransactionId(PG_GETARG_DATUM(n))

Definition at line 24 of file xid.c.

Referenced by xid_age(), xideq(), xidout(), and xidsend().

#define PG_RETURN_COMMANDID (   x  )     return CommandIdGetDatum(x)

Definition at line 28 of file xid.c.

Referenced by cidin(), and cidrecv().

#define PG_RETURN_TRANSACTIONID (   x  )     return TransactionIdGetDatum(x)

Definition at line 25 of file xid.c.

Referenced by xidin(), and xidrecv().


Function Documentation

Datum cideq ( PG_FUNCTION_ARGS   ) 

Definition at line 182 of file xid.c.

References PG_GETARG_COMMANDID, and PG_RETURN_BOOL.

Datum cidin ( PG_FUNCTION_ARGS   ) 

Definition at line 133 of file xid.c.

References PG_GETARG_CSTRING, and PG_RETURN_COMMANDID.

{
    char       *s = PG_GETARG_CSTRING(0);
    CommandId   c;

    c = atoi(s);

    PG_RETURN_COMMANDID(c);
}

Datum cidout ( PG_FUNCTION_ARGS   ) 

Definition at line 147 of file xid.c.

References palloc(), PG_GETARG_COMMANDID, PG_RETURN_CSTRING, and snprintf().

{
    CommandId   c = PG_GETARG_COMMANDID(0);
    char       *result = (char *) palloc(16);

    snprintf(result, 16, "%u", (unsigned int) c);
    PG_RETURN_CSTRING(result);
}

Datum cidrecv ( PG_FUNCTION_ARGS   ) 
Datum cidsend ( PG_FUNCTION_ARGS   ) 
Datum xid_age ( PG_FUNCTION_ARGS   ) 

Definition at line 93 of file xid.c.

References GetStableLatestTransactionId(), now(), PG_GETARG_TRANSACTIONID, PG_RETURN_INT32, and TransactionIdIsNormal.

{
    TransactionId xid = PG_GETARG_TRANSACTIONID(0);
    TransactionId now = GetStableLatestTransactionId();

    /* Permanent XIDs are always infinitely old */
    if (!TransactionIdIsNormal(xid))
        PG_RETURN_INT32(INT_MAX);

    PG_RETURN_INT32((int32) (now - xid));
}

int xidComparator ( const void *  arg1,
const void *  arg2 
)

Definition at line 113 of file xid.c.

Referenced by ProcArrayApplyRecoveryInfo().

{
    TransactionId xid1 = *(const TransactionId *) arg1;
    TransactionId xid2 = *(const TransactionId *) arg2;

    if (xid1 > xid2)
        return 1;
    if (xid1 < xid2)
        return -1;
    return 0;
}

Datum xideq ( PG_FUNCTION_ARGS   ) 
Datum xidin ( PG_FUNCTION_ARGS   ) 

Definition at line 32 of file xid.c.

References NULL, PG_GETARG_CSTRING, and PG_RETURN_TRANSACTIONID.

{
    char       *str = PG_GETARG_CSTRING(0);

    PG_RETURN_TRANSACTIONID((TransactionId) strtoul(str, NULL, 0));
}

Datum xidout ( PG_FUNCTION_ARGS   ) 

Definition at line 40 of file xid.c.

References palloc(), PG_GETARG_TRANSACTIONID, PG_RETURN_CSTRING, and snprintf().

{
    TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);

    /* maximum 32 bit unsigned integer representation takes 10 chars */
    char       *str = palloc(11);

    snprintf(str, 11, "%lu", (unsigned long) transactionId);

    PG_RETURN_CSTRING(str);
}

Datum xidrecv ( PG_FUNCTION_ARGS   ) 
Datum xidsend ( PG_FUNCTION_ARGS   )