![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
SQL function provsql.cmp_surviving_factors() – the factors of a row annotation that an aggregate comparison does not subsume.
More...
#include "postgres.h"#include "fmgr.h"#include "catalog/pg_type.h"#include "utils/array.h"#include "utils/uuid.h"#include "provsql_utils.h"#include "provsql_mmap.h"#include <cstdlib>#include <cstring>#include <exception>#include <functional>#include <string>#include <unordered_map>#include <unordered_set>#include <vector>
Go to the source code of this file.
Functions | |
| Datum | cmp_surviving_factors (PG_FUNCTION_ARGS) |
cmp_surviving_factors(tokens uuid[], cmp uuid) -> uuid[] | |
SQL function provsql.cmp_surviving_factors() – the factors of a row annotation that an aggregate comparison does not subsume.
When a comparison on an aggregate is lifted into the provenance circuit, its gate_cmp already entails that the compared group exists: the enumeration behind it ranges over the non-empty worlds of the very same per-row tokens. So the comparison supersedes the group's gate_delta rather than multiplying with it – conjoining both would count group existence twice in a non-idempotent semiring.
What it supersedes is precisely that δ, though, and not whatever else the row annotation happens to carry. A row token reaching the level that owns the comparison may be
gamma then sigma shape),gate_cmp on the same group (sigma after sigma), an input – which the new comparison does not subsume at all and which must be kept and multiplied. Dropping the whole annotation is right only in the first case; this walk distinguishes them structurally.A δ is subsumed when its ⊕ child's operands are exactly the provenance children of the compared aggregate's gate_semimod wires – that is, when it collapses the multiplicity of the very group the comparison ranges over.
The function is read-only: it returns the surviving factors flattened, and the caller rebuilds the product with provenance_times, so no gate is minted here.
The walk needs the type and the children of a few gates, all of which this backend created moments earlier in the same query (the comparison, the aggregates under it, their semimod wires, the row tokens and their δ and ⊕). They are read one by one through provsql_fetch_gate, which answers from the per-session cache and asks the worker only on a miss; loading the subcircuit under all these roots at once, as was done before, cost a synchronous round trip and a serialisation per group.
Definition in file cmp_supersede.cpp.
| Datum cmp_surviving_factors | ( | PG_FUNCTION_ARGS | ) |
cmp_surviving_factors(tokens uuid[], cmp uuid) -> uuid[]
Given the row-annotation factors at the level owning the comparison and the lifted comparison gate, returns the factors the comparison does not subsume, flattened; NULL on a NULL argument.
Definition at line 199 of file cmp_supersede.cpp.