ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
safe_query.h File Reference

Public surface of the safe-query (hierarchical-CQ) rewriter. More...

#include "postgres.h"
#include "nodes/parsenodes.h"
#include "provsql_utils.h"
Include dependency graph for safe_query.h:
This graph shows which files directly or indirectly include this file:

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.

Detailed Description

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.

Function Documentation

◆ inversion_free_analyze()

bool inversion_free_analyze ( const constants_t * constants,
Query * q,
char ** cert_out,
InvFreeMarker ** markers_out,
int * natoms_out )
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.

Returns
true if q is certified inversion-free (cert produced).

Definition at line 4934 of file safe_query.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strip_group_rte_pg18()

void strip_group_rte_pg18 ( Query * q)
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.

Here is the caller graph for this function:

◆ try_safe_query_rewrite()

Query * try_safe_query_rewrite ( const constants_t * constants,
Query * q )
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.

Parameters
constantsCached extension OIDs (from get_constants).
qInput Query, modified in place by side-effect-free helpers but not consumed; the rewriter copyObject's it before mutating.
Returns
A fresh rewritten Query, or NULL to fall through.

Definition at line 4971 of file safe_query.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ provsql_boolean_provenance

bool provsql_boolean_provenance
extern

GUC: opt-in safe-query optimisation, declared in provsql.c.

GUC: opt-in safe-query optimisation, declared in provsql.c.

Opt-in safe-query optimisation for hierarchical conjunctive queries; see the provsql.boolean_provenance GUC.

Definition at line 107 of file provsql.c.