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

Core types, constants, and utilities shared across ProvSQL. More...

#include "pg_config.h"
#include "c.h"
#include "postgres.h"
#include "utils/uuid.h"
#include "postgres_ext.h"
#include "nodes/pg_list.h"
#include "provsql_error.h"
Include dependency graph for provsql_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pg_uuid_t
 UUID structure. More...
 
struct  constants_t
 Structure to store the value of various constants. More...
 
struct  database_constants_t
 Structure to store the value of various constants for a specific database. More...
 

Macros

#define UUID_LEN   16
 Number of bytes in a UUID.
 

Enumerations

enum  gate_type {
  gate_input , gate_plus , gate_times , gate_monus ,
  gate_project , gate_zero , gate_one , gate_eq ,
  gate_agg , gate_semimod , gate_cmp , gate_delta ,
  gate_value , gate_mulinput , gate_update , gate_invalid ,
  nb_gate_types
}
 Possible gate type in the provenance circuit. More...
 

Functions

constants_t get_constants (bool failure_if_not_possible)
 Retrieve the cached OID constants for the current database.
 
Oid find_equality_operator (Oid ltypeId, Oid rtypeId)
 Find the equality operator OID for two given types.
 

Variables

const char * gate_type_name []
 Names of gate types.
 
bool provsql_interrupted
 Global variable that becomes true if this particular backend received an interrupt signal.
 
bool provsql_where_provenance
 Global variable that indicates if where-provenance support has been activated through the provsql.where_provenance run-time configuration parameter.
 
int provsql_verbose
 Global variable that indicates the verbosity level set by the provsql.verbose_level run-time configuration parameter was set.
 

Detailed Description

Core types, constants, and utilities shared across ProvSQL.

This header is included by virtually every source file in the extension. It provides:

  • The gate_type enumeration listing all circuit-gate kinds recognised by ProvSQL (input, semiring operations, aggregation, etc.)
  • The constants_t structure caching PostgreSQL OIDs for the types, functions, and operators that ProvSQL installs, so that OID lookups happen once per session rather than on every query.
  • The database_constants_t wrapper for per-database OID caches.
  • Helper declarations for OID lookup and UUID manipulation.
  • Global flags controlling interrupt handling, where-provenance, and verbosity.
  • An implicit inclusion of provsql_error.h for the provsql_error / provsql_warning / provsql_notice / provsql_log macros.

Definition in file provsql_utils.h.

Macro Definition Documentation

◆ UUID_LEN

#define UUID_LEN   16

Number of bytes in a UUID.

Definition at line 30 of file provsql_utils.h.

Enumeration Type Documentation

◆ gate_type

enum gate_type

Possible gate type in the provenance circuit.

Enumerator
gate_input 

Input (variable) gate of the circuit.

gate_plus 

Semiring plus.

gate_times 

Semiring times.

gate_monus 

M-Semiring monus.

gate_project 

Project gate (for where provenance)

gate_zero 

Semiring zero.

gate_one 

Semiring one.

gate_eq 

Equijoin gate (for where provenance)

gate_agg 

Aggregation operator (for aggregate provenance)

gate_semimod 

Semimodule scalar multiplication (for aggregate provenance)

gate_cmp 

Currently unused, meant for comparison of aggregate values.

gate_delta 

δ-semiring operator (see Amsterdamer, Deutch, Tannen, PODS 2011)

gate_value 

Scalar value (for aggregate provenance)

gate_mulinput 

Multivalued input (for Boolean provenance)

gate_update 

Update operation.

gate_invalid 

Invalid gate type.

nb_gate_types 

Total number of gate types.

Definition at line 45 of file provsql_utils.h.

Function Documentation

◆ find_equality_operator()

Oid find_equality_operator ( Oid  ltypeId,
Oid  rtypeId 
)

Find the equality operator OID for two given types.

Searches pg_operator for the = operator that accepts ltypeId on the left and rtypeId on the right.

Parameters
ltypeIdOID of the left operand type.
rtypeIdOID of the right operand type.
Returns
The operator OID, or InvalidOid if none is found.

Definition at line 109 of file provsql_utils.c.

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

◆ get_constants()

constants_t get_constants ( bool  failure_if_not_possible)

Retrieve the cached OID constants for the current database.

On first call (or after a cache miss) this function looks up the OIDs of all ProvSQL-specific types, functions, and operators in the system catalogs and stores them in a per-database cache. Subsequent calls return the cached values without touching the catalogs.

Parameters
failure_if_not_possibleIf true, call provsql_error when the ProvSQL schema cannot be found (e.g. the extension is not installed in the current database). If false, return a constants_t with ok==false instead of aborting.
Returns
A constants_t whose ok field is true on success.

Definition at line 425 of file provsql_utils.c.

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

Variable Documentation

◆ gate_type_name

const char* gate_type_name[]
extern

Names of gate types.

Definition at line 38 of file provsql_utils.c.

◆ provsql_interrupted

bool provsql_interrupted
extern

Global variable that becomes true if this particular backend received an interrupt signal.

Definition at line 62 of file provsql.c.

◆ provsql_verbose

int provsql_verbose
extern

Global variable that indicates the verbosity level set by the provsql.verbose_level run-time configuration parameter was set.

Global variable that indicates the verbosity level set by the provsql.verbose_level run-time configuration parameter was set.

Definition at line 66 of file provsql.c.

◆ provsql_where_provenance

bool provsql_where_provenance
extern

Global variable that indicates if where-provenance support has been activated through the provsql.where_provenance run-time configuration parameter.

Definition at line 64 of file provsql.c.