PostgreSQL Source Code git master
Loading...
Searching...
No Matches
uuid.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * uuid.c
4 * Functions for the built-in type "uuid".
5 *
6 * Copyright (c) 2007-2026, PostgreSQL Global Development Group
7 *
8 * IDENTIFICATION
9 * src/backend/utils/adt/uuid.c
10 *
11 *-------------------------------------------------------------------------
12 */
13
14#include "postgres.h"
15
16#include <limits.h>
17#include <time.h> /* for clock_gettime() */
18
19#include "common/hashfn.h"
20#include "lib/hyperloglog.h"
21#include "libpq/pqformat.h"
22#include "port/pg_bswap.h"
23#include "utils/fmgrprotos.h"
24#include "utils/guc.h"
25#include "utils/skipsupport.h"
26#include "utils/sortsupport.h"
27#include "utils/timestamp.h"
28#include "utils/uuid.h"
29
30/* helper macros */
31#define NS_PER_S INT64CONST(1000000000)
32#define NS_PER_MS INT64CONST(1000000)
33#define NS_PER_US INT64CONST(1000)
34#define US_PER_MS INT64CONST(1000)
35
36/*
37 * UUID version 7 uses 12 bits in "rand_a" to store 1/4096 (or 2^12) fractions of
38 * sub-millisecond. While most Unix-like platforms provide nanosecond-precision
39 * timestamps, some systems only offer microsecond precision, limiting us to 10
40 * bits of sub-millisecond information. For example, on macOS, real time is
41 * truncated to microseconds. Additionally, MSVC uses the ported version of
42 * gettimeofday() that returns microsecond precision.
43 *
44 * On systems with only 10 bits of sub-millisecond precision, we still use
45 * 1/4096 parts of a millisecond, but fill lower 2 bits with random numbers
46 * (see generate_uuidv7() for details).
47 *
48 * SUBMS_MINIMAL_STEP_NS defines the minimum number of nanoseconds that guarantees
49 * an increase in the UUID's clock precision.
50 */
51#if defined(__darwin__) || defined(_MSC_VER)
52#define SUBMS_MINIMAL_STEP_BITS 10
53#else
54#define SUBMS_MINIMAL_STEP_BITS 12
55#endif
56#define SUBMS_BITS 12
57#define SUBMS_MINIMAL_STEP_NS ((NS_PER_MS / (1 << SUBMS_MINIMAL_STEP_BITS)) + 1)
58
59/* sortsupport for uuid */
60typedef struct
61{
62 int64 input_count; /* number of non-null values seen */
63 bool estimating; /* true if estimating cardinality */
64
65 hyperLogLogState abbr_card; /* cardinality estimator */
67
68static void string_to_uuid(const char *source, pg_uuid_t *uuid, Node *escontext);
69static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2);
70static int uuid_fast_cmp(Datum x, Datum y, SortSupport ssup);
71static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup);
72static Datum uuid_abbrev_convert(Datum original, SortSupport ssup);
73static inline void uuid_set_version(pg_uuid_t *uuid, unsigned char version);
74static inline int64 get_real_time_ns_ascending(void);
76
87
90{
92 static const char hex_chars[] = "0123456789abcdef";
93 char *buf,
94 *p;
95 int i;
96
97 /* counts for the four hyphens and the zero-terminator */
98 buf = palloc(2 * UUID_LEN + 5);
99 p = buf;
100 for (i = 0; i < UUID_LEN; i++)
101 {
102 int hi;
103 int lo;
104
105 /*
106 * We print uuid values as a string of 8, 4, 4, 4, and then 12
107 * hexadecimal characters, with each group is separated by a hyphen
108 * ("-"). Therefore, add the hyphens at the appropriate places here.
109 */
110 if (i == 4 || i == 6 || i == 8 || i == 10)
111 *p++ = '-';
112
113 hi = uuid->data[i] >> 4;
114 lo = uuid->data[i] & 0x0F;
115
116 *p++ = hex_chars[hi];
117 *p++ = hex_chars[lo];
118 }
119 *p = '\0';
120
122}
123
124/*
125 * We allow UUIDs as a series of 32 hexadecimal digits with an optional dash
126 * after each group of 4 hexadecimal digits, and optionally surrounded by {}.
127 * (The canonical format 8x-4x-4x-4x-12x, where "nx" means n hexadecimal
128 * digits, is the only one used for output.)
129 */
130static void
131string_to_uuid(const char *source, pg_uuid_t *uuid, Node *escontext)
132{
133 const char *src = source;
134 bool braces = false;
135 int i;
136
137 if (src[0] == '{')
138 {
139 src++;
140 braces = true;
141 }
142
143 for (i = 0; i < UUID_LEN; i++)
144 {
145 char str_buf[3];
146
147 if (src[0] == '\0' || src[1] == '\0')
148 goto syntax_error;
149 memcpy(str_buf, src, 2);
150 if (!isxdigit((unsigned char) str_buf[0]) ||
151 !isxdigit((unsigned char) str_buf[1]))
152 goto syntax_error;
153
154 str_buf[2] = '\0';
155 uuid->data[i] = (unsigned char) strtoul(str_buf, NULL, 16);
156 src += 2;
157 if (src[0] == '-' && (i % 2) == 1 && i < UUID_LEN - 1)
158 src++;
159 }
160
161 if (braces)
162 {
163 if (*src != '}')
164 goto syntax_error;
165 src++;
166 }
167
168 if (*src != '\0')
169 goto syntax_error;
170
171 return;
172
174 ereturn(escontext,,
176 errmsg("invalid input syntax for type %s: \"%s\"",
177 "uuid", source)));
178}
179
180Datum
190
191Datum
193{
195 StringInfoData buffer;
196
197 pq_begintypsend(&buffer);
198 pq_sendbytes(&buffer, uuid->data, UUID_LEN);
200}
201
202/* internal uuid compare function */
203static int
205{
206 return memcmp(arg1->data, arg2->data, UUID_LEN);
207}
208
209Datum
217
218Datum
226
227Datum
235
236Datum
244
245Datum
253
254Datum
262
263/* handler for btree index operator */
264Datum
272
273/*
274 * Sort support strategy routine
275 */
276Datum
278{
280
282 ssup->ssup_extra = NULL;
283
284 if (ssup->abbreviate)
285 {
287 MemoryContext oldcontext;
288
289 oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
290
292 uss->input_count = 0;
293 uss->estimating = true;
294 initHyperLogLog(&uss->abbr_card, 10);
295
296 ssup->ssup_extra = uss;
297
302
303 MemoryContextSwitchTo(oldcontext);
304 }
305
307}
308
309/*
310 * SortSupport comparison func
311 */
312static int
320
321/*
322 * Callback for estimating effectiveness of abbreviated key optimization.
323 *
324 * We pay no attention to the cardinality of the non-abbreviated data, because
325 * there is no equality fast-path within authoritative uuid comparator.
326 */
327static bool
328uuid_abbrev_abort(int memtupcount, SortSupport ssup)
329{
331 double abbr_card;
332
334 return false;
335
336 abbr_card = estimateHyperLogLog(&uss->abbr_card);
337
338 /*
339 * If we have >100k distinct values, then even if we were sorting many
340 * billion rows we'd likely still break even, and the penalty of undoing
341 * that many rows of abbrevs would probably not be worth it. Stop even
342 * counting at that point.
343 */
344 if (abbr_card > 100000.0)
345 {
346 if (trace_sort)
347 elog(LOG,
348 "uuid_abbrev: estimation ends at cardinality %f"
349 " after " INT64_FORMAT " values (%d rows)",
350 abbr_card, uss->input_count, memtupcount);
351 uss->estimating = false;
352 return false;
353 }
354
355 /*
356 * Target minimum cardinality is 1 per ~2k of non-null inputs. 0.5 row
357 * fudge factor allows us to abort earlier on genuinely pathological data
358 * where we've had exactly one abbreviated value in the first 2k
359 * (non-null) rows.
360 */
361 if (abbr_card < uss->input_count / 2000.0 + 0.5)
362 {
363 if (trace_sort)
364 elog(LOG,
365 "uuid_abbrev: aborting abbreviation at cardinality %f"
366 " below threshold %f after " INT64_FORMAT " values (%d rows)",
367 abbr_card, uss->input_count / 2000.0 + 0.5, uss->input_count,
368 memtupcount);
369 return true;
370 }
371
372 if (trace_sort)
373 elog(LOG,
374 "uuid_abbrev: cardinality %f after " INT64_FORMAT
375 " values (%d rows)", abbr_card, uss->input_count, memtupcount);
376
377 return false;
378}
379
380/*
381 * Conversion routine for sortsupport. Converts original uuid representation
382 * to abbreviated key representation. Our encoding strategy is simple -- pack
383 * the first `sizeof(Datum)` bytes of uuid data into a Datum (on little-endian
384 * machines, the bytes are stored in reverse order), and treat it as an
385 * unsigned integer.
386 */
387static Datum
389{
392 Datum res;
393
394 memcpy(&res, authoritative->data, sizeof(Datum));
395 uss->input_count += 1;
396
397 if (uss->estimating)
398 {
399 uint32 tmp;
400
401 tmp = DatumGetUInt32(res) ^ (uint32) (DatumGetUInt64(res) >> 32);
402
403 addHyperLogLog(&uss->abbr_card, DatumGetUInt32(hash_uint32(tmp)));
404 }
405
406 /*
407 * Byteswap on little-endian machines.
408 *
409 * This is needed so that ssup_datum_unsigned_cmp() (an unsigned integer
410 * 3-way comparator) works correctly on all platforms. If we didn't do
411 * this, the comparator would have to call memcmp() with a pair of
412 * pointers to the first byte of each abbreviated key, which is slower.
413 */
414 res = DatumBigEndianToNative(res);
415
416 return res;
417}
418
419static Datum
421{
423
426 for (int i = UUID_LEN - 1; i >= 0; i--)
427 {
428 if (uuid->data[i] > 0)
429 {
430 uuid->data[i]--;
431 *underflow = false;
432 return UUIDPGetDatum(uuid);
433 }
434 uuid->data[i] = UCHAR_MAX;
435 }
436
437 pfree(uuid); /* cannot leak memory */
438
439 /* return value is undefined */
440 *underflow = true;
441 return (Datum) 0;
442}
443
444static Datum
446{
448
451 for (int i = UUID_LEN - 1; i >= 0; i--)
452 {
453 if (uuid->data[i] < UCHAR_MAX)
454 {
455 uuid->data[i]++;
456 *overflow = false;
457 return UUIDPGetDatum(uuid);
458 }
459 uuid->data[i] = 0;
460 }
461
462 pfree(uuid); /* cannot leak memory */
463
464 /* return value is undefined */
465 *overflow = true;
466 return (Datum) 0;
467}
468
469Datum
486
487/* hash index support */
488Datum
490{
491 pg_uuid_t *key = PG_GETARG_UUID_P(0);
492
493 return hash_any(key->data, UUID_LEN);
494}
495
496Datum
503
504/*
505 * Set the given UUID version and the variant bits
506 */
507static inline void
508uuid_set_version(pg_uuid_t *uuid, unsigned char version)
509{
510 /* set version field, top four bits */
511 uuid->data[6] = (uuid->data[6] & 0x0f) | (version << 4);
512
513 /* set variant field, top two bits are 1, 0 */
514 uuid->data[8] = (uuid->data[8] & 0x3f) | 0x80;
515}
516
517/*
518 * Generate UUID version 4.
519 *
520 * All UUID bytes are filled with strong random numbers except version and
521 * variant bits.
522 */
523Datum
525{
527
531 errmsg("could not generate random values")));
532
533 /*
534 * Set magic numbers for a "version 4" (pseudorandom) UUID and variant,
535 * see https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-4
536 */
538
540}
541
542/*
543 * Get the current timestamp with nanosecond precision for UUID generation.
544 * The returned timestamp is ensured to be at least SUBMS_MINIMAL_STEP greater
545 * than the previous returned timestamp (on this backend).
546 */
547static inline int64
549{
550 static int64 previous_ns = 0;
551 int64 ns;
552
553 /* Get the current real timestamp */
554
555#ifdef _MSC_VER
556 struct timeval tmp;
557
558 gettimeofday(&tmp, NULL);
559 ns = tmp.tv_sec * NS_PER_S + tmp.tv_usec * NS_PER_US;
560#else
561 struct timespec tmp;
562
563 /*
564 * We don't use gettimeofday(), instead use clock_gettime() with
565 * CLOCK_REALTIME where available in order to get a high-precision
566 * (nanoseconds) real timestamp.
567 *
568 * Note while a timestamp returned by clock_gettime() with CLOCK_REALTIME
569 * is nanosecond-precision on most Unix-like platforms, on some platforms
570 * such as macOS it's restricted to microsecond-precision.
571 */
573 ns = tmp.tv_sec * NS_PER_S + tmp.tv_nsec;
574#endif
575
576 /* Guarantee the minimal step advancement of the timestamp */
579 previous_ns = ns;
580
581 return ns;
582}
583
584/*
585 * Generate UUID version 7 per RFC 9562, with the given timestamp.
586 *
587 * UUID version 7 consists of a Unix timestamp in milliseconds (48 bits) and
588 * 74 random bits, excluding the required version and variant bits. To ensure
589 * monotonicity in scenarios of high-frequency UUID generation, we employ the
590 * method "Replace Leftmost Random Bits with Increased Clock Precision (Method 3)",
591 * described in the RFC. This method utilizes 12 bits from the "rand_a" bits
592 * to store a 1/4096 (or 2^12) fraction of sub-millisecond precision.
593 *
594 * unix_ts_ms is a number of milliseconds since start of the UNIX epoch,
595 * and sub_ms is a number of nanoseconds within millisecond. These values are
596 * used for time-dependent bits of UUID.
597 *
598 * NB: all numbers here are unsigned, unix_ts_ms cannot be negative per RFC.
599 */
600static pg_uuid_t *
602{
605
606 /* Fill in time part */
607 uuid->data[0] = (unsigned char) (unix_ts_ms >> 40);
608 uuid->data[1] = (unsigned char) (unix_ts_ms >> 32);
609 uuid->data[2] = (unsigned char) (unix_ts_ms >> 24);
610 uuid->data[3] = (unsigned char) (unix_ts_ms >> 16);
611 uuid->data[4] = (unsigned char) (unix_ts_ms >> 8);
612 uuid->data[5] = (unsigned char) unix_ts_ms;
613
614 /*
615 * sub-millisecond timestamp fraction (SUBMS_BITS bits, not
616 * SUBMS_MINIMAL_STEP_BITS)
617 */
619
620 /* Fill the increased clock precision to "rand_a" bits */
621 uuid->data[6] = (unsigned char) (increased_clock_precision >> 8);
622 uuid->data[7] = (unsigned char) (increased_clock_precision);
623
624 /* fill everything after the increased clock precision with random bytes */
625 if (!pg_strong_random(&uuid->data[8], UUID_LEN - 8))
628 errmsg("could not generate random values")));
629
630#if SUBMS_MINIMAL_STEP_BITS == 10
631
632 /*
633 * On systems that have only 10 bits of sub-ms precision, 2 least
634 * significant are dependent on other time-specific bits, and they do not
635 * contribute to uniqueness. To make these bit random we mix in two bits
636 * from CSPRNG. SUBMS_MINIMAL_STEP is chosen so that we still guarantee
637 * monotonicity despite altering these bits.
638 */
639 uuid->data[7] = uuid->data[7] ^ (uuid->data[8] >> 6);
640#endif
641
642 /*
643 * Set magic numbers for a "version 7" (pseudorandom) UUID and variant,
644 * see https://www.rfc-editor.org/rfc/rfc9562#name-version-field
645 */
647
648 return uuid;
649}
650
651/*
652 * Generate UUID version 7 with the current timestamp.
653 */
654Datum
662
663/*
664 * Similar to uuidv7() but with the timestamp adjusted by the given interval.
665 */
666Datum
668{
669 Interval *shift = PG_GETARG_INTERVAL_P(0);
670 TimestampTz ts;
673 int64 us;
674
675 /*
676 * Shift the current timestamp by the given interval. To calculate time
677 * shift correctly, we convert the UNIX epoch to TimestampTz and use
678 * timestamptz_pl_interval(). This calculation is done with microsecond
679 * precision.
680 */
681
682 ts = (TimestampTz) (ns / NS_PER_US) -
684
685 /* Compute time shift */
688 IntervalPGetDatum(shift)));
689
690 /* Convert a TimestampTz value back to an UNIX epoch timestamp */
692
693 /* Generate an UUIDv7 */
695
697}
698
699/*
700 * Start of a Gregorian epoch == date2j(1582,10,15)
701 * We cast it to 64-bit because it's used in overflow-prone computations
702 */
703#define GREGORIAN_EPOCH_JDATE INT64CONST(2299161)
704
705/*
706 * Extract timestamp from UUID.
707 *
708 * Returns null if not RFC 9562 variant or not a version that has a timestamp.
709 */
710Datum
712{
714 int version;
715 uint64 tms;
716 TimestampTz ts;
717
718 /* check if RFC 9562 variant */
719 if ((uuid->data[8] & 0xc0) != 0x80)
721
722 version = uuid->data[6] >> 4;
723
724 if (version == 1)
725 {
726 tms = ((uint64) uuid->data[0] << 24)
727 + ((uint64) uuid->data[1] << 16)
728 + ((uint64) uuid->data[2] << 8)
729 + ((uint64) uuid->data[3])
730 + ((uint64) uuid->data[4] << 40)
731 + ((uint64) uuid->data[5] << 32)
732 + (((uint64) uuid->data[6] & 0xf) << 56)
733 + ((uint64) uuid->data[7] << 48);
734
735 /* convert 100-ns intervals to us, then adjust */
736 ts = (TimestampTz) (tms / 10) -
739 }
740
741 if (version == 7)
742 {
743 tms = (uuid->data[5])
744 + (((uint64) uuid->data[4]) << 8)
745 + (((uint64) uuid->data[3]) << 16)
746 + (((uint64) uuid->data[2]) << 24)
747 + (((uint64) uuid->data[1]) << 32)
748 + (((uint64) uuid->data[0]) << 40);
749
750 /* convert ms to us, then adjust */
751 ts = (TimestampTz) (tms * US_PER_MS) -
753
755 }
756
757 /* not a timestamp-containing UUID version */
759}
760
761/*
762 * Extract UUID version.
763 *
764 * Returns null if not RFC 9562 variant.
765 */
766Datum
768{
770 uint16 version;
771
772 /* check if RFC 9562 variant */
773 if ((uuid->data[8] & 0xc0) != 0x80)
775
776 version = uuid->data[6] >> 4;
777
778 PG_RETURN_UINT16(version);
779}
Datum timestamptz_pl_interval(PG_FUNCTION_ARGS)
Definition timestamp.c:3380
#define INT64_FORMAT
Definition c.h:564
int64_t int64
Definition c.h:543
uint64_t uint64
Definition c.h:547
uint16_t uint16
Definition c.h:545
uint32_t uint32
Definition c.h:546
int64 TimestampTz
Definition timestamp.h:39
#define USECS_PER_SEC
Definition timestamp.h:134
#define UNIX_EPOCH_JDATE
Definition timestamp.h:234
#define SECS_PER_DAY
Definition timestamp.h:126
#define POSTGRES_EPOCH_JDATE
Definition timestamp.h:235
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define LOG
Definition elog.h:31
#define ereturn(context, dummy_value,...)
Definition elog.h:278
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
#define palloc_object(type)
Definition fe_memutils.h:74
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_RETURN_BYTEA_P(x)
Definition fmgr.h:373
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:686
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_CSTRING(x)
Definition fmgr.h:364
#define PG_GETARG_CSTRING(n)
Definition fmgr.h:278
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_GETARG_INT64(n)
Definition fmgr.h:284
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_RETURN_UINT16(x)
Definition fmgr.h:358
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
static Datum hash_uint32(uint32 k)
Definition hashfn.h:43
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
Definition hashfn.h:37
static Datum hash_any(const unsigned char *k, int keylen)
Definition hashfn.h:31
void initHyperLogLog(hyperLogLogState *cState, uint8 bwidth)
Definition hyperloglog.c:66
double estimateHyperLogLog(hyperLogLogState *cState)
void addHyperLogLog(hyperLogLogState *cState, uint32 hash)
int y
Definition isn.c:76
int x
Definition isn.c:75
int i
Definition isn.c:77
void pfree(void *pointer)
Definition mcxt.c:1616
void * palloc(Size size)
Definition mcxt.c:1387
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define DatumBigEndianToNative(x)
Definition pg_bswap.h:145
static rewind_source * source
Definition pg_rewind.c:89
static char buf[DEFAULT_XLOG_SEG_SIZE]
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:5581
bool pg_strong_random(void *buf, size_t len)
static uint32 DatumGetUInt32(Datum X)
Definition postgres.h:232
static uint64 DatumGetUInt64(Datum X)
Definition postgres.h:433
uint64_t Datum
Definition postgres.h:70
void pq_sendbytes(StringInfo buf, const void *data, int datalen)
Definition pqformat.c:126
void pq_begintypsend(StringInfo buf)
Definition pqformat.c:325
const char * pq_getmsgbytes(StringInfo msg, int datalen)
Definition pqformat.c:507
bytea * pq_endtypsend(StringInfo buf)
Definition pqformat.c:345
static int fb(int x)
struct SkipSupportData * SkipSupport
Definition skipsupport.h:50
struct SortSupportData * SortSupport
Definition sortsupport.h:58
struct StringInfoData * StringInfo
Definition string.h:15
Definition nodes.h:135
SkipSupportIncDec decrement
Definition skipsupport.h:91
SkipSupportIncDec increment
Definition skipsupport.h:92
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Datum(* abbrev_converter)(Datum original, SortSupport ssup)
MemoryContext ssup_cxt
Definition sortsupport.h:66
int(* abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup)
bool(* abbrev_abort)(int memtupcount, SortSupport ssup)
hyperLogLogState abbr_card
Definition uuid.c:65
int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup)
Definition tuplesort.c:3122
bool trace_sort
Definition tuplesort.c:122
static Datum TimestampTzGetDatum(TimestampTz X)
Definition timestamp.h:52
static Datum IntervalPGetDatum(const Interval *X)
Definition timestamp.h:58
#define PG_GETARG_INTERVAL_P(n)
Definition timestamp.h:65
#define PG_RETURN_TIMESTAMPTZ(x)
Definition timestamp.h:68
static TimestampTz DatumGetTimestampTz(Datum X)
Definition timestamp.h:34
#define uuid_hash
Definition uuid-ossp.c:31
Datum uuid_skipsupport(PG_FUNCTION_ARGS)
Definition uuid.c:470
#define US_PER_MS
Definition uuid.c:34
#define SUBMS_BITS
Definition uuid.c:56
Datum uuid_send(PG_FUNCTION_ARGS)
Definition uuid.c:192
static void string_to_uuid(const char *source, pg_uuid_t *uuid, Node *escontext)
Definition uuid.c:131
static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup)
Definition uuid.c:328
#define GREGORIAN_EPOCH_JDATE
Definition uuid.c:703
Datum uuidv7_interval(PG_FUNCTION_ARGS)
Definition uuid.c:667
Datum uuid_lt(PG_FUNCTION_ARGS)
Definition uuid.c:210
Datum uuid_gt(PG_FUNCTION_ARGS)
Definition uuid.c:246
Datum gen_random_uuid(PG_FUNCTION_ARGS)
Definition uuid.c:524
Datum uuid_recv(PG_FUNCTION_ARGS)
Definition uuid.c:181
Datum uuid_cmp(PG_FUNCTION_ARGS)
Definition uuid.c:265
#define NS_PER_MS
Definition uuid.c:32
static void uuid_set_version(pg_uuid_t *uuid, unsigned char version)
Definition uuid.c:508
Datum uuid_le(PG_FUNCTION_ARGS)
Definition uuid.c:219
#define SUBMS_MINIMAL_STEP_NS
Definition uuid.c:57
#define NS_PER_S
Definition uuid.c:31
static int64 get_real_time_ns_ascending(void)
Definition uuid.c:548
Datum uuid_extract_version(PG_FUNCTION_ARGS)
Definition uuid.c:767
Datum uuid_hash_extended(PG_FUNCTION_ARGS)
Definition uuid.c:497
Datum uuid_out(PG_FUNCTION_ARGS)
Definition uuid.c:89
Datum uuid_ne(PG_FUNCTION_ARGS)
Definition uuid.c:255
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
Definition uuid.c:204
Datum uuid_ge(PG_FUNCTION_ARGS)
Definition uuid.c:237
static Datum uuid_increment(Relation rel, Datum existing, bool *overflow)
Definition uuid.c:445
Datum uuid_eq(PG_FUNCTION_ARGS)
Definition uuid.c:228
static pg_uuid_t * generate_uuidv7(uint64 unix_ts_ms, uint32 sub_ms)
Definition uuid.c:601
#define NS_PER_US
Definition uuid.c:33
static int uuid_fast_cmp(Datum x, Datum y, SortSupport ssup)
Definition uuid.c:313
Datum uuid_in(PG_FUNCTION_ARGS)
Definition uuid.c:78
static Datum uuid_decrement(Relation rel, Datum existing, bool *underflow)
Definition uuid.c:420
static Datum uuid_abbrev_convert(Datum original, SortSupport ssup)
Definition uuid.c:388
Datum uuidv7(PG_FUNCTION_ARGS)
Definition uuid.c:655
Datum uuid_extract_timestamp(PG_FUNCTION_ARGS)
Definition uuid.c:711
Datum uuid_sortsupport(PG_FUNCTION_ARGS)
Definition uuid.c:277
static pg_uuid_t * DatumGetUUIDP(Datum X)
Definition uuid.h:35
#define PG_RETURN_UUID_P(X)
Definition uuid.h:32
#define UUID_LEN
Definition uuid.h:18
static Datum UUIDPGetDatum(const pg_uuid_t *X)
Definition uuid.h:27
#define PG_GETARG_UUID_P(X)
Definition uuid.h:40
int gettimeofday(struct timeval *tp, void *tzp)