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

SQL entry points for the joint-width UCQ compiler. More...

#include "postgres.h"
#include "fmgr.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/pg_type.h"
#include "executor/spi.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/resowner.h"
#include "utils/uuid.h"
#include "compatibility.h"
#include "provsql_utils.h"
#include "c_cpp_compatibility.h"
#include "JointEncoding.h"
#include "UCQJointCompiler.h"
#include "CircuitFromMMap.h"
#include "CertifiedDDMaterialize.h"
#include "GenericCircuit.h"
#include "provsql_utils_cpp.h"
#include <algorithm>
#include <cmath>
#include <limits>
#include <map>
#include <string>
#include <vector>
Include dependency graph for ucq_joint_evaluate.cpp:

Go to the source code of this file.

Functions

Datum ucq_joint_compile_stats (PG_FUNCTION_ARGS)
 PostgreSQL-callable entry point: UCQ probability plus compilation statistics (the three width columns and the structural stats).
Datum ucq_joint_materialize_tracked (PG_FUNCTION_ARGS)
 PostgreSQL-callable entry point: compile the UCQ over correlated inputs and materialise its certified d-D into the store, returning the root provenance token.
Datum ucq_joint_compile_stats_tracked (PG_FUNCTION_ARGS)
 PostgreSQL-callable entry point: correlated UCQ probability plus compilation statistics (the three width columns substantiate Prop.
static bool jwComputeCache (Datum descriptor, const std::vector< unsigned > &head_vars, JwAnswerCache *cache)
 Gather + single-DP materialise all answers into cache.
Datum ucq_joint_provenance_answer (PG_FUNCTION_ARGS)
 Per-answer joint-width provenance via the single top-down DP.

Detailed Description

SQL entry points for the joint-width UCQ compiler.

Exposes UCQJointCompiler (see UCQJointCompiler.h) to SQL. The compiler's job ends at the certified d-D circuit; probability / Shapley / expectation are the standard evaluation on the materialised token, so the SQL surface is materialisation, not probability:

  • ucq_joint_provenance_answer(): the planner-substituted per-answer entry point. On the first call of a query it gathers the facts once (ucq_joint_gather), runs the single top-down DP, and materialises every answer's d-D into the store, caching head -> token in fn_extra; each output group is then an O(1) lookup – one gather + one decomposition + one sweep for the whole GROUP BY.
  • ucq_joint_materialize_tracked(): materialise the Boolean (existence) d-D of a UCQ over real provenance tokens, returning its root token.
  • ucq_joint_compile_stats(): the same compilation returning the probability together with the three width columns (joint width, data-only and circuit-only degeneracy lower bounds) that substantiate thesis Prop. 4.2.11 empirically, and the structural statistics; the columnar form takes the query and facts as flat parallel arrays.

Element ids are dense integers assigned by the gather with a dictionary shared across relations (so join-compatible values match).

Definition in file ucq_joint_evaluate.cpp.

Function Documentation

◆ jwComputeCache()

bool jwComputeCache ( Datum descriptor,
const std::vector< unsigned > & head_vars,
JwAnswerCache * cache )
static

Gather + single-DP materialise all answers into cache.

Runs inside a subtransaction (the caller wraps it): a SQL error from the gather (e.g. an unsupported token type for which the joint route declines) propagates as an ereport and is caught by the caller's PG_CATCH; a compiler decline (joint width too large) is a C++ exception caught here and signalled by returning false. Returns true and fills cache on success.

Definition at line 861 of file ucq_joint_evaluate.cpp.

Here is the caller graph for this function:

◆ ucq_joint_compile_stats()

Datum ucq_joint_compile_stats ( PG_FUNCTION_ARGS )

PostgreSQL-callable entry point: UCQ probability plus compilation statistics (the three width columns and the structural stats).

Definition at line 708 of file ucq_joint_evaluate.cpp.

◆ ucq_joint_compile_stats_tracked()

Datum ucq_joint_compile_stats_tracked ( PG_FUNCTION_ARGS )

PostgreSQL-callable entry point: correlated UCQ probability plus compilation statistics (the three width columns substantiate Prop.

4.2.11: a correlated instance can have small data and circuit widths but large joint width).

Definition at line 780 of file ucq_joint_evaluate.cpp.

◆ ucq_joint_materialize_tracked()

Datum ucq_joint_materialize_tracked ( PG_FUNCTION_ARGS )

PostgreSQL-callable entry point: compile the UCQ over correlated inputs and materialise its certified d-D into the store, returning the root provenance token.

This is the architecturally-primary route: the joint-width compiler's job is to build the deterministic, decomposable circuit; the answer – probability, Shapley, expectation, any provenance-store evaluation – is then obtained through the single standard entry point on the returned token (e.g. probability_evaluate(token)), exploiting the d-D certificate for linear-time evaluation. Unlike the reachability route, the token is NOT wrapped in the 'absorptive' marker: the d-D is the exact Boolean provenance of the (non-recursive) UCQ.

Definition at line 756 of file ucq_joint_evaluate.cpp.

Here is the call graph for this function:

◆ ucq_joint_provenance_answer()

Datum ucq_joint_provenance_answer ( PG_FUNCTION_ARGS )

Per-answer joint-width provenance via the single top-down DP.

See ucq_joint_provenance_answer in provsql.common.sql.

Definition at line 961 of file ucq_joint_evaluate.cpp.

Here is the call graph for this function: