ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
provsql_utils.h
Go to the documentation of this file.
1/**
2 * @file provsql_utils.h
3 * @brief Core types, constants, and utilities shared across ProvSQL.
4 *
5 * This header is included by virtually every source file in the
6 * extension. It provides:
7 * - The @c gate_type enumeration listing all circuit-gate kinds
8 * recognised by ProvSQL (input, semiring operations, aggregation, etc.)
9 * - The @c constants_t structure caching PostgreSQL OIDs for the types,
10 * functions, and operators that ProvSQL installs, so that OID lookups
11 * happen once per session rather than on every query.
12 * - The @c database_constants_t wrapper for per-database OID caches.
13 * - Helper declarations for OID lookup and UUID manipulation.
14 * - Global flags controlling interrupt handling, where-provenance, and
15 * verbosity.
16 * - An implicit inclusion of @c provsql_error.h for the @c provsql_error
17 * / @c provsql_warning / @c provsql_notice / @c provsql_log macros.
18 */
19#ifndef PROVSQL_UTILS_H
20#define PROVSQL_UTILS_H
21
22#include "pg_config.h" // for PG_VERSION_NUM
23#include "c.h" // for int16
24
25#include "postgres.h"
26#include "utils/uuid.h"
27
28#if PG_VERSION_NUM < 100000
29/// Number of bytes in a UUID
30#define UUID_LEN 16
31
32/** UUID structure. In versions of PostgreSQL < 10, pg_uuid_t is declared
33 * to be an opaque struct pg_uuid_t in uuid.h, so we have to give the
34 * definition of struct pg_uuid_t; this problem is resolved in PostgreSQL 10. */
35struct pg_uuid_t
36{
37 unsigned char data[UUID_LEN]; ///< Raw 16-byte UUID storage
38};
39#endif /* PG_VERSION_NUM */
40
41#include "postgres_ext.h"
42#include "nodes/pg_list.h"
43
44/**
45 * @brief Possible gate types in the provenance circuit.
46 *
47 * @warning ON-DISK ABI: this enum's integer values are stored in the
48 * @c gates.mmap backing file (see @c MMappedCircuit). Reordering,
49 * inserting, or renumbering existing members will silently invalidate
50 * every existing installation's persistent circuit. New gate types
51 * must be appended **at the end**, just before @c gate_invalid. If an
52 * existing gate type ever needs to be removed or renumbered, the mmap
53 * format must gain a version header and a migration path.
54 */
55typedef enum gate_type {
56 gate_input, ///< Input (variable) gate of the circuit
57 gate_plus, ///< Semiring plus
58 gate_times, ///< Semiring times
59 gate_monus, ///< M-Semiring monus
60 gate_project, ///< Project gate (for where provenance)
61 gate_zero, ///< Semiring zero
62 gate_one, ///< Semiring one
63 gate_eq, ///< Equijoin gate (for where provenance)
64 gate_agg, ///< Aggregation operator (for aggregate provenance)
65 gate_semimod, ///< Semimodule scalar multiplication (for aggregate provenance)
66 gate_cmp, ///< Comparison of aggregate values (HAVING-clause provenance)
67 gate_delta, ///< δ-semiring operator (see Amsterdamer, Deutch, Tannen, PODS 2011)
68 gate_value, ///< Scalar value (for aggregate provenance)
69 gate_mulinput, ///< Multivalued input (for Boolean provenance)
70 gate_update, ///< Update operation
71 gate_rv, ///< Continuous random-variable leaf (extra encodes distribution)
72 gate_arith, ///< n-ary arithmetic gate over scalar-valued children (info1 holds operator tag)
73 gate_mixture, ///< Probabilistic mixture: three wires [p_token (gate_input Bernoulli), x_token, y_token]; samples x when p is true, y otherwise
74 gate_assumed_boolean, ///< Structural marker over a single child whose sub-circuit was computed under a Boolean-provenance assumption (e.g. the safe-query rewrite); transparent (identity) for Boolean-compatible evaluators, fatal error for the rest, kept as an explicit node in PROV-XML export
75 gate_invalid, ///< Invalid gate type
76 nb_gate_types ///< Total number of gate types
77} gate_type;
78
79/**
80 * @brief Arithmetic operator tags used by @c gate_arith.
81 *
82 * Stored in the gate's @c info1 field. Local enum (not a PostgreSQL
83 * operator OID) because arithmetic in the sampler / evaluator is just
84 * C++ doubles, with no need to dispatch through the PG catalog.
85 *
86 * @warning ON-DISK ABI: like @c gate_type, these integer values are
87 * persisted (in @c info1). Reordering or renumbering existing tags
88 * will silently invalidate every existing installation's persistent
89 * circuit. New tags must be appended at the end.
90 */
91typedef enum provsql_arith_op {
92 PROVSQL_ARITH_PLUS = 0, ///< n-ary, sum of children
93 PROVSQL_ARITH_TIMES = 1, ///< n-ary, product of children
94 PROVSQL_ARITH_MINUS = 2, ///< binary, child0 - child1
95 PROVSQL_ARITH_DIV = 3, ///< binary, child0 / child1
96 PROVSQL_ARITH_NEG = 4 ///< unary, -child0
98
99/** Names of gate types */
100extern const char *gate_type_name[];
101
102/**
103 * @brief Canonical name of the per-row provenance column installed by
104 * @c add_provenance / @c repair_key.
105 *
106 * Centralised so the planner-hook entry points (@c src/provsql.c) and
107 * the safe-query detector (@c src/safe_query.c) agree on the literal;
108 * see the @c provenance_guard trigger in @c sql/provsql.common.sql.
109 */
110#define PROVSQL_COLUMN_NAME "provsql"
111
112/** Structure to store the value of various constants. This is needed to
113 * uniquely identify types, functions, etc., in PostgreSQL through their
114 * Object Identifier Types (OIDs). */
115typedef struct constants_t {
116 Oid OID_SCHEMA_PROVSQL; ///< OID of the provsql SCHEMA
117 Oid OID_TYPE_GATE_TYPE; ///< OID of the provenance_gate TYPE
118 Oid OID_TYPE_AGG_TOKEN; ///< OID of the agg_token TYPE
119 Oid OID_TYPE_UUID; ///< OID of the uuid TYPE
120 Oid OID_TYPE_UUID_ARRAY; ///< OID of the uuid[] TYPE
121 Oid OID_TYPE_BOOL; ///< OID of the BOOL TYPE
122 Oid OID_TYPE_INT; ///< OID of the INT TYPE
123 Oid OID_TYPE_INT_ARRAY; ///< OID of the INT[] TYPE
124 Oid OID_TYPE_FLOAT; ///< OID of the FLOAT TYPE
125 Oid OID_TYPE_VARCHAR; ///< OID of the VARCHAR TYPE
126 Oid OID_TYPE_TSTZMULTIRANGE; ///< OID of the tstzmultirange TYPE (PG14+, InvalidOid otherwise)
127 Oid OID_TYPE_NUMMULTIRANGE; ///< OID of the nummultirange TYPE (PG14+, InvalidOid otherwise)
128 Oid OID_TYPE_INT4MULTIRANGE; ///< OID of the int4multirange TYPE (PG14+, InvalidOid otherwise)
129 Oid OID_FUNCTION_ARRAY_AGG; ///< OID of the array_agg FUNCTION
130 Oid OID_FUNCTION_PROVENANCE_PLUS; ///< OID of the provenance_plus FUNCTION
131 Oid OID_FUNCTION_PROVENANCE_TIMES; ///< OID of the provenance_times FUNCTION
132 Oid OID_FUNCTION_PROVENANCE_MONUS; ///< OID of the provenance_monus FUNCTION
133 Oid OID_FUNCTION_PROVENANCE_PROJECT; ///< OID of the provenance_project FUNCTION
134 Oid OID_FUNCTION_PROVENANCE_EQ;///< OID of the provenance_eq FUNCTION
135 Oid OID_FUNCTION_PROVENANCE_CMP; ///< OID of the provenance_cmp FUNCTION
136 Oid OID_FUNCTION_PROVENANCE; ///< OID of the provenance FUNCTION
137 Oid GATE_TYPE_TO_OID[nb_gate_types]; ///< Array of the OID of each provenance_gate ENUM value
138 Oid OID_FUNCTION_PROVENANCE_DELTA; ///< OID of the provenance_delta FUNCTION
139 Oid OID_FUNCTION_PROVENANCE_AGGREGATE; ///< OID of the provenance_aggregate FUNCTION
140 Oid OID_FUNCTION_PROVENANCE_SEMIMOD; ///< OID of the provenance_semimod FUNCTION
141 Oid OID_FUNCTION_GATE_ZERO; ///< OID of the provenance_zero FUNCTION
142 Oid OID_FUNCTION_GATE_ONE; ///< OID of the provenance_one FUNCTION
143 Oid OID_OPERATOR_NOT_EQUAL_UUID; ///< OID of the <> operator on UUIDs FUNCTION
144 Oid OID_FUNCTION_NOT_EQUAL_UUID; ///< OID of the = operator on UUIDs FUNCTION
145 Oid OID_FUNCTION_AGG_TOKEN_UUID; ///< OID of the agg_token_uuid FUNCTION
146 Oid OID_TYPE_RANDOM_VARIABLE; ///< OID of the random_variable TYPE
147 Oid OID_FUNCTION_RV_AGGREGATE_SEMIMOD; ///< OID of rv_aggregate_semimod helper (uuid, rv -> rv) used to wrap each per-row argument of an RV-returning aggregate (sum, avg, ...)
148 /** @brief OID of @c provsql.assume_boolean(uuid)->uuid.
149 *
150 * Installed by the @c 1.5.0--1.6.0 upgrade script. Wraps its child
151 * in a fresh @c gate_assumed_boolean and returns the wrapper's UUID.
152 * When @c InvalidOid the safe-query rewriter (and any other
153 * Boolean-only rewrite that needs the marker) is effectively
154 * disabled even if @c provsql.boolean_provenance is on: the
155 * rewriter refuses to produce unmarked roots on a schema that
156 * cannot enforce the semiring-compatibility check. */
158 /** OIDs of the @c random_variable_{eq,ne,le,lt,ge,gt} comparison
159 * procedure functions, indexed by the @c ComparisonOperator enum
160 * (@c EQ=0, @c NE=1, @c LE=2, @c LT=3, @c GE=4, @c GT=5; matches the
161 * order in @c src/Aggregation.h). Used by the planner hook to detect
162 * RV-comparison @c OpExpr nodes in WHERE clauses. */
164 bool ok; ///< true if constants were loaded
166
167
168
169
170/** Structure to store the value of various constants for a specific
171 * database. */
172typedef struct database_constants_t {
173 Oid database; ///< OID of the database these constants belong to
174 constants_t constants; ///< Cached OID constants for this database
176
177/**
178 * @brief Retrieve the cached OID constants for the current database.
179 *
180 * On first call (or after a cache miss) this function looks up the OIDs
181 * of all ProvSQL-specific types, functions, and operators in the system
182 * catalogs and stores them in a per-database cache. Subsequent calls
183 * return the cached values without touching the catalogs.
184 *
185 * @param failure_if_not_possible If @c true, call @c provsql_error when
186 * the ProvSQL schema cannot be found (e.g. the extension is not
187 * installed in the current database). If @c false, return a
188 * constants_t with @c ok==false instead of aborting.
189 * @return A @c constants_t whose @c ok field is @c true on success.
190 */
191constants_t get_constants(bool failure_if_not_possible);
192
193/**
194 * @brief Find the equality operator OID for two given types.
195 *
196 * Searches @c pg_operator for the @c = operator that accepts
197 * @p ltypeId on the left and @p rtypeId on the right.
198 *
199 * @param ltypeId OID of the left operand type.
200 * @param rtypeId OID of the right operand type.
201 * @return The operator OID, or @c InvalidOid if none is found.
202 */
203Oid find_equality_operator(Oid ltypeId, Oid rtypeId);
204
205/** Global variable that becomes true if this particular backend received
206 * an interrupt signal. */
207extern bool provsql_interrupted;
208
209/** Global variable that indicates if where-provenance support has been
210 * activated through the provsql.where_provenance run-time configuration
211 * parameter. */
212extern bool provsql_where_provenance;
213
214/** Global variable that indicates the verbosity level set by the
215 * provsql.verbose_level run-time configuration parameter was set */
216extern int provsql_verbose;
217
218/** Global flag controlling agg_token text output: when true,
219 * agg_token_out emits the underlying provenance UUID instead of the
220 * default "value (*)" display string. Driven by the
221 * provsql.aggtoken_text_as_uuid GUC. */
223
224/** Colon-separated list of directories prepended to PATH when ProvSQL
225 * spawns external tools (d4, c2d, minic2d, dsharp, weightmc, graph-easy),
226 * set by the provsql.tool_search_path run-time configuration parameter.
227 * NULL or empty means rely on the server's PATH alone. */
228extern char *provsql_tool_search_path;
229
230/** Seed for the Monte Carlo sampler, set by the provsql.monte_carlo_seed
231 * run-time configuration parameter. -1 (default) means seed from
232 * std::random_device for non-deterministic sampling; any other value
233 * (including 0) is a literal seed for std::mt19937_64. Used by both
234 * the Bernoulli path (BooleanCircuit::monteCarlo) and the continuous
235 * path (gate_rv sampling), so a single GUC controls reproducibility
236 * end-to-end. */
237extern int provsql_monte_carlo_seed;
238
239/** Default sample count for Monte Carlo fallbacks when an analytical
240 * evaluator (Expectation, future hybrid evaluator, ...) cannot
241 * decompose a sub-circuit structurally. Unlike
242 * @c probability_evaluate(token, 'monte-carlo', n) where the sample
243 * count is an explicit argument, these implicit MC paths have no
244 * natural place to take @c n from.
245 *
246 * Set by the @c provsql.rv_mc_samples run-time configuration
247 * parameter; default 10000. Setting it to 0 disables the implicit
248 * MC fallback entirely: callers must then raise an exception rather
249 * than sampling. Useful for callers that want to guarantee
250 * analytical-only evaluation. */
251extern int provsql_rv_mc_samples;
252
253/** @brief When @c true (default), every @c GenericCircuit returned by
254 * @c getGenericCircuit is run through the universal cmp-resolution
255 * passes (RangeCheck for now, plus any future passes that decide
256 * comparators to certain Boolean values). Decisions become Bernoulli
257 * @c gate_input gates with probability 0 or 1, transparent to every
258 * downstream consumer (semiring evaluators, MC, view_circuit, PROV
259 * export, etc.). Set @c provsql.simplify_on_load to @c off when
260 * inspecting a circuit's raw structure (e.g. debugging gate-creation
261 * code paths). */
262extern bool provsql_simplify_on_load;
263
264/** @brief Run the hybrid evaluator (simplifier + per-cmp island
265 * decomposer) before dispatching a probability_evaluate query.
266 *
267 * Debug-only GUC, hidden from @c SHOW @c ALL and from
268 * @c postgresql.conf.sample (registered with
269 * @c GUC_NO_SHOW_ALL @c | @c GUC_NOT_IN_SAMPLE). When on (default),
270 * @c probability_evaluate runs the @c HybridEvaluator simplifier
271 * between @c RangeCheck and @c AnalyticEvaluator and the per-cmp
272 * MC island decomposer after @c AnalyticEvaluator: @c gate_arith
273 * subtrees are constant-folded and family-closed (normals, Erlang),
274 * and residual continuous-island comparators are MC-marginalised
275 * into Bernoulli @c gate_input leaves so the surrounding circuit
276 * becomes purely Boolean.
277 *
278 * Set to @c off to bypass both passes: undecidable comparators
279 * then fall through to whole-circuit MC (for the @c monte-carlo
280 * method) or raise (for @c independent / @c tree-decomposition).
281 * End users have no reason to flip this -- on is strictly better
282 * for them. Exists for developer A/B testing of the analytic
283 * path against the raw MC path and as a bisection knob if a
284 * closure rule turns out to be unsound on some workload. */
285extern bool provsql_hybrid_evaluation;
286
287/** @brief Hidden diagnostic flag for the family of closed-form /
288 * analytic probability evaluators that resolve @c gate_cmps inside
289 * @c probability_evaluate ; see the
290 * @c provsql.cmp_probability_evaluation GUC.
291 *
292 * When on (default), @c probability_evaluate runs pre-passes that
293 * recognise specific @c gate_cmp shapes and replace each cmp with
294 * a Bernoulli @c gate_input carrying the closed-form probability,
295 * bypassing the DNF that @c provsql_having's
296 * @c enumerate_valid_worlds would otherwise emit. The first
297 * implementation in this family is the Poisson-binomial pre-pass
298 * for HAVING @c COUNT(*) @c op @c C over distinct @c gate_input
299 * leaves (see @c CountCmpEvaluator.h) ; future MIN / MAX / SUM
300 * evaluators will gate on the same flag. Off forces every cmp to
301 * fall through to the enumeration path. End users have no reason
302 * to flip this ; exists for developer A/B testing and as a
303 * bisection escape valve. */
305
306/** @brief Opt-in safe-query optimisation for hierarchical conjunctive
307 * queries; see the @c provsql.boolean_provenance GUC.
308 *
309 * When @c true, the planner is permitted to rewrite self-join-free
310 * hierarchical CQs (and independent UCQs) over TID / BID tables to
311 * a read-once form whose probability is computable in linear time.
312 * The rewriter tags the resulting root gate so that semiring
313 * evaluations incompatible with this rewrite refuse to run on the
314 * produced circuit. */
316
317#include "MMappedTableInfo.h"
318
319/**
320 * @brief Look up per-table provenance metadata with a backend-local cache.
321 *
322 * Resolves to a cached value when the relation's relcache entry has
323 * not been invalidated since the last fetch; otherwise issues one
324 * @c 's' IPC to the background worker. The cache is invalidated
325 * via @c CacheRegisterRelcacheCallback, so concurrent
326 * @c add_provenance / @c repair_key / @c remove_provenance in other
327 * backends are reflected here without polling.
328 *
329 * Safe to call from the planner hot path.
330 *
331 * @param relid pg_class OID of the relation to look up.
332 * @param out On @c true return, filled with the stored record.
333 * @return @c true if a record exists for @p relid, @c false otherwise.
334 */
335extern bool provsql_lookup_table_info(Oid relid, ProvenanceTableInfo *out);
336
337/**
338 * @brief Raw IPC fetch (no cache).
339 *
340 * Implementation detail of @c provsql_lookup_table_info, exposed only
341 * so the cache layer in @c provsql_utils.c can reach it. Callers in
342 * the planner hot path should go through @c provsql_lookup_table_info.
343 */
344extern bool provsql_fetch_table_info(Oid relid, ProvenanceTableInfo *out);
345
346/**
347 * @brief Look up the base-ancestor set of a tracked relation.
348 *
349 * Per-backend cached over IPC. Returns the ancestor set when
350 * @p relid is tracked and the registry has a non-empty entry for it.
351 * @c false either when @p relid has no metadata record at all (the
352 * relation was never run through @c add_provenance / @c repair_key)
353 * or when the record exists but @c ancestor_n @c == @c 0 (the CTAS
354 * hook hasn't populated the lineage yet, or the registry was
355 * explicitly cleared). The two failure modes share the false
356 * return because both make the safe-query rewriter take the
357 * conservative refuse path -- there is no use case for treating
358 * them differently.
359 *
360 * Backed by the same per-backend cache as
361 * @c provsql_lookup_table_info and invalidated through the same
362 * relcache-invalidation callback, so concurrent
363 * @c set_ancestors / @c add_provenance / @c repair_key calls in
364 * other backends are reflected here without polling.
365 *
366 * @param relid pg_class OID of the relation to look up.
367 * @param ancestor_n_out On @c true return, count of valid entries
368 * in @p ancestors_out.
369 * @param ancestors_out On @c true return, the sorted-deduplicated
370 * ancestor OIDs (caller-allocated buffer of
371 * @c PROVSQL_TABLE_INFO_MAX_ANCESTORS @c Oid).
372 * @return @c true on a non-empty ancestor set; @c false otherwise.
373 */
374extern bool provsql_lookup_ancestry(Oid relid,
375 uint16 *ancestor_n_out,
376 Oid *ancestors_out);
377
378/**
379 * @brief Raw IPC fetch for the ancestry half (no cache).
380 *
381 * Implementation detail of @c provsql_lookup_ancestry, exposed so
382 * the cache layer in @c provsql_utils.c can reach it. Callers in
383 * the planner hot path should go through @c provsql_lookup_ancestry.
384 */
385extern bool provsql_fetch_ancestry(Oid relid,
386 uint16 *ancestor_n_out,
387 Oid *ancestors_out);
388
389/**
390 * @brief Upper bounds for the relation-key cache.
391 *
392 * Each relation contributes at most @c PROVSQL_KEY_CACHE_MAX_KEYS
393 * distinct PRIMARY-KEY / NOT-NULL-UNIQUE column-sets, each over at
394 * most @c PROVSQL_KEY_CACHE_MAX_KEY_COLS columns. These bounds keep
395 * the cache entry fixed-size (so the backend-local sorted-array
396 * representation can reuse the @c provsql_lookup_table_info pattern
397 * verbatim); relations with more or wider keys silently drop the
398 * overflow, treating the missing keys as if they did not exist
399 * (over-conservative -- the §2 FD-aware detector simply misses an
400 * optimisation, never produces an unsound rewrite).
401 */
402#define PROVSQL_KEY_CACHE_MAX_KEYS 4
403#define PROVSQL_KEY_CACHE_MAX_KEY_COLS 8
404
405/**
406 * @brief One PRIMARY-KEY or NOT-NULL-UNIQUE key on a relation.
407 *
408 * @c col_n is the number of valid entries in @c cols (in
409 * @c pg_index.indkey order, i.e. column position in the key, not
410 * @c pg_attribute.attnum order). All columns are NOT NULL by
411 * construction: PRIMARY KEY enforces this implicitly, and UNIQUE
412 * constraints are admitted only when @c pg_attribute.attnotnull is
413 * @c true for every constituent column (the §2 soundness trap on
414 * nullable UNIQUE).
415 */
420
421/**
422 * @brief Per-relation set of PRIMARY-KEY and NOT-NULL-UNIQUE keys.
423 *
424 * Populated by @c provsql_lookup_relation_keys from @c pg_constraint
425 * (filtered by @c contype @c IN @c ('p','u')) joined to
426 * @c pg_index and @c pg_attribute (for the NOT-NULL check). The
427 * detector's §2 PK-FD pass walks @c keys and, for every key @c K it
428 * recognises among the query's equijoin equivalence classes, tags
429 * the determined columns as functionally fixed inside the relevant
430 * RTE.
431 */
437
438/**
439 * @brief Look up the PRIMARY-KEY and NOT-NULL-UNIQUE keys of a
440 * relation with a backend-local cache.
441 *
442 * Companion to @c provsql_lookup_table_info. The cache lives in a
443 * separate backing array with its own relcache-invalidation
444 * callback so that a future @c ALTER @c TABLE that adds / drops a
445 * constraint refreshes the next lookup without polling. Returns
446 * @c true when the relation has at least one PRIMARY KEY or
447 * NOT-NULL UNIQUE constraint; @c false otherwise (in which case
448 * @p *out is filled with @c key_n @c = @c 0). Safe to call from
449 * the planner hot path.
450 *
451 * @param relid pg_class OID of the relation to inspect.
452 * @param out Filled on return. @c out->relid is set to @p relid
453 * regardless of return value; @c out->keys holds up to
454 * @c PROVSQL_KEY_CACHE_MAX_KEYS keys.
455 */
456extern bool provsql_lookup_relation_keys(Oid relid,
458
459#include "provsql_error.h"
460
461#endif /* PROVSQL_UTILS_H */
Per-table provenance metadata persisted alongside the circuit store.
bool provsql_where_provenance
Global variable that indicates if where-provenance support has been activated through the provsql....
Definition provsql.c:76
int provsql_verbose
Verbosity level; controlled by the provsql.verbose_level GUC.
Definition provsql.c:78
bool provsql_simplify_on_load
Run universal cmp-resolution passes when getGenericCircuit returns; controlled by the provsql....
Definition provsql.c:83
int provsql_rv_mc_samples
Default sample count for analytical-evaluator MC fallbacks; 0 disables fallback (callers raise instea...
Definition provsql.c:82
int provsql_monte_carlo_seed
Seed for the Monte Carlo sampler; -1 means non-deterministic (std::random_device); controlled by the ...
Definition provsql.c:81
bool provsql_cmp_probability_evaluation
Run closed-form / analytic probability evaluators for gate_cmps inside probability_evaluate (currentl...
Definition provsql.c:85
char * provsql_tool_search_path
Colon-separated directory list prepended to PATH when invoking external tools (d4,...
Definition provsql.c:80
bool provsql_interrupted
Global variable that becomes true if this particular backend received an interrupt signal.
Definition provsql.c:74
bool provsql_boolean_provenance
Opt-in safe-query optimisation: when true, rewrites hierarchical conjunctive queries to a read-once f...
Definition provsql.c:86
bool provsql_hybrid_evaluation
Run the hybrid-evaluator simplifier inside probability_evaluate; controlled by the provsql....
Definition provsql.c:84
bool provsql_aggtoken_text_as_uuid
When true, agg_token::text emits the underlying provenance UUID instead of "value (*)".
Definition provsql.c:79
Uniform error-reporting macros for ProvSQL.
const char * gate_type_name[]
Names of gate types.
provsql_arith_op
Arithmetic operator tags used by gate_arith.
@ PROVSQL_ARITH_DIV
binary, child0 / child1
@ PROVSQL_ARITH_PLUS
n-ary, sum of children
@ PROVSQL_ARITH_NEG
unary, -child0
@ PROVSQL_ARITH_MINUS
binary, child0 - child1
@ PROVSQL_ARITH_TIMES
n-ary, product of children
Oid find_equality_operator(Oid ltypeId, Oid rtypeId)
Find the equality operator OID for two given types.
#define PROVSQL_KEY_CACHE_MAX_KEY_COLS
bool provsql_lookup_ancestry(Oid relid, uint16 *ancestor_n_out, Oid *ancestors_out)
Look up the base-ancestor set of a tracked relation.
bool provsql_lookup_table_info(Oid relid, ProvenanceTableInfo *out)
Look up per-table provenance metadata with a backend-local cache.
constants_t get_constants(bool failure_if_not_possible)
Retrieve the cached OID constants for the current database.
@ gate_rv
Continuous random-variable leaf (extra encodes distribution).
@ gate_assumed_boolean
Structural marker over a single child whose sub-circuit was computed under a Boolean-provenance assum...
@ gate_mixture
Probabilistic mixture: three wires [p_token (gate_input Bernoulli), x_token, y_token]; samples x when...
@ gate_arith
n-ary arithmetic gate over scalar-valued children (info1 holds operator tag)
@ nb_gate_types
Total number of gate types.
bool provsql_lookup_relation_keys(Oid relid, ProvenanceRelationKeys *out)
Look up the PRIMARY-KEY and NOT-NULL-UNIQUE keys of a relation with a backend-local cache.
bool provsql_fetch_table_info(Oid relid, ProvenanceTableInfo *out)
Raw IPC fetch (no cache).
#define UUID_LEN
Number of bytes in a UUID.
bool provsql_fetch_ancestry(Oid relid, uint16 *ancestor_n_out, Oid *ancestors_out)
Raw IPC fetch for the ancestry half (no cache).
#define PROVSQL_KEY_CACHE_MAX_KEYS
Upper bounds for the relation-key cache.
One PRIMARY-KEY or NOT-NULL-UNIQUE key on a relation.
AttrNumber cols[PROVSQL_KEY_CACHE_MAX_KEY_COLS]
Per-relation set of PRIMARY-KEY and NOT-NULL-UNIQUE keys.
ProvenanceRelationKey keys[PROVSQL_KEY_CACHE_MAX_KEYS]
Per-relation metadata for the safe-query optimisation.
Structure to store the value of various constants.
Oid OID_FUNCTION_PROVENANCE_EQ
OID of the provenance_eq FUNCTION.
Oid OID_FUNCTION_PROVENANCE_AGGREGATE
OID of the provenance_aggregate FUNCTION.
Oid OID_FUNCTION_PROVENANCE_SEMIMOD
OID of the provenance_semimod FUNCTION.
Oid OID_FUNCTION_PROVENANCE
OID of the provenance FUNCTION.
Oid OID_FUNCTION_AGG_TOKEN_UUID
OID of the agg_token_uuid FUNCTION.
Oid OID_FUNCTION_RV_AGGREGATE_SEMIMOD
OID of rv_aggregate_semimod helper (uuid, rv -> rv) used to wrap each per-row argument of an RV-retur...
Oid OID_TYPE_VARCHAR
OID of the VARCHAR TYPE.
Oid OID_FUNCTION_GATE_ZERO
OID of the provenance_zero FUNCTION.
Oid OID_SCHEMA_PROVSQL
OID of the provsql SCHEMA.
Oid OID_TYPE_GATE_TYPE
OID of the provenance_gate TYPE.
Oid OID_FUNCTION_PROVENANCE_PROJECT
OID of the provenance_project FUNCTION.
Oid OID_TYPE_FLOAT
OID of the FLOAT TYPE.
Oid OID_TYPE_AGG_TOKEN
OID of the agg_token TYPE.
Oid OID_FUNCTION_ARRAY_AGG
OID of the array_agg FUNCTION.
Oid OID_TYPE_INT
OID of the INT TYPE.
Oid GATE_TYPE_TO_OID[nb_gate_types]
Array of the OID of each provenance_gate ENUM value.
Oid OID_FUNCTION_PROVENANCE_PLUS
OID of the provenance_plus FUNCTION.
Oid OID_OPERATOR_NOT_EQUAL_UUID
OID of the <> operator on UUIDs FUNCTION.
Oid OID_TYPE_UUID
OID of the uuid TYPE.
Oid OID_TYPE_TSTZMULTIRANGE
OID of the tstzmultirange TYPE (PG14+, InvalidOid otherwise).
bool ok
true if constants were loaded
Oid OID_TYPE_INT_ARRAY
OID of the INT[] TYPE.
Oid OID_FUNCTION_PROVENANCE_DELTA
OID of the provenance_delta FUNCTION.
Oid OID_FUNCTION_ASSUME_BOOLEAN
OID of provsql.assume_boolean(uuid)->uuid.
Oid OID_FUNCTION_PROVENANCE_TIMES
OID of the provenance_times FUNCTION.
Oid OID_FUNCTION_PROVENANCE_MONUS
OID of the provenance_monus FUNCTION.
Oid OID_TYPE_BOOL
OID of the BOOL TYPE.
Oid OID_FUNCTION_NOT_EQUAL_UUID
OID of the = operator on UUIDs FUNCTION.
Oid OID_FUNCTION_GATE_ONE
OID of the provenance_one FUNCTION.
Oid OID_TYPE_NUMMULTIRANGE
OID of the nummultirange TYPE (PG14+, InvalidOid otherwise).
Oid OID_TYPE_UUID_ARRAY
OID of the uuid[] TYPE.
Oid OID_TYPE_RANDOM_VARIABLE
OID of the random_variable TYPE.
Oid OID_FUNCTION_PROVENANCE_CMP
OID of the provenance_cmp FUNCTION.
Oid OID_TYPE_INT4MULTIRANGE
OID of the int4multirange TYPE (PG14+, InvalidOid otherwise).
Oid OID_FUNCTION_RV_CMP[6]
OIDs of the random_variable_{eq,ne,le,lt,ge,gt} comparison procedure functions, indexed by the Compar...
Structure to store the value of various constants for a specific database.
Oid database
OID of the database these constants belong to.
constants_t constants
Cached OID constants for this database.
UUID structure.