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
29#include "postgres_ext.h"
30#include "nodes/pg_list.h"
31
32/**
33 * @brief Possible gate types in the provenance circuit.
34 *
35 * @warning ON-DISK ABI: this enum's integer values are stored in the
36 * @c gates.mmap backing file (see @c MMappedCircuit). Reordering,
37 * inserting, or renumbering existing members will silently invalidate
38 * every existing installation's persistent circuit. New gate types
39 * must be appended **at the end**, just before @c gate_invalid. If an
40 * existing gate type ever needs to be removed or renumbered, the mmap
41 * format must gain a version header and a migration path.
42 */
43typedef enum gate_type {
44 gate_input, ///< Input (variable) gate of the circuit
45 gate_plus, ///< Semiring plus
46 gate_times, ///< Semiring times
47 gate_monus, ///< M-Semiring monus
48 gate_project, ///< Project gate (for where provenance)
49 gate_zero, ///< Semiring zero
50 gate_one, ///< Semiring one
51 gate_eq, ///< Equijoin gate (for where provenance)
52 gate_agg, ///< Aggregation operator (for aggregate provenance)
53 gate_semimod, ///< Semimodule scalar multiplication (for aggregate provenance)
54 gate_cmp, ///< Comparison of aggregate values (HAVING-clause provenance)
55 gate_delta, ///< δ-semiring operator (see Amsterdamer, Deutch, Tannen, PODS 2011)
56 gate_value, ///< Scalar value (for aggregate provenance)
57 gate_mulinput, ///< Multivalued input (for Boolean provenance)
58 gate_update, ///< Update operation
59 gate_rv, ///< Continuous random-variable leaf (extra encodes distribution)
60 gate_arith, ///< n-ary arithmetic gate over scalar-valued children (info1 holds operator tag)
61 gate_mixture, ///< Probabilistic mixture: three wires [p_token (gate_input Bernoulli), x_token, y_token]; samples x when p is true, y otherwise
62 gate_assumed, ///< 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
63 gate_annotation, ///< Transparent single-child wrapper carrying a query-level annotation in @c extra (inversion-free certificate / per-input order key); identity for EVERY evaluator, and -- unlike the children-only convention -- its UUID folds in @c extra so distinct annotations over the same child are distinct gates.
64 gate_conditioned, ///< Conditioning marker with two children [target, evidence]: measure-only, @c probability_evaluate returns P(target ∧ evidence)/P(evidence) and the RV / agg_token evaluators the restricted distribution; for the uuid carrier a TERMINAL gate (never a semiring child), nested conditioning folding into a conjunction of evidence; refused by every general @c sr_* semiring (normalization is not a semiring operation).
65 gate_mobius, ///< Signed Möbius combination: a MEASURE-only gate carrying one integer coefficient per child (in @c extra, the @c gate_arith precedent), @c probability_evaluate returns Σ_i coeff_i · P(child_i); the one new primitive of the safe-UCQ Möbius-inversion route (see @c MobiusCompiler.h), with certified-independent Boolean islands below it; refused by every general @c sr_* semiring (a signed combination is not a semiring operation).
66 gate_case, ///< N-ary guarded selection over scalar (RV) children: wires are [guard_1, value_1, ..., guard_k, value_k, default] (odd length 2k+1), first-match semantics -- the value of the first guard (a Boolean @c gate_cmp / event) that holds, else the default. Carries data only in its wires (the @c gate_conditioned precedent: no @c info / @c extra). RV/measure-carrier: a real arm in the MC sampler / RangeCheck / Expectation footprint, refused by every general @c sr_* semiring (a guarded selection is not a semiring operation).
67 gate_observe, ///< Latent-variable observation (likelihood-weighting evidence): one wire → an observed bare @c gate_rv leaf, the datum in @c extra. Contributes a continuous density factor (the leaf's pdf at the datum) instead of a Boolean truth value, composing into an evidence circuit by @c gate_times exactly like a conditioning event. Evaluated only by the importance-sampling weight walk (@c Sampler::evalWeight); refused by every Boolean / semiring evaluator (a density factor is not a semiring operation).
68 gate_fixvar, ///< Unknown of an equation system (see @c gate_fixsystem): a leaf standing for the solution of one equation, meaningful only inside the @c gate_fixsystem that lists it. Never evaluated on its own.
69 gate_fixsystem, ///< Linear equation system x_i = f_i(x) of a recursive query, one equation per derived tuple: wires [x_1, ..., x_n, f_1, ..., f_n], where the x_i are @c gate_fixvar leaves and each f_i is an ordinary circuit over input tokens and the x_j. Not a value itself: read through @c gate_fixpoint.
70 gate_fixpoint, ///< Component of the least solution of an equation system: one wire to a @c gate_fixsystem, the 1-based component index in @c info1. Its value is solved per semiring at evaluation time (topological order on acyclic systems, value iteration in absorptive semirings on cyclic ones).
71 gate_invalid, ///< Invalid gate type
72 nb_gate_types ///< Total number of gate types
73} gate_type;
74
75/**
76 * @brief Scalar-aggregation flag, stored in the upper bit of a @c gate_agg's
77 * @c info2 (whose low 31 bits hold the aggregate result-type OID).
78 *
79 * Set by the query rewriter when the aggregation has no @c GROUP @c BY (a single
80 * always-present result row). It tells the value-aware evaluators that the
81 * empty-input world is a real possible world (carrying the aggregate's
82 * empty-group value), rather than the "no row" of a grouped query. Result-type
83 * OIDs never use bit 31, so the low 31 bits still recover the type via
84 * @c PROVSQL_AGG_TYPE_MASK.
85 *
86 * @warning The flag is folded into the gate's content UUID (see
87 * @c provenance_aggregate), so a scalar and a grouped aggregate over identical
88 * children stay distinct gates recording different infos.
89 */
90#define PROVSQL_AGG_SCALAR_FLAG 0x80000000u
91#define PROVSQL_AGG_TYPE_MASK 0x7FFFFFFFu
92
93/**
94 * @brief Arithmetic operator tags used by @c gate_arith.
95 *
96 * Stored in the gate's @c info1 field. Local enum (not a PostgreSQL
97 * operator OID) because arithmetic in the sampler / evaluator is just
98 * C++ doubles, with no need to dispatch through the PG catalog.
99 *
100 * @warning ON-DISK ABI: like @c gate_type, these integer values are
101 * persisted (in @c info1). Reordering or renumbering existing tags
102 * will silently invalidate every existing installation's persistent
103 * circuit. New tags must be appended at the end.
104 */
105typedef enum provsql_arith_op {
106 PROVSQL_ARITH_PLUS = 0, ///< n-ary, sum of children
107 PROVSQL_ARITH_TIMES = 1, ///< n-ary, product of children
108 PROVSQL_ARITH_MINUS = 2, ///< binary, child0 - child1
109 PROVSQL_ARITH_DIV = 3, ///< binary, child0 / child1
110 PROVSQL_ARITH_NEG = 4, ///< unary, -child0
111 PROVSQL_ARITH_MAX = 5, ///< n-ary, max of children (order statistic; greatest / max aggregate)
112 PROVSQL_ARITH_MIN = 6, ///< n-ary, min of children (order statistic; least / min aggregate)
113 PROVSQL_ARITH_POW = 7, ///< binary, child0 ^ child1 (real branch only:
114 ///< a negative base drawn with a non-integer
115 ///< exponent raises at evaluation)
116 PROVSQL_ARITH_LN = 8, ///< unary, natural logarithm of child0
117 ///< (a negative draw raises at evaluation)
118 PROVSQL_ARITH_EXP = 9, ///< unary, e^child0
119 PROVSQL_ARITH_PERCENTILE = 10,///< continuous percentile (order-statistic
120 ///< aggregate): wires are interleaved
121 ///< [ind_1, x_1, ..., ind_n, x_n] (even
122 ///< count) where ind_i is the row's 0/1
123 ///< presence indicator; the fraction is
124 ///< text-encoded in @c extra. Per draw:
125 ///< the values whose indicator draws 1 are
126 ///< sorted and linearly interpolated at the
127 ///< fraction (SQL @c percentile_cont); an
128 ///< empty draw has no value (SQL NULL).
129 PROVSQL_ARITH_INTDIV = 11,///< binary, child0 / child1 truncated toward
130 ///< zero: SQL's division of two integers
131 PROVSQL_ARITH_ROUND = 12, ///< child0 rounded half away from zero, to
132 ///< child1 decimal digits where a second child
133 ///< is given (SQL @c round(v) / @c round(v, d))
134 PROVSQL_ARITH_FLOOR = 13, ///< unary, greatest integer <= child0
135 PROVSQL_ARITH_CEIL = 14, ///< unary, least integer >= child0
136 PROVSQL_ARITH_ABS = 15, ///< unary, |child0|
137 PROVSQL_ARITH_ASFLOAT8 = 16,///< unary, child0 as @c double @c precision
138 ///< reads it. The gates compute in @c numeric,
139 ///< which loses nothing; a query whose expression
140 ///< is a float reads the value as SQL does, and
141 ///< this is what says so -- the rewriter puts it
142 ///< where the type would otherwise be lost (the
143 ///< widening cast it peels off an aggregate, the
144 ///< result of arithmetic it swapped onto the
145 ///< agg_token operators). Transparent to every
146 ///< pass that walks arithmetic: it is the value of
147 ///< its child, rounded to that type.
148 PROVSQL_ARITH_ASFLOAT4 = 17 ///< unary, child0 as @c real reads it
150
151/**
152 * @brief Tags identifying the planner-time route that produced a circuit.
153 *
154 * Three rewrites replace a query's ordinary lineage with a circuit of their
155 * own -- the safe-query (read-once) rewriter, the joint-width UCQ compiler and
156 * the recursive-reachability compiler -- and all three then hand that circuit
157 * to the ordinary probability dispatcher, which evaluates it by an independent
158 * / certified-island sweep. Without a tag the three are indistinguishable at
159 * evaluation time and all report @c independent. Each route therefore stamps
160 * its tag on the root gate it produces, and @c probability_evaluate.cpp turns
161 * that into a first-class method name (@c sq-rewrite / @c bounded-jw /
162 * @c reachability) for @c provsql.last_eval_method and for @c byName dispatch.
163 *
164 * Where the tag lives depends on what the route's root already carries:
165 * @c PROVSQL_ROUTE_SQ_REWRITE and @c PROVSQL_ROUTE_REACHABILITY go in @c info1
166 * of the @c gate_assumed wrapper the route puts on its root (the assumption
167 * kind in @c extra -- 'boolean' / 'absorptive' -- does not identify the route:
168 * both are also reachable through the public @c provenance_assume), while
169 * @c PROVSQL_ROUTE_BOUNDED_JW goes in @c info2 of the materialised d-D root,
170 * whose @c info1 is already @c DNNF_CERT_INFO.
171 *
172 * @warning ON-DISK ABI: like @c gate_type and @c provsql_arith_op, these
173 * integer values are persisted (in @c info1 / @c info2). Reordering or
174 * renumbering existing tags will silently mislabel every existing
175 * installation's persistent circuit. New tags must be appended at the end.
176 */
177typedef enum provsql_route {
178 PROVSQL_ROUTE_NONE = 0, ///< No route rewrite: ordinary lineage
179 PROVSQL_ROUTE_SQ_REWRITE = 1, ///< Hierarchical-CQ read-once rewrite (@c src/safe_query.c)
180 PROVSQL_ROUTE_BOUNDED_JW = 2, ///< Joint-width UCQ compiler (@c src/UCQJointCompiler.h)
181 PROVSQL_ROUTE_REACHABILITY = 3 ///< Recursive-reachability compiler (@c src/reachability_evaluate.cpp)
183
184/** @brief The name of a route, as the probability dispatcher reports it
185 * and as the annotation wrapper of a materialised root carries it
186 * (@c "route:<name>"); NULL for @c PROVSQL_ROUTE_NONE. */
187static inline const char *provsql_route_name(provsql_route route)
188{
189 switch(route) {
190 case PROVSQL_ROUTE_SQ_REWRITE: return "sq-rewrite";
191 case PROVSQL_ROUTE_BOUNDED_JW: return "bounded-jw";
192 case PROVSQL_ROUTE_REACHABILITY: return "reachability";
193 default: return NULL;
194 }
195}
196
197/** Names of gate types */
198extern const char *gate_type_name[];
199
200/**
201 * @brief Canonical name of the per-row provenance column installed by
202 * @c add_provenance / @c repair_key.
203 *
204 * Centralised so the planner-hook entry points (@c src/provsql.c) and
205 * the safe-query detector (@c src/safe_query.c) agree on the literal;
206 * see the @c provenance_guard trigger in @c sql/provsql.common.sql.
207 */
208#define PROVSQL_COLUMN_NAME "provsql"
209
210/** Structure to store the value of various constants. This is needed to
211 * uniquely identify types, functions, etc., in PostgreSQL through their
212 * Object Identifier Types (OIDs). */
213typedef struct constants_t {
214 Oid OID_SCHEMA_PROVSQL; ///< OID of the provsql SCHEMA
215 Oid OID_TYPE_GATE_TYPE; ///< OID of the provenance_gate TYPE
216 Oid OID_TYPE_AGG_TOKEN; ///< OID of the agg_token TYPE
217 Oid OID_TYPE_UUID; ///< OID of the uuid TYPE
218 Oid OID_TYPE_UUID_ARRAY; ///< OID of the uuid[] TYPE
219 Oid OID_TYPE_BOOL; ///< OID of the BOOL TYPE
220 Oid OID_TYPE_INT; ///< OID of the INT TYPE
221 Oid OID_TYPE_INT_ARRAY; ///< OID of the INT[] TYPE
222 Oid OID_TYPE_FLOAT; ///< OID of the FLOAT TYPE
223 Oid OID_TYPE_VARCHAR; ///< OID of the VARCHAR TYPE
224 Oid OID_TYPE_TSTZMULTIRANGE; ///< OID of the tstzmultirange TYPE (PG14+, InvalidOid otherwise)
225 Oid OID_TYPE_NUMMULTIRANGE; ///< OID of the nummultirange TYPE (PG14+, InvalidOid otherwise)
226 Oid OID_TYPE_INT4MULTIRANGE; ///< OID of the int4multirange TYPE (PG14+, InvalidOid otherwise)
227 Oid OID_FUNCTION_ARRAY_AGG; ///< OID of the array_agg FUNCTION
228 Oid OID_FUNCTION_PROVENANCE_PLUS; ///< OID of the provenance_plus FUNCTION
229 Oid OID_FUNCTION_PROVENANCE_TIMES; ///< OID of the provenance_times FUNCTION
230 Oid OID_FUNCTION_PROVENANCE_MONUS; ///< OID of the provenance_monus FUNCTION
231 Oid OID_FUNCTION_PROVENANCE_PROJECT; ///< OID of the provenance_project FUNCTION
232 Oid OID_FUNCTION_PROVENANCE_EQ;///< OID of the provenance_eq FUNCTION
233 Oid OID_FUNCTION_PROVENANCE_CMP; ///< OID of the provenance_cmp FUNCTION
234 Oid OID_FUNCTION_PROVENANCE; ///< OID of the provenance FUNCTION
235 Oid GATE_TYPE_TO_OID[nb_gate_types]; ///< Array of the OID of each provenance_gate ENUM value
236 Oid OID_FUNCTION_PROVENANCE_DELTA; ///< OID of the provenance_delta FUNCTION
237 Oid OID_FUNCTION_PROVENANCE_CMP_TIMES; ///< OID of the provenance_cmp_times FUNCTION
238 Oid OID_FUNCTION_PROVENANCE_AGGREGATE; ///< OID of the provenance_aggregate FUNCTION
239 Oid OID_FUNCTION_PROVENANCE_SEMIMOD; ///< OID of the provenance_semimod FUNCTION
240 /** @brief OID of @c provenance_semimod_nullable, the variant used for
241 * aggregates that see their NULL inputs (@c array_agg, ...); @c InvalidOid
242 * on a schema that predates it. */
244 /** @brief OID of @c row_number_as_rank, which @c row_number() over tracked
245 * relations is rewritten into; @c InvalidOid on a schema that predates
246 * it. */
248 /** @brief OID of the @c order_determined aggregate, the tie check of an
249 * order-dependent aggregate; @c InvalidOid on a schema that predates it. */
251 /** @brief OID of @c order_checked, which warns where that check fails;
252 * @c InvalidOid on a schema that predates it. */
254 /** @brief OID of @c ntile_as_rank, the tie check of a tracked
255 * @c ntile(); @c InvalidOid on a schema that predates it. */
257 /** @brief OID of @c agg_token_null_event, the IS [NOT] NULL of an
258 * aggregate column; @c InvalidOid on a schema that predates it. */
260 /** @brief OID of @c agg_count_can_be_zero; @c InvalidOid on a schema that
261 * predates it. */
263 /** @brief OID of @c window_distinct_tokens, used for @c dense_rank();
264 * @c InvalidOid on a schema that predates it. */
266 /** @brief OID of the marker @c plain(), which keeps a LIMIT a truncation
267 * of the actual result; @c InvalidOid on a schema that predates it. */
269 /** @brief OID of @c plain_truth(), whether a token holds in the database
270 * as it is; @c InvalidOid on a schema that predates it. */
272 /** @brief OID of @c agg_token_plain_text(), the sort key of an ORDER BY on
273 * an aggregate result; @c InvalidOid on a schema that predates it. */
275 /** @brief OID of @c agg_token_frozen_value(), the value of an aggregate
276 * result that ProvSQL casts to a plain value; @c InvalidOid on a schema
277 * that predates it. */
279 /** @brief OID of @c agg_token_explode_children(), the children of the
280 * gate of a @c choose() result exploded into rows; @c InvalidOid on a
281 * schema that predates it. */
283 /** @brief OID of @c agg_possible_values(), the values an aggregate result
284 * takes over the possible worlds, one per exploded row; @c InvalidOid on
285 * a schema that predates it. */
287 /** @brief OID of @c agg_guard_holds(), the truth of a comparison of
288 * aggregate results in the database as it is, read off the values they
289 * record; @c InvalidOid on a schema that predates it. */
291 /** @brief OID of @c provenance_semimod_flat(), the contributions of an
292 * aggregate result aggregated again; @c InvalidOid on a schema that
293 * predates it. */
295 /** @brief OID of @c provenance_semimod_nested(), the contribution of an
296 * aggregate result aggregated by an aggregate of another kind, whose M
297 * side is the inner aggregate's gate; @c InvalidOid on a schema that
298 * predates it. */
300 /** @brief OID of the @c provenance_contributions_cat aggregate, which
301 * collects them; @c InvalidOid on a schema that predates it. */
303 /** @brief OID of @c gate_null(), the value gate of the NULL value (a NULL
304 * branch of a CASE over aggregates) */
306 Oid OID_FUNCTION_GATE_ZERO; ///< OID of the provenance_zero FUNCTION
307 Oid OID_FUNCTION_GATE_ONE; ///< OID of the provenance_one FUNCTION
308 Oid OID_OPERATOR_NOT_EQUAL_UUID; ///< OID of the <> operator on UUIDs FUNCTION
309 Oid OID_FUNCTION_NOT_EQUAL_UUID; ///< OID of the = operator on UUIDs FUNCTION
310 Oid OID_FUNCTION_AGG_TOKEN_UUID; ///< OID of the agg_token_uuid FUNCTION
311 Oid OID_FUNCTION_AGG_VALUE_GATE; ///< agg_value_gate(numeric) -> uuid
312 Oid OID_FUNCTION_GET_CHILDREN; ///< OID of the get_children FUNCTION
313 Oid OID_FUNCTION_GET_EXTRA; ///< OID of the get_extra FUNCTION
314 Oid OID_UNNEST; ///< OID of the unnest(anyarray) FUNCTION
315 Oid OID_TYPE_RANDOM_VARIABLE; ///< OID of the random_variable TYPE
316 Oid OID_TYPE_RANDOM_VARIABLE_ARRAY; ///< OID of the random_variable[] TYPE
317 /** @name Order-statistic constructors the planner lifts a builtin
318 * @c GREATEST / @c LEAST over @c random_variable arguments into. */
319 /**@{*/
320 Oid OID_FUNCTION_RV_GREATEST; ///< provsql.greatest(VARIADIC random_variable[])
321 Oid OID_FUNCTION_RV_LEAST; ///< provsql.least(VARIADIC random_variable[])
322 /**@}*/
323 Oid OID_FUNCTION_RV_AGGREGATE_SEMIMOD; ///< OID of rv_aggregate_semimod(uuid, rv) -> rv: wraps a per-row argument as mixture(prov, rv, as_random(0)) (identity 0, for sum / avg-numerator)
324 Oid OID_FUNCTION_RV_AGGREGATE_SEMIMOD_ID; ///< OID of the 3-arg rv_aggregate_semimod(uuid, rv, float8): identity-parameterised wrap mixture(prov, rv, as_random(identity)) for product / max / min
325 Oid OID_FUNCTION_RV_AGGREGATE_INDICATOR; ///< OID of rv_aggregate_indicator(uuid) -> rv: the avg denominator wrap mixture(prov, 1, 0)
326 Oid OID_FUNCTION_RV_AGGREGATE_INDICATOR_VALUED; ///< OID of rv_aggregate_indicator(uuid, rv) -> rv: NULL when the row's value is NULL (SQL NULL-skip for avg's count)
327 Oid OID_FUNCTION_RV_DIV; ///< OID of random_variable_div(rv, rv) -> rv: builds the avg num/denom division gate
328 /** @brief OIDs of the RV-returning aggregates, keyed for the per-aggregate
329 * identity dispatch in @c make_rv_aggregate_expression (product / max /
330 * min bake their identity into the wrap; avg rewrites to sum/sum). */
331 /**@{*/
332 Oid OID_AGG_SUM_RV; ///< provsql.sum(random_variable)
333 Oid OID_AGG_PRODUCT_RV; ///< provsql.product(random_variable)
334 Oid OID_AGG_AVG_RV; ///< provsql.avg(random_variable)
335 Oid OID_AGG_MAX_RV; ///< provsql.max(random_variable)
336 Oid OID_AGG_MIN_RV; ///< provsql.min(random_variable)
337 Oid OID_AGG_RV_SUM_OR_NULL; ///< provsql.rv_sum_or_null(random_variable): the avg-numerator sum, NULL on an empty group (so avg is NULL for an empty group after STRICT division)
338 /**@}*/
339 /** @brief SQL-standard statistic aggregates over @c random_variable rows
340 * and their internal indicator-carrying rewrite targets.
341 *
342 * The public forms wrap every row with the certain indicator
343 * @c as_random(1); a provenance-tracked query is rewritten by
344 * @c make_rv_aggregate_expression to the @c _impl form whose extra
345 * leading argument is the row's provenance indicator
346 * @c rv_aggregate_indicator(prov), so absent rows drop out of the
347 * statistic (count, sums, and the percentile's member set alike). */
348 /**@{*/
349 Oid OID_AGG_COVAR_POP_RV; ///< provsql.covar_pop(rv, rv)
350 Oid OID_AGG_COVAR_SAMP_RV; ///< provsql.covar_samp(rv, rv)
351 Oid OID_AGG_CORR_RV; ///< provsql.corr(rv, rv)
352 Oid OID_AGG_STDDEV_POP_RV; ///< provsql.stddev_pop(rv)
353 Oid OID_AGG_STDDEV_SAMP_RV; ///< provsql.stddev_samp(rv)
354 Oid OID_AGG_PERCENTILE_CONT_RV; ///< provsql.percentile_cont(float8) WITHIN GROUP (ORDER BY rv)
355 Oid OID_AGG_RV_COVAR_POP_IMPL; ///< provsql.rv_covar_pop_impl(ind rv, x rv, y rv)
356 Oid OID_AGG_RV_COVAR_SAMP_IMPL; ///< provsql.rv_covar_samp_impl(ind rv, x rv, y rv)
357 Oid OID_AGG_RV_CORR_IMPL; ///< provsql.rv_corr_impl(ind rv, x rv, y rv)
358 Oid OID_AGG_RV_STDDEV_POP_IMPL; ///< provsql.rv_stddev_pop_impl(ind rv, x rv)
359 Oid OID_AGG_RV_STDDEV_SAMP_IMPL; ///< provsql.rv_stddev_samp_impl(ind rv, x rv)
360 Oid OID_AGG_RV_PERCENTILE_IMPL; ///< provsql.rv_percentile_impl(fraction float8, ind rv, x rv)
361 /**@}*/
362 Oid OID_FUNCTION_CHOOSE; ///< OID of the choose(anyelement) aggregate (keeps the first non-NULL value); used to decorrelate scalar subqueries into a LEFT JOIN + GROUP BY
363 Oid OID_FUNCTION_ARRAY_COLLECT; ///< OID of the array_collect(anynonarray) aggregate (array_agg with @c {} over no rows); the value of a decorrelated @c ARRAY(SELECT ...)
364 /** @brief OID of @c provsql.assume_boolean(uuid)->uuid.
365 *
366 * Installed by the @c 1.5.0--1.6.0 upgrade script. Wraps its child
367 * in a fresh @c gate_assumed and returns the wrapper's UUID.
368 * When @c InvalidOid the safe-query rewriter (and any other
369 * Boolean-only rewrite that needs the marker) is effectively
370 * disabled even if @c provsql.boolean_provenance is on: the
371 * rewriter refuses to produce unmarked roots on a schema that
372 * cannot enforce the semiring-compatibility check. */
374 /** @brief OID of @c provsql.annotate(uuid,text)->uuid.
375 *
376 * Wraps its child in a fresh transparent @c gate_annotation whose UUID
377 * folds in the @c extra text, and returns the wrapper's UUID. Used to
378 * attach the inversion-free tractability certificate (on the root) and the
379 * per-input order keys. @c InvalidOid on a schema predating the gate
380 * (the inversion-free carrier is then disabled). */
382 /** @brief OID of @c provsql.inversion_free_key(text,text,int)->text.
383 *
384 * Builds the @c K-prefixed per-input order-key string the planner attaches
385 * (via @c annotate) to each certified atom's provenance on the
386 * inversion-free path. @c InvalidOid on a schema predating it (markers are
387 * then not attached; the path declines and falls back). */
389 /** OIDs of the @c random_variable_{eq,ne,le,lt,ge,gt} comparison
390 * procedure functions, indexed by the @c ComparisonOperator enum
391 * (@c EQ=0, @c NE=1, @c LE=2, @c LT=3, @c GE=4, @c GT=5; matches the
392 * order in @c src/Aggregation.h). Used by the planner hook to detect
393 * RV-comparison @c OpExpr nodes in WHERE clauses. */
395 /** @brief OID of @c provsql.cond(uuid,uuid)->uuid.
396 *
397 * Builds the terminal @c gate_conditioned (value-level conditioning, the
398 * binary @c | operator). The rewriter wraps a row's output provenance in
399 * it when a @c given(...) marker is present. @c InvalidOid on a schema
400 * predating the conditioning feature (the @c given rewrite is then
401 * disabled). */
403 /** @brief OID of @c provsql.given(uuid)->uuid.
404 *
405 * The whole-tuple output-conditioning marker: a consumed select-list term
406 * the rewriter strips from the visible projection, conditioning each output
407 * row's provenance on the marker's argument. @c InvalidOid on a schema
408 * predating the feature. */
410 /** @brief OID of @c provsql.random_variable_cond(random_variable,uuid).
411 * The real conditioning constructor the planner emits when rewriting the
412 * @c "X | (predicate)" placeholder. @c InvalidOid disables the rewrite. */
414 /** @brief OID of @c provsql.agg_token_cond(agg_token,uuid): the conditioning
415 * constructor for the @c agg_token carrier the planner emits when rewriting
416 * the @c "SUM(x) | (predicate)" placeholder. */
418 /** @name @c "X | (predicate)" placeholder OIDs (carrier-parametric).
419 * Each is a no-op placeholder operator whose right operand is a Boolean
420 * combination of random_variable / agg_token comparisons; the planner
421 * converts that predicate into a condition gate and emits the matching
422 * conditioning constructor. @c InvalidOid disables the rewrite. */
423 /**@{*/
424 Oid OID_FUNCTION_COND_PREDICATE; ///< cond_predicate(uuid,boolean)
425 Oid OID_FUNCTION_RV_COND_PREDICATE; ///< random_variable_cond_predicate(random_variable,boolean)
426 Oid OID_FUNCTION_AGG_COND_PREDICATE; ///< agg_token_cond_predicate(agg_token,boolean)
427 Oid OID_FUNCTION_PREDICATE_COND_PREDICATE; ///< predicate_cond_predicate(boolean,boolean) -- (A)|(B), both events
428 Oid OID_FUNCTION_GIVEN_PREDICATE; ///< given_predicate(boolean) -- prefix whole-tuple
429 /**@}*/
430 /** @brief OID of @c provsql.regular_indicator(boolean): the deterministic
431 * @c gate_one/@c gate_zero indicator the planner emits for an ordinary
432 * (regular-type) comparison appearing inside a mixed conditioning
433 * predicate. */
435 /** @brief OID of the real @c provsql.probability_evaluate(uuid,text,text).
436 * The target of the @c probability(<predicate>) rewrite: the planner emits
437 * a call to it over the event token built from the Boolean argument. */
439 /** @brief OID of the @c probability(boolean,text,text) placeholder.
440 * When its argument carries a probabilistic (random_variable / aggregate)
441 * comparison the planner rewrites the whole call into
442 * @c probability_evaluate over the argument's event token; a purely
443 * deterministic argument is left to the SQL body (which returns @c 1/0).
444 * The predicate surface is only on @c probability, not
445 * @c probability_evaluate, to avoid an unknown-literal overload ambiguity
446 * (see @c sql/provsql.common.sql). @c InvalidOid disables the rewrite. */
448 /** @brief OID of @c provsql.rv_case(uuid[])->random_variable.
449 * Builds a @c gate_case from the flattened
450 * @c [guard_1, value_1, ..., default] wire list the planner emits for an
451 * RV-typed @c CASE expression. @c InvalidOid on a schema predating
452 * @c gate_case (the @c CASE-over-RV rewrite is then disabled). */
454 /** @brief OID of @c agg_case(uuid[]), the @c agg_token constructor the
455 * planner hook lowers an aggregate-carrier @c CASE into. @c InvalidOid on
456 * a schema predating it (the rewrite is then disabled). */
458 bool ok; ///< true if constants were loaded
460
461
462
463
464/** Structure to store the value of various constants for a specific
465 * database. */
466typedef struct database_constants_t {
467 Oid database; ///< OID of the database these constants belong to
468 constants_t constants; ///< Cached OID constants for this database
470
471/**
472 * @brief Retrieve the cached OID constants for the current database.
473 *
474 * On first call (or after a cache miss) this function looks up the OIDs
475 * of all ProvSQL-specific types, functions, and operators in the system
476 * catalogs and stores them in a per-database cache. Subsequent calls
477 * return the cached values without touching the catalogs.
478 *
479 * @param failure_if_not_possible If @c true, call @c provsql_error when
480 * the ProvSQL schema cannot be found (e.g. the extension is not
481 * installed in the current database). If @c false, return a
482 * constants_t with @c ok==false instead of aborting.
483 * @return A @c constants_t whose @c ok field is @c true on success.
484 */
485constants_t get_constants(bool failure_if_not_possible);
486
487/**
488 * @brief Find the equality operator OID for two given types.
489 *
490 * Searches @c pg_operator for the @c = operator that accepts
491 * @p ltypeId on the left and @p rtypeId on the right.
492 *
493 * @param ltypeId OID of the left operand type.
494 * @param rtypeId OID of the right operand type.
495 * @return The operator OID, or @c InvalidOid if none is found.
496 */
497Oid find_equality_operator(Oid ltypeId, Oid rtypeId);
498
499/** Global variable that becomes true if this particular backend received
500 * an interrupt signal. */
501extern bool provsql_interrupted;
502
503/** Global variable that indicates if where-provenance support has been
504 * activated through the provsql.where_provenance run-time configuration
505 * parameter. */
506extern bool provsql_where_provenance;
507
508/** Global variable that indicates the verbosity level set by the
509 * provsql.verbose_level run-time configuration parameter was set */
510extern int provsql_verbose;
511
512/** Global variable backing the provsql.transaction_token run-time
513 * configuration parameter: the textual UUID of the update gate standing
514 * for the current transaction, or empty when it has none yet. */
515extern char *provsql_transaction_token;
516
517/** Global variable set by the provsql.store_synchronous_commit run-time
518 * configuration parameter: when true, a transaction that has written to
519 * the circuit store forces the store to stable storage before it
520 * commits. */
522
523/** Global variable holding the probability evaluation method(s) used by the
524 * most recent probability_evaluate call, exposed via the
525 * provsql.last_eval_method run-time configuration parameter. */
526extern char *provsql_last_eval_method;
527
528/** Global flag controlling agg_token text output: when true,
529 * agg_token_out emits the underlying provenance UUID instead of the
530 * default "value (*)" display string. Driven by the
531 * provsql.aggtoken_text_as_uuid GUC. */
533
534/** @brief Serial of the user's current statement (@c provsql.c), read by the
535 * @c agg_token conversions to warn once for a statement, not once per row. */
536extern unsigned provsql_stmt_serial;
537
538/** Colon-separated list of directories prepended to PATH when ProvSQL
539 * spawns external tools (d4, c2d, minic2d, dsharp, weightmc, graph-easy),
540 * set by the provsql.tool_search_path run-time configuration parameter.
541 * NULL or empty means rely on the server's PATH alone. */
542extern char *provsql_tool_search_path;
543
544/** Compiler invoked as the final fallback in BooleanCircuit::makeDD when
545 * both interpretAsDD() and the in-process tree-decomposition path fail
546 * (the latter typically on treewidth blow-up). Defaults to "d4"; set by
547 * the provsql.fallback_compiler run-time configuration parameter to any
548 * compiler accepted by BooleanCircuit::compilation (d4 / d4v2 / c2d /
549 * minic2d / dsharp / panini-*). */
550extern char *provsql_fallback_compiler;
551
552/** Launch command for the managed KCMCP knowledge-compiler server, set by
553 * the provsql.kcmcp_server run-time configuration parameter (PGC_SIGHUP).
554 * The literal substring "{endpoint}" is replaced by the Unix-socket path the
555 * supervisor background worker chooses, e.g. "tdkc --kcmcp unix:{endpoint}".
556 * NULL or empty means no managed server is launched. */
557extern char *provsql_kcmcp_server;
558
559/** Read the live endpoint of the managed KCMCP server from shared memory
560 * (e.g. "unix:/tmp/..."), or an empty string when none is running. */
561const char *provsql_kcmcp_managed_endpoint(void);
562
563/** Register the supervisor background worker that launches and supervises the
564 * managed KCMCP server; called from _PG_init alongside the mmap worker. */
566
567/** Seed for the Monte Carlo sampler, set by the provsql.monte_carlo_seed
568 * run-time configuration parameter. -1 (default) means seed from
569 * std::random_device for non-deterministic sampling; any other value
570 * (including 0) is a literal seed for std::mt19937_64. Used by both
571 * the Bernoulli path (BooleanCircuit::monteCarlo) and the continuous
572 * path (gate_rv sampling), so a single GUC controls reproducibility
573 * end-to-end. */
574extern int provsql_monte_carlo_seed;
575
576/** Default sample count for Monte Carlo fallbacks when an analytical
577 * evaluator (Expectation, future hybrid evaluator, ...) cannot
578 * decompose a sub-circuit structurally. Unlike
579 * @c probability_evaluate(token, 'monte-carlo', n) where the sample
580 * count is an explicit argument, these implicit MC paths have no
581 * natural place to take @c n from.
582 *
583 * Set by the @c provsql.rv_mc_samples run-time configuration
584 * parameter; default 10000. Setting it to 0 disables the implicit
585 * MC fallback entirely: callers must then raise an exception rather
586 * than sampling. Useful for callers that want to guarantee
587 * analytical-only evaluation. */
588extern int provsql_rv_mc_samples;
589
590/* Effective-sample-size warning threshold for likelihood-weighting posterior
591 * inference (@c provsql.ess_warn_fraction; default 0.1). A readout over
592 * @c gate_observe evidence warns when the posterior ESS falls below this
593 * fraction of the accepted draws (the weights are degenerating). 0 silences
594 * the warning. */
595extern double provsql_ess_warn_fraction;
596
597/* Debug/safety hard cap on d-tree subproblems before the method bails to the
598 * next (0 = off). The chooser auto-budgets the d-tree at the next-best
599 * method's estimated cost regardless; this imposes an extra fixed cap. */
601
602/* Joint-width UCQ compiler (see UCQJointCompiler.h): the maximum joint
603 * treewidth attempted before the path declines (the SQL layer then falls
604 * back to the default cost-based probability evaluation). Default =
605 * TreeDecomposition::MAX_TREEWIDTH (10). */
607
608/* Joint-width UCQ compiler: the per-bag DP state-count cap, the true safety
609 * net (the static enumerating-variable count is only a predictor). Default
610 * 1<<16. */
611extern int provsql_joint_max_states;
612extern int provsql_gate_cache_size;
613/* Memory an evaluation may add to the backend, in MB (0: no limit); see
614 * provsql_interrupt.h */
615extern int provsql_max_memory;
616/* Possible worlds of a group a condition on its aggregate may enumerate
617 * (0: no limit) */
618extern int provsql_max_worlds;
619
620/* Recognise unsafe UCQs at planner time and route their existence provenance
621 * through the joint-width compiler (on by default); provsql.joint_width is a
622 * debug-only switch to disable it. */
623extern bool provsql_joint_width;
624
625/* Try the safe-UCQ Möbius-inversion route before the joint-width compiler,
626 * short-circuiting on success (on by default); provsql.mobius is a debug-only
627 * switch to disable it. */
628extern bool provsql_mobius;
629
630/* Data-cost cap of the Möbius route: it declines once its compile has built
631 * more than this many gates; provsql.mobius_max_gates GUC. */
632extern int provsql_mobius_max_gates;
633
634/* Query-cost cap of the Möbius route: it declines when the CNF of a sentence
635 * has more than this many conjuncts (the inclusion-exclusion lattice it walks
636 * has 2^M elements); provsql.mobius_max_cnf GUC. */
637extern int provsql_mobius_max_cnf;
638
639/** @brief When @c true (default), every @c GenericCircuit returned by
640 * @c getGenericCircuit is run through the universal cmp-resolution
641 * passes (RangeCheck for now, plus any future passes that decide
642 * comparators to certain Boolean values). Decisions become Bernoulli
643 * @c gate_input gates with probability 0 or 1, transparent to every
644 * downstream consumer (semiring evaluators, MC, view_circuit, PROV
645 * export, etc.). Set @c provsql.simplify_on_load to @c off when
646 * inspecting a circuit's raw structure (e.g. debugging gate-creation
647 * code paths). */
648extern bool provsql_simplify_on_load;
649
650/**
651 * @brief Values of the @c provsql.prob_cache and @c provsql.idp_fold GUCs.
652 *
653 * Both optimizations change which computation answers a probability
654 * request, so by default they apply only where ProvSQL chooses the method.
655 */
656typedef enum {
657 PROVSQL_EVAL_OPT_OFF, ///< Never applied.
658 PROVSQL_EVAL_OPT_AUTO, ///< Applied by the default method only (default).
659 PROVSQL_EVAL_OPT_ON ///< Also applied to a method called by name.
661
662/** @brief Backing variable of @c provsql.prob_cache: when the per-backend
663 * cache of compiled d-DNNFs, keyed by canonical form, is consulted. */
664extern int provsql_prob_cache;
665
666/** @brief Backing variable of @c provsql.prob_cache_size: the budget, in
667 * kB, of the per-backend cache of compiled d-DNNFs. */
668extern int provsql_prob_cache_size;
669
670/** @brief Backing variable of @c provsql.idp_fold: when an AND or OR root is
671 * split into independent groups evaluated separately. */
672extern int provsql_idp_fold;
673
674/** @brief Run the hybrid evaluator (simplifier + per-cmp island
675 * decomposer) before dispatching a probability_evaluate query.
676 *
677 * Debug-only GUC, hidden from @c SHOW @c ALL and from
678 * @c postgresql.conf.sample (registered with
679 * @c GUC_NO_SHOW_ALL @c | @c GUC_NOT_IN_SAMPLE). When on (default),
680 * @c probability_evaluate runs the @c HybridEvaluator simplifier
681 * between @c RangeCheck and @c AnalyticEvaluator and the per-cmp
682 * MC island decomposer after @c AnalyticEvaluator: @c gate_arith
683 * subtrees are constant-folded and family-closed (normals, Erlang),
684 * and residual continuous-island comparators are MC-marginalised
685 * into Bernoulli @c gate_input leaves so the surrounding circuit
686 * becomes purely Boolean.
687 *
688 * Set to @c off to bypass both passes: undecidable comparators
689 * then fall through to whole-circuit MC (for the @c monte-carlo
690 * method) or raise (for @c independent / @c tree-decomposition).
691 * End users have no reason to flip this -- on is strictly better
692 * for them. Exists for developer A/B testing of the analytic
693 * path against the raw MC path and as a bisection knob if a
694 * closure rule turns out to be unsound on some workload. */
695extern bool provsql_hybrid_evaluation;
696
697/** @brief Hidden diagnostic flag for the family of closed-form /
698 * analytic probability evaluators that resolve @c gate_cmps inside
699 * @c probability_evaluate ; see the
700 * @c provsql.cmp_probability_evaluation GUC.
701 *
702 * When on (default), @c probability_evaluate runs pre-passes that
703 * recognise specific @c gate_cmp shapes and replace each cmp with
704 * a Bernoulli @c gate_input carrying the closed-form probability,
705 * bypassing the DNF that @c provsql_having's
706 * @c enumerate_valid_worlds would otherwise emit. The first
707 * implementation in this family is the Poisson-binomial pre-pass
708 * for HAVING @c COUNT(*) @c op @c C over distinct @c gate_input
709 * leaves (see @c CountCmpEvaluator.h) ; future MIN / MAX / SUM
710 * evaluators will gate on the same flag. Off forces every cmp to
711 * fall through to the enumeration path. End users have no reason
712 * to flip this ; exists for developer A/B testing and as a
713 * bisection escape valve. */
715
716/** @brief Kill-switch for the inversion-free structured-d-DNNF probability
717 * path; see the @c provsql.inversion_free GUC.
718 *
719 * When on (default), @c probability_evaluate, on a query carrying an
720 * inversion-free tractability certificate, tries the structured-d-DNNF
721 * builder after @c independentEvaluation and before tree-decomposition / d4.
722 * Off disables only that automatic insertion (for A/B testing); the explicit
723 * @c probability_evaluate(token,'inversion-free') method ignores this flag.
724 * The path is self-gating on the certificate, which is attached only to
725 * certified queries, so leaving it on is safe. */
726extern bool provsql_inversion_free;
727
728/** @brief Opt-in safe-query optimisation for hierarchical conjunctive
729 * queries; see the @c provsql.boolean_provenance GUC.
730 *
731 * When @c true, the planner is permitted to rewrite self-join-free
732 * hierarchical CQs (and independent UCQs) over TID / BID tables to
733 * a read-once form whose probability is computable in linear time.
734 * The rewriter tags the resulting root gate so that semiring
735 * evaluations incompatible with this rewrite refuse to run on the
736 * produced circuit. */
738
739/** @brief Derived flag of the @c provsql.provenance GUC: the session's
740 * provenance class is 'absorptive' or 'boolean', licensing
741 * constructions sound for absorptive semirings only (the
742 * bounded-treewidth reachability route, tagged tokens). */
744
745#include "MMappedTableInfo.h"
746
747/**
748 * @brief Look up per-table provenance metadata with a backend-local cache.
749 *
750 * Resolves to a cached value when the relation's relcache entry has
751 * not been invalidated since the last fetch; otherwise issues one
752 * @c 's' IPC to the background worker. The cache is invalidated
753 * via @c CacheRegisterRelcacheCallback, so concurrent
754 * @c add_provenance / @c repair_key / @c remove_provenance in other
755 * backends are reflected here without polling.
756 *
757 * Safe to call from the planner hot path.
758 *
759 * @param relid pg_class OID of the relation to look up.
760 * @param out On @c true return, filled with the stored record.
761 * @return @c true if a record exists for @p relid, @c false otherwise.
762 */
763extern bool provsql_lookup_table_info(Oid relid, ProvenanceTableInfo *out);
764
765/**
766 * @brief Raw IPC fetch (no cache).
767 *
768 * Implementation detail of @c provsql_lookup_table_info, exposed only
769 * so the cache layer in @c provsql_utils.c can reach it. Callers in
770 * the planner hot path should go through @c provsql_lookup_table_info.
771 */
772extern bool provsql_fetch_table_info(Oid relid, ProvenanceTableInfo *out);
773
774/**
775 * @brief Look up the base-ancestor set of a tracked relation.
776 *
777 * Per-backend cached over IPC. Returns the ancestor set when
778 * @p relid is tracked and the registry has a non-empty entry for it.
779 * @c false either when @p relid has no metadata record at all (the
780 * relation was never run through @c add_provenance / @c repair_key)
781 * or when the record exists but @c ancestor_n @c == @c 0 (the CTAS
782 * hook hasn't populated the lineage yet, or the registry was
783 * explicitly cleared). The two failure modes share the false
784 * return because both make the safe-query rewriter take the
785 * conservative refuse path -- there is no use case for treating
786 * them differently.
787 *
788 * Backed by the same per-backend cache as
789 * @c provsql_lookup_table_info and invalidated through the same
790 * relcache-invalidation callback, so concurrent
791 * @c set_ancestors / @c add_provenance / @c repair_key calls in
792 * other backends are reflected here without polling.
793 *
794 * @param relid pg_class OID of the relation to look up.
795 * @param ancestor_n_out On @c true return, count of valid entries
796 * in @p ancestors_out.
797 * @param ancestors_out On @c true return, the sorted-deduplicated
798 * ancestor OIDs (caller-allocated buffer of
799 * @c PROVSQL_TABLE_INFO_MAX_ANCESTORS @c Oid).
800 * @return @c true on a non-empty ancestor set; @c false otherwise.
801 */
802extern bool provsql_lookup_ancestry(Oid relid,
803 uint16 *ancestor_n_out,
804 Oid *ancestors_out);
805
806/**
807 * @brief Raw IPC fetch for the ancestry half (no cache).
808 *
809 * Implementation detail of @c provsql_lookup_ancestry, exposed so
810 * the cache layer in @c provsql_utils.c can reach it. Callers in
811 * the planner hot path should go through @c provsql_lookup_ancestry.
812 */
813extern bool provsql_fetch_ancestry(Oid relid,
814 uint16 *ancestor_n_out,
815 Oid *ancestors_out);
816
817/**
818 * @brief Upper bounds for the relation-key cache.
819 *
820 * Each relation contributes at most @c PROVSQL_KEY_CACHE_MAX_KEYS
821 * distinct PRIMARY-KEY / NOT-NULL-UNIQUE column-sets, each over at
822 * most @c PROVSQL_KEY_CACHE_MAX_KEY_COLS columns. These bounds keep
823 * the cache entry fixed-size (so the backend-local sorted-array
824 * representation can reuse the @c provsql_lookup_table_info pattern
825 * verbatim); relations with more or wider keys silently drop the
826 * overflow, treating the missing keys as if they did not exist
827 * (over-conservative -- the §2 FD-aware detector simply misses an
828 * optimisation, never produces an unsound rewrite).
829 */
830#define PROVSQL_KEY_CACHE_MAX_KEYS 4
831#define PROVSQL_KEY_CACHE_MAX_KEY_COLS 8
832
833/**
834 * @brief One PRIMARY-KEY or NOT-NULL-UNIQUE key on a relation.
835 *
836 * @c col_n is the number of valid entries in @c cols (in
837 * @c pg_index.indkey order, i.e. column position in the key, not
838 * @c pg_attribute.attnum order). All columns are NOT NULL by
839 * construction: PRIMARY KEY enforces this implicitly, and UNIQUE
840 * constraints are admitted only when @c pg_attribute.attnotnull is
841 * @c true for every constituent column (the §2 soundness trap on
842 * nullable UNIQUE).
843 */
848
849/**
850 * @brief Per-relation set of PRIMARY-KEY and NOT-NULL-UNIQUE keys.
851 *
852 * Populated by @c provsql_lookup_relation_keys from @c pg_constraint
853 * (filtered by @c contype @c IN @c ('p','u')) joined to
854 * @c pg_index and @c pg_attribute (for the NOT-NULL check). The
855 * detector's §2 PK-FD pass walks @c keys and, for every key @c K it
856 * recognises among the query's equijoin equivalence classes, tags
857 * the determined columns as functionally fixed inside the relevant
858 * RTE.
859 */
865
866/**
867 * @brief Look up the PRIMARY-KEY and NOT-NULL-UNIQUE keys of a
868 * relation with a backend-local cache.
869 *
870 * Companion to @c provsql_lookup_table_info. The cache lives in a
871 * separate backing array with its own relcache-invalidation
872 * callback so that a future @c ALTER @c TABLE that adds / drops a
873 * constraint refreshes the next lookup without polling. Returns
874 * @c true when the relation has at least one PRIMARY KEY or
875 * NOT-NULL UNIQUE constraint; @c false otherwise (in which case
876 * @p *out is filled with @c key_n @c = @c 0). Safe to call from
877 * the planner hot path.
878 *
879 * @param relid pg_class OID of the relation to inspect.
880 * @param out Filled on return. @c out->relid is set to @p relid
881 * regardless of return value; @c out->keys holds up to
882 * @c PROVSQL_KEY_CACHE_MAX_KEYS keys.
883 */
884extern bool provsql_lookup_relation_keys(Oid relid,
886
887#include "provsql_error.h"
888
889#ifdef __cplusplus
890/* Neutralise the PostgreSQL macros (gettext family, port.h's printf-family
891 * replacements) that break STL / Boost headers included after this point;
892 * see c_cpp_compatibility.h. Done here so every C++ translation unit that
893 * pulls in the PostgreSQL headers through provsql_utils.h is covered
894 * without having to mind its include order. */
895#include "c_cpp_compatibility.h"
896#endif
897
898/**
899 * @brief SHA-1 of @p len bytes of @p data (RFC 3174).
900 *
901 * Self-contained, so that gate addresses, which are version-5 UUIDs, are
902 * computed the same way on every supported PostgreSQL version. Defined in
903 * @c CertifiedDDMaterialize.cpp.
904 */
905#ifdef __cplusplus
906extern "C"
907#endif
908void provsql_sha1(const unsigned char *data, size_t len, unsigned char out[20]);
909
910/**
911 * @brief The state of an incremental SHA-1: the digest of a text given in
912 * pieces, without holding it whole (the name of a gate with millions
913 * of children).
914 */
915typedef struct provsql_sha1_ctx {
916 uint32_t h[5]; ///< Hash state
917 uint64_t len; ///< Bytes hashed so far
918 unsigned char block[64]; ///< The bytes not yet hashed, short of a block
919 size_t used; ///< How many of @c block are used
921
922#ifdef __cplusplus
923extern "C" {
924#endif
925/** @brief Start an incremental SHA-1. */
927/** @brief Hash @p len more bytes of @p data. */
928void provsql_sha1_update(provsql_sha1_ctx *ctx, const unsigned char *data,
929 size_t len);
930/** @brief The SHA-1 of all the bytes given to @p ctx. */
931void provsql_sha1_final(provsql_sha1_ctx *ctx, unsigned char out[20]);
932#ifdef __cplusplus
933}
934#endif
935
936/**
937 * @brief Pre-create ("plant") a gate at the canonical address of a multiset
938 * of tokens, for the working table of the recursive CTE being lowered.
939 *
940 * The gate, of type @p type (@c gate_plus or @c gate_times), has the single
941 * child @p target and the given infos; its address is remembered in this
942 * backend, where @c provenance_plus / @c provenance_times return it in place
943 * of an ordinary gate over @p children. Defined in @c gate_builders.c.
944 *
945 * @param work_name working table the tokens belong to; NULL for the one
946 * declared last by @c planted_scope()
947 * @param type @c gate_plus or @c gate_times
948 * @param children the multiset the planted gate stands for
949 * @param n number of @p children
950 * @param target root of the certified circuit, the gate's single child
951 * @param info1 first info of the planted gate
952 * @param info2 second info of the planted gate
953 * @return the address of the planted gate
954 */
955#ifdef __cplusplus
956extern "C"
957#endif
958pg_uuid_t provsql_plant_canonical(const char *work_name, gate_type type,
959 const pg_uuid_t *children, int n,
960 const pg_uuid_t *target,
961 unsigned info1, unsigned info2);
962
963/**
964 * @brief Forget what @c gate_builders.c remembers of the store (planted
965 * gates, value gates written). For @c circuit_cleanup, which may
966 * remove gates.
967 */
968#ifdef __cplusplus
969extern "C"
970#endif
972
973/** @brief UUID of the semiring zero gate: the result of the SQL function
974 * @c gate_zero(), created with the extension (test @c agg_filter checks
975 * the two agree). */
976#define PROVSQL_GATE_ZERO_UUID "19257535-6aaf-5275-b02b-899c48576553"
977/** @brief UUID of the semiring one gate, the result of @c gate_one(). */
978#define PROVSQL_GATE_ONE_UUID "d265daa9-f206-561d-845c-2a85fa0fa72c"
979/** @brief UUID of the constant value gate standing for the NULL value, the
980 * result of @c gate_null(). */
981#define PROVSQL_GATE_NULL_UUID "417134e7-a404-57a7-86fd-2577ebe0f3ba"
982
983#endif /* PROVSQL_UTILS_H */
Per-relation provenance metadata: the in-memory record.
Fix macro conflicts between PostgreSQL headers and the C++ STL/Boost.
int provsql_mobius_max_gates
Data-cost cap of the Möbius route: it declines (falling through to joint-width / the cost-based choos...
Definition provsql.c:136
bool provsql_where_provenance
Global variable that indicates if where-provenance support has been activated through the provsql....
Definition provsql.c:113
bool provsql_absorptive_provenance
Derived flag: the session's provenance class is 'absorptive' or 'boolean' – licenses constructions so...
Definition provsql.c:154
int provsql_verbose
Verbosity level; controlled by the provsql.verbose_level GUC.
Definition provsql.c:115
bool provsql_simplify_on_load
Run universal cmp-resolution passes when getGenericCircuit returns; controlled by the provsql....
Definition provsql.c:138
int provsql_mobius_max_cnf
Query-cost cap of the Möbius route: it declines when a sentence's CNF has more than this many conjunc...
Definition provsql.c:137
int provsql_prob_cache_size
Byte budget, in kB, of the per-backend cache of compiled d-DNNFs; provsql.prob_cache_size GUC.
Definition provsql.c:140
char * provsql_transaction_token
Textual UUID of the update gate standing for the current transaction, or empty; set with SET LOCAL by...
Definition provsql.c:120
bool provsql_inversion_free
Insert the inversion-free structured-d-DNNF path into the default probability chain (after independen...
Definition provsql.c:152
double provsql_ess_warn_fraction
Effective-sample-size warning threshold for likelihood weighting: warn when the posterior ESS falls b...
Definition provsql.c:127
char * provsql_last_eval_method
Last probability evaluation method(s) used; exposed via provsql.last_eval_method.
Definition provsql.c:119
bool provsql_mobius
Try the safe-UCQ Möbius-inversion route (a guaranteed-PTIME exact route for its class) BEFORE the joi...
Definition provsql.c:135
int provsql_rv_mc_samples
Default sample count for analytical-evaluator MC fallbacks; 0 disables fallback (callers raise instea...
Definition provsql.c:126
int provsql_dtree_max_subproblems
Debug/safety hard cap on d-tree subproblems before it bails (0 = off; the chooser auto-budgets at the...
Definition provsql.c:128
unsigned provsql_stmt_serial
Counts the user's statements, so that a warning a conversion emits at run time is given once for a st...
Definition provsql.c:254
char * provsql_kcmcp_server
Launch command for the managed KCMCP server (with a {endpoint} placeholder); controlled by the provsq...
Definition provsql.c:124
int provsql_idp_fold
Backing variable of provsql.idp_fold: when an AND or OR root is split into independent groups evaluat...
Definition provsql.c:141
bool provsql_joint_width
Recognise unsafe UCQs at planner time and route their existence provenance through the joint-width co...
Definition provsql.c:134
int provsql_monte_carlo_seed
Seed for the Monte Carlo sampler; -1 means non-deterministic (std::random_device); controlled by the ...
Definition provsql.c:125
bool provsql_cmp_probability_evaluation
Run closed-form / analytic probability evaluators for gate_cmps inside probability_evaluate (currentl...
Definition provsql.c:151
char * provsql_tool_search_path
Colon-separated directory list prepended to PATH when invoking external tools (d4,...
Definition provsql.c:122
bool provsql_interrupted
Set by provsql_sigint_handler: this backend received a cancel.
Definition provsql.c:111
bool provsql_boolean_provenance
Derived flag: the session's provenance class is 'boolean' – enables the Boolean-only machinery (safe-...
Definition provsql.c:153
int provsql_joint_max_states
Per-bag DP state-count cap of the joint-width UCQ compiler (the true safety net); provsql....
Definition provsql.c:133
char * provsql_fallback_compiler
Compiler used by BooleanCircuit::makeDD as the final fallback after interpretAsDD and tree-decomposit...
Definition provsql.c:123
int provsql_max_worlds
Possible worlds of a group that a condition on its aggregate may have enumerated before the evaluatio...
Definition provsql.c:132
int provsql_max_memory
Memory, in MB, that the evaluations of a statement may add to the backend's resident set,...
Definition provsql.c:131
bool provsql_hybrid_evaluation
Run the hybrid-evaluator simplifier inside probability_evaluate; controlled by the provsql....
Definition provsql.c:150
int provsql_joint_max_treewidth
Maximum joint treewidth the joint-width UCQ compiler attempts before declining (caller falls back to ...
Definition provsql.c:129
bool provsql_aggtoken_text_as_uuid
When true, agg_token::text emits the underlying provenance UUID instead of "value (*)".
Definition provsql.c:121
int provsql_gate_cache_size
Byte budget, in kB, of the per-backend gate cache; provsql.gate_cache_size GUC.
Definition provsql.c:130
int provsql_prob_cache
Backing variable of provsql.prob_cache: when the per-backend cache of compiled d-DNNFs,...
Definition provsql.c:139
Uniform error-reporting macros for ProvSQL.
bool provsql_store_synchronous_commit
Global variable set by the provsql.store_synchronous_commit run-time configuration parameter: when tr...
const char * gate_type_name[]
Names of gate types.
provsql_arith_op
Arithmetic operator tags used by gate_arith.
@ PROVSQL_ARITH_PERCENTILE
continuous percentile (order-statistic aggregate): wires are interleaved [ind_1, x_1,...
@ PROVSQL_ARITH_DIV
binary, child0 / child1
@ PROVSQL_ARITH_ASFLOAT8
unary, child0 as double precision
@ PROVSQL_ARITH_LN
unary, natural logarithm of child0 (a negative draw raises at evaluation)
@ PROVSQL_ARITH_ROUND
child0 rounded half away from zero, to child1 decimal digits where a second child is given (SQL round...
@ PROVSQL_ARITH_PLUS
n-ary, sum of children
@ PROVSQL_ARITH_POW
binary, child0 ^ child1 (real branch only: a negative base drawn with a non-integer exponent raises a...
@ PROVSQL_ARITH_ABS
unary, |child0|
@ PROVSQL_ARITH_FLOOR
unary, greatest integer <= child0
@ PROVSQL_ARITH_NEG
unary, -child0
@ PROVSQL_ARITH_INTDIV
binary, child0 / child1 truncated toward zero: SQL's division of two integers
@ PROVSQL_ARITH_MINUS
binary, child0 - child1
@ PROVSQL_ARITH_CEIL
unary, least integer >= child0
@ PROVSQL_ARITH_EXP
unary, e^child0
@ PROVSQL_ARITH_TIMES
n-ary, product of children
@ PROVSQL_ARITH_MIN
n-ary, min of children (order statistic; least / min aggregate)
@ PROVSQL_ARITH_MAX
n-ary, max of children (order statistic; greatest / max aggregate)
@ PROVSQL_ARITH_ASFLOAT4
unary, child0 as real reads it
provsql_eval_opt_t
Values of the provsql.prob_cache and provsql.idp_fold GUCs.
@ PROVSQL_EVAL_OPT_OFF
Never applied.
@ PROVSQL_EVAL_OPT_ON
Also applied to a method called by name.
@ PROVSQL_EVAL_OPT_AUTO
Applied by the default method only (default).
Oid find_equality_operator(Oid ltypeId, Oid rtypeId)
Find the equality operator OID for two given types.
#define PROVSQL_KEY_CACHE_MAX_KEY_COLS
void RegisterProvSQLKCMCPWorker(void)
Register the supervisor background worker that launches and supervises the managed KCMCP server; call...
pg_uuid_t provsql_plant_canonical(const char *work_name, gate_type type, const pg_uuid_t *children, int n, const pg_uuid_t *target, unsigned info1, unsigned info2)
Pre-create ("plant") a gate at the canonical address of a multiset of tokens, for the working table o...
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.
const char * provsql_kcmcp_managed_endpoint(void)
Read the live endpoint of the managed KCMCP server from shared memory (e.g.
constants_t get_constants(bool failure_if_not_possible)
Retrieve the cached OID constants for the current database.
@ gate_observe
Latent-variable observation (likelihood-weighting evidence): one wire → an observed bare gate_rv leaf...
@ gate_rv
Continuous random-variable leaf (extra encodes distribution).
@ gate_case
N-ary guarded selection over scalar (RV) children: wires are [guard_1, value_1, .....
@ gate_annotation
Transparent single-child wrapper carrying a query-level annotation in extra (inversion-free certifica...
@ gate_mobius
Signed Möbius combination: a MEASURE-only gate carrying one integer coefficient per child (in extra,...
@ gate_fixpoint
Component of the least solution of an equation system: one wire to a gate_fixsystem,...
@ gate_conditioned
Conditioning marker with two children [target, evidence]: measure-only, probability_evaluate returns ...
@ gate_fixsystem
Linear equation system x_i = f_i(x) of a recursive query, one equation per derived tuple: wires [x_1,...
@ gate_fixvar
Unknown of an equation system (see gate_fixsystem): a leaf standing for the solution of one equation,...
@ 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)
@ gate_assumed
Structural marker over a single child whose sub-circuit was computed under a Boolean-provenance assum...
@ 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).
Definition table_info.c:175
void provsql_sha1(const unsigned char *data, size_t len, unsigned char out[20])
SHA-1 of len bytes of data (RFC 3174).
void provsql_gate_builders_forget(void)
Forget what gate_builders.c remembers of the store (planted gates, value gates written).
bool provsql_fetch_ancestry(Oid relid, uint16 *ancestor_n_out, Oid *ancestors_out)
Raw IPC fetch for the ancestry half (no cache).
Definition table_info.c:180
#define PROVSQL_KEY_CACHE_MAX_KEYS
Upper bounds for the relation-key cache.
provsql_route
Tags identifying the planner-time route that produced a circuit.
@ PROVSQL_ROUTE_BOUNDED_JW
Joint-width UCQ compiler (src/UCQJointCompiler.h).
@ PROVSQL_ROUTE_SQ_REWRITE
Hierarchical-CQ read-once rewrite (src/safe_query.c).
@ PROVSQL_ROUTE_NONE
No route rewrite: ordinary lineage.
@ PROVSQL_ROUTE_REACHABILITY
Recursive-reachability compiler (src/reachability_evaluate.cpp).
void provsql_sha1_final(provsql_sha1_ctx *ctx, unsigned char out[20])
The SHA-1 of all the bytes given to ctx.
static const char * provsql_route_name(provsql_route route)
The name of a route, as the probability dispatcher reports it and as the annotation wrapper of a mate...
void provsql_sha1_init(provsql_sha1_ctx *ctx)
Start an incremental SHA-1.
void provsql_sha1_update(provsql_sha1_ctx *ctx, const unsigned char *data, size_t len)
Hash len more bytes of data.
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_REGULAR_INDICATOR
OID of provsql.regular_indicator(boolean): the deterministic gate_one/gate_zero indicator the planner...
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_WINDOW_DISTINCT_TOKENS
OID of window_distinct_tokens, used for dense_rank(); InvalidOid on a schema that predates it.
Oid OID_FUNCTION_PROVENANCE_SEMIMOD
OID of the provenance_semimod FUNCTION.
Oid OID_FUNCTION_RV_DIV
OID of random_variable_div(rv, rv) -> rv: builds the avg num/denom division gate.
Oid OID_AGG_AVG_RV
provsql.avg(random_variable)
Oid OID_AGG_RV_CORR_IMPL
provsql.rv_corr_impl(ind rv, x rv, y rv)
Oid OID_AGG_RV_SUM_OR_NULL
provsql.rv_sum_or_null(random_variable): the avg-numerator sum, NULL on an empty group (so avg is NUL...
Oid OID_AGG_SUM_RV
OIDs of the RV-returning aggregates, keyed for the per-aggregate identity dispatch in make_rv_aggrega...
Oid OID_FUNCTION_CHOOSE
OID of the choose(anyelement) aggregate (keeps the first non-NULL value); used to decorrelate scalar ...
Oid OID_AGG_RV_STDDEV_SAMP_IMPL
provsql.rv_stddev_samp_impl(ind rv, x rv)
Oid OID_AGG_STDDEV_SAMP_RV
provsql.stddev_samp(rv)
Oid OID_FUNCTION_ANNOTATE
OID of provsql.annotate(uuid,text)->uuid.
Oid OID_FUNCTION_PROVENANCE
OID of the provenance FUNCTION.
Oid OID_FUNCTION_AGG_TOKEN_PLAIN_TEXT
OID of agg_token_plain_text(), the sort key of an ORDER BY on an aggregate result; InvalidOid on a sc...
Oid OID_FUNCTION_RV_LEAST
provsql.least(VARIADIC random_variable[])
Oid OID_FUNCTION_RV_CASE
OID of provsql.rv_case(uuid[])->random_variable.
Oid OID_FUNCTION_INVERSION_FREE_KEY
OID of provsql.inversion_free_key(text,text,int)->text.
Oid OID_FUNCTION_AGG_VALUE_GATE
agg_value_gate(numeric) -> uuid
Oid OID_FUNCTION_AGG_TOKEN_UUID
OID of the agg_token_uuid FUNCTION.
Oid OID_AGG_STDDEV_POP_RV
provsql.stddev_pop(rv)
Oid OID_FUNCTION_RV_AGGREGATE_SEMIMOD
OID of rv_aggregate_semimod(uuid, rv) -> rv: wraps a per-row argument as mixture(prov,...
Oid OID_TYPE_VARCHAR
OID of the VARCHAR TYPE.
Oid OID_FUNCTION_ORDER_CHECKED
OID of order_checked, which warns where that check fails; InvalidOid on a schema that predates it.
Oid OID_FUNCTION_GATE_ZERO
OID of the provenance_zero FUNCTION.
Oid OID_SCHEMA_PROVSQL
OID of the provsql SCHEMA.
Oid OID_FUNCTION_AGG_TOKEN_FROZEN_VALUE
OID of agg_token_frozen_value(), the value of an aggregate result that ProvSQL casts to a plain value...
Oid OID_TYPE_RANDOM_VARIABLE_ARRAY
OID of the random_variable[] TYPE.
Oid OID_AGG_PRODUCT_RV
provsql.product(random_variable)
Oid OID_FUNCTION_AGG_GUARD_HOLDS
OID of agg_guard_holds(), the truth of a comparison of aggregate results in the database as it is,...
Oid OID_FUNCTION_AGG_TOKEN_EXPLODE_CHILDREN
OID of agg_token_explode_children(), the children of the gate of a choose() result exploded into rows...
Oid OID_FUNCTION_COND
OID of provsql.cond(uuid,uuid)->uuid.
Oid OID_TYPE_GATE_TYPE
OID of the provenance_gate TYPE.
Oid OID_FUNCTION_PROVENANCE_PROJECT
OID of the provenance_project FUNCTION.
Oid OID_FUNCTION_PROVENANCE_CONTRIBUTIONS_CAT
OID of the provenance_contributions_cat aggregate, which collects them; InvalidOid on a schema that p...
Oid OID_FUNCTION_RV_AGGREGATE_INDICATOR
OID of rv_aggregate_indicator(uuid) -> rv: the avg denominator wrap mixture(prov, 1,...
Oid OID_FUNCTION_GET_CHILDREN
OID of the get_children FUNCTION.
Oid OID_FUNCTION_ROW_NUMBER_AS_RANK
OID of row_number_as_rank, which row_number() over tracked relations is rewritten into; InvalidOid on...
Oid OID_FUNCTION_RV_AGGREGATE_SEMIMOD_ID
OID of the 3-arg rv_aggregate_semimod(uuid, rv, float8): identity-parameterised wrap mixture(prov,...
Oid OID_UNNEST
OID of the unnest(anyarray) FUNCTION.
Oid OID_FUNCTION_COND_PREDICATE
cond_predicate(uuid,boolean)
Oid OID_AGG_MIN_RV
provsql.min(random_variable)
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_FUNCTION_AGG_TOKEN_NULL_EVENT
OID of agg_token_null_event, the IS [NOT] NULL of an aggregate column; InvalidOid on a schema that pr...
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_PLAIN
OID of the marker plain(), which keeps a LIMIT a truncation of the actual result; InvalidOid on a sch...
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_AGG_RV_PERCENTILE_IMPL
provsql.rv_percentile_impl(fraction float8, ind rv, x rv)
Oid OID_FUNCTION_AGG_COUNT_CAN_BE_ZERO
OID of agg_count_can_be_zero; InvalidOid on a schema that predates it.
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_AGG_POSSIBLE_VALUES
OID of agg_possible_values(), the values an aggregate result takes over the possible worlds,...
Oid OID_FUNCTION_PROVENANCE_TIMES
OID of the provenance_times FUNCTION.
Oid OID_FUNCTION_PROVENANCE_MONUS
OID of the provenance_monus FUNCTION.
Oid OID_FUNCTION_AGG_COND_PREDICATE
agg_token_cond_predicate(agg_token,boolean)
Oid OID_FUNCTION_GIVEN_PREDICATE
given_predicate(boolean) – prefix whole-tuple
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_ARRAY_COLLECT
OID of the array_collect(anynonarray) aggregate (array_agg with {} over no rows); the value of a deco...
Oid OID_FUNCTION_AGG_CASE
OID of agg_case(uuid[]), the agg_token constructor the planner hook lowers an aggregate-carrier CASE ...
Oid OID_AGG_CORR_RV
provsql.corr(rv, rv)
Oid OID_FUNCTION_GIVEN
OID of provsql.given(uuid)->uuid.
Oid OID_FUNCTION_PLAIN_TRUTH
OID of plain_truth(), whether a token holds in the database as it is; InvalidOid on a schema that pre...
Oid OID_FUNCTION_GATE_ONE
OID of the provenance_one FUNCTION.
Oid OID_FUNCTION_PROVENANCE_SEMIMOD_NESTED
OID of provenance_semimod_nested(), the contribution of an aggregate result aggregated by an aggregat...
Oid OID_AGG_COVAR_SAMP_RV
provsql.covar_samp(rv, rv)
Oid OID_TYPE_NUMMULTIRANGE
OID of the nummultirange TYPE (PG14+, InvalidOid otherwise).
Oid OID_FUNCTION_RV_AGGREGATE_INDICATOR_VALUED
OID of rv_aggregate_indicator(uuid, rv) -> rv: NULL when the row's value is NULL (SQL NULL-skip for a...
Oid OID_FUNCTION_PROVENANCE_SEMIMOD_FLAT
OID of provenance_semimod_flat(), the contributions of an aggregate result aggregated again; InvalidO...
Oid OID_FUNCTION_PROBABILITY_EVALUATE
OID of the real provsql.probability_evaluate(uuid,text,text).
Oid OID_FUNCTION_RV_COND
OID of provsql.random_variable_cond(random_variable,uuid).
Oid OID_FUNCTION_NTILE_AS_RANK
OID of ntile_as_rank, the tie check of a tracked ntile(); InvalidOid on a schema that predates it.
Oid OID_FUNCTION_RV_COND_PREDICATE
random_variable_cond_predicate(random_variable,boolean)
Oid OID_TYPE_UUID_ARRAY
OID of the uuid[] TYPE.
Oid OID_FUNCTION_PREDICATE_COND_PREDICATE
predicate_cond_predicate(boolean,boolean) – (A)|(B), both events
Oid OID_AGG_MAX_RV
provsql.max(random_variable)
Oid OID_FUNCTION_AGG_COND
OID of provsql.agg_token_cond(agg_token,uuid): the conditioning constructor for the agg_token carrier...
Oid OID_FUNCTION_PROBABILITY_PREDICATE
OID of the probability(boolean,text,text) placeholder.
Oid OID_FUNCTION_GATE_NULL
OID of gate_null(), the value gate of the NULL value (a NULL branch of a CASE over aggregates).
Oid OID_TYPE_RANDOM_VARIABLE
OID of the random_variable TYPE.
Oid OID_AGG_COVAR_POP_RV
SQL-standard statistic aggregates over random_variable rows and their internal indicator-carrying rew...
Oid OID_FUNCTION_PROVENANCE_CMP
OID of the provenance_cmp FUNCTION.
Oid OID_AGG_PERCENTILE_CONT_RV
provsql.percentile_cont(float8) WITHIN GROUP (ORDER BY rv)
Oid OID_FUNCTION_RV_GREATEST
provsql.greatest(VARIADIC random_variable[])
Oid OID_AGG_RV_COVAR_POP_IMPL
provsql.rv_covar_pop_impl(ind rv, x rv, y rv)
Oid OID_AGG_RV_STDDEV_POP_IMPL
provsql.rv_stddev_pop_impl(ind rv, x rv)
Oid OID_TYPE_INT4MULTIRANGE
OID of the int4multirange TYPE (PG14+, InvalidOid otherwise).
Oid OID_AGG_RV_COVAR_SAMP_IMPL
provsql.rv_covar_samp_impl(ind rv, x rv, y rv)
Oid OID_FUNCTION_PROVENANCE_SEMIMOD_NULLABLE
OID of provenance_semimod_nullable, the variant used for aggregates that see their NULL inputs (array...
Oid OID_FUNCTION_GET_EXTRA
OID of the get_extra FUNCTION.
Oid OID_FUNCTION_RV_CMP[6]
OIDs of the random_variable_{eq,ne,le,lt,ge,gt} comparison procedure functions, indexed by the Compar...
Oid OID_FUNCTION_PROVENANCE_CMP_TIMES
OID of the provenance_cmp_times FUNCTION.
Oid OID_FUNCTION_ORDER_DETERMINED
OID of the order_determined aggregate, the tie check of an order-dependent aggregate; InvalidOid on a...
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.
The state of an incremental SHA-1: the digest of a text given in pieces, without holding it whole (th...
uint64_t len
Bytes hashed so far.
unsigned char block[64]
The bytes not yet hashed, short of a block.
size_t used
How many of block are used.
uint32_t h[5]
Hash state.