![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
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"
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. | |
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):
"boolean" → semiring::Boolean "counting" → semiring::Counting "formula" → semiring::Formula (symbolic representation as a formula)"how" → semiring::How (canonical polynomial provenance ℕ[X])"why" → semiring::Why (witness sets)"which" → semiring::Which (lineage)"boolexpr" → semiring::BoolExpr (Boolean circuit for probability)"tropical" → semiring::Tropical (min-plus, shortest-cost)"viterbi" → semiring::Viterbi (max-times, most-likely derivation)"lukasiewicz" → semiring::Lukasiewicz (Łukasiewicz fuzzy t-norm)"interval_union" → semiring::IntervalUnion (multirange union, PG14+) for any of tstzmultirange, nummultirange, int4multirange; selected by the result type of the call"minmax" / "maxmin" → semiring::MinMax over any user-defined PostgreSQL enum type, selected by get_typtype() == TYPTYPE_ENUM "subset" / "clearance" / "consent" → semiring::Subset, the subsets of the labels of an enum type, returned as a bigint bitmask (declared in SQL as subset_evaluate)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.
|
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.
Definition at line 682 of file provenance_evaluate_compiled.cpp.


| 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.
| table | OID of the provenance mapping relation. |
| uuids | List of UUID strings to join against. |
true if a temporary table was created (caller must drop it). Definition at line 300 of file provenance_evaluate_compiled.cpp.


| 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.

| 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.

| Datum provenance_evaluate_compiled | ( | PG_FUNCTION_ARGS | ) |
PostgreSQL-callable wrapper for provenance_evaluate_compiled().
Definition at line 793 of file provenance_evaluate_compiled.cpp.

|
static |
Core implementation of compiled provenance evaluation.
| token | UUID of the root provenance gate. |
| table | OID of the provenance mapping relation. |
| semiring | Name of the semiring to evaluate over. |
| type | OID of the result element type. |
Definition at line 428 of file provenance_evaluate_compiled.cpp.


| 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.

| 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.

| 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.
| 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.

| 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.
|
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.
Definition at line 570 of file provenance_evaluate_compiled.cpp.


| 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.