PostgreSQL Source Code git master
Macros | Functions
pg_lsn.c File Reference
#include "postgres.h"
#include "libpq/pqformat.h"
#include "utils/fmgrprotos.h"
#include "utils/numeric.h"
#include "utils/pg_lsn.h"
Include dependency graph for pg_lsn.c:

Go to the source code of this file.

Macros

#define  MAXPG_LSNLEN   17
 
#define  MAXPG_LSNCOMPONENT   8
 

Functions

XLogRecPtr  pg_lsn_in_safe (const char *str, Node *escontext)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Macro Definition Documentation

MAXPG_LSNCOMPONENT

#define MAXPG_LSNCOMPONENT   8

Definition at line 22 of file pg_lsn.c.

MAXPG_LSNLEN

#define MAXPG_LSNLEN   17

Definition at line 21 of file pg_lsn.c.

Function Documentation

pg_lsn_cmp()

Datum pg_lsn_cmp ( PG_FUNCTION_ARGS  )

Definition at line 186 of file pg_lsn.c.

187{
190
191 if (a > b)
193 else if (a == b)
195 else
196 PG_RETURN_INT32(-1);
197}
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
b
int b
Definition: isn.c:74
a
int a
Definition: isn.c:73
#define PG_GETARG_LSN(n)
Definition: pg_lsn.h:36
uint64 XLogRecPtr
Definition: xlogdefs.h:21

References a, b, PG_GETARG_LSN, and PG_RETURN_INT32.

pg_lsn_eq()

Datum pg_lsn_eq ( PG_FUNCTION_ARGS  )

Definition at line 113 of file pg_lsn.c.

114{
115 XLogRecPtr lsn1 = PG_GETARG_LSN(0);
116 XLogRecPtr lsn2 = PG_GETARG_LSN(1);
117
118 PG_RETURN_BOOL(lsn1 == lsn2);
119}
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

References PG_GETARG_LSN, and PG_RETURN_BOOL.

pg_lsn_ge()

Datum pg_lsn_ge ( PG_FUNCTION_ARGS  )

Definition at line 158 of file pg_lsn.c.

159{
160 XLogRecPtr lsn1 = PG_GETARG_LSN(0);
161 XLogRecPtr lsn2 = PG_GETARG_LSN(1);
162
163 PG_RETURN_BOOL(lsn1 >= lsn2);
164}

References PG_GETARG_LSN, and PG_RETURN_BOOL.

pg_lsn_gt()

Datum pg_lsn_gt ( PG_FUNCTION_ARGS  )

Definition at line 140 of file pg_lsn.c.

141{
142 XLogRecPtr lsn1 = PG_GETARG_LSN(0);
143 XLogRecPtr lsn2 = PG_GETARG_LSN(1);
144
145 PG_RETURN_BOOL(lsn1 > lsn2);
146}

References PG_GETARG_LSN, and PG_RETURN_BOOL.

pg_lsn_hash()

Datum pg_lsn_hash ( PG_FUNCTION_ARGS  )

Definition at line 201 of file pg_lsn.c.

202{
203 /* We can use hashint8 directly */
204 return hashint8(fcinfo);
205}
Datum hashint8(PG_FUNCTION_ARGS)
Definition: hashfunc.c:83

References hashint8().

pg_lsn_hash_extended()

Datum pg_lsn_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 208 of file pg_lsn.c.

209{
210 return hashint8extended(fcinfo);
211}
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:103

References hashint8extended().

pg_lsn_in()

Datum pg_lsn_in ( PG_FUNCTION_ARGS  )

Definition at line 64 of file pg_lsn.c.

65{
66 char *str = PG_GETARG_CSTRING(0);
67 XLogRecPtr result;
68
69 result = pg_lsn_in_safe(str, fcinfo->context);
70
71 PG_RETURN_LSN(result);
72}
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
const char * str
XLogRecPtr pg_lsn_in_safe(const char *str, Node *escontext)
Definition: pg_lsn.c:32
#define PG_RETURN_LSN(x)
Definition: pg_lsn.h:37

References PG_GETARG_CSTRING, pg_lsn_in_safe(), PG_RETURN_LSN, and str.

Referenced by libpqrcv_create_slot(), and parse_subscription_options().

pg_lsn_in_safe()

XLogRecPtr pg_lsn_in_safe ( const char *  str,
Nodeescontext 
)

Definition at line 32 of file pg_lsn.c.

33{
34 int len1,
35 len2;
36 uint32 id,
37 off;
38 XLogRecPtr result;
39
40 /* Sanity check input format. */
41 len1 = strspn(str, "0123456789abcdefABCDEF");
42 if (len1 < 1 || len1 > MAXPG_LSNCOMPONENT || str[len1] != '/')
43 goto syntax_error;
44
45 len2 = strspn(str + len1 + 1, "0123456789abcdefABCDEF");
46 if (len2 < 1 || len2 > MAXPG_LSNCOMPONENT || str[len1 + 1 + len2] != '0円')
47 goto syntax_error;
48
49 /* Decode result. */
50 id = (uint32) strtoul(str, NULL, 16);
51 off = (uint32) strtoul(str + len1 + 1, NULL, 16);
52 result = ((uint64) id << 32) | off;
53
54 return result;
55
57 ereturn(escontext, InvalidXLogRecPtr,
58 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
59 errmsg("invalid input syntax for type %s: \"%s\"",
60 "pg_lsn", str)));
61}
uint64_t uint64
Definition: c.h:539
uint32_t uint32
Definition: c.h:538
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ereturn(context, dummy_value,...)
Definition: elog.h:278
#define MAXPG_LSNCOMPONENT
Definition: pg_lsn.c:22
void syntax_error(const char *source, int lineno, const char *line, const char *command, const char *msg, const char *more, int column)
Definition: pgbench.c:5551
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28

References ereturn, errcode(), errmsg(), InvalidXLogRecPtr, MAXPG_LSNCOMPONENT, str, and syntax_error().

Referenced by check_recovery_target_lsn(), and pg_lsn_in().

pg_lsn_larger()

Datum pg_lsn_larger ( PG_FUNCTION_ARGS  )

Definition at line 167 of file pg_lsn.c.

168{
169 XLogRecPtr lsn1 = PG_GETARG_LSN(0);
170 XLogRecPtr lsn2 = PG_GETARG_LSN(1);
171
172 PG_RETURN_LSN((lsn1 > lsn2) ? lsn1 : lsn2);
173}

References PG_GETARG_LSN, and PG_RETURN_LSN.

pg_lsn_le()

Datum pg_lsn_le ( PG_FUNCTION_ARGS  )

Definition at line 149 of file pg_lsn.c.

150{
151 XLogRecPtr lsn1 = PG_GETARG_LSN(0);
152 XLogRecPtr lsn2 = PG_GETARG_LSN(1);
153
154 PG_RETURN_BOOL(lsn1 <= lsn2);
155}

References PG_GETARG_LSN, and PG_RETURN_BOOL.

pg_lsn_lt()

Datum pg_lsn_lt ( PG_FUNCTION_ARGS  )

Definition at line 131 of file pg_lsn.c.

132{
133 XLogRecPtr lsn1 = PG_GETARG_LSN(0);
134 XLogRecPtr lsn2 = PG_GETARG_LSN(1);
135
136 PG_RETURN_BOOL(lsn1 < lsn2);
137}

References PG_GETARG_LSN, and PG_RETURN_BOOL.

pg_lsn_mi()

Datum pg_lsn_mi ( PG_FUNCTION_ARGS  )

Definition at line 219 of file pg_lsn.c.

220{
221 XLogRecPtr lsn1 = PG_GETARG_LSN(0);
222 XLogRecPtr lsn2 = PG_GETARG_LSN(1);
223 char buf[256];
224 Datum result;
225
226 /* Output could be as large as plus or minus 2^63 - 1. */
227 if (lsn1 < lsn2)
228 snprintf(buf, sizeof buf, "-" UINT64_FORMAT, lsn2 - lsn1);
229 else
230 snprintf(buf, sizeof buf, UINT64_FORMAT, lsn1 - lsn2);
231
232 /* Convert to numeric. */
236 Int32GetDatum(-1));
237
238 return result;
239}
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:626
#define UINT64_FORMAT
Definition: c.h:557
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:686
static char * buf
Definition: pg_test_fsync.c:72
#define snprintf
Definition: port.h:239
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
uint64_t Datum
Definition: postgres.h:70
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:360
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:222

References buf, CStringGetDatum(), DirectFunctionCall3, Int32GetDatum(), numeric_in(), ObjectIdGetDatum(), PG_GETARG_LSN, snprintf, and UINT64_FORMAT.

Referenced by pg_wal_lsn_diff().

pg_lsn_mii()

Datum pg_lsn_mii ( PG_FUNCTION_ARGS  )

Definition at line 280 of file pg_lsn.c.

281{
282 XLogRecPtr lsn = PG_GETARG_LSN(0);
283 Numeric nbytes = PG_GETARG_NUMERIC(1);
284 Datum num;
285 Datum res;
286 char buf[32];
287
288 if (numeric_is_nan(nbytes))
290 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
291 errmsg("cannot subtract NaN from pg_lsn")));
292
293 /* Convert to numeric */
294 snprintf(buf, sizeof(buf), UINT64_FORMAT, lsn);
298 Int32GetDatum(-1));
299
300 /* Subtract two numerics */
302 num,
303 NumericGetDatum(nbytes));
304
305 /* Convert to pg_lsn */
307}
Datum numeric_sub(PG_FUNCTION_ARGS)
Definition: numeric.c:2940
bool numeric_is_nan(Numeric num)
Definition: numeric.c:834
Datum numeric_pg_lsn(PG_FUNCTION_ARGS)
Definition: numeric.c:4679
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:684
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:682
#define PG_GETARG_NUMERIC(n)
Definition: numeric.h:81
static Datum NumericGetDatum(Numeric X)
Definition: numeric.h:76

References buf, CStringGetDatum(), DirectFunctionCall1, DirectFunctionCall2, DirectFunctionCall3, ereport, errcode(), errmsg(), ERROR, Int32GetDatum(), numeric_in(), numeric_is_nan(), numeric_pg_lsn(), numeric_sub(), NumericGetDatum(), ObjectIdGetDatum(), PG_GETARG_LSN, PG_GETARG_NUMERIC, snprintf, and UINT64_FORMAT.

pg_lsn_ne()

Datum pg_lsn_ne ( PG_FUNCTION_ARGS  )

Definition at line 122 of file pg_lsn.c.

123{
124 XLogRecPtr lsn1 = PG_GETARG_LSN(0);
125 XLogRecPtr lsn2 = PG_GETARG_LSN(1);
126
127 PG_RETURN_BOOL(lsn1 != lsn2);
128}

References PG_GETARG_LSN, and PG_RETURN_BOOL.

pg_lsn_out()

Datum pg_lsn_out ( PG_FUNCTION_ARGS  )

Definition at line 75 of file pg_lsn.c.

76{
78 char buf[MAXPG_LSNLEN + 1];
79 char *result;
80
81 snprintf(buf, sizeof buf, "%X/%08X", LSN_FORMAT_ARGS(lsn));
82 result = pstrdup(buf);
83 PG_RETURN_CSTRING(result);
84}
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
char * pstrdup(const char *in)
Definition: mcxt.c:1759
#define MAXPG_LSNLEN
Definition: pg_lsn.c:21
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:46

References buf, LSN_FORMAT_ARGS, MAXPG_LSNLEN, PG_GETARG_LSN, PG_RETURN_CSTRING, pstrdup(), and snprintf.

pg_lsn_pli()

Datum pg_lsn_pli ( PG_FUNCTION_ARGS  )

Definition at line 246 of file pg_lsn.c.

247{
248 XLogRecPtr lsn = PG_GETARG_LSN(0);
249 Numeric nbytes = PG_GETARG_NUMERIC(1);
250 Datum num;
251 Datum res;
252 char buf[32];
253
254 if (numeric_is_nan(nbytes))
256 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
257 errmsg("cannot add NaN to pg_lsn")));
258
259 /* Convert to numeric */
260 snprintf(buf, sizeof(buf), UINT64_FORMAT, lsn);
264 Int32GetDatum(-1));
265
266 /* Add two numerics */
268 num,
269 NumericGetDatum(nbytes));
270
271 /* Convert to pg_lsn */
273}
Datum numeric_add(PG_FUNCTION_ARGS)
Definition: numeric.c:2865

References buf, CStringGetDatum(), DirectFunctionCall1, DirectFunctionCall2, DirectFunctionCall3, ereport, errcode(), errmsg(), ERROR, Int32GetDatum(), numeric_add(), numeric_in(), numeric_is_nan(), numeric_pg_lsn(), NumericGetDatum(), ObjectIdGetDatum(), PG_GETARG_LSN, PG_GETARG_NUMERIC, snprintf, and UINT64_FORMAT.

pg_lsn_recv()

Datum pg_lsn_recv ( PG_FUNCTION_ARGS  )

Definition at line 87 of file pg_lsn.c.

88{
90 XLogRecPtr result;
91
92 result = pq_getmsgint64(buf);
93 PG_RETURN_LSN(result);
94}
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:453
struct StringInfoData * StringInfo
Definition: string.h:15

References buf, PG_GETARG_POINTER, PG_RETURN_LSN, and pq_getmsgint64().

pg_lsn_send()

Datum pg_lsn_send ( PG_FUNCTION_ARGS  )

Definition at line 97 of file pg_lsn.c.

98{
101
103 pq_sendint64(&buf, lsn);
105}
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:326
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:346
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:152

References buf, PG_GETARG_LSN, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint64().

pg_lsn_smaller()

Datum pg_lsn_smaller ( PG_FUNCTION_ARGS  )

Definition at line 176 of file pg_lsn.c.

177{
178 XLogRecPtr lsn1 = PG_GETARG_LSN(0);
179 XLogRecPtr lsn2 = PG_GETARG_LSN(1);
180
181 PG_RETURN_LSN((lsn1 < lsn2) ? lsn1 : lsn2);
182}

References PG_GETARG_LSN, and PG_RETURN_LSN.

AltStyle によって変換されたページ (->オリジナル) /