Case Studies: Overview

The tutorial introduces the core workflow – add provenance to a table, run a query, evaluate the result in a semiring – on a single small example. The case studies are further worked examples, each built around a realistic dataset and centred on a different aspect of ProvSQL.

Each case study states its scenario and tasks up front and can be read on its own. Most ship a single setup.sql to download and load; case study 3 explains how to fetch the Île-de-France GTFS dataset (too large to bundle), and case study 4 loads the data files under doc/casestudy4/data/ in the source tree. The coverage matrix at the end of this page shows which study demonstrates a given feature.

Tip

No install required. Every case study here except case study 3 (whose GTFS dataset is too large to bundle) runs in the ProvSQL Playground, the browser build of ProvSQL Studio, on a ready-made database. All but case studies 3 and 4 also ship as runnable notebooks; each chapter links to what it has. The Playground bundles no external tools, so steps that explicitly call an external knowledge compiler (d4, c2d…) or graph-easy do not run there, but the built-in methods and everything else do. See the Playground note.

What each case study covers

Case study 1 – Intelligence Agency

The broadest tour of provenance evaluation: a security-classification scenario over seven agents drives a custom min-clearance semiring, where-provenance, circuit export, and the full probability-method line-up side by side (possible-worlds, Monte-Carlo, tree-decomposition, and knowledge compilation through d4 / c2d / dsharp / minic2d), ending on revising a probability already used with replace_input. Start here for a panoramic view.

Case study 2 – Open Science Database

Evidence synthesis over a fictional biomedical corpus – single-source vs. replicated claims, contradictions, strength-of-evidence ranking. The home of Shapley and Banzhaf values, attributing a result to the studies behind it.

Case study 3 – Île-de-France Public Transit

Provenance at real-world scale. On the STIF GTFS dataset (hundreds of routes, tens of thousands of stops) a result token is true iff every record along the trip carries the accessibility flag – which stops are reachable from Luxembourg by a fully wheelchair-accessible journey? Then recursion over the whole network: one WITH RECURSIVE query answers travel times, accessible journeys and the probability of getting there through disruptions, each semiring solving its equations by its own method.

Case study 4 – Government Ministers Over Time

The temporal extension and data-modification tracking. Over French and Singaporean ministers every fact carries a validity interval; the study time-travels, takes history and timeslices, and rolls back an INSERT / DELETE round-trip with undo.

Case study 5 – Wildlife Photo Archive

Uncertainty from a machine-learning detector: block-correlated alternatives via repair_key and the mulinput gate, with candidate species per bounding box. It contrasts probabilistic ranking against naive confidence thresholding, computes expected species counts with expected, and closes on NULL semantics: EXCEPT, NOT IN, NOT EXISTS and an outer join giving three genuinely different – and possible-worlds-correct – answers over unidentified detections, and INTERSECT against = ANY for the positive question.

Case study 6 – City Air-Quality Sensor Network

Continuous distributions end to end: random_variable columns (Normal / Uniform / Exponential / Erlang noise models, joined by the Gamma / Weibull / Pareto constructors and Bernoulli mixtures), arithmetic, comparison, and CASE on them, analytic moments with Monte-Carlo fallback, conditional inference, order statistics and quantiles, fleet statistics under sensor dropout (percentile_cont, corr), a CASE-over-aggregates triage headline, mutual information, and NULL (offline-sensor) readings. The first study driven primarily through ProvSQL Studio.

Case study 7 – Peer-Review Assignment and Knowledge Compilation

How a query’s shape, the schema’s keys, and the structure of the data decide which probability method is cheap and which needs a compiler. A peer-reviewing scenario organised by where tractability comes from: the query is safe (the four Dalvi-Suciu routes, including the Möbius-cancellation witness q_9), the query is \#P-hard (the knowledge-compilation pipeline), or the data is well-structured (the joint-width compiler and recursive network reliability).

Case study 8 – ProvSQL as a Probability Calculator

ProvSQL as an exact, correlation-aware probability calculator driven in SQL. It answers textbook problems with one-line queries (the conditioning ones through the | (“given”) operator): the base-rate fallacy, correlation breaking the independence formula, the method portfolio and its cost chooser, a continuous posterior by truncation, the conditional expectation of an aggregate, denial constraints as evidence, a skewed waiting time (log-normal, quantiles, transforms), discrete counts with a Beta rate posterior, the information gain of a Bayesian update (entropy, KL), a Gaussian-mixture cohort, empirically-loaded posteriors and forecast tables, and full Bayesian inference: a latent (random_variable) distribution parameter updated from data by likelihood weighting (observe / and_agg / evidence).

Case study 9 – A Sales Forecast Dashboard

Aggregates over uncertain data, the queries of an ordinary dashboard over deals that close with some probability: expected revenue with and without the regions that close nothing, ROLLUP subtotals, shares of a total, the leading region and each region’s rank, comparisons with a target, a NULLIF percentage, aggregates of aggregates, grouping by an aggregate’s value, DISTINCT ON, and plain for a value meant without provenance.

Feature coverage matrix

The tables below cross-reference every user-facing feature documented under the User Guide against the tutorial and the nine case studies.

Columns:

Cells: ✓ the feature is exercised; (✓) it is mentioned in passing but not actually executed; empty means it is not covered. The administration features (the circuit store and its maintenance, replication, the gate cache) are shown in their reference pages, not in a case study.

Setup and basics

Feature

T

1

2

3

4

5

6

7

8

9

add_provenance

✓

✓

✓

✓

✓

✓

✓

✓

✓

✓

remove_provenance

✓

✓

✓

provenance() (SELECT list)

✓

✓

✓

✓

✓

✓

✓

✓

✓

✓

create_provenance_mapping (table)

✓

✓

✓

✓

✓

✓

create_provenance_mapping (maintained)

✓

Hand-built mapping table

✓

✓

setup_search_path

(✓)

(✓)

(✓)

(✓)

(✓)

(✓)

provsql.active GUC

✓

gate_one / gate_zero (semiring constants)

Supported SQL constructs

Feature

T

1

2

3

4

5

6

7

8

9

SELECT … FROM … WHERE / inner join

✓

✓

✓

✓

✓

✓

✓

✓

✓

NATURAL JOIN

Self-join

✓

✓

✓

✓

✓

✓

Subqueries in FROM / nested

✓

✓

✓

✓

GROUP BY

✓

✓

✓

✓

✓

✓

✓

✓

✓

SELECT DISTINCT

✓

✓

✓

✓

✓

EXCEPT (monus)

✓

✓

✓

✓

UNION / UNION ALL

✓

✓

HAVING

✓

✓

✓

VALUES

✓

✓

CTE (WITH)

✓

✓

✓

WITH RECURSIVE

✓

✓

LATERAL

✓

✓

FILTER clause on aggregates

✓

✓

CREATE TABLE … AS SELECT

✓

✓

✓

✓

✓

✓

CREATE MATERIALIZED VIEW

Provenance-bearing view

✓

✓

✓

INSERT … SELECT (provenance propagation)

✓

Outer join (LEFT / RIGHT / FULL JOIN)

✓

✓

EXISTS / NOT EXISTS subquery

✓

IN / NOT IN subquery

✓

Quantified comparison (= ANY / ALL)

✓

Scalar subquery

✓

✓

✓

ARRAY(SELECT …)

EXISTS (…) as a Boolean value in the SELECT list

✓

INTERSECT

✓

DISTINCT ON

✓

LIMIT / ORDER BY … LIMIT

✓

✓

✓

FETCH … WITH TIES / OFFSET

✓

plain() (a value read without provenance)

✓

✓

provsql.implicit_freeze GUC (warn or refuse on an untracked part)

✓

Window functions (row_number / rank / dense_rank / cume_dist / percent_rank / ntile)

✓

Aggregates as window functions (sum(…) OVER)

✓

GROUPING SETS / ROLLUP / CUBE

✓

NULL values and zero-annotated rows

Feature

T

1

2

3

4

5

6

7

8

9

present (drop zero-annotated rows)

✓

nonzero (semiring-parameterised zero test)

(✓)

NULL-discriminating idioms (EXCEPT vs NOT IN vs NOT EXISTS)

✓

NULL random_variable values (unknown comparisons, aggregate skipping)

✓

Aggregation

Feature

T

1

2

3

4

5

6

7

8

9

count / sum / min / max / avg

✓

✓

✓

✓

✓

✓

sum / avg / product over random_variable

✓

Statistic aggregates over random_variable (covar_pop / corr / stddev_pop / percentile_cont…)

✓

string_agg / array_agg

✓

count(DISTINCT …)

✓

Arithmetic / cast on aggregate result

✓

✓

Provenance-preserving agg_token arithmetic (+ - * /, agg-vs-agg, in HAVING)

✓

CASE over aggregates (guarded selection, agg_case)

✓

agg_token_value_text / provsql.aggtoken_text_as_uuid GUC

choose aggregate

✓

explode_table (agg_token column to rows)

stddev / variance over tracked rows

✓

bool_and / bool_or

✓

Functions of an aggregate result (round / abs / power…)

✓

COALESCE / NULLIF / GREATEST over aggregates

✓

Aggregate of an aggregate result (avg of a count…)

✓

GROUP BY / DISTINCT on an aggregate value

✓

✓

Comparison over an aggregate in the SELECT list

✓

Ranking groups by an aggregate (rank() OVER (ORDER BY count(*)))

✓

provsql.max_worlds GUC (worlds enumerated for a condition on an aggregate)

Circuit inspection

Feature

T

1

2

3

4

5

6

7

8

9

get_gate_type

✓

✓

get_children

✓

identify_token

✓

get_nb_gates

✓

get_infos

✓

get_extra

✓

✓

circuit_subgraph / resolve_input (Studio Circuit mode)

✓

✓

simplified_circuit_subgraph

(✓)

✓

provenance_plus / provenance_times / provenance_not (circuits built by hand)

Knowledge compilation and safe queries

Feature

T

1

2

3

4

5

6

7

8

9

provsql.provenance = 'boolean'

✓

provsql.provenance = 'absorptive' (cyclic recursion)

✓

Bounded-treewidth network reliability (recursive reachability)

✓

provsql.classify_top_level GUC (TID/BID pills)

✓

Safe-query rewriter (hierarchical / read-once)

✓

Joint-width UCQ compiler (bounded joint treewidth)

✓

Möbius-inversion route (safe-by-cancellation UCQ)

✓

Tseytin CNF export (DIMACS)

✓

tseytin_cnf / tseytin_cnf_mapping

✓

ddnnf_stats

✓

compile_to_ddnnf / compile_to_ddnnf_dot

✓

tree_decomposition_dot

✓

tool_available (compiler-picker filter)

✓

HAVING Poisson-binomial pre-pass

✓

Inversion-free certificate (annotate / inversion_free_key / Studio IF badge)

✓

External-tool registry (provsql.tools, register_tool, set_tool_preference, set_tool_enabled, unregister_tool)

(✓)

provsql.fallback_compiler GUC

provsql.tool_search_path GUC

provsql.kcmcp_server GUC (managed KCMCP server)

provsql.joint_max_states / provsql.joint_max_treewidth GUCs

provsql.mobius_max_cnf / provsql.mobius_max_gates GUCs

provsql.max_memory GUC (memory limit of an evaluation)

Semiring evaluation

Feature

T

1

2

3

4

5

6

7

8

9

sr_boolean

✓

sr_boolexpr

✓

✓

sr_formula

✓

✓

✓

✓

✓

✓

sr_counting

✓

✓

✓

sr_why

✓

(✓)

sr_how

(✓)

sr_which

✓

sr_tropical

✓

✓

sr_tropical(…, nonnegative => true) (absorptive min-plus)

✓

✓

sr_regex (regular expressions, non-commutative)

✓

sr_tropical_paths (least cost with its paths)

✓

sr_best_path (least cost with one path)

✓

sr_viterbi

✓

sr_lukasiewicz

✓

sr_minmax / sr_maxmin

✓

sr_clearance / visible_at / clearance_settling

✓

sr_consent / consented_for / consent_conflicts

✓

sr_subset

✓

sr_temporal / sr_interval_num / sr_interval_int

✓

Custom semiring via provenance_evaluate

✓

Probabilities

Feature

T

1

2

3

4

5

6

7

8

9

set_prob

✓

✓

✓

✓

✓

✓

✓

✓

get_prob

✓

✓

probability_evaluate (default fallback)

✓

✓

✓

✓

✓

✓

Conditioning operator | / cond / given

✓

P(A | B) conditional probability

✓

expected(X | C) / variance(X | C) (conditional moments)

✓

'independent' method

(✓)

✓

✓

✓

'possible-worlds' method

✓

✓

✓

'monte-carlo' method

(✓)

✓

✓

✓

✓

✓

'tree-decomposition' method

(✓)

✓

✓

✓

✓

'compilation' (d4 / c2d / dsharp / minic2d)

(✓)

✓

✓

'inversion-free' method

✓

'wmc' counters

✓

'd-tree' method (certified anytime bounds)

'sieve' method (inclusion-exclusion)

'karp-luby' method (relative FPRAS)

'stopping-rule' method (additive FPRAS)

Guarantee request ('relative' / 'additive', cost-based chooser)

✓

probability_bounds (cheap lower / upper marginals)

Studio benchmark panel

✓

expected of count / sum / min / max

✓

✓

✓

✓

repair_key (block-independent, mulinput)

✓

✓

✓

provsql.monte_carlo_seed GUC

✓

✓

provsql.rv_mc_samples GUC

✓

✓

provsql.simplify_on_load GUC

✓

probability_is_set

replace_input / replace_block / replace_update (change a probability already used)

✓

provsql.last_eval_method GUC

✓

Continuous random variables

Feature

T

1

2

3

4

5

6

7

8

9

random_variable type / provsql.normal

✓

✓

provsql.uniform / provsql.exponential

✓

provsql.erlang / provsql.categorical

✓

provsql.gamma / provsql.chi_squared

✓

provsql.lognormal (exp/ln bridges, product closure)

✓

provsql.weibull / provsql.pareto

✓

provsql.beta

✓

provsql.logistic / inverse_gamma / inverse_gaussian (wald)

✓

Discrete counts (poisson / binomial / geometric / hypergeometric / negative_binomial)

✓

provsql.mixture (Bernoulli and ad-hoc overloads)

✓

Latent (random_variable) distribution parameters, e.g., normal(mu, 2)

✓

provsql.as_random and implicit numeric→rv casts

✓

Arithmetic on random_variable (+ - * /, unary -)

✓

Order statistics (greatest / least, max / min aggregate)

✓

Transforms ^ / pow / ln / exp / sqrt

✓

CASE over random_variable (rv_case / abs / ReLU / clamp)

✓

Comparison < <= = <> >= > (planner-hook rewrite, incl. mixed-family quadrature)

✓

✓

expected(random_variable) (unconditional)

✓

✓

variance(random_variable)

✓

✓

covariance / correlation / stddev (same-row)

✓

entropy / kl / mutual_information

✓

✓

gmm (Gaussian-mixture constructor)

✓

empirical_samples / empirical_cdf (data-driven loaders)

✓

moment / central_moment / support over rv

✓

✓

quantile (inverse CDF / percentiles / VaR)

✓

✓

Conditional inference via provenance() argument

✓

✓

Likelihood-weighting posterior (observe / and_agg / evidence)

✓

probability((A) | (B)) over two comparison events

✓

rv_sample / rv_histogram

✓

rv_analytical_curves (PDF/CDF overlay)

✓

categorical_from_log_pmf

rv_families (list of the distribution families)

provsql.ess_warn_fraction GUC

✓

Shapley and Banzhaf values

Feature

T

1

2

3

4

5

6

7

8

9

shapley

✓

shapley_all_vars

✓

shapley_observe (attribution under likelihood-weighting evidence)

✓

banzhaf

✓

banzhaf_all_vars

✓

Where-provenance

Feature

T

1

2

3

4

5

6

7

8

9

provsql.provenance = 'where'

✓

✓

where_provenance(col)

✓

✓

Data-modification tracking

Feature

T

1

2

3

4

5

6

7

8

9

provsql.update_provenance GUC

✓

INSERT / UPDATE / DELETE tracked

✓

update_provenance log table

✓

undo

✓

transaction_token

Temporal features

Feature

T

1

2

3

4

5

6

7

8

9

union_tstzintervals

timeslice

✓

timetravel

✓

history

✓

time_validity_view extension

✓

get_valid_time

Export and visualisation

Feature

T

1

2

3

4

5

6

7

8

9

to_provxml

✓

view_circuit (graph-easy)

✓

provsql.verbose_level

(✓)

provsql.trace_rewrite / provsql.verify_rewrite GUCs (debugging the rewriting)

ProvSQL Studio

Feature

T

1

2

3

4

5

6

7

8

9

Circuit mode

(✓)

(✓)

✓

✓

(✓)

Contributions mode

✓

Where mode

(✓)

✓

Temporal mode

✓

Notebook mode

✓