17#include <boost/archive/binary_iarchive.hpp>
18#include <boost/iostreams/device/array.hpp>
19#include <boost/iostreams/stream.hpp>
54 provsql_error(
"Cannot write to pipe (message type %c)", message_char);
57 if(!
READB(size,
unsigned long))
58 provsql_error(
"Cannot read from pipe (message type %c)", message_char);
60 char *buf =
new char[size], *p = buf;
61 ssize_t actual_read, remaining_size=size;
66 provsql_error(
"Cannot read from pipe (message type %c)", message_char);
68 remaining_size-=actual_read;
74 boost::iostreams::stream<boost::iostreams::array_source> stream(buf, size);
75 boost::archive::binary_iarchive ia(stream);
88 std::unordered_map<gate_t, gate_t> &gc_to_bc)
96 auto u=
static_cast<gate_t>(i);
115 std::unordered_map<gate_t, gate_t> gc_to_bc;
188 char message_char =
'j';
189 unsigned nb_roots = 2;
202 if(!
READB(size,
unsigned long))
205 char *buf =
new char[size], *p = buf;
206 ssize_t actual_read, remaining_size=size;
213 remaining_size-=actual_read;
219 boost::iostreams::stream<boost::iostreams::array_source> stream(buf, size);
220 boost::archive::binary_iarchive ia(stream);
Boolean-expression (lineage formula) semiring.
@ IN
Input (variable) gate representing a base tuple.
@ MULIN
Multivalued-input gate (one of several options).
static GenericCircuit getJointCircuitFromMMap(pg_uuid_t root_token, pg_uuid_t event_token)
IPC: ship a 'j' (joint) request to the mmap worker and deserialise the returned GenericCircuit.
BooleanCircuit getBooleanCircuit(GenericCircuit &gc, pg_uuid_t token, gate_t &gate, std::unordered_map< gate_t, gate_t > &gc_to_bc)
Build a BooleanCircuit from an already-loaded GenericCircuit.
GenericCircuit getJointCircuit(pg_uuid_t root_token, pg_uuid_t event_token, gate_t &root_gate, gate_t &event_gate)
Build a GenericCircuit containing the closures of two roots, with shared subgraphs unified.
static C getCircuitFromMMap(pg_uuid_t token, char message_char)
Read and deserialise a circuit rooted at token from the mmap worker.
GenericCircuit getGenericCircuit(pg_uuid_t token)
Build a GenericCircuit from the mmap store rooted at token.
static void applyLoadTimeSimplification(GenericCircuit &gc)
Apply the universal load-time simplification passes to gc.
Build in-memory circuits from the mmap-backed persistent store.
gate_t
Strongly-typed gate identifier.
Peephole simplifier for continuous gate_arith sub-circuits.
Support-based bound check for continuous-RV comparators.
Boolean circuit for provenance formula evaluation.
gate_t setGate(BooleanGate type) override
Allocate a new gate with type type and no UUID.
void setInfo(gate_t g, unsigned info)
Store an integer annotation on gate g.
std::vector< gate_t > & getWires(gate_t g)
Return a mutable reference to the child-wire list of gate g.
gateType getGateType(gate_t g) const
Return the type of gate g.
void addWire(gate_t f, gate_t t)
Add a directed wire from gate f (parent) to gate t (child).
uuid getUUID(gate_t g) const
Return the UUID string associated with gate g.
gate_t getGate(const uuid &u)
Return (or create) the gate associated with UUID u.
std::vector< gate_t >::size_type getNbGates() const
Return the total number of gates in the circuit.
In-memory provenance circuit with semiring-generic evaluation.
S::value_type evaluate(gate_t g, std::unordered_map< gate_t, typename S::value_type > &provenance_mapping, S semiring) const
Evaluate the sub-circuit rooted at gate g over semiring semiring.
void foldSemiringIdentities()
Drop semiring identity wires and collapse single-wire gate_times / gate_plus to their lone non-identi...
double getProb(gate_t g) const
Return the probability for gate g.
const std::set< gate_t > & getInputs() const
Return the set of input (leaf) gates.
std::pair< unsigned, unsigned > getInfos(gate_t g) const
Return the integer annotation pair for gate g.
void foldBooleanIdentities()
Apply Boolean-only simplification rules to gate_plus and gate_times.
Provenance-as-Boolean-circuit semiring.
Provenance evaluation helper for HAVING-clause circuits.
void provsql_having(GenericCircuit &c, gate_t g, MapT &mapping, SemiringT S=SemiringT{})
Rewrite HAVING comparison gates in the circuit by enumerating possible worlds.
unsigned runConstantFold(GenericCircuit &gc)
Constant-fold pass over every gate_arith in gc.
unsigned runRangeCheck(GenericCircuit &gc)
Run the support-based pruning pass over gc.
bool provsql_simplify_on_load
Run universal cmp-resolution passes when getGenericCircuit returns; controlled by the provsql....
bool provsql_boolean_provenance
Opt-in safe-query optimisation: when true, rewrites hierarchical conjunctive queries to a read-once f...
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
Background worker and IPC primitives for mmap-backed circuit storage.
#define READB(var, type)
Read one value of type from the main-to-background pipe.
#define STARTWRITEM()
Reset the shared write buffer for a new batched write.
#define ADDWRITEM(pvar, type)
Append one value of type to the shared write buffer.
#define SENDWRITEM()
Flush the shared write buffer to the background-to-main pipe atomically.
void provsql_shmem_unlock(void)
Release the ProvSQL LWLock.
void provsql_shmem_lock_exclusive(void)
Acquire the ProvSQL LWLock in exclusive mode.
provsqlSharedState * provsql_shared_state
Pointer to the ProvSQL shared-memory segment (set in provsql_shmem_startup).
Shared-memory segment and inter-process pipe management.
Core types, constants, and utilities shared across ProvSQL.
string uuid2string(pg_uuid_t uuid)
Format a pg_uuid_t as a std::string.
C++ utility functions for UUID manipulation.