![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Per-relation provenance metadata: the in-memory record. More...
#include <stdint.h>#include "postgres.h"#include "access/attnum.h"

Go to the source code of this file.
Classes | |
| struct | ProvenanceTableInfo |
| Per-relation metadata for the safe-query optimisation. More... | |
Macros | |
| #define | PROVSQL_TABLE_INFO_MAX_BLOCK_KEY 16 |
| Cap on the number of block-key columns recorded per relation. | |
| #define | PROVSQL_TABLE_INFO_MAX_ANCESTORS 64 |
| Cap on the number of base ancestors recorded per relation. | |
Enumerations | |
| enum | provsql_table_kind { PROVSQL_TABLE_TID = 0 , PROVSQL_TABLE_BID = 1 , PROVSQL_TABLE_OPAQUE = 2 } |
| How the provenance leaves of a tracked relation are correlated. More... | |
Per-relation provenance metadata: the in-memory record.
A ProvenanceTableInfo describes one relation ProvSQL tracks, and feeds the safe-query optimisation: the planner-time hierarchy detector needs to know whether each base relation is TID (independent leaves; the default after add_provenance) or BID (block-correlated leaves; produced by repair_key) before it can decide whether a query is safe to rewrite into read-once form.
The records live in the provsql.table_info heap table (table_info.c), where metadata about relations belongs: every change follows the transaction that made it, and pg_dump carries them. This struct is what the C side reads them into.
Before ProvSQL 1.13.0 they lived in a fifth mmap-backed file, provsql_table_info.mmap, laid out as a fixed-stride vector of this struct behind the usual 16-byte ProvSQL header. provsql.migrate_table_info() (TableInfoMigrate.cpp) still reads that layout, which is why the field order below must not change while any installation may still have such a file to import.
Definition in file MMappedTableInfo.h.
| #define PROVSQL_TABLE_INFO_MAX_ANCESTORS 64 |
Cap on the number of base ancestors recorded per relation.
The base-ancestor set lists the pg_class OIDs of the original add_provenance / repair_key relations a derived (CTAS / SELECT INTO / CREATE MATERIALIZED VIEW) relation's provenance ultimately reads from. Base tables carry {self}; the safe-query rewriter consults the set to enforce that joined FROM entries have disjoint base ancestors before firing the read-once factoring. Sixty-four covers practical CTAS workloads (typical derivations span 1-10 sources); set-ancestors raises a clear error if a wider set is requested, in which case the relation should be left untracked (the safe-query rewriter will then refuse it on the missing-ancestry conservative path).
Definition at line 69 of file MMappedTableInfo.h.
| #define PROVSQL_TABLE_INFO_MAX_BLOCK_KEY 16 |
Cap on the number of block-key columns recorded per relation.
BID tables (produced by repair_key) can have multi-column keys. We store the column numbers inline in a fixed-size array so each record is fixed-stride and MMappedVector can back the file directly. Sixteen is generous in practice – provenance-tracked tables rarely use composite keys wider than a handful of columns. repair_key raises a clear error if a wider key is requested.
Definition at line 52 of file MMappedTableInfo.h.
| enum provsql_table_kind |
How the provenance leaves of a tracked relation are correlated.
Three cases need distinguishing for the safe-query rewriter:
PROVSQL_TABLE_TID – independent input leaves; the post-add_provenance default. Each row's provenance token is a fresh gate_input with its own probability.PROVSQL_TABLE_BID – block-correlated leaves produced by repair_key. Rows sharing the same value of block_key are mutually exclusive (they originate from a single block gate_input via gate_mulinput children). An empty block_key means the whole table is one block.PROVSQL_TABLE_OPAQUE – correlations are unknown. Used for relations whose provenance is derived from a tracked source via CREATE TABLE AS SELECT, INSERT INTO SELECT, or UPDATE under provsql.update_provenance. The safe-query rewriter must bail on these.Stored as uint8_t in ProvenanceTableInfo so the on-disk size matches the previous bool field exactly.
provsql_table_info.mmap. Do not reorder or renumber existing members; new kinds must be appended. | Enumerator | |
|---|---|
| PROVSQL_TABLE_TID | |
| PROVSQL_TABLE_BID | |
| PROVSQL_TABLE_OPAQUE | |
Definition at line 97 of file MMappedTableInfo.h.