42#include "access/xact.h"
44#include "utils/builtins.h"
45#include "utils/uuid.h"
111 case XACT_EVENT_COMMIT:
112 case XACT_EVENT_PARALLEL_COMMIT:
113 case XACT_EVENT_PREPARE:
117 case XACT_EVENT_ABORT:
118 case XACT_EVENT_PARALLEL_ABORT:
134 "transaction that just rolled back; they stand as "
140 case XACT_EVENT_PRE_PREPARE:
142 provsql_error(
"cannot PREPARE a transaction that has written "
143 "provenance probabilities: the write would have to be "
144 "undone if the prepared transaction rolled back, and "
145 "ProvSQL keeps that undo list in the backend");
153 SubTransactionId mySubid,
154 SubTransactionId parentSubid,
157 (void) mySubid; (void) parentSubid; (void) arg;
159 case SUBXACT_EVENT_ABORT_SUB:
170 "subtransaction that just rolled back; they stand "
175 case SUBXACT_EVENT_COMMIT_SUB:
196 provsql_error(
"ProvSQL: out of memory recording a probability write");
228 provsql_error(
"ProvSQL: out of memory recording a replacement leaf");
246 provsql_error(
"Invalid NULL value passed to note_fresh_leaf");
259 PG_RETURN_BOOL(
false);
261 token = DatumGetUUIDP(PG_GETARG_DATUM(0));
264 PG_RETURN_BOOL(
true);
265 PG_RETURN_BOOL(
false);
270 double existing = 0.;
275 if(prob < 0. || prob > 1.)
276 provsql_error(
"set_prob: probability %g is outside [0, 1]", prob);
291 unsigned nb_children = 0;
305 hint =
"Use provsql.replace_block() to give a repair_key block a "
306 "different set of probabilities: a block's values share one "
307 "key gate and their masses are meaningful together, so they "
308 "are replaced together.";
311 hint =
"Use provsql.replace_update() to give a recorded data "
312 "modification a different probability.";
315 hint =
"Use provsql.replace_input() to give a tuple a different "
316 "probability: it mints a fresh input gate and returns it, "
317 "for the row's provsql column to carry.";
322 (errmsg(
"probability of gate %s is already set to %g",
323 DatumGetCString(DirectFunctionCall1(
324 uuid_out, UUIDPGetDatum(token))),
326 errdetail(
"Probabilities are written once, so that a "
327 "transaction that rolls back leaves the circuit as "
329 errhint(
"%s", hint)));
352 if(PG_ARGISNULL(0) || PG_ARGISNULL(1))
355 token = DatumGetUUIDP(PG_GETARG_DATUM(0));
356 prob = PG_GETARG_FLOAT8(1);
359 unsigned nb_children = 0;
363 if(children) free(children);
366 peeled = children[0];
392 token = DatumGetUUIDP(PG_GETARG_DATUM(0));
static bool prob_callbacks_registered
static void fresh_leaves_record(const pg_uuid_t *token)
Remember that this transaction minted token as a replacement leaf for a tracked row.
static int fresh_leaves_len
static void prob_subxact_callback(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
static int prob_writes_len
static void prob_writes_reparent(int level)
Move the recorded writes at nesting level level up to its parent, so a later outer rollback still und...
static void prob_writes_unwind(int level, bool undo)
Drop the recorded writes at nesting level level or deeper, clearing each one's probability in the sto...
static void prob_xact_callback(XactEvent event, void *arg)
static int fresh_leaves_cap
void provsql_set_prob_tracked(const pg_uuid_t *token, double prob)
Write token's probability and record the write, so that a rollback of the current (sub)transaction cl...
Datum is_fresh_leaf(PG_FUNCTION_ARGS)
Whether token was minted as a replacement leaf by this transaction (see note_fresh_leaf).
static pg_uuid_t * fresh_leaves
Replacement leaves minted by this transaction; see the block below.
Datum probability_is_set(PG_FUNCTION_ARGS)
Report whether a probability has been written on a gate.
static int prob_writes_cap
static void prob_writes_record(const pg_uuid_t *token)
Record that this transaction wrote token's probability.
static void prob_writes_forget(void)
Release the list without touching the store.
static prob_write * prob_writes
Datum note_fresh_leaf(PG_FUNCTION_ARGS)
Declare a just-minted leaf gate a replacement for a tracked row.
Datum set_prob(PG_FUNCTION_ARGS)
Write a gate's probability, once.
Write-once probabilities: the entry points other files use.
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
#define provsql_warning(fmt,...)
Emit a ProvSQL warning message (execution continues).
gate_type provsql_fetch_gate(const pg_uuid_t *token, unsigned *nb_children_out, pg_uuid_t **children_out)
PostgreSQL-callable wrapper for get_gate_type().
provsql_set_prob_result provsql_internal_set_prob(const pg_uuid_t *token, double prob, double *existing)
Write a gate's probability from in-extension C/C++ code.
bool provsql_internal_get_prob_written(const pg_uuid_t *token, double *prob)
Report whether a probability has been written on a gate.
void provsql_internal_clear_prob(const pg_uuid_t *token)
Drop a gate's probability, leaving it as it was before anyone wrote one.
Background worker and IPC primitives for mmap-backed circuit storage.
provsql_set_prob_result
Outcome of a probability write, mirroring MMappedCircuit::SetProbResult across the IPC boundary.
@ PROVSQL_SET_PROB_NOT_PROB_GATE
The gate carries no probability.
@ PROVSQL_SET_PROB_WRITTEN
Written; undo on rollback.
@ PROVSQL_SET_PROB_ALREADY_SET
Holds a different value; refused.
@ PROVSQL_SET_PROB_UNCHANGED
Already held exactly this value.
Core types, constants, and utilities shared across ProvSQL.
@ gate_annotation
Transparent single-child wrapper carrying a query-level annotation in extra (inversion-free certifica...
One recorded probability write, awaiting commit or rollback.