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

SQL function provsql.provenance_evaluate_compiled() – C++ semiring evaluation. More...

#include "postgres.h"
#include "fmgr.h"
#include "catalog/pg_type.h"
#include "utils/uuid.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/datum.h"
#include "utils/array.h"
#include "access/xact.h"
#include "access/htup_details.h"
#include "funcapi.h"
#include "compatibility.h"
#include "provsql_utils.h"
#include "provsql_mmap.h"
#include "agg_token.h"
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <deque>
#include <limits>
#include <unordered_set>
#include "CertifiedDDMaterialize.h"
#include "CircuitFromMMap.h"
#include "Expectation.h"
#include "having_semantics.hpp"
#include "provenance_evaluate_compiled.hpp"
#include "provsql_interrupt.h"
#include "semiring/Boolean.h"
#include "semiring/Counting.h"
#include "semiring/Formula.h"
#include "semiring/How.h"
#include "semiring/Why.h"
#include "semiring/Which.h"
#include "semiring/BoolExpr.h"
#include "semiring/Tropical.h"
#include "semiring/Viterbi.h"
#include "semiring/Lukasiewicz.h"
#include "semiring/IntervalUnion.h"
#include "semiring/MinMax.h"
#include "semiring/Subset.h"
#include "semiring/Regex.h"
#include "semiring/TropicalPaths.h"
#include "semiring/BestPath.h"
Include dependency graph for provenance_evaluate_compiled.cpp:

Go to the source code of this file.

Functions

bool join_with_temp_uuids (Oid table, const std::vector< std::string > &uuids)
 Join a provenance mapping table with a set of UUIDs using SPI.
static Datum provenance_evaluate_compiled_internal (pg_uuid_t token, Oid table, const std::string &semiring, Oid type)
 Core implementation of compiled provenance evaluation.
static std::pair< double, std::string > tropical_paths_internal (pg_uuid_t token, Oid costs, Oid labels)
 Min-cost derivations of token and the derivations of that cost (semiring::TropicalPaths), each leaf with its cost from costs and its label from labels.
Datum provenance_evaluate_tropical_paths (PG_FUNCTION_ARGS)
 PostgreSQL-callable wrapper for tropical_paths_internal().
static semiring::best_path_t best_path_internal (pg_uuid_t token, Oid costs, Oid labels)
 A least-cost derivation of token (semiring::BestPath), each leaf with its cost from costs and its label from labels.
Datum provenance_evaluate_best_path (PG_FUNCTION_ARGS)
 PostgreSQL-callable wrapper for best_path_internal().
Datum provenance_evaluate_compiled (PG_FUNCTION_ARGS)
 PostgreSQL-callable wrapper for provenance_evaluate_compiled().
Datum plain_truth (PG_FUNCTION_ARGS)
 Whether a token holds in the database as it is, every input tuple present: sr_boolean without a mapping.
Datum subset_labels (PG_FUNCTION_ARGS)
 The labels a subset bitmask holds, as an array of the enum type of element_one, in enumsortorder.
Datum subset_settling (PG_FUNCTION_ARGS)
 The settling level of a set of clearance levels: the lowest level from which membership no longer changes up to the top level.
Datum subset_member (PG_FUNCTION_ARGS)
 Membership of a label, given as text, in the subset annotation of a token: the predicate behind visible_at and consented_for.
Datum sr_formula_rows (PG_FUNCTION_ARGS)
 The formula of a token as rows (name, formula), each bounded in size: sr_formula with the large sub-terms named.

Variables

const char * drop_temp_table = "DROP TABLE IF EXISTS tmp_uuids;"
 DROP TABLE statement for the per-query temporary provenance mapping table.

Detailed Description

SQL function provsql.provenance_evaluate_compiled() – C++ semiring evaluation.

Implements the compiled (C++ generic) variant of provenance circuit evaluation. Unlike provenance_evaluate() (which calls user-supplied PostgreSQL functions for each semiring operation), this function evaluates the circuit using one of the built-in C++ semiring implementations from the semiring/ directory.

Supported semirings (selected by the semiring argument):

Each compiled semiring exposes parse_leaf() and (for text-valued carriers) to_text() member functions, so this file is purely a dispatcher: it picks the right semiring instance from the (result-type, semiring-name) pair, then calls the pec() template which runs the same four-step pipeline for every semiring (build leaf mapping, evaluate HAVING sub-circuits, evaluate the main circuit, encode the result as a Datum).

Definition in file provenance_evaluate_compiled.cpp.

Function Documentation

◆ best_path_internal()

semiring::best_path_t best_path_internal ( pg_uuid_t token,
Oid costs,
Oid labels )
static

A least-cost derivation of token (semiring::BestPath), each leaf with its cost from costs and its label from labels.

An input missing from costs costs 0, one missing from labels is the empty word.

Returns
The cost ( \(+\infty\) with no derivation) and the labels of the derivation, in order.

Definition at line 682 of file provenance_evaluate_compiled.cpp.

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

◆ join_with_temp_uuids()

bool join_with_temp_uuids ( Oid table,
const std::vector< std::string > & uuids )

Join a provenance mapping table with a set of UUIDs using SPI.

Parameters
tableOID of the provenance mapping relation.
uuidsList of UUID strings to join against.
Returns
true if a temporary table was created (caller must drop it).

Definition at line 300 of file provenance_evaluate_compiled.cpp.

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

◆ plain_truth()

Datum plain_truth ( PG_FUNCTION_ARGS )

Whether a token holds in the database as it is, every input tuple present: sr_boolean without a mapping.

The rewriter filters by it the rows a displayed aggregate value reads, so that the value is what plain SQL computes on the same data: a row kept only for its provenance (the padding of a lowered outer join, a group a HAVING rejects, a row beyond a rank-filtered LIMIT) does not count. Gates whose truth follows from their children's (⊗, ⊕, ⊖, δ, ...) are walked directly, through the backend's gate cache; a comparison is left to the evaluation over the Boolean semiring, with no mapping to read.

Definition at line 954 of file provenance_evaluate_compiled.cpp.

Here is the call graph for this function:

◆ provenance_evaluate_best_path()

Datum provenance_evaluate_best_path ( PG_FUNCTION_ARGS )

PostgreSQL-callable wrapper for best_path_internal().

Definition at line 751 of file provenance_evaluate_compiled.cpp.

Here is the call graph for this function:

◆ provenance_evaluate_compiled()

Datum provenance_evaluate_compiled ( PG_FUNCTION_ARGS )

PostgreSQL-callable wrapper for provenance_evaluate_compiled().

Definition at line 793 of file provenance_evaluate_compiled.cpp.

Here is the call graph for this function:

◆ provenance_evaluate_compiled_internal()

Datum provenance_evaluate_compiled_internal ( pg_uuid_t token,
Oid table,
const std::string & semiring,
Oid type )
static

Core implementation of compiled provenance evaluation.

Parameters
tokenUUID of the root provenance gate.
tableOID of the provenance mapping relation.
semiringName of the semiring to evaluate over.
typeOID of the result element type.
Returns
Datum containing the semiring evaluation result.

Definition at line 428 of file provenance_evaluate_compiled.cpp.

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

◆ provenance_evaluate_tropical_paths()

Datum provenance_evaluate_tropical_paths ( PG_FUNCTION_ARGS )

PostgreSQL-callable wrapper for tropical_paths_internal().

Definition at line 639 of file provenance_evaluate_compiled.cpp.

Here is the call graph for this function:

◆ sr_formula_rows()

Datum sr_formula_rows ( PG_FUNCTION_ARGS )

The formula of a token as rows (name, formula), each bounded in size: sr_formula with the large sub-terms named.

Definition at line 1395 of file provenance_evaluate_compiled.cpp.

Here is the call graph for this function:

◆ subset_labels()

Datum subset_labels ( PG_FUNCTION_ARGS )

The labels a subset bitmask holds, as an array of the enum type of element_one, in enumsortorder.

Bits above the last label (the unrestricted element of the consent semiring) are ignored.

Definition at line 1008 of file provenance_evaluate_compiled.cpp.

◆ subset_member()

Datum subset_member ( PG_FUNCTION_ARGS )

Membership of a label, given as text, in the subset annotation of a token: the predicate behind visible_at and consented_for.

The enum type is that of the mapping table's value column (or the element type of an array column), so that the caller writes the label as a plain string. In consent mode, a purpose holds only where the unrestricted element does too.

Definition at line 1063 of file provenance_evaluate_compiled.cpp.

Here is the call graph for this function:

◆ subset_settling()

Datum subset_settling ( PG_FUNCTION_ARGS )

The settling level of a set of clearance levels: the lowest level from which membership no longer changes up to the top level.

Settledness is upward-closed, so it always exists; the membership it settles to is that of the top level.

Definition at line 1036 of file provenance_evaluate_compiled.cpp.

◆ tropical_paths_internal()

std::pair< double, std::string > tropical_paths_internal ( pg_uuid_t token,
Oid costs,
Oid labels )
static

Min-cost derivations of token and the derivations of that cost (semiring::TropicalPaths), each leaf with its cost from costs and its label from labels.

An input missing from costs costs 0, one missing from labels is the empty word.

Returns
The cost ( \(+\infty\) with no derivation) and the derivations, as a regular expression.

Definition at line 570 of file provenance_evaluate_compiled.cpp.

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

Variable Documentation

◆ drop_temp_table

const char* drop_temp_table = "DROP TABLE IF EXISTS tmp_uuids;"

DROP TABLE statement for the per-query temporary provenance mapping table.

Definition at line 98 of file provenance_evaluate_compiled.cpp.