20 #include "utils/fmgrprotos.h"
30 #define hibits(addr) \
31 ((unsigned long)(((addr)->a<<16)|((addr)->b<<8)|((addr)->c)))
33 #define lobits(addr) \
34 ((unsigned long)(((addr)->d<<16)|((addr)->e<<8)|((addr)->f)))
58 Node *escontext = fcinfo->context;
71 count = sscanf(
str,
"%x:%x:%x:%x:%x:%x%1s",
72 &
a, &
b, &
c, &d, &
e, &f, junk);
74 count = sscanf(
str,
"%x-%x-%x-%x-%x-%x%1s",
75 &
a, &
b, &
c, &d, &
e, &f, junk);
77 count = sscanf(
str,
"%2x%2x%2x:%2x%2x%2x%1s",
78 &
a, &
b, &
c, &d, &
e, &f, junk);
80 count = sscanf(
str,
"%2x%2x%2x-%2x%2x%2x%1s",
81 &
a, &
b, &
c, &d, &
e, &f, junk);
83 count = sscanf(
str,
"%2x%2x.%2x%2x.%2x%2x%1s",
84 &
a, &
b, &
c, &d, &
e, &f, junk);
86 count = sscanf(
str,
"%2x%2x-%2x%2x-%2x%2x%1s",
87 &
a, &
b, &
c, &d, &
e, &f, junk);
89 count = sscanf(
str,
"%2x%2x%2x%2x%2x%2x%1s",
90 &
a, &
b, &
c, &d, &
e, &f, junk);
93 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
94 errmsg(
"invalid input syntax for type %s: \"%s\"",
"macaddr",
97 if ((
a < 0) || (
a > 255) || (
b < 0) || (
b > 255) ||
98 (
c < 0) || (
c > 255) || (d < 0) || (d > 255) ||
99 (
e < 0) || (
e > 255) || (f < 0) || (f > 255))
101 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
102 errmsg(
"invalid octet value in \"macaddr\" value: \"%s\"",
str)));
126 result = (
char *)
palloc(32);
128 snprintf(result, 32,
"%02x:%02x:%02x:%02x:%02x:%02x",
129 addr->
a, addr->
b, addr->
c, addr->
d, addr->
e, addr->
f);
293 result->
a = ~addr->
a;
294 result->
b = ~addr->
b;
295 result->
c = ~addr->
c;
296 result->
d = ~addr->
d;
297 result->
e = ~addr->
e;
298 result->
f = ~addr->
f;
310 result->
a = addr1->
a & addr2->
a;
311 result->
b = addr1->
b & addr2->
b;
312 result->
c = addr1->
c & addr2->
c;
313 result->
d = addr1->
d & addr2->
d;
314 result->
e = addr1->
e & addr2->
e;
315 result->
f = addr1->
f & addr2->
f;
327 result->
a = addr1->
a | addr2->
a;
328 result->
b = addr1->
b | addr2->
b;
329 result->
c = addr1->
c | addr2->
c;
330 result->
d = addr1->
d | addr2->
d;
331 result->
e = addr1->
e | addr2->
e;
332 result->
f = addr1->
f | addr2->
f;
420 if (memtupcount < 10000 || uss->input_count < 10000 || !uss->estimating)
431 if (abbr_card > 100000.0)
435 "macaddr_abbrev: estimation ends at cardinality %f"
448 if (abbr_card < uss->input_count / 2000.0 + 0.5)
452 "macaddr_abbrev: aborting abbreviation at cardinality %f"
453 " below threshold %f after " INT64_FORMAT " values (%d rows)",
462 " values (%d rows)", abbr_card, uss->
input_count, memtupcount);
488 #if SIZEOF_DATUM == 8
506 #if SIZEOF_DATUM == 8
523 res = DatumBigEndianToNative(
res);
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#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_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)
static const FormData_pg_attribute a1
static const FormData_pg_attribute a2
void initHyperLogLog(hyperLogLogState *cState, uint8 bwidth)
double estimateHyperLogLog(hyperLogLogState *cState)
void addHyperLogLog(hyperLogLogState *cState, uint32 hash)
Datum macaddr_lt(PG_FUNCTION_ARGS)
Datum macaddr_cmp(PG_FUNCTION_ARGS)
static int macaddr_cmp_internal(macaddr *a1, macaddr *a2)
Datum hashmacaddrextended(PG_FUNCTION_ARGS)
Datum hashmacaddr(PG_FUNCTION_ARGS)
static Datum macaddr_abbrev_convert(Datum original, SortSupport ssup)
Datum macaddr_or(PG_FUNCTION_ARGS)
Datum macaddr_recv(PG_FUNCTION_ARGS)
Datum macaddr_ne(PG_FUNCTION_ARGS)
Datum macaddr_trunc(PG_FUNCTION_ARGS)
Datum macaddr_eq(PG_FUNCTION_ARGS)
Datum macaddr_in(PG_FUNCTION_ARGS)
Datum macaddr_not(PG_FUNCTION_ARGS)
static bool macaddr_abbrev_abort(int memtupcount, SortSupport ssup)
Datum macaddr_and(PG_FUNCTION_ARGS)
Datum macaddr_send(PG_FUNCTION_ARGS)
Datum macaddr_sortsupport(PG_FUNCTION_ARGS)
Datum macaddr_ge(PG_FUNCTION_ARGS)
static int macaddr_fast_cmp(Datum x, Datum y, SortSupport ssup)
Datum macaddr_le(PG_FUNCTION_ARGS)
Datum macaddr_out(PG_FUNCTION_ARGS)
Datum macaddr_gt(PG_FUNCTION_ARGS)
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)
hyperLogLogState abbr_card
int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup)
#define PG_GETARG_MACADDR_P(n)
#define PG_RETURN_MACADDR_P(x)
static macaddr * DatumGetMacaddrP(Datum X)