![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Public surface of the safe-query (hierarchical-CQ) rewriter. More...


Go to the source code of this file.
Classes | |
| struct | InvFreeMarker |
| Per-atom marker spec for the inversion-free path. More... | |
| struct | InvFreeMarkerCtx |
| Per-query marker context for the inversion-free path, threaded through the recursive query rewrite to reach base inputs nested in subqueries. More... | |
Functions | |
| Query * | try_safe_query_rewrite (const constants_t *constants, Query *q) |
| Top-level entry point for the hierarchical-CQ rewriter. | |
| bool | inversion_free_analyze (const constants_t *constants, Query *q, char **cert_out, InvFreeMarker **markers_out, int *natoms_out) |
Inversion-free analysis of the lineage query q. | |
| void | strip_group_rte_pg18 (Query *q) |
PG 18 helper: strip the synthetic RTE_GROUP entry from q in place, resolving every grouped Var back to its base-table expression. | |
Variables | |
| bool | provsql_boolean_provenance |
GUC: opt-in safe-query optimisation, declared in provsql.c. | |
Public surface of the safe-query (hierarchical-CQ) rewriter.
The implementation lives in safe_query.c. ProvSQL's main planner hook (process_query in provsql.c) calls try_safe_query_rewrite between the AGG-DISTINCT rewrite and get_provenance_attributes, but only when the provsql.boolean_provenance GUC is on. Returning a non-NULL Query feeds the rewriter's output back through process_query from the top; returning NULL makes the caller fall through to the existing pipeline.
Definition in file safe_query.h.
|
extern |
Inversion-free analysis of the lineage query q.
Runs the detector on q itself (the query whose provenance lineage is being built), so the certificate and the per-atom marker specs align with the lineage by construction, independent of any read-once pre-pass. On success sets cert_out to a palloc'd C-prefixed serialised SafeCert recipe (for the per-row root) and, when the marker model applies, markers_out to a palloc'd array of *natoms_out InvFreeMarker (one per atom); otherwise leaves them NULL.
true if q is certified inversion-free (cert produced). Definition at line 4934 of file safe_query.c.


|
extern |
PG 18 helper: strip the synthetic RTE_GROUP entry from q in place, resolving every grouped Var back to its base-table expression.
Defined in provsql.c.
Idempotent: a no-op on earlier PostgreSQL versions and when q->hasGroupRTE is already false. The safe-query rewriter applies it before the union-find pass so the range table is flat.

|
extern |
Top-level entry point for the hierarchical-CQ rewriter.
Runs the shape gate, then the hierarchy detector. When both accept, applies the rewrite and returns the rewritten Query (the caller is expected to re-enter process_query on the result). Returns NULL when q is outside the safe-query scope.
| constants | Cached extension OIDs (from get_constants). |
| q | Input Query, modified in place by side-effect-free helpers but not consumed; the rewriter copyObject's it before mutating. |
Query, or NULL to fall through. Definition at line 4971 of file safe_query.c.


|
extern |