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

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 <exception>
#include <string>
#include <unordered_set>
#include <vector>
#include "CircuitFromMMap.h"
#include "GenericCircuit.h"
#include "provsql_utils_cpp.h"
Include dependency graph for cmp_supersede.cpp:

Go to the source code of this file.

Functions

Datum cmp_surviving_factors (PG_FUNCTION_ARGS)
 cmp_surviving_factors(tokens uuid[], cmp uuid) -> uuid[]

Detailed Description

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

  • the bare δ (the plain gamma then sigma shape),
  • a ⊗ mixing the δ with other factors (a view or CTE holding gamma joined with another relation), whose other factors must survive,
  • or something else entirely – an earlier comparison's 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.

Definition in file cmp_supersede.cpp.

Function Documentation

◆ cmp_surviving_factors()

Datum cmp_surviving_factors ( PG_FUNCTION_ARGS )

cmp_surviving_factors(tokens uuid[], cmp uuid) -> uuid[]

Given the row-annotation factors at the level owning a lifted comparison and that comparison's gate, returns the factors the comparison does not subsume, for the caller to multiply with it. NULL entries are dropped.

Definition at line 149 of file cmp_supersede.cpp.

Here is the call graph for this function: