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

Public surface of the query-time TID / BID / OPAQUE classifier. More...

#include "postgres.h"
#include "nodes/parsenodes.h"
#include "nodes/pg_list.h"
#include "MMappedTableInfo.h"
Include dependency graph for classify_query.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ProvSQLClassification
 Result of provsql_classify_query. More...

Functions

void provsql_classify_query (Query *q, ProvSQLClassification *out)
 Classify the result relation of a parsed top-level Query.
void provsql_classify_emit_notice (const ProvSQLClassification *c)
 Render the result of provsql_classify_query as a NOTICE.

Variables

bool provsql_classify_top_level
 GUC: emit a classification NOTICE on every top-level SELECT.

Detailed Description

Public surface of the query-time TID / BID / OPAQUE classifier.

The classifier is invoked by provsql_planner on the top-level Query when the provsql.classify_top_level GUC is on, and emits a NOTICE carrying the certified kind and the set of provenance-tracked base relations the query touches. Independent- TID join inference, BID block-key preservation under projection and GROUP BY, transitive ancestor-set computation through the per-relation registry, view descent, and ANSI INNER / CROSS JOIN handling all live in this same file's helpers and the matching propagation pre-passes in src/safe_query.c.

Definition in file classify_query.h.

Function Documentation

◆ provsql_classify_emit_notice()

void provsql_classify_emit_notice ( const ProvSQLClassification * c)
extern

Render the result of provsql_classify_query as a NOTICE.

Formats :

*   ProvSQL: query result is TID (sources: schema.t1, schema.t2)
*   ProvSQL: query result is BID (sources: schema.t1)
*   ProvSQL: query result is TID (no provenance-tracked sources)
*   ProvSQL: query result is OPAQUE
* 

The OPAQUE form omits the parenthetical because the rtable walk only reaches syntactically visible sources : when the shape gate trips on a sublink, set operation, GROUP BY, ... the list would be partial and falsely suggest completeness.

Definition at line 713 of file classify_query.c.

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

◆ provsql_classify_query()

void provsql_classify_query ( Query * q,
ProvSQLClassification * out )
extern

Classify the result relation of a parsed top-level Query.

Scope :

  • Single-source classification : a flat fromlist of RangeTblRefs, with no kind-altering features (SubLinks, modifying CTEs, cteList, DISTINCT, GROUP BY, HAVING, aggregates, window functions, set-returning functions in the target list). Zero or one provenance-tracked base relation reached either directly (RTE_RELATION) or through any depth of RTE_SUBQUERY entries (view bodies after PG rewriting, inline FROM subqueries). The PG 18 virtual RTE_GROUP is skipped transparently. When a single tracked base relation is reached, the source's recorded kind is preserved verbatim. ORDER BY, LIMIT, OFFSET do not change row lineages and are therefore transparent.
  • UNION ALL specialisation : a fully-UNION-ALL tree of subquery legs each of which classifies as TID over a base- relid set that is disjoint from every other leg's promotes to TID with the cumulative source list.
  • Zero tracked sources : trivially deterministic, reported as TID with an empty source list.
  • Everything else is reported as OPAQUE.
  • Multi-source TID promotion : n_meta >= 2 promotes to TID when every classifier-reported source is TID and the registered ancestor sets are pairwise disjoint.
  • BID projection preservation : the single-source BID branch walks the outer target list (transitively through any depth of RTE_SUBQUERY TLE projection) and downgrades to OPAQUE when any block-key column is dropped.
  • BID GROUP BY block-key promotion : a pre-dispatch special case promotes SELECT k FROM bid_t GROUP BY k to TID (each output row is one block).
  • ANSI INNER / CROSS JOIN : the shape gate accepts JoinExpr fromlist entries when jointype == JOIN_INNER, recursing into both arms.
Parameters
qParsed Query to classify. Read-only; not mutated.
outOutput struct. source_relids is built in the current memory context.

Definition at line 638 of file classify_query.c.

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

Variable Documentation

◆ provsql_classify_top_level

bool provsql_classify_top_level
extern

GUC: emit a classification NOTICE on every top-level SELECT.

GUC: emit a classification NOTICE on every top-level SELECT.

Definition at line 56 of file classify_query.c.