ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
joint_width_query.h
Go to the documentation of this file.
1/**
2 * @file joint_width_query.h
3 * @brief Planner-time recognition of unsafe UCQs for the joint-width
4 * compiler.
5 *
6 * When @c provsql.provenance is @c 'boolean' and the safe-query rewriter
7 * has declined (i.e. the query is an *unsafe* conjunctive query -- H0,
8 * Hk, the @c \#P-hard cases the Dalvi-Suciu dichotomy rules out from
9 * lifted inference), this recogniser extracts the UCQ structure from the
10 * query's abstract syntax and builds the JSON descriptor consumed by
11 * @c provsql.ucq_joint_provenance(): the relations, how their columns map
12 * to query variables, and the atoms. The descriptor drives the
13 * joint-width compiler, whose certified d-D the standard evaluators
14 * (@c probability_evaluate, @c shapley) then exploit -- so a recognised
15 * query is answered exactly through the one evaluation pipeline.
16 */
17#ifndef JOINT_WIDTH_QUERY_H
18#define JOINT_WIDTH_QUERY_H
19
20#include "postgres.h"
21#include "nodes/parsenodes.h"
22
23#include "provsql_utils.h"
24
25/**
26 * @brief Build the joint-width descriptor for a recognised UCQ.
27 *
28 * Recognises a conjunctive query over provenance-tracked base relations:
29 * a flat @c FROM list (or inner @c JOIN @c ... @c ON tree) of tracked
30 * @c RTE_RELATION entries, a @c WHERE that is a conjunction of equalities,
31 * no @c HAVING / window functions / sublinks / aggregates other than the
32 * provenance aggregation. The variable structure is the column
33 * equivalence relation induced by the @c Var @c = @c Var join equalities;
34 * a @c Var @c = @c Const selection pins that variable to the literal (the
35 * same Sel mechanism as a head). The per-answer heads are the @c GROUP
36 * @c BY keys (bare tracked columns); the @c SELECT list itself is
37 * arbitrary (a function of the keys), so what is displayed does not
38 * constrain recognition.
39 *
40 * A @c UNION [@c ALL] of such conjunctive queries (the body of an
41 * aggregated subquery) is recognised as a genuine multi-disjunct UCQ: one
42 * disjunct per arm, relations merged across the arms. Both the Boolean
43 * existence and the per-answer form (a free-variable head exposed by every
44 * arm and grouped by the outer query) are handled; the head is numbered
45 * canonically so a single Sel-pin forces it across all disjuncts.
46 *
47 * @param constants Cached extension OIDs.
48 * @param q The parsed query (read-only).
49 * @param all_existential Output: set to @c true iff no variable of the
50 * UCQ is exposed in the target list (the query
51 * computes the Boolean *existence* of the UCQ --
52 * the @c \#P-hard case the substitution targets);
53 * @c false when output/grouped variables remain
54 * (a per-answer query).
55 * @param head_var_idx Output (may be @c NULL): when the query is
56 * per-answer and every exposed target column is a
57 * bare integer @c Var over a tracked atom, the
58 * @c List of the head variables' query-variable
59 * indices (@c Integer nodes), in output order,
60 * deduplicated; @c NIL if the heads cannot be
61 * cleanly extracted (the per-answer substitution
62 * then declines).
63 * @param head_exprs Output (may be @c NULL): parallel @c List of the
64 * target @c Var @c Expr exposing each head variable
65 * (the per-group head value at execution).
66 * @return A palloc'd JSON descriptor string (the shape
67 * @c ucq_joint_provenance expects), or @c NULL when @p q is
68 * outside the recogniser's scope.
69 */
70extern char *provsql_joint_width_descriptor(const constants_t *constants,
71 Query *q, bool *all_existential,
72 List **head_var_idx,
73 List **head_exprs);
74
75#endif /* JOINT_WIDTH_QUERY_H */
char * provsql_joint_width_descriptor(const constants_t *constants, Query *q, bool *all_existential, List **head_var_idx, List **head_exprs)
Build the joint-width descriptor for a recognised UCQ.
Core types, constants, and utilities shared across ProvSQL.
Structure to store the value of various constants.