ProvSQL SQL API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches

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.

Detailed Description

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.

Source code
provsql.sql line 524

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.
Parameters
relidpg_class OID of the relation.
kindOne of 'tid' / 'bid' / 'opaque'.
block_keyBlock-key column numbers (only meaningful for 'bid'; ignored otherwise but conventionally passed empty).
Source code
provsql.sql line 582

Remove per-relation provenance metadata. No-op when missing.

Source code
provsql.sql line 588

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.

Source code
provsql.sql line 601

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).

Parameters
relidpg_class OID of the relation.
ancestorsSorted, deduplicated base-relation OIDs.
Source code
provsql.sql line 624

Clear the ancestor half of a per-relation RECORD (keeps kind/block_key). No-op when missing.

Source code
provsql.sql line 631

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).

Source code
provsql.sql line 642

BEFORE INSERT OR UPDATE OF provsql row trigger installed by add_provenance.

Two jobs:

  1. Fill 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").
  2. When the user does supply a non-NULL 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.
    Source code
    provsql.sql line 664
    Enable provenance tracking on an existing table

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.

Parameters
_tblthe table to add provenance tracking to
Source code
provsql.sql line 696

Remove provenance tracking from a table

Drops the provsql column and associated triggers.

Parameters
_tblthe table to remove provenance tracking from
Source code
provsql.sql line 741

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.

Parameters
_tblthe table to repair
key_attthe key attribute(s) as a comma-separated string, or empty string if the whole table is one group
Source code
provsql.sql line 779

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.

Source code
provsql.sql line 896 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).

Parameters
newtblname of the mapping table to create
oldtblsource table with provenance tracking
attattribute whose values populate the mapping
preserve_caseif true, quote the table name to preserve case
Source code
provsql.sql line 930

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.

Parameters
newviewname of the view to create
oldtblsource table with provenance tracking
attattribute whose values populate the mapping
preserve_caseif true, quote the view name to preserve case
Source code
provsql.sql line 977

UUID namespace and identity element functions used for deterministic gate generation.

Function Documentation

◆ epsilon()

DOUBLE PRECISION update_provenance::epsilon ( )

Return the epsilon threshold used for probability comparisons.

Source code
provsql.sql line 1034

◆ gate_one()

UUID update_provenance::gate_one ( )

Return the UUID of the semiring one gate.

Source code
provsql.sql line 1028

◆ gate_zero()

UUID update_provenance::gate_zero ( )

Return the UUID of the semiring zero gate.

Source code
provsql.sql line 1022

◆ uuid_ns_provsql()

UUID update_provenance::uuid_ns_provsql ( )

Return the ProvSQL UUID namespace (used for deterministic gate UUIDs).

Source code
provsql.sql line 1015