![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Write-once probabilities and their rollback. More...
#include "postgres.h"#include <math.h>#include "access/xact.h"#include "fmgr.h"#include "utils/builtins.h"#include "utils/uuid.h"#include "probability_store.h"#include "provsql_mmap.h"#include "provsql_utils.h"
Go to the source code of this file.
Classes | |
| struct | prob_write |
| One recorded probability write, awaiting commit or rollback. More... | |
Functions | |
| 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 store when undo. | |
| 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 undoes them. | |
| static void | prob_writes_forget (void) |
| Release the list without touching the store. | |
| static void | prob_xact_callback (XactEvent event, void *arg) |
| static void | prob_subxact_callback (SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg) |
| static void | prob_writes_record (const pg_uuid_t *token) |
Record that this transaction wrote token's probability. | |
| static void | fresh_leaves_record (const pg_uuid_t *token) |
Remember that this transaction minted token as a replacement leaf for a tracked row. | |
| Datum | note_fresh_leaf (PG_FUNCTION_ARGS) |
| Declare a just-minted leaf gate a replacement for a tracked row. | |
| Datum | is_fresh_leaf (PG_FUNCTION_ARGS) |
Whether token was minted as a replacement leaf by this transaction (see note_fresh_leaf). | |
| 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 clears it. | |
| Datum | set_prob (PG_FUNCTION_ARGS) |
| Write a gate's probability, once. | |
| Datum | probability_is_set (PG_FUNCTION_ARGS) |
| Report whether a probability has been written on a gate. | |
Variables | |
| static prob_write * | prob_writes = NULL |
| static int | prob_writes_len = 0 |
| static int | prob_writes_cap = 0 |
| static bool | prob_callbacks_registered = false |
| static pg_uuid_t * | fresh_leaves = NULL |
| Replacement leaves minted by this transaction; see the block below. | |
| static int | fresh_leaves_len = 0 |
| static int | fresh_leaves_cap = 0 |
Write-once probabilities and their rollback.
The circuit store is append-only: a gate, once created, never changes, and a gate created by a transaction that later rolls back is an orphan rather than an inconsistency – no committed row can reference it, and the same expression recomputed lands on the same content-addressed UUID. A probability is the one thing about a gate that used to be rewritten in place, which is what made a rolled-back set_prob stick.
This file makes a probability a fact appended to the circuit like the gate itself:
set_prob writes it when the gate has none, reports success without writing when the gate already holds exactly that value (so setup scripts and notebook cells stay re-runnable, the same idempotence create_gate and add_provenance offer), and raises otherwise;provsql.replace_input does; the base table's token column is the place of truth, exactly as it is for the token rewrites the data-modification triggers perform.What is not closed here is isolation: another session can read a probability between the write and the rollback. Closing that would mean deferring the write to XACT_EVENT_PRE_COMMIT behind a backend-local overlay, at the price of making every reader consult the overlay.
Definition in file probability_store.c.
|
static |
Remember that this transaction minted token as a replacement leaf for a tracked row.
Definition at line 222 of file probability_store.c.

| Datum is_fresh_leaf | ( | PG_FUNCTION_ARGS | ) |
Whether token was minted as a replacement leaf by this transaction (see note_fresh_leaf).
Definition at line 254 of file probability_store.c.
| Datum note_fresh_leaf | ( | PG_FUNCTION_ARGS | ) |
Declare a just-minted leaf gate a replacement for a tracked row.
Called by provsql.replace_input / replace_block right after they create the gate, so that the UPDATE which stores it does not look to provenance_guard like a user pasting in an arbitrary token.
Definition at line 243 of file probability_store.c.

|
static |
Definition at line 152 of file probability_store.c.


|
static |
Release the list without touching the store.
Definition at line 102 of file probability_store.c.

|
static |
Record that this transaction wrote token's probability.
Definition at line 184 of file probability_store.c.


|
static |
Move the recorded writes at nesting level level up to its parent, so a later outer rollback still undoes them.
Definition at line 94 of file probability_store.c.

|
static |
Drop the recorded writes at nesting level level or deeper, clearing each one's probability in the store when undo.
Definition at line 77 of file probability_store.c.


|
static |
Definition at line 107 of file probability_store.c.


| Datum probability_is_set | ( | PG_FUNCTION_ARGS | ) |
Report whether a probability has been written on a gate.
get_prob() answers the value an evaluation would use, so it cannot tell a gate nobody gave a probability from one written as 1. This can, which is what a UI needs in order to offer "set" on the first and "replace" on the second.
Definition at line 385 of file probability_store.c.

| 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 clears it.
Raises when the gate carries no probability, when prob is outside [0, 1], and when the gate already holds a different probability. Writing the value the gate already holds is a no-op.
Definition at line 268 of file probability_store.c.


| Datum set_prob | ( | PG_FUNCTION_ARGS | ) |
Write a gate's probability, once.
Transparent gate_annotation wrappers (an inversion-free certificate / order marker attached by the planner to a certified query's row roots) are peeled first: a probability set on a wrapped token belongs to the input gate underneath, so the documented "set_prob(provenance(), p) FROM t" pattern keeps working when the query happens to be certified.
Definition at line 346 of file probability_store.c.

|
static |
Replacement leaves minted by this transaction; see the block below.
Definition at line 71 of file probability_store.c.
|
static |
Definition at line 73 of file probability_store.c.
|
static |
Definition at line 72 of file probability_store.c.
|
static |
Definition at line 68 of file probability_store.c.
|
static |
Definition at line 65 of file probability_store.c.
|
static |
Definition at line 67 of file probability_store.c.
|
static |
Definition at line 66 of file probability_store.c.