39 int stopLow = lowbound ? *lowbound : 0;
44 while (stopLow < stopHigh)
48 stopMiddle = stopLow + (stopHigh - stopLow) / 2;
58 *lowbound = stopMiddle + 1;
62 stopLow = stopMiddle + 1;
64 stopHigh = stopMiddle;
100 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
101 errmsg(
"number of pairs (%d) exceeds the maximum allowed (%d)",
106 for (
i = 0,
j = 0;
i < key_count;
i++)
112 key_pairs[
j].
val = NULL;
178 for (
i = 0;
i < nkeys;
i++)
181 key_pairs[
i].
key, key_pairs[
i].keylen);
212 for (
i = 0;
i < nkeys;
i++)
215 key_pairs[
i].
key, key_pairs[
i].keylen);
266 bufd = ptrd =
STRPTR(out);
269 for (
i = 0;
i < count; ++
i)
274 if (!(
len == keylen && memcmp(ptrs, keyptr, keylen) == 0))
331 for (
i =
j = 0;
i < hs_count;)
341 if (skeylen == key_pairs[
j].keylen)
344 key_pairs[
j].keylen);
414 for (
i =
j = 0;
i < hs_count;)
425 if (skeylen == s2keylen)
522 for (s1idx = s2idx = 0; s1idx < s1count || s2idx < s2count; ++outcount)
526 if (s1idx >= s1count)
528 else if (s2idx >= s2count)
535 if (s1keylen == s2keylen)
592 out_nulls =
palloc(
sizeof(
bool) * key_count);
594 for (
i = 0;
i < key_count; ++
i)
607 out_datums[
i] = (
Datum) 0;
614 out_nulls[
i] =
false;
622 TEXTOID, -1,
false, TYPALIGN_INT);
662 for (
i = 0;
i < nkeys; ++
i)
665 key_pairs[
i].
key, key_pairs[
i].keylen);
669 out_pairs[out_count].
key = key_pairs[
i].
key;
670 bufsiz += (out_pairs[out_count].
keylen = key_pairs[
i].
keylen);
674 out_pairs[out_count].
needfree =
false;
710 for (
i = 0;
i < count; ++
i)
745 nulls = (
bool *)
palloc(
sizeof(
bool) * count);
747 for (
i = 0;
i < count; ++
i)
765 TEXTOID, -1,
false, TYPALIGN_INT);
777 int out_size[2] = {0, 2};
785 if (count == 0 || ndims == 0)
788 out_size[0] = count * 2 / ndims;
790 out_nulls =
palloc(
sizeof(
bool) * count * 2);
792 for (
i = 0;
i < count; ++
i)
798 out_nulls[
i * 2] =
false;
802 out_datums[
i * 2 + 1] = (
Datum) 0;
803 out_nulls[
i * 2 + 1] =
true;
811 out_nulls[
i * 2 + 1] =
false;
817 TEXTOID, -1,
false, TYPALIGN_INT);
869 elog(
ERROR,
"return type must be a row type");
940 (funcctx)->call_cntr++;
968 char *tstr =
STRPTR(tmpl);
982 for (
i = 0;
res &&
i < tcount; ++
i)
1044 bool nulls[2] = {
false,
false};
1054 dvalues[1] = (
Datum) 0;
1090 if (hcount1 == 0 || hcount2 == 0)
1098 else if (hcount2 > 0)
1104 char *str1 =
STRPTR(hs1);
1105 char *str2 =
STRPTR(hs2);
1108 size_t len1 =
HSE_ENDPOS(ent1[2 * hcount1 - 1]);
1109 size_t len2 =
HSE_ENDPOS(ent2[2 * hcount2 - 1]);
1111 res = memcmp(str1, str2,
Min(len1, len2));
1117 else if (len1 < len2)
1119 else if (hcount1 > hcount2)
1121 else if (hcount2 > hcount1)
1125 int count = hcount1 * 2;
1128 for (
i = 0;
i < count; ++
i)
1147 res = (
res > 0) ? 1 : -1;
Datum idx(PG_FUNCTION_ARGS)
#define PG_GETARG_ARRAYTYPE_P(n)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
ArrayType * construct_empty_array(Oid elmtype)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
#define Assert(condition)
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_GETARG_TEXT_PP(n)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_INT64(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define SRF_RETURN_DONE(_funcctx)
Datum difference(PG_FUNCTION_ARGS)
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
static Datum hash_any(const unsigned char *k, int keylen)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define CALCDATASIZE(x, lenstr)
#define HS_FINALIZE(hsp_, count_, buf_, ptr_)
#define HSTORE_KEY(arr_, str_, i_)
#define HS_FIXSIZE(hsp_, count_)
#define PG_GETARG_HSTORE_P(x)
#define HSTORE_VALISNULL(arr_, i_)
#define HSTORE_VALLEN(arr_, i_)
#define HSTORE_KEYLEN(arr_, i_)
#define HS_SETCOUNT(hsp_, c_)
#define HS_COPYITEM(dent_, dbuf_, dptr_, sptr_, klen_, vlen_, vnull_)
#define HSTORE_VAL(arr_, str_, i_)
Datum hstore_contained(PG_FUNCTION_ARGS)
Datum hstore_cmp(PG_FUNCTION_ARGS)
Pairs * hstoreArrayToPairs(ArrayType *a, int *npairs)
Datum hstore_slice_to_array(PG_FUNCTION_ARGS)
Datum hstore_slice_to_hstore(PG_FUNCTION_ARGS)
static ArrayType * hstore_to_array_internal(HStore *hs, int ndims)
Datum hstore_concat(PG_FUNCTION_ARGS)
Datum hstore_ne(PG_FUNCTION_ARGS)
Datum hstore_contains(PG_FUNCTION_ARGS)
Datum hstore_hash(PG_FUNCTION_ARGS)
Datum hstore_lt(PG_FUNCTION_ARGS)
Datum hstore_each(PG_FUNCTION_ARGS)
Datum hstore_eq(PG_FUNCTION_ARGS)
Datum hstore_delete(PG_FUNCTION_ARGS)
Datum hstore_delete_hstore(PG_FUNCTION_ARGS)
HSTORE_POLLUTE(hstore_fetchval, fetchval)
Datum hstore_le(PG_FUNCTION_ARGS)
Datum hstore_ge(PG_FUNCTION_ARGS)
Datum hstore_to_matrix(PG_FUNCTION_ARGS)
Datum hstore_svals(PG_FUNCTION_ARGS)
Datum hstore_avals(PG_FUNCTION_ARGS)
Datum hstore_akeys(PG_FUNCTION_ARGS)
Datum hstore_fetchval(PG_FUNCTION_ARGS)
Datum hstore_delete_array(PG_FUNCTION_ARGS)
Datum hstore_skeys(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(hstore_fetchval)
int hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen)
Datum hstore_hash_extended(PG_FUNCTION_ARGS)
Datum hstore_exists_any(PG_FUNCTION_ARGS)
Datum hstore_exists_all(PG_FUNCTION_ARGS)
Datum hstore_gt(PG_FUNCTION_ARGS)
Datum hstore_defined(PG_FUNCTION_ARGS)
Datum hstore_to_array(PG_FUNCTION_ARGS)
Datum hstore_exists(PG_FUNCTION_ARGS)
static void setup_firstcall(FuncCallContext *funcctx, HStore *hs, FunctionCallInfo fcinfo)
#define hstoreUniquePairs
if(TABLE==NULL||TABLE_index==NULL)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
static int32 DatumGetInt32(Datum X)
MemoryContextSwitchTo(old_ctx)
MemoryContext multi_call_memory_ctx
#define SET_VARSIZE(PTR, len)
#define VARSIZE_ANY_EXHDR(PTR)
text * cstring_to_text_with_len(const char *s, int len)