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

Low-level functions for creating and querying provenance circuit gates. More...

Functions

VOID provsql.create_gate (UUID token, PROVENANCE_GATE type, UUID[] children=NULL)
 Create a new gate in the provenance circuit.
PROVENANCE_GATE provsql.get_gate_type (UUID token)
 Return the gate type of a provenance token.
UUID[] provsql.get_children (UUID token)
 Return the children of a provenance gate.
VOID provsql.set_prob (UUID token, DOUBLE PRECISION p)
 Set the probability of an input gate.
DOUBLE PRECISION provsql.get_prob (UUID token)
 Get the probability associated with an input gate.
VOID provsql.set_infos (UUID token, INT info1, INT info2=NULL)
 Set additional INTEGER values on provenance circuit gate.
RECORD provsql.get_infos (UUID token, OUT INT info1, OUT INT info2)
 Get the INTEGER info values associated with a circuit gate.
UUID provsql.assume_boolean (UUID token)
 Wrap token in a fresh gate_assumed_boolean and return the wrapper's UUID.
UUID provsql.annotate (UUID token, TEXT extra)
 Wrap token in a fresh transparent gate_annotation carrying extra, and return the wrapper's UUID.
TEXT provsql.inversion_free_key (TEXT root, TEXT sec, INT factor)
 Build a per-input order-key string for the inversion-free path.
VOID provsql.set_extra (UUID token, TEXT data)
 Set extra TEXT information on provenance circuit gate.
TEXT provsql.get_extra (UUID token)
 Get the TEXT-encoded extra data associated with a circuit gate.
BIGINT provsql.get_nb_gates ()
 Return the total number of materialized gates in the provenance circuit.

Detailed Description

Low-level functions for creating and querying provenance circuit gates.

Function Documentation

◆ annotate()

UUID provsql.annotate ( UUID token,
TEXT extra )

Wrap token in a fresh transparent gate_annotation carrying extra, and return the wrapper's UUID.

Unlike every other gate, the annotation wrapper's UUID folds in extra (not just the child): uuid_generate_v5 over concat('annotation', token, extra). This is deliberate – two annotations over the same child with different extra must be distinct gates (e.g. the same input tuple carrying different per-occurrence order keys, or two queries attaching different certificates to a shared root). The wrapper is transparent (identity) for EVERY evaluator; extra is inert metadata read only by the code that placed it. No-op (returns NULL) on a NULL input.

Source code
provsql.sql line 186

◆ assume_boolean()

UUID provsql.assume_boolean ( UUID token)

Wrap token in a fresh gate_assumed_boolean and return the wrapper's UUID.

Public primitive callable from any rewrite that needs to flag a sub-circuit as having been computed under a Boolean-provenance assumption (the safe-query rewriter is the first caller; future Boolean-only simplifications should reuse this). The wrapper is transparent for Boolean-compatible evaluators (probability, the sr_boolean / sr_boolexpr / sr_formula / sr_interval_* family, where-provenance) and raises a CircuitException for the rest. Always kept as an explicit node in PROV-XML export.

The wrapper UUID is content-derived via uuid_generate_v5 on the child, so identical children always wrap to the same outer UUID (and distinct children always wrap to distinct outer UUIDs). No-op (returns NULL) on a NULL input.

Source code
provsql.sql line 157

◆ create_gate()

VOID provsql.create_gate ( UUID token,
PROVENANCE_GATE type,
UUID[] children = NULL )

Create a new gate in the provenance circuit.

Parameters
tokenUUID identifying the new gate
typegate type (see PROVENANCE_GATE)
childrenoptional array of child gate UUIDs
Source code
provsql.sql line 75

◆ get_children()

UUID[] provsql.get_children ( UUID token)

Return the children of a provenance gate.

Source code
provsql.sql line 92

◆ get_extra()

TEXT provsql.get_extra ( UUID token)

Get the TEXT-encoded extra data associated with a circuit gate.

Source code
provsql.sql line 241

◆ get_gate_type()

PROVENANCE_GATE provsql.get_gate_type ( UUID token)

Return the gate type of a provenance token.

Returns 'input' for any token not yet materialized in the circuit, since input is the default semantics of an unmaterialized provenance token.

Source code
provsql.sql line 87

◆ get_infos()

RECORD provsql.get_infos ( UUID token,
OUT INT info1,
OUT INT info2 )

Get the INTEGER info values associated with a circuit gate.

Source code
provsql.sql line 134

◆ get_nb_gates()

BIGINT provsql.get_nb_gates ( )

Return the total number of materialized gates in the provenance circuit.

Input gates for provenance-tracked table rows are created lazily on first reference; rows that have never appeared in a query result are not counted.

Source code
provsql.sql line 252

◆ get_prob()

DOUBLE PRECISION provsql.get_prob ( UUID token)

Get the probability associated with an input gate.

Source code
provsql.sql line 107

◆ inversion_free_key()

TEXT provsql.inversion_free_key ( TEXT root,
TEXT sec,
INT factor )

Build a per-input order-key string for the inversion-free path.

Emitted by the planner per certified atom: K-prefixed, length-prefixed "K<factor> <octet_length(root)>:<root><octet_length(sec)>:<sec>", parsed back at evaluation by safe_cert_key_parse. root / sec are the tuple's root- and secondary-class column values (TEXT-cast by the caller); the byte-length prefixes keep the values unambiguous for any column type, including TEXT containing spaces, colons or digits. factor is the atom's factor id (or -1 for the shared self-join guard). IMMUTABLE so the planner can fold it and the marker dedups by content-addressing.

Source code
provsql.sql line 215

◆ set_extra()

VOID provsql.set_extra ( UUID token,
TEXT data )

Set extra TEXT information on provenance circuit gate.

This function sets TEXT-encoded data associated to a circuit gate, used in different ways by different gate types:

  • for project, it is a TEXT-encoded ARRAY of two-element ARRAYs that indicate mappings between input attribute (first element) and output attribute (second element)
  • for value and agg, it is the TEXT-encoded (base for value, computed for agg) scalar value
Parameters
tokenUUID of the circuit gate
dataTEXT-encoded information
Source code
provsql.sql line 236

◆ set_infos()

VOID provsql.set_infos ( UUID token,
INT info1,
INT info2 = NULL )

Set additional INTEGER values on provenance circuit gate.

This function sets two INTEGER values associated to a circuit gate, used in different ways by different gate types:

  • for mulinput, info1 indicates the value of this multivalued variable
  • for eq, info1 and info2 indicate the attribute index of the equijoin in, respectively, the first and second columns
  • for agg, info1 is the oid of the aggregate function and info2 the oid of the aggregate result type
  • for cmp, info1 is the oid of the comparison operator
Parameters
tokenUUID of the circuit gate
info1first INTEGER value
info2second INTEGER value
Source code
provsql.sql line 128

◆ set_prob()

VOID provsql.set_prob ( UUID token,
DOUBLE PRECISION p )

Set the probability of an input gate.

Parameters
tokenUUID of the input gate
pprobability value in [0,1]
Source code
provsql.sql line 102