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

Predicate-tree classification helpers shared by the query rewriters (the safe-query rewrite and the joint-width UCQ recogniser). More...

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

Go to the source code of this file.

Classes

struct  qc_vars_ctx
 Walker context for qc_collect_vars_walker. More...
struct  qc_varnos_ctx
 Walker context for qc_collect_varnos_walker. More...

Functions

bool qc_collect_vars_walker (Node *node, qc_vars_ctx *ctx)
 Tree walker that collects every distinct base-level Var node (varlevelsup == 0), deduplicated by (varno, varattno).
int qc_var_index (List *vars, Index varno, AttrNumber varattno)
 Position of a Var inside vars (matched on (varno, varattno)); -1 if absent.
bool qc_is_var_eq (Expr *qual, Var **l, Var **r)
 Recognise a conjunct equating two base Vars (the canonical equality for the operand types, through RelabelType casts).
bool qc_is_var_const_eq (Expr *qual, Var **var, Const **konst)
 Recognise a conjunct of shape Var=Const (either order, through RelabelType casts; non-NULL literal, canonical equality).
void qc_collect_equalities (Node *quals, List **out)
 Walk quals as an AND tree, appending each Var=Var equijoin's two Vars (left, right) to *out.
bool qc_collect_varnos_walker (Node *node, qc_varnos_ctx *ctx)
 Collect the distinct base-level varno values referenced by a sub-tree (used to tell a single-relation selection from a cross-relation predicate).
void qc_flatten_and (Node *n, List **out)
 Flatten the top-level AND tree of a qual into a flat list of leaf conjuncts (a bare List is an implicit AND).
void qc_split_quals (Node *quals, int natoms, List **per_atom_out, Node **out_residual)
 Partition top-level conjuncts into atom-local selections and the cross-atom residual.

Detailed Description

Predicate-tree classification helpers shared by the query rewriters (the safe-query rewrite and the joint-width UCQ recogniser).

These are pure, side-effect-free analyses of a WHERE / ON qual tree of base-relation Var nodes: flatten an AND tree, recognise Var=Var equijoins and Var=Const selections, collect the base Vars / varnos a sub-tree touches, and split a conjunction into the single-relation selections (pushable into a relation scan) and the cross-relation residual (joins). They encode the same notion of "structure vs. pre-filter" both rewriters rely on: an equijoin identifies variables (structure); a single-relation predicate is a selection (a pre-filter); everything else is residual.

They carry no safety-specific logic, so both the safe-query and joint-width rewriters share them.

Definition in file qual_classify.h.

Function Documentation

◆ qc_collect_equalities()

void qc_collect_equalities ( Node * quals,
List ** out )
extern

Walk quals as an AND tree, appending each Var=Var equijoin's two Vars (left, right) to *out.

OR / NOT are not traversed (they are not equijoins).

Definition at line 126 of file qual_classify.c.

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

◆ qc_collect_varnos_walker()

bool qc_collect_varnos_walker ( Node * node,
qc_varnos_ctx * ctx )
extern

Collect the distinct base-level varno values referenced by a sub-tree (used to tell a single-relation selection from a cross-relation predicate).

Definition at line 154 of file qual_classify.c.

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

◆ qc_collect_vars_walker()

bool qc_collect_vars_walker ( Node * node,
qc_vars_ctx * ctx )
extern

Tree walker that collects every distinct base-level Var node (varlevelsup == 0), deduplicated by (varno, varattno).

Definition at line 21 of file qual_classify.c.

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

◆ qc_flatten_and()

void qc_flatten_and ( Node * n,
List ** out )
extern

Flatten the top-level AND tree of a qual into a flat list of leaf conjuncts (a bare List is an implicit AND).

The result shares pointers with the input; copyObject before mutating.

Definition at line 167 of file qual_classify.c.

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

◆ qc_is_var_const_eq()

bool qc_is_var_const_eq ( Expr * qual,
Var ** var,
Const ** konst )
extern

Recognise a conjunct of shape Var=Const (either order, through RelabelType casts; non-NULL literal, canonical equality).

Fills *var, *konst on match.

Definition at line 86 of file qual_classify.c.

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

◆ qc_is_var_eq()

bool qc_is_var_eq ( Expr * qual,
Var ** l,
Var ** r )
extern

Recognise a conjunct equating two base Vars (the canonical equality for the operand types, through RelabelType casts).

Fills *l, *r on match.

Definition at line 54 of file qual_classify.c.

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

◆ qc_split_quals()

void qc_split_quals ( Node * quals,
int natoms,
List ** per_atom_out,
Node ** out_residual )
extern

Partition top-level conjuncts into atom-local selections and the cross-atom residual.

per_atom_out is a caller-allocated, zero-initialised array of length natoms; a conjunct whose base Vars all reference a single varno (1..natoms) and that is non-volatile lands in that atom's list, the rest in *out_residual (rebuilt as NULL / the lone conjunct / a fresh AND). Volatile predicates stay in the residual (the inner DISTINCT must not change their evaluation count).

Definition at line 186 of file qual_classify.c.

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

◆ qc_var_index()

int qc_var_index ( List * vars,
Index varno,
AttrNumber varattno )
extern

Position of a Var inside vars (matched on (varno, varattno)); -1 if absent.

Definition at line 41 of file qual_classify.c.

Here is the caller graph for this function: