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.

Functions

Query * try_safe_query_rewrite (const constants_t *constants, Query *q)
 Top-level entry point for the hierarchical-CQ rewriter.
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

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

Top-level entry point for the hierarchical-CQ rewriter.

Runs the shape gate then the hierarchy detector. If both accept, applies the single-level rewrite and returns the rewritten Query; the caller (process_query) feeds it back from the top so that inner subqueries are themselves re-considered (multi-level recursion via Choice A). Returns NULL to fall through to the existing pipeline.

Definition at line 4674 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 86 of file provsql.c.