Veil
veil_funcs.h
Go to the documentation of this file.
1 /**
2  * @file veil_funcs.h
3  * \code
4  * Author: Marc Munro
5  * Copyright (c) 2005 - 2011 Marc Munro
6  * License: BSD
7  * \endcode
8  * @brief
9  * Provide definitions for all non-local C-callable Veil functions.
10  *
11  */
12 
13 #include "veil_datatypes.h"
14 #include "fmgr.h"
15 
16 /* veil_utils */
17 extern void *vl_malloc(size_t size);
18 char *vl_ObjTypeName(ObjType obj);
19 
20 
21 /* veil_variables */
22 extern VarEntry *vl_lookup_shared_variable(char *name);
23 extern VarEntry *vl_lookup_variable(char *name);
25 extern void vl_ClearInt4Array(Int4Array *array);
26 extern Int4Array *vl_NewInt4Array(Int4Array *current, bool shared,
27  int32 min, int32 max);
28 extern void vl_Int4ArraySet(Int4Array *array, int32 idx, int32 value);
29 extern int32 vl_Int4ArrayGet(Int4Array *array, int32 idx);
30 
31 
32 /* veil_datatypes */
33 extern Range *vl_NewRange(bool shared);
34 extern Int4Var *vl_NewInt4(bool shared);
35 
36 /* veil_bitmap */
37 extern void vl_ClearBitmap(Bitmap *bitmap);
38 extern void vl_NewBitmap(Bitmap **p_bitmap, bool shared, int32 min, int32 max);
39 extern void vl_BitmapSetbit(Bitmap *bitmap, int32 bit);
40 extern void vl_BitmapClearbit(Bitmap *bitmap, int32 bit);
41 extern bool vl_BitmapTestbit(Bitmap *bitmap, int32 bit);
42 extern void vl_BitmapUnion(Bitmap *target, Bitmap *source);
43 extern void vl_BitmapIntersect(Bitmap *target, Bitmap *source);
44 extern int32 vl_BitmapNextBit(Bitmap *bitmap, int32 bit, bool *found);
45 extern Bitmap *vl_BitmapFromArray(BitmapArray *bmarray, int32 elem);
46 extern void vl_ClearBitmapArray(BitmapArray *bmarray);
47 extern void vl_NewBitmapArray(BitmapArray **p_bmarray, bool shared,
48  int32 arrayzero, int32 arraymax,
49  int32 bitzero, int32 bitmax);
50 extern VarEntry *vl_NextHashEntry(HTAB *hash, VarEntry *prev);
51 extern void vl_NewBitmapHash(BitmapHash **p_bmhash, char *name,
52  int32 bitzero, int32 bitmax);
53 extern Bitmap *vl_BitmapFromHash(BitmapHash *bmhash, char *hashelem);
54 extern Bitmap *vl_AddBitmapToHash(BitmapHash *bmhash, char *hashelem);
55 extern bool vl_BitmapHashHasKey(BitmapHash *bmhash, char *hashelem);
56 
57 /* veil_shmem */
58 extern HTAB *vl_get_shared_hash(void);
59 extern bool vl_prepare_context_switch(void);
60 extern bool vl_complete_context_switch(void);
61 extern void vl_force_context_switch(void);
62 extern void *vl_shmalloc(size_t size);
63 extern void vl_free(void *mem);
64 extern void _PG_init(void);
65 
66 /* veil_query */
67 extern int vl_spi_connect(bool *p_pushed);
68 extern int vl_spi_finish(bool pushed);
69 extern bool vl_bool_from_query(const char *qry, bool *result);
70 extern bool vl_db_exists(Oid db_id);
71 extern int vl_call_init_fns(bool param);
72 
73 /* veil_config */
74 extern void veil_config_init(void);
75 extern void veil_load_config(void);
76 extern int veil_shared_hash_elems(void);
77 extern int veil_dbs_in_cluster(void);
78 extern int veil_shmem_context_size(void);
79 
80 
81 /* veil_interface */
82 extern void vl_type_mismatch(char *name, ObjType expected, ObjType got);
83 extern Datum veil_variables(PG_FUNCTION_ARGS);
84 extern Datum veil_share(PG_FUNCTION_ARGS);
85 extern Datum veil_init_range(PG_FUNCTION_ARGS);
86 extern Datum veil_range(PG_FUNCTION_ARGS);
87 extern Datum veil_init_bitmap(PG_FUNCTION_ARGS);
88 extern Datum veil_clear_bitmap(PG_FUNCTION_ARGS);
89 extern Datum veil_bitmap_setbit(PG_FUNCTION_ARGS);
90 extern Datum veil_bitmap_clearbit(PG_FUNCTION_ARGS);
91 extern Datum veil_bitmap_testbit(PG_FUNCTION_ARGS);
92 extern Datum veil_bitmap_union(PG_FUNCTION_ARGS);
93 extern Datum veil_bitmap_intersect(PG_FUNCTION_ARGS);
94 extern Datum veil_bitmap_bits(PG_FUNCTION_ARGS);
95 extern Datum veil_bitmap_range(PG_FUNCTION_ARGS);
96 extern Datum veil_init_bitmap_array(PG_FUNCTION_ARGS);
97 extern Datum veil_clear_bitmap_array(PG_FUNCTION_ARGS);
98 extern Datum veil_bitmap_from_array(PG_FUNCTION_ARGS);
99 extern Datum veil_bitmap_array_testbit(PG_FUNCTION_ARGS);
100 extern Datum veil_bitmap_array_setbit(PG_FUNCTION_ARGS);
101 extern Datum veil_bitmap_array_clearbit(PG_FUNCTION_ARGS);
102 extern Datum veil_union_from_bitmap_array(PG_FUNCTION_ARGS);
103 extern Datum veil_intersect_from_bitmap_array(PG_FUNCTION_ARGS);
104 extern Datum veil_bitmap_array_bits(PG_FUNCTION_ARGS);
105 extern Datum veil_bitmap_array_arange(PG_FUNCTION_ARGS);
106 extern Datum veil_bitmap_array_brange(PG_FUNCTION_ARGS);
107 extern Datum veil_init_bitmap_hash(PG_FUNCTION_ARGS);
108 extern Datum veil_clear_bitmap_hash(PG_FUNCTION_ARGS);
109 extern Datum veil_bitmap_hash_key_exists(PG_FUNCTION_ARGS);
110 extern Datum veil_bitmap_from_hash(PG_FUNCTION_ARGS);
111 extern Datum veil_bitmap_hash_testbit(PG_FUNCTION_ARGS);
112 extern Datum veil_bitmap_hash_setbit(PG_FUNCTION_ARGS);
113 extern Datum veil_bitmap_hash_clearbit(PG_FUNCTION_ARGS);
114 extern Datum veil_union_into_bitmap_hash(PG_FUNCTION_ARGS);
115 extern Datum veil_union_from_bitmap_hash(PG_FUNCTION_ARGS);
116 extern Datum veil_intersect_from_bitmap_hash(PG_FUNCTION_ARGS);
117 extern Datum veil_bitmap_hash_bits(PG_FUNCTION_ARGS);
118 extern Datum veil_bitmap_hash_entries(PG_FUNCTION_ARGS);
119 extern Datum veil_bitmap_from_hash(PG_FUNCTION_ARGS);
120 extern Datum veil_bitmap_hash_range(PG_FUNCTION_ARGS);
121 extern Datum veil_int4_set(PG_FUNCTION_ARGS);
122 extern Datum veil_int4_get(PG_FUNCTION_ARGS);
123 extern Datum veil_init_int4array(PG_FUNCTION_ARGS);
124 extern Datum veil_clear_int4array(PG_FUNCTION_ARGS);
125 extern Datum veil_int4array_set(PG_FUNCTION_ARGS);
126 extern Datum veil_int4array_get(PG_FUNCTION_ARGS);
127 extern Datum veil_init(PG_FUNCTION_ARGS);
128 extern Datum veil_perform_reset(PG_FUNCTION_ARGS);
129 extern Datum veil_force_reset(PG_FUNCTION_ARGS);
130 extern Datum veil_version(PG_FUNCTION_ARGS);
131 extern Datum veil_serialise(PG_FUNCTION_ARGS);
132 extern Datum veil_deserialise(PG_FUNCTION_ARGS);
133 
134 
135 /* veil_serialise */
136 extern char *vl_serialise_var(char *name);
137 extern int32 vl_deserialise(char **p_stream);
138 extern VarEntry *vl_deserialise_next(char **p_stream);
Datum veil_init_bitmap_array(PG_FUNCTION_ARGS)
veil_init_bitmap_array(text, text, text) returns bool Create or reset a BitmapArray.
veil_variable_t * vl_next_variable(veil_variable_t *prev)
Return the next variable from a scan of the hash of variables.
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...
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...
Bitmap * vl_BitmapFromHash(BitmapHash *bmhash, char *hashelem)
Return a specified Bitmap from a BitmapHash.
Definition: veil_bitmap.c:548
Subtype of Object for storing arrays of integers.
Int4Var * vl_NewInt4(bool shared)
Create a new session or shared Int4Var object.
Subtype of Object for storing bitmaps.
Bitmap * vl_BitmapFromArray(BitmapArray *bmarray, int32 elem)
Return a specified Bitmap from a BitmapArray.
Definition: veil_bitmap.c:321
Datum veil_init_int4array(PG_FUNCTION_ARGS)
veil_init_int4array(arrayname text, range text) returns bool Initialise an Int4Array variable...
Subtype of Object for storing simple int4 values.
VarEntry * vl_NextHashEntry(HTAB *hash, VarEntry *prev)
Utility function for scanning the hash table of a BitmapHash.
Definition: veil_bitmap.c:474
HTAB * vl_get_shared_hash(void)
Return the shared hash for the current context.
Definition: veil_shmem.c:552
Describes a veil shared or session variable.
bool vl_bool_from_query(const char *qry, bool *result)
Executes a query that returns a single bool value.
Definition: veil_query.c:232
VarEntry * vl_lookup_shared_variable(char *name)
Define a new, or attach to an existing, shared variable.
Datum veil_bitmap_intersect(PG_FUNCTION_ARGS)
veil_bitmap_intersect(result_name text, name2 text) returns bool Intersect the bitmap specified in pa...
Datum veil_clear_bitmap(PG_FUNCTION_ARGS)
veil_clear_bitmap(name text) returns bool Clear all bits in the specified Bitmap. ...
void vl_ClearBitmap(Bitmap *bitmap)
Clear all bits in a Bitmap.
Definition: veil_bitmap.c:73
Datum veil_bitmap_clearbit(PG_FUNCTION_ARGS)
veil_bitmap_clearbit(name int4, bit_number text) returns bool Clear the specified bit in the specifie...
void vl_BitmapClearbit(Bitmap *bitmap, int32 bit)
Clear a bit within a Bitmap.
Definition: veil_bitmap.c:181
int32 vl_Int4ArrayGet(Int4Array *array, int32 idx)
Get an entry from an Int4Array.
void vl_BitmapSetbit(Bitmap *bitmap, int32 bit)
Set a bit within a Bitmap.
Definition: veil_bitmap.c:151
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 ...
Datum veil_version(PG_FUNCTION_ARGS)
veil_version() returns text Return a string describing this version of veil.
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_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_clear_int4array(PG_FUNCTION_ARGS)
veil_clear_int4array(name text) returns bool Clear an Int4Array variable.
char * vl_serialise_var(char *name)
Serialise a veil variable.
void vl_NewBitmapArray(BitmapArray **p_bmarray, bool shared, int32 arrayzero, int32 arraymax, int32 bitzero, int32 bitmax)
Return a newly initialised (empty) BitmapArray.
Definition: veil_bitmap.c:368
bool vl_BitmapHashHasKey(BitmapHash *bmhash, char *hashelem)
Determine whether the supplied key exists in the BitmapHash.
Definition: veil_bitmap.c:629
Range * vl_NewRange(bool shared)
Create a new session or shared Range object.
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_bitmap_setbit(PG_FUNCTION_ARGS)
veil_bitmap_setbit(name text, bit_number int4) returns bool Set the specified bit in the specified Bi...
Datum veil_serialise(PG_FUNCTION_ARGS)
veil_serialise(varname text) returns text Return a string representing the contents of our variable...
void _PG_init(void)
Veil's startup function.
Definition: veil_shmem.c:141
Datum veil_bitmap_testbit(PG_FUNCTION_ARGS)
veil_bitmap_testbit(name text, bit_number int4) returns bool Test the specified bit in the specified ...
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...
Datum veil_variables(PG_FUNCTION_ARGS)
veil_variables() returns setof veil_variable_t Return a veil_variable_t record for each defined varia...
void vl_NewBitmapHash(BitmapHash **p_bmhash, char *name, int32 bitzero, int32 bitmax)
Return a newly initialised (empty) BitmapHash.
Definition: veil_bitmap.c:499
void vl_free(void *mem)
Free a piece of shared memory within the current context.
Definition: veil_shmem.c:437
bool vl_prepare_context_switch(void)
Prepare for a switch to the alternate context.
Definition: veil_shmem.c:604
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...
int32 vl_BitmapNextBit(Bitmap *bitmap, int32 bit, bool *found)
Return the next set bit in the Bitmap.
Definition: veil_bitmap.c:295
Datum veil_force_reset(PG_FUNCTION_ARGS)
veil_force_reset() returns bool Reset veil shared memory for this database, ignoring existing transac...
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 ...
int vl_spi_finish(bool pushed)
Reciprocal function for vl_spi_connect()
Definition: veil_query.c:62
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 ...
Datum veil_bitmap_union(PG_FUNCTION_ARGS)
veil_bitmap_union(result_name text, name2 text) returns bool Union the bitmap specified in parameter ...
Subtype of Object for storing bitmap hashes.
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...
Datum veil_clear_bitmap_hash(PG_FUNCTION_ARGS)
veil_clear_bitmap_hash(bmhash text) returns bool Clear the bits in an existing BitmapHash.
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...
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).
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...
A Veil variable.
Int4Array * vl_NewInt4Array(Int4Array *current, bool shared, int32 min, int32 max)
Return a newly initialised (zeroed) Int4Array.
Datum veil_init(PG_FUNCTION_ARGS)
veil_init(doing_reset bool) returns bool Initialise or reset a veil session.
Datum veil_int4_get(PG_FUNCTION_ARGS)
veil_int4_get(name text) returns int4 Return the value of an Int4Var variable.
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...
Subtype of Object for storing range values.
bool vl_BitmapTestbit(Bitmap *bitmap, int32 bit)
Test a bit within a Bitmap.
Definition: veil_bitmap.c:210
void * vl_shmalloc(size_t size)
Dynamically allocate a piece of shared memory from the current context.
Definition: veil_shmem.c:414
void vl_Int4ArraySet(Int4Array *array, int32 idx, int32 value)
Set an entry within an Int4Array.
void vl_force_context_switch(void)
In desparation, if we are unable to complete a context switch, we should use this function...
Definition: veil_shmem.c:719
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_range(PG_FUNCTION_ARGS)
veil_range(name text) returns veil_range_t Return the range (as a SQL veil_range_t composite type) fr...
Datum veil_int4array_set(PG_FUNCTION_ARGS)
veil_int4array_set(array text, idx int4, value int4) returns int4 Set an Int4Array entry...
void * vl_malloc(size_t size)
Dynamically allocate memory using palloc in TopMemoryContext.
Definition: veil_utils.c:28
int veil_dbs_in_cluster(void)
Return the number of databases, within the database cluster, that will use Veil.
Definition: veil_config.c:52
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_intersect_from_bitmap_hash(PG_FUNCTION_ARGS)
veil_intersect_from_bitmap_hash(bitmap text, bmhash text, key text) returns bool Intersect a Bitmap w...
bool vl_db_exists(Oid db_id)
Determine whether the given oid represents an existing database or not.
Definition: veil_query.c:275
Datum veil_perform_reset(PG_FUNCTION_ARGS)
veil_perform_reset() returns bool Reset veil shared memory for this database.
int veil_shared_hash_elems(void)
Return the number of entries that should be allocated for shared variables in our shared hashes...
Definition: veil_config.c:65
Subtype of Object for storing bitmap arrays.
void vl_BitmapIntersect(Bitmap *target, Bitmap *source)
Create the intersection of two bitmaps, updating the first with the result.
Definition: veil_bitmap.c:262
int vl_call_init_fns(bool param)
Identify any registered init_functions and execute them.
Definition: veil_query.c:336
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_deserialise(PG_FUNCTION_ARGS)
veil_deserialise(stream text) returns text Create or reset variables based on the output of previous ...
int vl_spi_connect(bool *p_pushed)
If already connected in this session, push the current connection, and get a new one.
Definition: veil_query.c:46
Datum veil_int4array_get(PG_FUNCTION_ARGS)
veil_int4array_get(array text, idx int4) returns int4 Get an Int4Array entry.
int32 vl_deserialise(char **p_stream)
De-serialise a base64 string containing, possibly many, derialised veil variables.
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_intersect_from_bitmap_array(PG_FUNCTION_ARGS)
veil_intersect_from_bitmap_array(bitmap text, bmarray text, arr_idx int4) returns bool Intersect a Bi...
void veil_load_config(void)
Retrieve Veil's GUC variables for this session.
Definition: veil_config.c:133
Datum veil_init_bitmap(PG_FUNCTION_ARGS)
veil_init_bitmap(bitmap_name text, range_nametext) returns bool Create or re-initialise a Bitmap...
void veil_config_init(void)
Initialise Veil's use of GUC variables.
Definition: veil_config.c:92
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...
VarEntry * vl_deserialise_next(char **p_stream)
De-serialise the next veil variable from *p_stream.
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...
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...
void vl_BitmapUnion(Bitmap *target, Bitmap *source)
Create the union of two bitmaps, updating the first with the result.
Definition: veil_bitmap.c:232
Bitmap * vl_AddBitmapToHash(BitmapHash *bmhash, char *hashelem)
Create a newly allocated empty Bitmap to a BitmapHash.
Definition: veil_bitmap.c:588
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...
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...
Datum veil_share(PG_FUNCTION_ARGS)
veil_share(name text) returns bool Define a shared variable called NAME, returning true...
bool vl_complete_context_switch(void)
Complete the context switch started by vl_prepare_context_switch().
Definition: veil_shmem.c:678
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 ...
char * vl_ObjTypeName(ObjType obj)
Return a static string describing an ObjType object.
Definition: veil_utils.c:45
void vl_ClearBitmapArray(BitmapArray *bmarray)
Clear all bitmaps in the given BitmapArray.
Definition: veil_bitmap.c:341
void vl_NewBitmap(Bitmap **p_bitmap, bool shared, int32 min, int32 max)
Return a newly initialised (empty) Bitmap.
Definition: veil_bitmap.c:95
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_clearbit(PG_FUNCTION_ARGS)
veil_bitmap_hash_clearbit(bmhash text, key text, bitno int4) returns bool Clear a specified bit withi...
int veil_shmem_context_size(void)
Return the amount of shared memory to be requested for each of the two shared memory contexts...
Definition: veil_config.c:82
Define all Veil public datatypes.