27#include "utils/fmgrprotos.h"
38 bool length_not_specified);
94#define PG_STR_GET_BYTEA(str_) \
95 DatumGetByteaPP(DirectFunctionCall1(byteain, CStringGetDatum(str_)))
101 bool length_not_specified)
112 if (length_not_specified)
124 (
errcode(ERRCODE_SUBSTRING_ERROR),
125 errmsg(
"negative substring length not allowed")));
172 (
errcode(ERRCODE_SUBSTRING_ERROR),
173 errmsg(
"negative substring length not allowed")));
176 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
177 errmsg(
"integer out of range")));
191#define VAL(CH) ((CH) - '0')
192#define DIG(VAL) ((VAL) + '0')
204 Node *escontext = fcinfo->context;
205 size_t len = strlen(inputText);
212 if (inputText[0] ==
'\\' && inputText[1] ==
'x')
232 else if ((tp[1] >=
'0' && tp[1] <=
'3') &&
233 (tp[2] >=
'0' && tp[2] <=
'7') &&
234 (tp[3] >=
'0' && tp[3] <=
'7'))
242 *rp++ = v +
VAL(tp[3]);
246 else if (tp[1] ==
'\\')
257 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
258 errmsg(
"invalid input syntax for type %s",
"bytea")));
302 else if ((
unsigned char) *vp < 0x20 || (
unsigned char) *vp > 0x7e)
315 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
327 else if ((
unsigned char) *vp < 0x20 || (
unsigned char) *vp > 0x7e)
346 elog(
ERROR,
"unrecognized \"bytea_output\" setting: %d",
364 nbytes =
buf->len -
buf->cursor;
395 bool isfirst =
false;
416 elog(
ERROR,
"bytea_string_agg_transfn called in non-aggregate context");
618 for (p = 0; p <=
px; p++)
620 if ((*p2 == *p1) && (memcmp(p1, p2, len2) == 0))
648 if (n < 0 || n >=
len)
650 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
651 errmsg(
"index %d out of valid range, 0..%d",
681 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
682 errmsg(
"index %" PRId64
" out of valid range, 0..%" PRId64,
686 byteNo = (int) (n / 8);
687 bitNo = (int) (n % 8);
691 if (
byte & (1 << bitNo))
715 if (n < 0 || n >=
len)
717 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
718 errmsg(
"index %d out of valid range, 0..%d",
724 ((
unsigned char *)
VARDATA(res))[n] = newByte;
753 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
754 errmsg(
"index %" PRId64
" out of valid range, 0..%" PRId64,
758 byteNo = (int) (n / 8);
759 bitNo = (int) (n % 8);
764 if (newBit != 0 && newBit != 1)
766 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
767 errmsg(
"new bit must be 0 or 1")));
772 oldByte = ((
unsigned char *)
VARDATA(res))[byteNo];
775 newByte = oldByte & (~(1 << bitNo));
777 newByte = oldByte | (1 << bitNo);
779 ((
unsigned char *)
VARDATA(res))[byteNo] = newByte;
793 const char *endp = p +
len;
971 if ((
cmp == 0) && (len1 != len2))
972 cmp = (len1 < len2) ? -1 : 1;
994 result = ((
cmp > 0) || ((
cmp == 0) && (len1 > len2)) ? arg1 : arg2);
1013 result = ((
cmp < 0) || ((
cmp == 0) && (len1 < len2)) ? arg1 : arg2);
1038 result = memcmp(a1p, a2p,
Min(len1, len2));
1039 if ((result == 0) && (len1 != len2))
1040 result = (len1 < len2) ? -1 : 1;
1060 const size_t max_prefix_bytes =
sizeof(
Datum);
1063 char *authoritative_data =
VARDATA_ANY(authoritative);
1069 pres = (
char *) &res;
1072 memset(pres, 0, max_prefix_bytes);
1096 memcpy(pres, authoritative_data,
Min(
len, max_prefix_bytes));
1137 pfree(authoritative);
1154 double abbrev_distinct,
1160 if (memtupcount < 100)
1171 if (abbrev_distinct < 1.0)
1172 abbrev_distinct = 1.0;
1174 if (key_distinct < 1.0)
1179 double norm_abbrev_card = abbrev_distinct / (double) memtupcount;
1181 elog(
LOG,
"bytea_abbrev: abbrev_distinct after %d: %f "
1182 "(key_distinct: %f, norm_abbrev_card: %f, prop_card: %f)",
1183 memtupcount, abbrev_distinct, key_distinct, norm_abbrev_card,
1191 if (abbrev_distinct > key_distinct * bss->
prop_card)
1196 if (memtupcount > 10000)
1206 elog(
LOG,
"bytea_abbrev: aborted abbreviation at %d "
1207 "(abbrev_distinct: %f, key_distinct: %f, prop_card: %f)",
1208 memtupcount, abbrev_distinct, key_distinct, bss->
prop_card);
1257 if (
len >
sizeof(result))
1259 errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1260 errmsg(
"smallint out of range"));
1264 for (
int i = 0;
i <
len;
i++)
1282 if (
len >
sizeof(result))
1284 errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1285 errmsg(
"integer out of range"));
1289 for (
int i = 0;
i <
len;
i++)
1307 if (
len >
sizeof(result))
1309 errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1310 errmsg(
"bigint out of range"));
1314 for (
int i = 0;
i <
len;
i++)
Datum byteacat(PG_FUNCTION_ARGS)
Datum byteaoverlay(PG_FUNCTION_ARGS)
Datum byteaeq(PG_FUNCTION_ARGS)
Datum byteagt(PG_FUNCTION_ARGS)
Datum bytea_int2(PG_FUNCTION_ARGS)
Datum bytea_string_agg_finalfn(PG_FUNCTION_ARGS)
Datum int2_bytea(PG_FUNCTION_ARGS)
Datum byteapos(PG_FUNCTION_ARGS)
static bytea * bytea_overlay(bytea *t1, bytea *t2, int sp, int sl)
Datum byteane(PG_FUNCTION_ARGS)
Datum byteage(PG_FUNCTION_ARGS)
Datum byteacmp(PG_FUNCTION_ARGS)
Datum byteaGetBit(PG_FUNCTION_ARGS)
Datum bytea_bit_count(PG_FUNCTION_ARGS)
Datum byteaSetBit(PG_FUNCTION_ARGS)
Datum byteaSetByte(PG_FUNCTION_ARGS)
static int byteafastcmp(Datum x, Datum y, SortSupport ssup)
Datum bytea_substr_no_len(PG_FUNCTION_ARGS)
Datum byteale(PG_FUNCTION_ARGS)
#define PG_STR_GET_BYTEA(str_)
Datum int8_bytea(PG_FUNCTION_ARGS)
Datum bytea_int4(PG_FUNCTION_ARGS)
Datum bytearecv(PG_FUNCTION_ARGS)
Datum bytea_smaller(PG_FUNCTION_ARGS)
Datum bytea_sortsupport(PG_FUNCTION_ARGS)
static bytea * bytea_substring(Datum str, int S, int L, bool length_not_specified)
static Datum bytea_abbrev_convert(Datum original, SortSupport ssup)
static bool bytea_abbrev_abort(int memtupcount, SortSupport ssup)
static bytea * bytea_catenate(bytea *t1, bytea *t2)
Datum bytea_reverse(PG_FUNCTION_ARGS)
Datum byteaoverlay_no_len(PG_FUNCTION_ARGS)
Datum bytea_int8(PG_FUNCTION_ARGS)
Datum bytea_larger(PG_FUNCTION_ARGS)
Datum byteaoctetlen(PG_FUNCTION_ARGS)
Datum byteaout(PG_FUNCTION_ARGS)
Datum byteain(PG_FUNCTION_ARGS)
Datum bytea_string_agg_transfn(PG_FUNCTION_ARGS)
Datum byteaGetByte(PG_FUNCTION_ARGS)
Datum int4_bytea(PG_FUNCTION_ARGS)
Datum bytea_substr(PG_FUNCTION_ARGS)
Datum bytealt(PG_FUNCTION_ARGS)
Datum byteasend(PG_FUNCTION_ARGS)
Size toast_raw_datum_size(Datum value)
int errmsg_internal(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
uint64 hex_decode_safe(const char *src, size_t len, char *dst, Node *escontext)
uint64 hex_encode(const char *src, size_t len, char *dst)
#define palloc_object(type)
#define PG_FREE_IF_COPY(ptr, n)
#define DatumGetByteaPSlice(X, m, n)
#define PG_GETARG_BYTEA_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define DatumGetByteaPP(X)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_RETURN_INT64(x)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_RETURN_INT16(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_POINTER(x)
#define PG_GETARG_BYTEA_P_COPY(n)
#define PG_RETURN_BOOL(x)
void px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
static Datum hash_uint32(uint32 k)
static Datum hash_any(const unsigned char *k, int keylen)
Assert(PointerIsAligned(start, uint64))
void initHyperLogLog(hyperLogLogState *cState, uint8 bwidth)
double estimateHyperLogLog(hyperLogLogState *cState)
void addHyperLogLog(hyperLogLogState *cState, uint32 hash)
Datum int8send(PG_FUNCTION_ARGS)
Datum int2send(PG_FUNCTION_ARGS)
Datum int4send(PG_FUNCTION_ARGS)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
void pfree(void *pointer)
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static uint64 pg_popcount(const char *buf, int bytes)
#define DatumBigEndianToNative(x)
#define PG_CACHE_LINE_SIZE
static char buf[DEFAULT_XLOG_SEG_SIZE]
static uint32 DatumGetUInt32(Datum X)
static uint64 DatumGetUInt64(Datum X)
static Datum PointerGetDatum(const void *X)
static int cmp(const chr *x, const chr *y, size_t len)
static unsigned hash(unsigned *uv, int n)
struct SortSupportData * SortSupport
struct StringInfoData * StringInfo
StringInfo makeStringInfo(void)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
hyperLogLogState full_card
hyperLogLogState abbr_card
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)
int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static Size VARSIZE(const void *PTR)
static char * VARDATA(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)