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

Planner-time recognition of unsafe UCQs for the joint-width compiler. More...

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

Go to the source code of this file.

Functions

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.

Detailed Description

Planner-time recognition of unsafe UCQs for the joint-width compiler.

When provsql.provenance is 'boolean' and the safe-query rewriter has declined (i.e. the query is an unsafe conjunctive query – H0, Hk, the #P-hard cases the Dalvi-Suciu dichotomy rules out from lifted inference), this recogniser extracts the UCQ structure from the query's abstract syntax and builds the JSON descriptor consumed by provsql.ucq_joint_provenance(): the relations, how their columns map to query variables, and the atoms. The descriptor drives the joint-width compiler, whose certified d-D the standard evaluators (probability_evaluate, shapley) then exploit – so a recognised query is answered exactly through the one evaluation pipeline.

Definition in file joint_width_query.h.

Function Documentation

◆ provsql_joint_width_descriptor()

char * provsql_joint_width_descriptor ( const constants_t * constants,
Query * q,
bool * all_existential,
List ** head_var_idx,
List ** head_exprs )
extern

Build the joint-width descriptor for a recognised UCQ.

Recognises a conjunctive query over provenance-tracked base relations: a flat FROM list (or inner JOIN ... ON tree) of tracked RTE_RELATION entries, a WHERE that is a conjunction of equalities, no HAVING / window functions / sublinks / aggregates other than the provenance aggregation. The variable structure is the column equivalence relation induced by the Var = Var join equalities; a Var = Const selection pins that variable to the literal (the same Sel mechanism as a head). The per-answer heads are the GROUP BY keys (bare tracked columns); the SELECT list itself is arbitrary (a function of the keys), so what is displayed does not constrain recognition.

A UNION [ALL] of such conjunctive queries (the body of an aggregated subquery) is recognised as a genuine multi-disjunct UCQ: one disjunct per arm, relations merged across the arms. Both the Boolean existence and the per-answer form (a free-variable head exposed by every arm and grouped by the outer query) are handled; the head is numbered canonically so a single Sel-pin forces it across all disjuncts.

Parameters
constantsCached extension OIDs.
qThe parsed query (read-only).
all_existentialOutput: set to true iff no variable of the UCQ is exposed in the target list (the query computes the Boolean existence of the UCQ – the #P-hard case the substitution targets); false when output/grouped variables remain (a per-answer query).
head_var_idxOutput (may be NULL): when the query is per-answer and every exposed target column is a bare integer Var over a tracked atom, the List of the head variables' query-variable indices (Integer nodes), in output order, deduplicated; NIL if the heads cannot be cleanly extracted (the per-answer substitution then declines).
head_exprsOutput (may be NULL): parallel List of the target Var Expr exposing each head variable (the per-group head value at execution).
Returns
A palloc'd JSON descriptor string (the shape ucq_joint_provenance expects), or NULL when q is outside the recogniser's scope.

Definition at line 559 of file joint_width_query.c.

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