20 #include "utils/fmgrprotos.h"
56 static const char hex_chars[] =
"0123456789abcdef";
74 if (
i == 4 ||
i == 6 ||
i == 8 ||
i == 10)
77 hi = uuid->
data[
i] >> 4;
78 lo = uuid->
data[
i] & 0x0F;
111 if (src[0] ==
'\0' || src[1] ==
'\0')
113 memcpy(str_buf, src, 2);
114 if (!isxdigit((
unsigned char) str_buf[0]) ||
115 !isxdigit((
unsigned char) str_buf[1]))
119 uuid->
data[
i] = (
unsigned char) strtoul(str_buf, NULL, 16);
121 if (src[0] ==
'-' && (
i % 2) == 1 &&
i <
UUID_LEN - 1)
139 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
140 errmsg(
"invalid input syntax for type %s: \"%s\"",
297 if (memtupcount < 10000 || uss->input_count < 10000 || !uss->estimating)
308 if (abbr_card > 100000.0)
312 "uuid_abbrev: estimation ends at cardinality %f"
325 if (abbr_card < uss->input_count / 2000.0 + 0.5)
329 "uuid_abbrev: aborting abbreviation at cardinality %f"
330 " below threshold %f after " INT64_FORMAT " values (%d rows)",
339 " values (%d rows)", abbr_card, uss->
input_count, memtupcount);
365 #if SIZEOF_DATUM == 8
382 res = DatumBigEndianToNative(
res);
411 (
errcode(ERRCODE_INTERNAL_ERROR),
412 errmsg(
"could not generate random values")));
418 uuid->
data[6] = (uuid->
data[6] & 0x0f) | 0x40;
419 uuid->
data[8] = (uuid->
data[8] & 0x3f) | 0x80;
424 #define UUIDV1_EPOCH_JDATE 2299161
440 if ((uuid->
data[8] & 0xc0) != 0x80)
443 version = uuid->
data[6] >> 4;
447 tms = ((uint64) uuid->
data[0] << 24)
448 + ((uint64) uuid->
data[1] << 16)
449 + ((uint64) uuid->
data[2] << 8)
450 + ((uint64) uuid->
data[3])
451 + ((uint64) uuid->
data[4] << 40)
452 + ((uint64) uuid->
data[5] << 32)
453 + (((uint64) uuid->
data[6] & 0xf) << 56)
454 + ((uint64) uuid->
data[7] << 48);
479 if ((uuid->
data[8] & 0xc0) != 0x80)
482 version = uuid->
data[6] >> 4;
#define POSTGRES_EPOCH_JDATE
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_RETURN_INT32(x)
#define PG_RETURN_UINT16(x)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
static Datum hash_uint32(uint32 k)
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
static Datum hash_any(const unsigned char *k, int keylen)
void initHyperLogLog(hyperLogLogState *cState, uint8 bwidth)
double estimateHyperLogLog(hyperLogLogState *cState)
void addHyperLogLog(hyperLogLogState *cState, uint32 hash)
static rewind_source * source
void syntax_error(const char *source, int lineno, const char *line, const char *command, const char *msg, const char *more, int column)
bool pg_strong_random(void *buf, size_t len)
static uint32 DatumGetUInt32(Datum X)
MemoryContextSwitchTo(old_ctx)
struct SortSupportData * SortSupport
StringInfoData * StringInfo
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Datum(* abbrev_converter)(Datum original, SortSupport ssup)
int(* abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup)
bool(* abbrev_abort)(int memtupcount, SortSupport ssup)
unsigned char data[UUID_LEN]
hyperLogLogState abbr_card
int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup)
#define PG_RETURN_TIMESTAMPTZ(x)
Datum uuid_send(PG_FUNCTION_ARGS)
static void string_to_uuid(const char *source, pg_uuid_t *uuid, Node *escontext)
static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup)
Datum uuid_lt(PG_FUNCTION_ARGS)
Datum uuid_gt(PG_FUNCTION_ARGS)
Datum gen_random_uuid(PG_FUNCTION_ARGS)
Datum uuid_recv(PG_FUNCTION_ARGS)
Datum uuid_cmp(PG_FUNCTION_ARGS)
#define UUIDV1_EPOCH_JDATE
Datum uuid_le(PG_FUNCTION_ARGS)
Datum uuid_hash(PG_FUNCTION_ARGS)
Datum uuid_extract_version(PG_FUNCTION_ARGS)
Datum uuid_hash_extended(PG_FUNCTION_ARGS)
Datum uuid_out(PG_FUNCTION_ARGS)
Datum uuid_ne(PG_FUNCTION_ARGS)
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
Datum uuid_ge(PG_FUNCTION_ARGS)
Datum uuid_eq(PG_FUNCTION_ARGS)
static int uuid_fast_cmp(Datum x, Datum y, SortSupport ssup)
Datum uuid_in(PG_FUNCTION_ARGS)
static Datum uuid_abbrev_convert(Datum original, SortSupport ssup)
Datum uuid_extract_timestamp(PG_FUNCTION_ARGS)
Datum uuid_sortsupport(PG_FUNCTION_ARGS)
#define PG_RETURN_UUID_P(X)
static pg_uuid_t * DatumGetUUIDP(Datum X)
#define PG_GETARG_UUID_P(X)