![]() |
ProvSQL SQL API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Trigger function for DELETE statement provenance tracking. More...
Topics | |
| Semiring operations | |
| Return the ProvSQL UUID namespace (used for deterministic gate UUIDs). | |
Functions | |
| UUID | uuid_ns_provsql () |
| Return the ProvSQL UUID namespace (used for deterministic gate UUIDs). | |
| UUID | gate_zero () |
| Return the UUID of the semiring zero gate. | |
| UUID | gate_one () |
| Return the UUID of the semiring one gate. | |
| DOUBLE PRECISION | epsilon () |
| Return the epsilon threshold used for probability comparisons. | |
Trigger function for DELETE statement provenance tracking.
UUID namespace and identity element functions used for deterministic gate generation.
Records the deletion and applies monus to provenance tokens of deleted rows. This is the version for PostgreSQL < 14.
Record per-relation provenance metadata used by the safe-query optimisation.
Stores a (relid, kind, block_key) RECORD in the persistent mmap-backed table-info store. kind is one of:
'tid' – independent input leaves (post-add_provenance default)'bid' – block-correlated leaves; rows sharing the same value of block_key are mutually exclusive. An empty block_key means the whole table is one block.'opaque' – arbitrary correlations from a derived source (CREATE TABLE AS SELECT, INSERT INTO SELECT, UPDATE under provsql.update_provenance); the safe-query rewriter must bail on these.| relid | pg_class OID of the relation. |
| kind | One of 'tid' / 'bid' / 'opaque'. |
| block_key | Block-key column numbers (only meaningful for 'bid'; ignored otherwise but conventionally passed empty). |
Remove per-relation provenance metadata. No-op when missing.
Read per-relation provenance metadata.
Returns NULL if no RECORD exists. kind is one of 'tid' / 'bid' / 'opaque'; block_key is the (possibly empty) array of block-key column numbers, only meaningful when kind = 'bid'. Used by the planner-time hierarchy detector to gate the safe-query rewrite.
Record the base-relation ancestor set of a tracked relation.
Base tables created with add_provenance / repair_key carry {self}; CTAS-derived tables inherit the union of their sources' ancestor sets. The safe-query rewriter consults the registry to enforce that joined FROM entries have disjoint base ancestors before firing the read-once factoring.
The worker preserves the relation's existing kind / block_key half on update; it silently no-ops when no kind RECORD exists for relid (callers should run add_provenance / repair_key first). The ancestor list is capped at 64 entries (clear error if exceeded).
| relid | pg_class OID of the relation. |
| ancestors | Sorted, deduplicated base-relation OIDs. |
Clear the ancestor half of a per-relation RECORD (keeps kind/block_key). No-op when missing.
Read the base-relation ancestor set of a tracked relation.
Returns NULL when no ancestor RECORD exists for relid (or the RECORD is empty – both cases make the safe-query rewriter take its conservative refuse path, so they collapse here).
BEFORE INSERT OR UPDATE OF provsql row trigger installed by add_provenance.
Two jobs:
NEW.provsql with a fresh uuid_generate_v4 leaf when the user did not supply one (a column DEFAULT would not do here: it fires before the trigger sees the row, so we could not tell "user omitted the column" from "user supplied a value").provsql on INSERT, or changes it on UPDATE, flip the table's per-table metadata to OPAQUE. The user is free to write whatever UUIDs they want (cross-table reuse, compound tokens minted via create_gate, ...); the cost is that the safe-query rewriter then refuses to fire on this table, because TID independence can no longer be assumed. Adds a provsql UUID column to the table, an index for fast UUID-keyed lookups, and a BEFORE INSERT/UPDATE row trigger (provenance_guard) that mints a fresh uuid_generate_v4 leaf when the user omits the column on INSERT, or flips the table's metadata to OPAQUE when the user supplies their own value. Input gates for existing rows are created lazily when first referenced by a query.
| _tbl | the table to add provenance tracking to |
Remove provenance tracking from a table
Drops the provsql column and associated triggers.
| _tbl | the table to remove provenance tracking from |
Set up provenance for a table with duplicate key values
When a table has duplicate rows for a given key, this function replaces simple input gates with multivalued input (mulinput) gates that model a uniform distribution over duplicates.
| _tbl | the table to repair |
| key_att | the key attribute(s) as a comma-separated string, or empty string if the whole table is one group |
Event trigger that purges per-table provenance metadata when a tracked relation is dropped outside of remove_provenance().
Plain DROP TABLE bypasses remove_provenance() and would otherwise leave a stale entry in the table-info store keyed by a now-recycled OID, with confusing consequences for the safe-query rewriter the next time the OID is reused. This trigger forwards every dropped relation OID to provsql.remove_table_info(), which is a no-op for relations that were not tracked.
EXECUTE PROCEDURE (rather than the PG 11+ EXECUTE FUNCTION alias) so the extension installs on PG 10 too.Create a provenance mapping table from an attribute
Creates a new table mapping provenance tokens to values of a given attribute, for use with semiring evaluation functions. Idempotent: if the mapping table already exists, raises a NOTICE and changes nothing (drop it first to rebuild).
| newtbl | name of the mapping table to create |
| oldtbl | source table with provenance tracking |
| att | attribute whose values populate the mapping |
| preserve_case | if true, quote the table name to preserve case |
Create a view mapping provenance tokens to attribute values
Like create_provenance_mapping but creates a view instead of a table, so it always reflects the current state of the source table.
| newview | name of the view to create |
| oldtbl | source table with provenance tracking |
| att | attribute whose values populate the mapping |
| preserve_case | if true, quote the view name to preserve case |
UUID namespace and identity element functions used for deterministic gate generation.
| DOUBLE PRECISION update_provenance::epsilon | ( | ) |
Return the epsilon threshold used for probability comparisons.
| UUID update_provenance::gate_one | ( | ) |
Return the UUID of the semiring one gate.
| UUID update_provenance::gate_zero | ( | ) |
Return the UUID of the semiring zero gate.
| UUID update_provenance::uuid_ns_provsql | ( | ) |
Return the ProvSQL UUID namespace (used for deterministic gate UUIDs).