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/lsyscache.h"
#include "provsql_shmem.h"
#include "provsql_utils.h"
#include <string>
#include <sstream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include "having_semantics.hpp"
#include "provenance_evaluate_compiled.hpp"
#include "semiring/Boolean.h"
#include "semiring/Counting.h"
#include "semiring/Formula.h"
#include "semiring/Why.h"
#include "semiring/BoolExpr.h"
Include dependency graph for provenance_evaluate_compiled.cpp:

Go to the source code of this file.

Functions

static Datum pec_bool (const constants_t &constants, GenericCircuit &c, gate_t g, const std::set< gate_t > &inputs, const std::string &semiring, bool drop_table)
 Evaluate the Boolean semiring provenance for a circuit.
 
static Datum pec_boolexpr (const constants_t &constants, BooleanCircuit &bc, gate_t root)
 Evaluate the Boolean-expression semiring provenance for a circuit.
 
static Datum pec_why (const constants_t &constants, GenericCircuit &c, gate_t g, const std::set< gate_t > &inputs, bool drop_table)
 Evaluate the Why-provenance semiring for a circuit.
 
static Datum pec_varchar (const constants_t &constants, GenericCircuit &c, gate_t g, const std::set< gate_t > &inputs, const std::string &semiring, bool drop_table)
 Evaluate a varchar semiring provenance for a circuit.
 
static Datum pec_int (const constants_t &constants, GenericCircuit &c, gate_t g, const std::set< gate_t > &inputs, const std::string &semiring, bool drop_table)
 Evaluate an integer semiring provenance for a circuit.
 
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.
 
Datum provenance_evaluate_compiled (PG_FUNCTION_ARGS)
 PostgreSQL-callable wrapper for provenance_evaluate_compiled().
 

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):

The function first builds a provenance mapping (input-gate UUID → semiring value) by querying the tmp_uuids table via SPI (using initialize_provenance_mapping()), then evaluates the GenericCircuit with GenericCircuit::evaluate() and returns the result as text.

Definition in file provenance_evaluate_compiled.cpp.

Function Documentation

◆ 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 245 of file provenance_evaluate_compiled.cpp.

Here is the caller graph for this function:

◆ pec_bool()

static Datum pec_bool ( const constants_t constants,
GenericCircuit c,
gate_t  g,
const std::set< gate_t > &  inputs,
const std::string &  semiring,
bool  drop_table 
)
static

Evaluate the Boolean semiring provenance for a circuit.

Parameters
constantsExtension OID cache.
cGeneric circuit to evaluate.
gRoot gate of the sub-circuit.
inputsSet of input gate IDs.
semiringSemiring name (must be "boolean").
drop_tableWhether the temporary UUID table should be dropped.
Returns
Bool datum with the evaluated provenance.

Definition at line 63 of file provenance_evaluate_compiled.cpp.

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

◆ pec_boolexpr()

static Datum pec_boolexpr ( const constants_t constants,
BooleanCircuit bc,
gate_t  root 
)
static

Evaluate the Boolean-expression semiring provenance for a circuit.

Parameters
constantsExtension OID cache.
bcBoolean circuit to render as a formula.
rootRoot gate of the circuit.
Returns
Text datum with the formula string.

Definition at line 92 of file provenance_evaluate_compiled.cpp.

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

◆ pec_int()

static Datum pec_int ( const constants_t constants,
GenericCircuit c,
gate_t  g,
const std::set< gate_t > &  inputs,
const std::string &  semiring,
bool  drop_table 
)
static

Evaluate an integer semiring provenance for a circuit.

Parameters
constantsExtension OID cache.
cGeneric circuit to evaluate.
gRoot gate.
inputsSet of input gate IDs.
semiringSemiring name (e.g. "counting").
drop_tableWhether the temporary UUID table should be dropped.
Returns
Int32 datum with the evaluated provenance.

Definition at line 216 of file provenance_evaluate_compiled.cpp.

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

◆ pec_varchar()

static Datum pec_varchar ( const constants_t constants,
GenericCircuit c,
gate_t  g,
const std::set< gate_t > &  inputs,
const std::string &  semiring,
bool  drop_table 
)
static

Evaluate a varchar semiring provenance for a circuit.

Parameters
constantsExtension OID cache.
cGeneric circuit to evaluate.
gRoot gate.
inputsSet of input gate IDs.
semiringSemiring name (e.g. "formula").
drop_tableWhether the temporary UUID table should be dropped.
Returns
Varchar datum containing the serialised provenance.

Definition at line 177 of file provenance_evaluate_compiled.cpp.

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

◆ pec_why()

static Datum pec_why ( const constants_t constants,
GenericCircuit c,
gate_t  g,
const std::set< gate_t > &  inputs,
bool  drop_table 
)
static

Evaluate the Why-provenance semiring for a circuit.

Parameters
constantsExtension OID cache.
cGeneric circuit to evaluate.
gRoot gate.
inputsSet of input gate IDs.
drop_tableWhether the temporary UUID table should be dropped.
Returns
Varchar datum containing the serialised Why-provenance.

Definition at line 114 of file provenance_evaluate_compiled.cpp.

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

◆ provenance_evaluate_compiled()

Datum provenance_evaluate_compiled ( PG_FUNCTION_ARGS  )

PostgreSQL-callable wrapper for provenance_evaluate_compiled().

Definition at line 369 of file provenance_evaluate_compiled.cpp.

Here is the call graph for this function:

◆ provenance_evaluate_compiled_internal()

static 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 332 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 51 of file provenance_evaluate_compiled.cpp.