15 #include "access/xact.h" 16 #include "executor/spi.h" 18 #include "utils/hsearch.h" 19 #include "utils/memutils.h" 38 char *out = palloc(VARSIZE(in) - VARHDRSZ + 1);
39 memcpy(out, VARDATA(in), VARSIZE(in) - VARHDRSZ);
40 out[VARSIZE(in) - VARHDRSZ] =
'\0';
55 text *out = palloc(len + VARHDRSZ);
56 memcpy(VARDATA(out), in, len);
57 SET_VARSIZE(out, (len + VARHDRSZ));
80 out = palloc(len + VARHDRSZ);
81 memcpy(VARDATA(out), in, len);
82 SET_VARSIZE(out, (len + VARHDRSZ));
97 char *
new = palloc((
sizeof(
char) * strlen(str) + 1));
111 char *
new = palloc((
sizeof(
char) * 17));
113 sprintf(
new,
"%d", val);
126 char *
new = palloc((
sizeof(
char) * 2));
147 bool success =
false;
148 TransactionId this_xid;
151 static bool done =
false;
152 static TransactionId xid = 0;
155 this_xid = GetCurrentTransactionId();
156 if (xid == this_xid) {
162 if (ok != SPI_OK_CONNECT) {
164 (errcode(ERRCODE_INTERNAL_ERROR),
165 errmsg(
"failed to initialise session (1)"),
166 errdetail(
"SPI_connect() failed, returning %d.", ok)));
174 (errcode(ERRCODE_INTERNAL_ERROR),
175 errmsg(
"failed to initialise session (2)"),
176 errdetail(
"veil_init() did not return true.")));
180 if (ok != SPI_OK_FINISH) {
182 (errcode(ERRCODE_INTERNAL_ERROR),
183 errmsg(
"failed to initialise session (3)"),
184 errdetail(
"SPI_finish() failed, returning %d.", ok)));
204 (errcode(ERRCODE_INTERNAL_ERROR),
205 errmsg(
"type mismatch in %s: expected %s, got %s",
207 errdetail(
"Variable %s is not of the expected type.", name)));
231 if (i4v->
type != OBJ_INT4) {
268 if (range->
type != OBJ_RANGE) {
305 if (bitmap->
type != OBJ_BITMAP) {
306 if (allow_ref && (bitmap->
type == OBJ_BITMAP_REF)) {
308 if (bmref->
xid == GetCurrentTransactionId()) {
313 (errcode(ERRCODE_INTERNAL_ERROR),
314 errmsg(
"BitmapRef %s is not defined",
316 errhint(
"Perhaps the name is mis-spelled, or its " 317 "definition is missing from " 376 if (bmref->
type != OBJ_BITMAP_REF) {
383 (errcode(ERRCODE_INTERNAL_ERROR),
384 errmsg(
"illegal attempt to define shared BitmapRef %s",
386 errhint(
"BitmapRefs may only be defined as session, " 387 "not shared, variables.")));
391 bmref->
type = OBJ_BITMAP_REF;
438 if (bmarray->
type != OBJ_BITMAP_ARRAY) {
494 if (bmhash->
type != OBJ_BITMAP_HASH) {
550 if (array->
type != OBJ_INT4_ARRAY) {
600 TupleTableSlot *slot;
601 AttInMetadata *attinmeta;
602 FuncCallContext *funcctx;
609 if (SRF_IS_FIRSTCALL())
612 MemoryContext oldcontext;
615 funcctx = SRF_FIRSTCALL_INIT();
616 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
618 tupdesc = RelationNameGetTupleDesc(
"veil.veil_variable_t");
619 slot = TupleDescGetSlot(tupdesc);
620 funcctx->slot = slot;
621 attinmeta = TupleDescGetAttInMetadata(tupdesc);
622 funcctx->attinmeta = attinmeta;
624 MemoryContextSwitchTo(oldcontext);
625 funcctx->user_fctx = NULL;
628 funcctx = SRF_PERCALL_SETUP();
630 funcctx->user_fctx = var;
633 values = (
char **) palloc(3 *
sizeof(
char *));
638 slot = funcctx->slot;
639 attinmeta = funcctx->attinmeta;
641 tuple = BuildTupleFromCStrings(attinmeta, values);
642 datum = TupleGetDatum(slot, tuple);
643 SRF_RETURN_NEXT(funcctx, datum);
647 SRF_RETURN_DONE(funcctx);
682 PG_RETURN_BOOL((var->
obj != NULL));
709 min = PG_GETARG_INT32(1);
710 max = PG_GETARG_INT32(2);
716 PG_RETURN_INT32(max + 1 - min);
731 static bool init_done =
false;
732 static TupleDesc tupdesc;
733 static AttInMetadata *attinmeta;
734 __attribute__ ((unused)) TupleTableSlot *slot;
742 MemoryContext oldcontext = MemoryContextSwitchTo(TopMemoryContext);
745 tupdesc = RelationNameGetTupleDesc(
"veil.veil_range_t");
746 slot = TupleDescGetSlot(tupdesc);
747 attinmeta = TupleDescGetAttInMetadata(tupdesc);
749 MemoryContextSwitchTo(oldcontext);
753 values = (
char **) palloc(2 *
sizeof(
char *));
757 tuple = BuildTupleFromCStrings(attinmeta, values);
758 slot = TupleDescGetSlot(tupdesc);
763 return TupleGetDatum(slot, tuple);
793 PG_RETURN_DATUM(datum);
825 range =
GetRange(range_name,
false);
831 PG_RETURN_BOOL(
true);
859 PG_RETURN_BOOL(
true);
883 bit = PG_GETARG_INT32(1);
887 PG_RETURN_BOOL(
true);
911 bit = PG_GETARG_INT32(1);
915 PG_RETURN_BOOL(
true);
940 bit = PG_GETARG_INT32(1);
945 PG_RETURN_BOOL(result);
974 target =
GetBitmap(bitmap1_name,
false,
true);
975 source =
GetBitmap(bitmap2_name,
false,
true);
977 if (target && source) {
981 PG_RETURN_BOOL(
true);
1010 target =
GetBitmap(bitmap1_name,
false,
true);
1011 source =
GetBitmap(bitmap2_name,
false,
true);
1014 PG_RETURN_BOOL(
true);
1030 struct bitmap_bits_state {
1034 FuncCallContext *funcctx;
1035 MemoryContext oldcontext;
1040 if (SRF_IS_FIRSTCALL())
1045 funcctx = SRF_FIRSTCALL_INIT();
1046 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1047 state = palloc(
sizeof(
struct bitmap_bits_state));
1048 MemoryContextSwitchTo(oldcontext);
1051 state->bitmap =
GetBitmap(name,
false,
true);
1053 if (!state->bitmap) {
1055 (errcode(ERRCODE_INTERNAL_ERROR),
1056 errmsg(
"Bitmap %s is not defined",
1058 errhint(
"Perhaps the name is mis-spelled, or its " 1059 "definition is missing from veil_init().")));
1062 state->bit = state->bitmap->bitzero;
1063 funcctx->user_fctx = state;
1066 funcctx = SRF_PERCALL_SETUP();
1067 state = funcctx->user_fctx;
1072 datum = Int32GetDatum(state->bit);
1074 SRF_RETURN_NEXT(funcctx, datum);
1077 SRF_RETURN_DONE(funcctx);
1104 (errcode(ERRCODE_INTERNAL_ERROR),
1105 errmsg(
"Bitmap %s is not defined", name),
1106 errhint(
"Perhaps the name is mis-spelled, or its " 1107 "definition is missing from veil_init().")));
1131 char *arrayrange_name;
1132 char *maprange_name;
1144 arrayrange_name =
strfromtext(PG_GETARG_TEXT_P(1));
1145 arrayrange =
GetRange(arrayrange_name,
false);
1147 maprange =
GetRange(maprange_name,
false);
1150 arrayrange->
min, arrayrange->
max,
1151 maprange->
min, maprange->
max);
1155 PG_RETURN_BOOL(
true);
1182 PG_RETURN_BOOL(
true);
1210 bmref_text = PG_GETARG_TEXT_P(0);
1217 arrayelem = PG_GETARG_INT32(2);
1221 (errcode(ERRCODE_INTERNAL_ERROR),
1222 errmsg(
"Range error for BitmapArray %s, %d not in %d - %d",
1223 bmarray_name, arrayelem,
1228 bmref->
xid = GetCurrentTransactionId();
1229 PG_RETURN_TEXT_P(bmref_text);
1255 arrayelem = PG_GETARG_INT32(1);
1256 bit = PG_GETARG_INT32(2);
1266 PG_RETURN_BOOL(
false);
1294 arrayelem = PG_GETARG_INT32(1);
1295 bit = PG_GETARG_INT32(2);
1302 PG_RETURN_BOOL(
true);
1306 (errcode(ERRCODE_INTERNAL_ERROR),
1307 errmsg(
"Bitmap Array range error (%d not in %d..%d)",
1309 errdetail(
"Attempt to reference BitmapArray element " 1310 "outside of the BitmapArray's defined range")));
1312 PG_RETURN_BOOL(
true);
1339 arrayelem = PG_GETARG_INT32(1);
1340 bit = PG_GETARG_INT32(2);
1347 PG_RETURN_BOOL(
true);
1351 (errcode(ERRCODE_INTERNAL_ERROR),
1352 errmsg(
"Bitmap Array range error (%d not in %d..%d)",
1354 errdetail(
"Attempt to reference BitmapArray element " 1355 "outside of the BitmapArray's defined range")));
1357 PG_RETURN_BOOL(
true);
1387 arrayelem = PG_GETARG_INT32(2);
1391 target =
GetBitmap(bitmap_name,
false,
true);
1398 PG_RETURN_BOOL(
true);
1428 arrayelem = PG_GETARG_INT32(2);
1432 target =
GetBitmap(bitmap_name,
false,
true);
1439 PG_RETURN_BOOL(
true);
1457 struct bitmap_array_bits_state {
1461 FuncCallContext *funcctx;
1462 MemoryContext oldcontext;
1469 if (SRF_IS_FIRSTCALL())
1474 funcctx = SRF_FIRSTCALL_INIT();
1475 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1476 state = palloc(
sizeof(
struct bitmap_array_bits_state));
1477 MemoryContextSwitchTo(oldcontext);
1480 arrayelem = PG_GETARG_INT32(1);
1485 (errcode(ERRCODE_INTERNAL_ERROR),
1486 errmsg(
"BitmapArray %s is not defined",
1488 errhint(
"Perhaps the name is mis-spelled, or its " 1489 "definition is missing from " 1494 if (!state->bitmap) {
1496 (errcode(ERRCODE_INTERNAL_ERROR),
1497 errmsg(
"Bitmap Array range error (%d not in %d..%d)",
1499 errdetail(
"Attempt to reference BitmapArray element " 1500 "outside of the BitmapArray's defined range")));
1503 state->bit = state->bitmap->bitzero;
1504 funcctx->user_fctx = state;
1507 funcctx = SRF_PERCALL_SETUP();
1508 state = funcctx->user_fctx;
1513 datum = Int32GetDatum(state->bit);
1515 SRF_RETURN_NEXT(funcctx, datum);
1518 SRF_RETURN_DONE(funcctx);
1545 (errcode(ERRCODE_INTERNAL_ERROR),
1546 errmsg(
"BitmapArray %s is not defined",
1548 errhint(
"Perhaps the name is mis-spelled, or its " 1549 "definition is missing from veil_init().")));
1579 (errcode(ERRCODE_INTERNAL_ERROR),
1580 errmsg(
"BitmapArray %s is not defined",
1582 errhint(
"Perhaps the name is mis-spelled, or its " 1583 "definition is missing from veil_init().")));
1618 range =
GetRange(range_name,
false);
1620 if (bmhash_var->
shared) {
1622 (errcode(ERRCODE_INTERNAL_ERROR),
1623 errmsg(
"illegal attempt to define shared BitmapHash %s",
1625 errhint(
"BitmapHashes may only be defined as session, " 1626 "not shared, variables.")));
1633 PG_RETURN_BOOL(
true);
1664 PG_RETURN_BOOL(
true);
1693 PG_RETURN_BOOL(found);
1721 bmref_text = PG_GETARG_TEXT_P(0);
1732 bmref->
xid = GetCurrentTransactionId();
1733 PG_RETURN_TEXT_P(bmref_text);
1761 bit = PG_GETARG_INT32(2);
1771 PG_RETURN_BOOL(
false);
1800 bit = PG_GETARG_INT32(2);
1807 PG_RETURN_BOOL(
true);
1835 bit = PG_GETARG_INT32(2);
1842 PG_RETURN_BOOL(
true);
1876 bitmap =
GetBitmap(bitmap_name,
false,
true);
1880 if (target && bitmap) {
1883 PG_RETURN_BOOL(
true);
1916 target =
GetBitmap(bitmap_name,
false,
true);
1923 PG_RETURN_BOOL(
true);
1956 target =
GetBitmap(bitmap_name,
false,
true);
1968 PG_RETURN_BOOL(
true);
1985 struct bitmap_hash_bits_state {
1989 FuncCallContext *funcctx;
1990 MemoryContext oldcontext;
1997 if (SRF_IS_FIRSTCALL())
2002 funcctx = SRF_FIRSTCALL_INIT();
2003 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
2004 state = palloc(
sizeof(
struct bitmap_hash_bits_state));
2005 MemoryContextSwitchTo(oldcontext);
2013 (errcode(ERRCODE_INTERNAL_ERROR),
2014 errmsg(
"Bitmap Hash %s not defined", name)));
2018 if (!state->bitmap) {
2019 SRF_RETURN_DONE(funcctx);
2022 state->bit = state->bitmap->bitzero;
2023 funcctx->user_fctx = state;
2026 funcctx = SRF_PERCALL_SETUP();
2027 state = funcctx->user_fctx;
2032 datum = Int32GetDatum(state->bit);
2034 SRF_RETURN_NEXT(funcctx, datum);
2037 SRF_RETURN_DONE(funcctx);
2064 (errcode(ERRCODE_INTERNAL_ERROR),
2065 errmsg(
"Bitmap Hash %s not defined", name)));
2083 struct bitmap_hash_entries_state {
2087 FuncCallContext *funcctx;
2088 MemoryContext oldcontext;
2093 if (SRF_IS_FIRSTCALL())
2098 funcctx = SRF_FIRSTCALL_INIT();
2099 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
2100 state = palloc(
sizeof(
struct bitmap_hash_entries_state));
2101 MemoryContextSwitchTo(oldcontext);
2106 if (!state->bmhash) {
2108 (errcode(ERRCODE_INTERNAL_ERROR),
2109 errmsg(
"Bitmap Hash %s not defined", name)));
2113 funcctx->user_fctx = state;
2116 funcctx = SRF_PERCALL_SETUP();
2117 state = funcctx->user_fctx;
2123 datum = PointerGetDatum(result);
2124 SRF_RETURN_NEXT(funcctx, datum);
2127 SRF_RETURN_DONE(funcctx);
2152 if (PG_ARGISNULL(0)) {
2159 if (PG_ARGISNULL(1)) {
2164 value = PG_GETARG_INT32(1);
2167 PG_RETURN_INT32(value);
2196 PG_RETURN_INT32(var->
value);
2227 range =
GetRange(range_name,
false);
2232 PG_RETURN_BOOL(
true);
2257 PG_RETURN_BOOL(
true);
2282 idx = PG_GETARG_INT32(1);
2283 value = PG_GETARG_INT32(2);
2286 PG_RETURN_INT32(value);
2310 idx = PG_GETARG_INT32(1);
2313 PG_RETURN_INT32(value);
2336 bool param = PG_GETARG_BOOL(0);
2341 (errcode(ERRCODE_INTERNAL_ERROR),
2342 errmsg(
"No user defined veil init functions found"),
2343 errhint(
"You must redefine veil.veil_init() or register your " 2344 "own init functions in the veil.veil_init_fns table.")));
2346 PG_RETURN_BOOL(
true);
2366 bool success =
true;
2373 if (ok != SPI_OK_CONNECT) {
2375 (errcode(ERRCODE_INTERNAL_ERROR),
2376 errmsg(
"failed to perform reset"),
2377 errdetail(
"SPI_connect() failed, returning %d.", ok)));
2383 elog(NOTICE,
"veil_init returns %s to veil_perform_reset",
2384 success?
"true":
"false");
2387 "vl_complete_context_switch returns %s to veil_perform_reset",
2388 success?
"true":
"false");
2393 (errcode(ERRCODE_INTERNAL_ERROR),
2394 errmsg(
"failed to perform reset"),
2395 errdetail(
"Unable to prepare for memory reset. " 2396 "Maybe another process is performing a reset, " 2397 "or maybe there is a long-running transaction that " 2398 "is still using the previous memory context.")));
2402 PG_RETURN_BOOL(success);
2424 PG_RETURN_BOOL(
true);
2442 version_str = palloc(
sizeof(
char) * strlen(
VEIL_VERSION) +
2447 PG_RETURN_TEXT_P(version_text);
2467 if (PG_ARGISNULL(0)) {
2503 if (PG_ARGISNULL(0)) {
2507 txt = PG_GETARG_TEXT_P(0);
2511 PG_RETURN_INT32(result);
veil_variable_t * vl_next_variable(veil_variable_t *prev)
Return the next variable from a scan of the hash of variables.
Datum veil_int4array_get(PG_FUNCTION_ARGS)
veil_int4array_get(array text, idx int4) returns int4 Get an Int4Array entry.
Datum veil_bitmap_from_array(PG_FUNCTION_ARGS)
veil_bitmap_from_array(bmref text, bmarray text, index int4) returns text Place a reference to the sp...
Datum veil_clear_bitmap_hash(PG_FUNCTION_ARGS)
veil_clear_bitmap_hash(bmhash text) returns bool Clear the bits in an existing BitmapHash.
TransactionId xid
The xid for which this variable is valid.
Subtype of Object for storing arrays of integers.
Subtype of Object for storing bitmap refs.
Datum veil_clear_bitmap(PG_FUNCTION_ARGS)
veil_clear_bitmap(name text) returns bool Clear all bits in the specified Bitmap. ...
Subtype of Object for storing bitmaps.
int32 value
the integer value of the variable
static BitmapRef * GetBitmapRef(char *name)
Return the BitmapRef matching the name parameter, possibly creating the VarEntry (variable) for it...
void vl_BitmapIntersect(Bitmap *target, Bitmap *source)
Create the intersection of two bitmaps, updating the first with the result.
static Range * GetRange(char *name, bool create)
Return the Range variable matching the name parameter, possibly creating the variable.
static text * textfromstr(char *in)
Create a dynamically allocated text value as a copy of a C string.
void vl_NewBitmap(Bitmap **p_bitmap, bool shared, int32 min, int32 max)
Return a newly initialised (empty) Bitmap.
int32 bitzero
The index of the lowest bit each bitmap can store.
Bitmap * bitmap
Pointer to the referenced bitmap.
int32 bitmax
The index of the highest bit each bitmap can store.
Subtype of Object for storing simple int4 values.
HTAB * vl_get_shared_hash(void)
Return the shared hash for the current context.
ObjType type
This must have the value OBJ_BITMAP.
Describes a veil shared or session variable.
bool shared
Whether this is a shared variable (as opposed to a session variable)
VarEntry * vl_lookup_shared_variable(char *name)
Define a new, or attach to an existing, shared variable.
bool vl_bool_from_query(const char *qry, bool *result)
Executes a query that returns a single bool value.
void vl_BitmapUnion(Bitmap *target, Bitmap *source)
Create the union of two bitmaps, updating the first with the result.
Datum veil_bitmap_hash_testbit(PG_FUNCTION_ARGS)
veil_bitmap_hash_testbit(bmhash text, key text, bitno int4) returns bool Test a specified bit within ...
ObjType type
This must have the value OBJ_BITMAP_ARRAY.
Datum veil_bitmap_hash_key_exists(PG_FUNCTION_ARGS)
veil_bitmap_hashkey_exists(bmhash text, key text) returns bool Return true if the key exists in the b...
Datum veil_bitmap_array_setbit(PG_FUNCTION_ARGS)
veil_bitmap_array_setbit(bmarray text, arr_idx int4, bitno int4) returns bool Set a specified bit wit...
char * name
The name of the variable.
Datum veil_clear_bitmap_array(PG_FUNCTION_ARGS)
veil_clear_bitmap_array(bmarray text) returns bool Clear the bits in an existing BitmapArray.
Datum veil_range(PG_FUNCTION_ARGS)
veil_range(name text) returns veil_range_t Return the range (as a SQL veil_range_t composite type) fr...
int32 vl_BitmapNextBit(Bitmap *bitmap, int32 bit, bool *found)
Return the next set bit in the Bitmap.
bool vl_BitmapTestbit(Bitmap *bitmap, int32 bit)
Test a bit within a Bitmap.
void vl_ClearBitmap(Bitmap *bitmap)
Clear all bits in a Bitmap.
static Int4Array * GetInt4ArrayFromVar(VarEntry *var, bool allow_empty)
Return the Int4Array from an Int4Array variable.
int32 vl_Int4ArrayGet(Int4Array *array, int32 idx)
Get an entry from an Int4Array.
Datum veil_bitmap_hash_clearbit(PG_FUNCTION_ARGS)
veil_bitmap_hash_clearbit(bmhash text, key text, bitno int4) returns bool Clear a specified bit withi...
ObjType type
This must have the value OBJ_RANGE.
int32 bitmax
The index of the highest bit the bitmap can store.
static BitmapArray * GetBitmapArrayFromVar(VarEntry *var, bool allow_empty)
Return the BitmapArray from a bitmap array variable.
static Bitmap * GetBitmapFromVar(VarEntry *var, bool allow_empty, bool allow_ref)
Return the Bitmap from a bitmap variable.
Datum veil_bitmap_hash_bits(PG_FUNCTION_ARGS)
veil_bitmap_hash_bits(bmhash text, key text) returns setof int4 Return the set of all bits set in the...
Datum veil_union_from_bitmap_array(PG_FUNCTION_ARGS)
veil_union_from_bitmap_array(bitmap text, bmarray text, arr_idx int4) returns bool Union a Bitmap wit...
static char * strfromint(int32 val)
Create a dynamically allocated C string as a copy of an integer value.
static BitmapHash * GetBitmapHashFromVar(VarEntry *var, bool allow_empty)
Return the BitmapHash from a bitmap hash variable.
#define VEIL_VERSION
The version number for this version of veil.
ObjType type
This must have the value OBJ_INT4_ARRAY.
VarEntry * vl_lookup_variable(char *name)
Lookup a variable by name, creating it as as a session variable if it does not already exist...
Datum veil_bitmap_intersect(PG_FUNCTION_ARGS)
veil_bitmap_intersect(result_name text, name2 text) returns bool Intersect the bitmap specified in pa...
char * vl_serialise_var(char *name)
Serialise a veil variable.
#define HASH_KEYLEN
The key length for veil hash types.
Datum veil_bitmap_array_brange(PG_FUNCTION_ARGS)
veil_bitmap_array_brange(bmarray text) returns veil_range_t Return composite type giving the range of...
Datum veil_force_reset(PG_FUNCTION_ARGS)
veil_force_reset() returns bool Reset veil shared memory for this database, ignoring existing transac...
Datum veil_init_bitmap_array(PG_FUNCTION_ARGS)
veil_init_bitmap_array(text, text, text) returns bool Create or reset a BitmapArray.
Datum veil_init(PG_FUNCTION_ARGS)
veil_init(doing_reset bool) returns bool Initialise or reset a veil session.
Datum veil_init_range(PG_FUNCTION_ARGS)
veil_init_range(name text, min int4, max int4) returns int4 Initialise a Range variable called NAME c...
static char * strfromtext(text *in)
Create a dynamically allocated C string as a copy of a text value.
Datum veil_bitmap_testbit(PG_FUNCTION_ARGS)
veil_bitmap_testbit(name text, bit_number int4) returns bool Test the specified bit in the specified ...
Bitmap * vl_BitmapFromArray(BitmapArray *bmarray, int32 elem)
Return a specified Bitmap from a BitmapArray.
Datum veil_bitmap_bits(PG_FUNCTION_ARGS)
veil_bitmap_bits(name text) returns setof int4 Return the set of all bits set in the specified Bitmap...
Datum veil_bitmap_array_testbit(PG_FUNCTION_ARGS)
veil_bitmap_array_testbit(bmarray text, arr_idx int4, bitno int4) returns bool Test a specified bit w...
static BitmapArray * GetBitmapArray(char *name, bool allow_empty)
Return the BitmapArray matching the name parameter, possibly creating the (VarEntry) variable...
void vl_NewBitmapHash(BitmapHash **p_bmhash, char *name, int32 bitzero, int32 bitmax)
Return a newly initialised (empty) BitmapHash.
Datum veil_bitmap_array_bits(PG_FUNCTION_ARGS)
veil_bitmap_array_bits(bmarray text, arr_idx int4) returns setof int4 Return the set of all bits set ...
Datum veil_bitmap_clearbit(PG_FUNCTION_ARGS)
veil_bitmap_clearbit(name int4, bit_number text) returns bool Clear the specified bit in the specifie...
int32 arraymax
The index of the lowest numbered bitmap in the array.
static Int4Var * GetInt4Var(char *name, bool create)
Return the Int4Var variable matching the name parameter, possibly creating the variable.
bool vl_prepare_context_switch(void)
Prepare for a switch to the alternate context.
static BitmapRef * GetBitmapRefFromVar(VarEntry *var)
Return the BitmapRef from a bitmap ref variable.
void vl_BitmapSetbit(Bitmap *bitmap, int32 bit)
Set a bit within a Bitmap.
Datum veil_variables(PG_FUNCTION_ARGS)
veil_variables() returns setof veil_variable_t Return a veil_variable_t record for each defined varia...
Provide definitions for all non-local C-callable Veil functions.
static Int4Array * GetInt4Array(char *name, bool allow_empty)
Return the Int4Array matching the name parameter, possibly creating the VarEntry (variable) for it...
Datum veil_intersect_from_bitmap_array(PG_FUNCTION_ARGS)
veil_intersect_from_bitmap_array(bitmap text, bmarray text, arr_idx int4) returns bool Intersect a Bi...
int vl_spi_finish(bool pushed)
Reciprocal function for vl_spi_connect()
bool shared
Whether this is a shared variable.
General purpose object-type.
Provides version information for veil.
Datum veil_init_bitmap(PG_FUNCTION_ARGS)
veil_init_bitmap(bitmap_name text, range_nametext) returns bool Create or re-initialise a Bitmap...
int32 bitzero
The index of the lowest bit the bitmap can store.
static BitmapHash * GetBitmapHash(char *name, bool allow_empty)
Return the BitmapHash matching the name parameter, possibly creating the VarEntry (variable) for it...
Subtype of Object for storing bitmap hashes.
Datum veil_bitmap_from_hash(PG_FUNCTION_ARGS)
veil_bitmap_from_hash(bmref text, bmhash text, key text) returns text Place a reference to the specif...
Datum veil_intersect_from_bitmap_hash(PG_FUNCTION_ARGS)
veil_intersect_from_bitmap_hash(bitmap text, bmhash text, key text) returns bool Intersect a Bitmap w...
char * type
The type of the variable (eg "Bitmap")
ObjType
Describes the type of an Object record or one of its subtypes.
void vl_ClearInt4Array(Int4Array *array)
Reset all Int4 entries in an Int4Array (to zero).
Bitmap * vl_BitmapFromHash(BitmapHash *bmhash, char *hashelem)
Return a specified Bitmap from a BitmapHash.
static Bitmap * GetBitmap(char *name, bool allow_empty, bool allow_ref)
Return the Bitmap matching the name parameter, possibly creating the VarEntry (variable) for it...
static char * copystr(char *str)
Create a dynamically allocated text value as a copy of a C string, applying a limit to the length...
Bitmap * vl_AddBitmapToHash(BitmapHash *bmhash, char *hashelem)
Create a newly allocated empty Bitmap to a BitmapHash.
VarEntry * vl_NextHashEntry(HTAB *hash, VarEntry *prev)
Utility function for scanning the hash table of a BitmapHash.
Int4Array * vl_NewInt4Array(Int4Array *current, bool shared, int32 min, int32 max)
Return a newly initialised (zeroed) Int4Array.
Datum veil_bitmap_hash_setbit(PG_FUNCTION_ARGS)
veil_bitmap_hash_setbit(bmhash text, key text, bitno int4) returns bool Set a specified bit within a ...
Datum veil_int4array_set(PG_FUNCTION_ARGS)
veil_int4array_set(array text, idx int4, value int4) returns int4 Set an Int4Array entry...
ObjType type
This must have the value OBJ_BITMAP_REF.
int32 arrayzero
The index of array element zero: the index of the lowest numbered bitmap in the array.
Datum veil_bitmap_array_arange(PG_FUNCTION_ARGS)
veil_bitmap_array_arange(bmarray text) returns veil_range_t Return composite type giving the range of...
void vl_type_mismatch(char *name, ObjType expected, ObjType got)
Report, by raising an error, a type mismatch between the expected and actual type of a VarEntry varia...
Subtype of Object for storing range values.
int32 max
Upper limit for range.
void vl_ClearBitmapArray(BitmapArray *bmarray)
Clear all bitmaps in the given BitmapArray.
void vl_NewBitmapArray(BitmapArray **p_bmarray, bool shared, int32 arrayzero, int32 arraymax, int32 bitzero, int32 bitmax)
Return a newly initialised (empty) BitmapArray.
Datum veil_init_bitmap_hash(PG_FUNCTION_ARGS)
veil_init_bitmap_hash(bmhash text, range text) returns bool Create or reset a BitmapHash.
Datum veil_bitmap_hash_entries(PG_FUNCTION_ARGS)
veil_bitmap_hash_entries(bmhash text) returns setof text Return the key of every Bitmap within the Bi...
void vl_Int4ArraySet(Int4Array *array, int32 idx, int32 value)
Set an entry within an Int4Array.
Datum veil_bitmap_union(PG_FUNCTION_ARGS)
veil_bitmap_union(result_name text, name2 text) returns bool Union the bitmap specified in parameter ...
Datum veil_init_int4array(PG_FUNCTION_ARGS)
veil_init_int4array(arrayname text, range text) returns bool Initialise an Int4Array variable...
void vl_force_context_switch(void)
In desparation, if we are unable to complete a context switch, we should use this function...
int32 bitzero
The index of the lowest bit each bitmap can store.
void * vl_malloc(size_t size)
Dynamically allocate memory using palloc in TopMemoryContext.
static void ensure_init()
Perform session initialisation once for the session.
Datum veil_union_into_bitmap_hash(PG_FUNCTION_ARGS)
veil_union_into_bitmap_hash(bmhash text, key text, bitmap text) returns bool Union a Bitmap with the ...
Datum veil_bitmap_setbit(PG_FUNCTION_ARGS)
veil_bitmap_setbit(name text, bit_number int4) returns bool Set the specified bit in the specified Bi...
int32 bitmax
The index of the highest bit each bitmap can store.
ObjType type
This must have the value OBJ_BITMAP_HASH.
Datum veil_perform_reset(PG_FUNCTION_ARGS)
veil_perform_reset() returns bool Reset veil shared memory for this database.
Object * obj
Pointer to the contents of the variable.
Datum veil_union_from_bitmap_hash(PG_FUNCTION_ARGS)
veil_union_from_bitmap_hash(bmhash text, key text, bitmap text) returns bool Union a Bitmap with the ...
Subtype of Object for storing bitmap arrays.
int vl_call_init_fns(bool param)
Identify any registered init_functions and execute them.
int vl_spi_connect(bool *p_pushed)
If already connected in this session, push the current connection, and get a new one.
static text * textfromstrn(char *in, int limit)
Create a dynamically allocated text value as a copy of a C string, applying a limit to the length...
Int4Var * vl_NewInt4(bool shared)
Create a new session or shared Int4Var object.
ObjType type
This must have the value OBJ_INT4.
Datum veil_int4_set(PG_FUNCTION_ARGS)
veil_int4_set(name text,value int4) returns int4 Set an Int4Var variable type to a specified value...
int32 vl_deserialise(char **p_stream)
De-serialise a base64 string containing, possibly many, derialised veil variables.
Datum veil_bitmap_hash_range(PG_FUNCTION_ARGS)
veil_bitmap_hash_range(bmhash text) returns veil_range_t Return composite type giving the range of ev...
int32 min
Lower limit for range.
Datum veil_version(PG_FUNCTION_ARGS)
veil_version() returns text Return a string describing this version of veil.
static char * strfrombool(bool val)
Create a dynamically allocated C string as a copy of a boolean value.
bool isnull
if true, the value is null
static Datum datum_from_range(int64 min, int64 max)
Create a datum containing the values of a veil_range_t composite type.
Datum veil_serialise(PG_FUNCTION_ARGS)
veil_serialise(varname text) returns text Return a string representing the contents of our variable...
Datum veil_bitmap_array_clearbit(PG_FUNCTION_ARGS)
veil_bitmap_array_clearbit(bmarray text, arr_idx int4, bitno int4) returns bool Clear a specified bit...
Datum veil_deserialise(PG_FUNCTION_ARGS)
veil_deserialise(stream text) returns text Create or reset variables based on the output of previous ...
bool vl_BitmapHashHasKey(BitmapHash *bmhash, char *hashelem)
Determine whether the supplied key exists in the BitmapHash.
Datum veil_int4_get(PG_FUNCTION_ARGS)
veil_int4_get(name text) returns int4 Return the value of an Int4Var variable.
Datum veil_clear_int4array(PG_FUNCTION_ARGS)
veil_clear_int4array(name text) returns bool Clear an Int4Array variable.
bool vl_complete_context_switch(void)
Complete the context switch started by vl_prepare_context_switch().
Datum veil_bitmap_range(PG_FUNCTION_ARGS)
veil_bitmap_range(name text) returns veil_range_t Return composite type giving the range of the speci...
#define VEIL_VERSION_INFO
The version number suffix, indicating stability.
char key[60]
String containing variable name.
char * vl_ObjTypeName(ObjType obj)
Return a static string describing an ObjType object.
Range * vl_NewRange(bool shared)
Create a new session or shared Range object.
void vl_BitmapClearbit(Bitmap *bitmap, int32 bit)
Clear a bit within a Bitmap.
Define all Veil public datatypes.
Datum veil_share(PG_FUNCTION_ARGS)
veil_share(name text) returns bool Define a shared variable called NAME, returning true...