ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
safe_query.h
Go to the documentation of this file.
1/**
2 * @file safe_query.h
3 * @brief Public surface of the safe-query (hierarchical-CQ) rewriter.
4 *
5 * The implementation lives in @c safe_query.c. ProvSQL's main planner
6 * hook (@c process_query in @c provsql.c) calls @c try_safe_query_rewrite
7 * between the AGG-DISTINCT rewrite and @c get_provenance_attributes,
8 * but only when the @c provsql.boolean_provenance GUC is on. Returning
9 * a non-NULL @c Query feeds the rewriter's output back through
10 * @c process_query from the top; returning @c NULL makes the caller
11 * fall through to the existing pipeline.
12 */
13#ifndef SAFE_QUERY_H
14#define SAFE_QUERY_H
15
16#include "postgres.h"
17#include "nodes/parsenodes.h"
18
19#include "provsql_utils.h"
20
21/** @brief GUC: opt-in safe-query optimisation, declared in @c provsql.c. */
23
24/**
25 * @brief Top-level entry point for the hierarchical-CQ rewriter.
26 *
27 * Runs the shape gate, then the hierarchy detector. When both accept,
28 * applies the rewrite and returns the rewritten @c Query (the caller
29 * is expected to re-enter @c process_query on the result). Returns
30 * @c NULL when @p q is outside the safe-query scope.
31 *
32 * @param constants Cached extension OIDs (from @c get_constants).
33 * @param q Input @c Query, modified in place by side-effect-free
34 * helpers but @em not consumed; the rewriter
35 * @c copyObject's it before mutating.
36 * @return A fresh rewritten @c Query, or @c NULL to fall through.
37 */
38extern Query *try_safe_query_rewrite(const constants_t *constants, Query *q);
39
40/**
41 * @brief PG 18 helper: strip the synthetic @c RTE_GROUP entry from
42 * @p q in place, resolving every grouped @c Var back to its
43 * base-table expression. Defined in @c provsql.c.
44 *
45 * Idempotent: a no-op on earlier PostgreSQL versions and when
46 * @c q->hasGroupRTE is already false. The safe-query rewriter
47 * applies it before the union-find pass so the range table is flat.
48 */
49extern void strip_group_rte_pg18(Query *q);
50
51#endif /* SAFE_QUERY_H */
bool provsql_boolean_provenance
Opt-in safe-query optimisation: when true, rewrites hierarchical conjunctive queries to a read-once f...
Definition provsql.c:86
Core types, constants, and utilities shared across ProvSQL.
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 t...
Structure to store the value of various constants.