PostgreSQL Source Code  git master
tid.c File Reference
#include "postgres.h"
#include <math.h>
#include <limits.h>
#include "access/heapam.h"
#include "access/sysattr.h"
#include "access/tableam.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/parsetree.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/varlena.h"
Include dependency graph for tid.c:

Go to the source code of this file.

Macros

#define DatumGetItemPointer(X)   ((ItemPointer) DatumGetPointer(X))
 
#define ItemPointerGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_ITEMPOINTER(n)   DatumGetItemPointer(PG_GETARG_DATUM(n))
 
#define PG_RETURN_ITEMPOINTER(x)   return ItemPointerGetDatum(x)
 
#define LDELIM   '('
 
#define RDELIM   ')'
 
#define DELIM   ','
 
#define NTIDARGS   2
 

Functions

Datum tidin (PG_FUNCTION_ARGS)
 
Datum tidout (PG_FUNCTION_ARGS)
 
Datum tidrecv (PG_FUNCTION_ARGS)
 
Datum tidsend (PG_FUNCTION_ARGS)
 
Datum tideq (PG_FUNCTION_ARGS)
 
Datum tidne (PG_FUNCTION_ARGS)
 
Datum tidlt (PG_FUNCTION_ARGS)
 
Datum tidle (PG_FUNCTION_ARGS)
 
Datum tidgt (PG_FUNCTION_ARGS)
 
Datum tidge (PG_FUNCTION_ARGS)
 
Datum bttidcmp (PG_FUNCTION_ARGS)
 
Datum tidlarger (PG_FUNCTION_ARGS)
 
Datum tidsmaller (PG_FUNCTION_ARGS)
 
Datum hashtid (PG_FUNCTION_ARGS)
 
Datum hashtidextended (PG_FUNCTION_ARGS)
 
void setLastTid (const ItemPointer tid)
 
static Datum currtid_for_view (Relation viewrel, ItemPointer tid)
 
Datum currtid_byreloid (PG_FUNCTION_ARGS)
 
Datum currtid_byrelname (PG_FUNCTION_ARGS)
 

Variables

static ItemPointerData Current_last_tid = {{0, 0}, 0}
 

Macro Definition Documentation

◆ DatumGetItemPointer

#define DatumGetItemPointer (   X)    ((ItemPointer) DatumGetPointer(X))

Definition at line 40 of file tid.c.

◆ DELIM

#define DELIM   ','

Definition at line 47 of file tid.c.

Referenced by tidin().

◆ ItemPointerGetDatum

#define ItemPointerGetDatum (   X)    PointerGetDatum(X)

Definition at line 41 of file tid.c.

◆ LDELIM

#define LDELIM   '('

Definition at line 45 of file tid.c.

Referenced by tidin().

◆ NTIDARGS

#define NTIDARGS   2

Definition at line 48 of file tid.c.

Referenced by tidin().

◆ PG_GETARG_ITEMPOINTER

◆ PG_RETURN_ITEMPOINTER

#define PG_RETURN_ITEMPOINTER (   x)    return ItemPointerGetDatum(x)

Definition at line 43 of file tid.c.

Referenced by currtid_byrelname(), currtid_byreloid(), tidin(), tidlarger(), tidrecv(), and tidsmaller().

◆ RDELIM

#define RDELIM   ')'

Definition at line 46 of file tid.c.

Referenced by tidin().

Function Documentation

◆ bttidcmp()

Datum bttidcmp ( PG_FUNCTION_ARGS  )

Definition at line 218 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_INT32.

219 {
222 
223  PG_RETURN_INT32(ItemPointerCompare(arg1, arg2));
224 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353

◆ currtid_byrelname()

Datum currtid_byrelname ( PG_FUNCTION_ARGS  )

Definition at line 406 of file tid.c.

References AccessShareLock, ACL_SELECT, aclcheck_error(), ACLCHECK_OK, currtid_for_view(), elog, ERROR, get_namespace_name(), get_relkind_objtype(), GetLatestSnapshot(), GetUserId(), ItemPointerCopy, makeRangeVarFromNameList(), palloc(), pg_class_aclcheck(), PG_GETARG_ITEMPOINTER, PG_GETARG_TEXT_PP, PG_RETURN_ITEMPOINTER, RelationData::rd_rel, RegisterSnapshot(), RelationGetNamespace, RelationGetRelationName, RelationGetRelid, relname, table_beginscan_tid(), table_close(), table_endscan(), table_openrv(), table_tuple_get_latest_tid(), textToQualifiedNameList(), and UnregisterSnapshot().

407 {
410  ItemPointer result;
411  RangeVar *relrv;
412  Relation rel;
413  AclResult aclresult;
414  Snapshot snapshot;
415  TableScanDesc scan;
416 
418  rel = table_openrv(relrv, AccessShareLock);
419 
420  aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
421  ACL_SELECT);
422  if (aclresult != ACLCHECK_OK)
423  aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind),
425 
426  if (rel->rd_rel->relkind == RELKIND_VIEW)
427  return currtid_for_view(rel, tid);
428 
429  if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
430  elog(ERROR, "cannot look at latest visible tid for relation \"%s.%s\"",
433 
434  result = (ItemPointer) palloc(sizeof(ItemPointerData));
435  ItemPointerCopy(tid, result);
436 
437  snapshot = RegisterSnapshot(GetLatestSnapshot());
438  scan = table_beginscan_tid(rel, snapshot);
439  table_tuple_get_latest_tid(scan, result);
440  table_endscan(scan);
441  UnregisterSnapshot(snapshot);
442 
444 
445  PG_RETURN_ITEMPOINTER(result);
446 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:810
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
Oid GetUserId(void)
Definition: miscinit.c:476
#define AccessShareLock
Definition: lockdefs.h:36
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3061
Form_pg_class rd_rel
Definition: rel.h:109
NameData relname
Definition: pg_class.h:38
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
ItemPointerData * ItemPointer
Definition: itemptr.h:49
static Datum currtid_for_view(Relation viewrel, ItemPointer tid)
Definition: tid.c:292
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3294
#define ERROR
Definition: elog.h:43
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
Definition: tableam.c:246
#define RelationGetRelationName(relation)
Definition: rel.h:490
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3644
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:852
AclResult
Definition: acl.h:177
#define ACL_SELECT
Definition: parsenodes.h:75
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: table.c:102
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:325
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4563
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:863
static TableScanDesc table_beginscan_tid(Relation rel, Snapshot snapshot)
Definition: tableam.h:839
void * palloc(Size size)
Definition: mcxt.c:950
#define elog(elevel,...)
Definition: elog.h:214
ObjectType get_relkind_objtype(char relkind)
Definition: c.h:562
#define RelationGetRelid(relation)
Definition: rel.h:456
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:161
#define RelationGetNamespace(relation)
Definition: rel.h:497

◆ currtid_byreloid()

Datum currtid_byreloid ( PG_FUNCTION_ARGS  )

Definition at line 359 of file tid.c.

References AccessShareLock, ACL_SELECT, aclcheck_error(), ACLCHECK_OK, Current_last_tid, currtid_for_view(), elog, ERROR, get_namespace_name(), get_relkind_objtype(), GetLatestSnapshot(), GetUserId(), ItemPointerCopy, palloc(), pg_class_aclcheck(), PG_GETARG_ITEMPOINTER, PG_GETARG_OID, PG_RETURN_ITEMPOINTER, RelationData::rd_rel, RegisterSnapshot(), RelationGetNamespace, RelationGetRelationName, RelationGetRelid, table_beginscan_tid(), table_close(), table_endscan(), table_open(), table_tuple_get_latest_tid(), and UnregisterSnapshot().

Referenced by currtid_for_view().

360 {
361  Oid reloid = PG_GETARG_OID(0);
363  ItemPointer result;
364  Relation rel;
365  AclResult aclresult;
366  Snapshot snapshot;
367  TableScanDesc scan;
368 
369  result = (ItemPointer) palloc(sizeof(ItemPointerData));
370  if (!reloid)
371  {
372  *result = Current_last_tid;
373  PG_RETURN_ITEMPOINTER(result);
374  }
375 
376  rel = table_open(reloid, AccessShareLock);
377 
378  aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
379  ACL_SELECT);
380  if (aclresult != ACLCHECK_OK)
381  aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind),
383 
384  if (rel->rd_rel->relkind == RELKIND_VIEW)
385  return currtid_for_view(rel, tid);
386 
387  if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
388  elog(ERROR, "cannot look at latest visible tid for relation \"%s.%s\"",
391 
392  ItemPointerCopy(tid, result);
393 
394  snapshot = RegisterSnapshot(GetLatestSnapshot());
395  scan = table_beginscan_tid(rel, snapshot);
396  table_tuple_get_latest_tid(scan, result);
397  table_endscan(scan);
398  UnregisterSnapshot(snapshot);
399 
401 
402  PG_RETURN_ITEMPOINTER(result);
403 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Snapshot RegisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:810
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
Oid GetUserId(void)
Definition: miscinit.c:476
#define AccessShareLock
Definition: lockdefs.h:36
Form_pg_class rd_rel
Definition: rel.h:109
unsigned int Oid
Definition: postgres_ext.h:31
ItemPointerData * ItemPointer
Definition: itemptr.h:49
static Datum currtid_for_view(Relation viewrel, ItemPointer tid)
Definition: tid.c:292
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3294
#define ERROR
Definition: elog.h:43
static ItemPointerData Current_last_tid
Definition: tid.c:278
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
void table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
Definition: tableam.c:246
#define RelationGetRelationName(relation)
Definition: rel.h:490
void UnregisterSnapshot(Snapshot snapshot)
Definition: snapmgr.c:852
AclResult
Definition: acl.h:177
#define ACL_SELECT
Definition: parsenodes.h:75
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:325
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4563
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:863
static TableScanDesc table_beginscan_tid(Relation rel, Snapshot snapshot)
Definition: tableam.h:839
void * palloc(Size size)
Definition: mcxt.c:950
#define elog(elevel,...)
Definition: elog.h:214
ObjectType get_relkind_objtype(char relkind)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define RelationGetRelid(relation)
Definition: rel.h:456
#define ItemPointerCopy(fromPointer, toPointer)
Definition: itemptr.h:161
#define RelationGetNamespace(relation)
Definition: rel.h:497

◆ currtid_for_view()

static Datum currtid_for_view ( Relation  viewrel,
ItemPointer  tid 
)
static

Definition at line 292 of file tid.c.

References AccessShareLock, RewriteRule::actions, CMD_SELECT, currtid_byreloid(), DirectFunctionCall2, elog, ERROR, RewriteRule::event, TargetEntry::expr, get_tle_by_resno(), i, IS_SPECIAL_VARNO, IsA, linitial, list_length(), NameStr, TupleDescData::natts, RuleLock::numLocks, ObjectIdGetDatum, PointerGetDatum, RelationData::rd_rules, RelationGetDescr, rt_fetch, Query::rtable, RuleLock::rules, SelfItemPointerAttributeNumber, table_close(), Query::targetList, TupleDescAttr, Var::varattno, and Var::varno.

Referenced by currtid_byrelname(), and currtid_byreloid().

293 {
294  TupleDesc att = RelationGetDescr(viewrel);
295  RuleLock *rulelock;
296  RewriteRule *rewrite;
297  int i,
298  natts = att->natts,
299  tididx = -1;
300 
301  for (i = 0; i < natts; i++)
302  {
303  Form_pg_attribute attr = TupleDescAttr(att, i);
304 
305  if (strcmp(NameStr(attr->attname), "ctid") == 0)
306  {
307  if (attr->atttypid != TIDOID)
308  elog(ERROR, "ctid isn't of type TID");
309  tididx = i;
310  break;
311  }
312  }
313  if (tididx < 0)
314  elog(ERROR, "currtid cannot handle views with no CTID");
315  rulelock = viewrel->rd_rules;
316  if (!rulelock)
317  elog(ERROR, "the view has no rules");
318  for (i = 0; i < rulelock->numLocks; i++)
319  {
320  rewrite = rulelock->rules[i];
321  if (rewrite->event == CMD_SELECT)
322  {
323  Query *query;
324  TargetEntry *tle;
325 
326  if (list_length(rewrite->actions) != 1)
327  elog(ERROR, "only one select rule is allowed in views");
328  query = (Query *) linitial(rewrite->actions);
329  tle = get_tle_by_resno(query->targetList, tididx + 1);
330  if (tle && tle->expr && IsA(tle->expr, Var))
331  {
332  Var *var = (Var *) tle->expr;
333  RangeTblEntry *rte;
334 
335  if (!IS_SPECIAL_VARNO(var->varno) &&
337  {
338  rte = rt_fetch(var->varno, query->rtable);
339  if (rte)
340  {
341  Datum result;
342 
344  ObjectIdGetDatum(rte->relid),
345  PointerGetDatum(tid));
346  table_close(viewrel, AccessShareLock);
347  return result;
348  }
349  }
350  }
351  break;
352  }
353  }
354  elog(ERROR, "currtid cannot handle this view");
355  return (Datum) 0;
356 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
int numLocks
Definition: prs2lock.h:42
#define RelationGetDescr(relation)
Definition: rel.h:482
#define PointerGetDatum(X)
Definition: postgres.h:556
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define AccessShareLock
Definition: lockdefs.h:36
AttrNumber varattno
Definition: primnodes.h:186
Definition: primnodes.h:181
List * targetList
Definition: parsenodes.h:140
#define IS_SPECIAL_VARNO(varno)
Definition: primnodes.h:175
#define linitial(l)
Definition: pg_list.h:195
List * rtable
Definition: parsenodes.h:137
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
Datum currtid_byreloid(PG_FUNCTION_ARGS)
Definition: tid.c:359
CmdType event
Definition: prs2lock.h:27
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
RewriteRule ** rules
Definition: prs2lock.h:43
List * actions
Definition: prs2lock.h:29
#define rt_fetch(rangetable_index, rangetable)
Definition: parsetree.h:31
Index varno
Definition: primnodes.h:184
uintptr_t Datum
Definition: postgres.h:367
Expr * expr
Definition: primnodes.h:1407
RuleLock * rd_rules
Definition: rel.h:113
static int list_length(const List *l)
Definition: pg_list.h:169
#define elog(elevel,...)
Definition: elog.h:214
int i
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
#define NameStr(name)
Definition: c.h:622
#define SelfItemPointerAttributeNumber
Definition: sysattr.h:21
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ hashtid()

Datum hashtid ( PG_FUNCTION_ARGS  )

Definition at line 245 of file tid.c.

References hash_any(), sort-test::key, and PG_GETARG_ITEMPOINTER.

246 {
248 
249  /*
250  * While you'll probably have a lot of trouble with a compiler that
251  * insists on appending pad space to struct ItemPointerData, we can at
252  * least make this code work, by not using sizeof(ItemPointerData).
253  * Instead rely on knowing the sizes of the component fields.
254  */
255  return hash_any((unsigned char *) key,
256  sizeof(BlockIdData) + sizeof(OffsetNumber));
257 }
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
uint16 OffsetNumber
Definition: off.h:24
static Datum hash_any(const unsigned char *k, int keylen)
Definition: hashfn.h:31

◆ hashtidextended()

Datum hashtidextended ( PG_FUNCTION_ARGS  )

Definition at line 260 of file tid.c.

References hash_any_extended(), sort-test::key, PG_GETARG_INT64, and PG_GETARG_ITEMPOINTER.

261 {
263  uint64 seed = PG_GETARG_INT64(1);
264 
265  /* As above */
266  return hash_any_extended((unsigned char *) key,
267  sizeof(BlockIdData) + sizeof(OffsetNumber),
268  seed);
269 }
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
Definition: hashfn.h:37
uint16 OffsetNumber
Definition: off.h:24
#define PG_GETARG_INT64(n)
Definition: fmgr.h:282

◆ setLastTid()

void setLastTid ( const ItemPointer  tid)

Definition at line 281 of file tid.c.

Referenced by ExecInsert().

282 {
283  Current_last_tid = *tid;
284 }
static ItemPointerData Current_last_tid
Definition: tid.c:278

◆ tideq()

Datum tideq ( PG_FUNCTION_ARGS  )

Definition at line 164 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

165 {
168 
169  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) == 0);
170 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ tidge()

Datum tidge ( PG_FUNCTION_ARGS  )

Definition at line 209 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

210 {
213 
214  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) >= 0);
215 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ tidgt()

Datum tidgt ( PG_FUNCTION_ARGS  )

Definition at line 200 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

201 {
204 
205  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) > 0);
206 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ tidin()

Datum tidin ( PG_FUNCTION_ARGS  )

Definition at line 55 of file tid.c.

References DELIM, ereport, errcode(), errmsg(), ERROR, i, ItemPointerSet, LDELIM, NTIDARGS, palloc(), PG_GETARG_CSTRING, PG_RETURN_ITEMPOINTER, RDELIM, and generate_unaccent_rules::str.

Referenced by make_tuple_from_result_row().

56 {
57  char *str = PG_GETARG_CSTRING(0);
58  char *p,
59  *coord[NTIDARGS];
60  int i;
61  ItemPointer result;
62  BlockNumber blockNumber;
63  OffsetNumber offsetNumber;
64  char *badp;
65  int hold_offset;
66 
67  for (i = 0, p = str; *p && i < NTIDARGS && *p != RDELIM; p++)
68  if (*p == DELIM || (*p == LDELIM && !i))
69  coord[i++] = p + 1;
70 
71  if (i < NTIDARGS)
72  ereport(ERROR,
73  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
74  errmsg("invalid input syntax for type %s: \"%s\"",
75  "tid", str)));
76 
77  errno = 0;
78  blockNumber = strtoul(coord[0], &badp, 10);
79  if (errno || *badp != DELIM)
80  ereport(ERROR,
81  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
82  errmsg("invalid input syntax for type %s: \"%s\"",
83  "tid", str)));
84 
85  hold_offset = strtol(coord[1], &badp, 10);
86  if (errno || *badp != RDELIM ||
87  hold_offset > USHRT_MAX || hold_offset < 0)
88  ereport(ERROR,
89  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
90  errmsg("invalid input syntax for type %s: \"%s\"",
91  "tid", str)));
92 
93  offsetNumber = hold_offset;
94 
95  result = (ItemPointer) palloc(sizeof(ItemPointerData));
96 
97  ItemPointerSet(result, blockNumber, offsetNumber);
98 
99  PG_RETURN_ITEMPOINTER(result);
100 }
#define LDELIM
Definition: tid.c:45
#define RDELIM
Definition: tid.c:46
int errcode(int sqlerrcode)
Definition: elog.c:610
#define NTIDARGS
Definition: tid.c:48
uint32 BlockNumber
Definition: block.h:31
uint16 OffsetNumber
Definition: off.h:24
ItemPointerData * ItemPointer
Definition: itemptr.h:49
#define ERROR
Definition: elog.h:43
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:43
#define DELIM
Definition: tid.c:47
#define ereport(elevel,...)
Definition: elog.h:144
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:824
int i
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127

◆ tidlarger()

Datum tidlarger ( PG_FUNCTION_ARGS  )

Definition at line 227 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

228 {
231 
232  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) >= 0 ? arg1 : arg2);
233 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:43

◆ tidle()

Datum tidle ( PG_FUNCTION_ARGS  )

Definition at line 191 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

192 {
195 
196  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) <= 0);
197 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ tidlt()

Datum tidlt ( PG_FUNCTION_ARGS  )

Definition at line 182 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

183 {
186 
187  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) < 0);
188 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ tidne()

Datum tidne ( PG_FUNCTION_ARGS  )

Definition at line 173 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_BOOL.

174 {
177 
178  PG_RETURN_BOOL(ItemPointerCompare(arg1, arg2) != 0);
179 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ tidout()

Datum tidout ( PG_FUNCTION_ARGS  )

Definition at line 107 of file tid.c.

References buf, ItemPointerGetBlockNumberNoCheck, ItemPointerGetOffsetNumberNoCheck, PG_GETARG_ITEMPOINTER, PG_RETURN_CSTRING, pstrdup(), and snprintf.

Referenced by pgrowlocks().

108 {
109  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
110  BlockNumber blockNumber;
111  OffsetNumber offsetNumber;
112  char buf[32];
113 
114  blockNumber = ItemPointerGetBlockNumberNoCheck(itemPtr);
115  offsetNumber = ItemPointerGetOffsetNumberNoCheck(itemPtr);
116 
117  /* Perhaps someday we should output this as a record. */
118  snprintf(buf, sizeof(buf), "(%u,%u)", blockNumber, offsetNumber);
119 
121 }
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:108
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
char * pstrdup(const char *in)
Definition: mcxt.c:1187
uint32 BlockNumber
Definition: block.h:31
uint16 OffsetNumber
Definition: off.h:24
static char * buf
Definition: pg_test_fsync.c:67
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:89
#define snprintf
Definition: port.h:193

◆ tidrecv()

Datum tidrecv ( PG_FUNCTION_ARGS  )

Definition at line 127 of file tid.c.

References buf, ItemPointerSet, palloc(), PG_GETARG_POINTER, PG_RETURN_ITEMPOINTER, and pq_getmsgint().

128 {
130  ItemPointer result;
131  BlockNumber blockNumber;
132  OffsetNumber offsetNumber;
133 
134  blockNumber = pq_getmsgint(buf, sizeof(blockNumber));
135  offsetNumber = pq_getmsgint(buf, sizeof(offsetNumber));
136 
137  result = (ItemPointer) palloc(sizeof(ItemPointerData));
138 
139  ItemPointerSet(result, blockNumber, offsetNumber);
140 
141  PG_RETURN_ITEMPOINTER(result);
142 }
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
uint32 BlockNumber
Definition: block.h:31
uint16 OffsetNumber
Definition: off.h:24
ItemPointerData * ItemPointer
Definition: itemptr.h:49
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:43
static char * buf
Definition: pg_test_fsync.c:67
void * palloc(Size size)
Definition: mcxt.c:950
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127

◆ tidsend()

Datum tidsend ( PG_FUNCTION_ARGS  )

Definition at line 148 of file tid.c.

References buf, ItemPointerGetBlockNumberNoCheck, ItemPointerGetOffsetNumberNoCheck, PG_GETARG_ITEMPOINTER, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendint16(), and pq_sendint32().

149 {
150  ItemPointer itemPtr = PG_GETARG_ITEMPOINTER(0);
152 
153  pq_begintypsend(&buf);
157 }
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137
#define ItemPointerGetOffsetNumberNoCheck(pointer)
Definition: itemptr.h:108
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:369
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static char * buf
Definition: pg_test_fsync.c:67
#define ItemPointerGetBlockNumberNoCheck(pointer)
Definition: itemptr.h:89

◆ tidsmaller()

Datum tidsmaller ( PG_FUNCTION_ARGS  )

Definition at line 236 of file tid.c.

References ItemPointerCompare(), PG_GETARG_ITEMPOINTER, and PG_RETURN_ITEMPOINTER.

237 {
240 
241  PG_RETURN_ITEMPOINTER(ItemPointerCompare(arg1, arg2) <= 0 ? arg1 : arg2);
242 }
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
Definition: itemptr.c:52
#define PG_GETARG_ITEMPOINTER(n)
Definition: tid.c:42
#define PG_RETURN_ITEMPOINTER(x)
Definition: tid.c:43

Variable Documentation

◆ Current_last_tid

ItemPointerData Current_last_tid = {{0, 0}, 0}
static

Definition at line 278 of file tid.c.

Referenced by currtid_byreloid().