Expand description
SQL/PGQ pattern matching: GRAPH_TABLE (g MATCH … COLUMNS (…)) (#296).
Ursa’s parser rewrites GRAPH_TABLE ( body ) into graph_table('body');
the relation planner hands the body here. parse reads it into a
Pattern; lower resolves each variable to one of the graph’s element
tables and says what to join: a Lowered match, which the planner
builds as a logical plan (scans of the element tables, equality
conditions, the pattern’s conditions and COLUMNS). DataFusion’s
optimizer turns the equalities into hash joins.
Supported:
GRAPH_TABLE ( graph
MATCH path [, path …]
[WHERE condition]
COLUMNS ( expression [AS name], … ) )
path := [var =] [selector] [mode [PATH | PATHS]] node (edge node)*
selector := ANY SHORTEST | ALL SHORTEST | ANY [k] | SHORTEST k | ALL
mode := WALK | TRAIL | SIMPLE | ACYCLIC
node := ( [var] [:label | IS label] [WHERE condition] )
edge := (-[ spec ]-> | <-[ spec ]- | -[ spec ]- | -> | <- | -) [quantifier]
quantifier := * | + | ? | {n} | {m,n} | {m,} | {,n}
spec := [var] [:label | IS label] [WHERE condition]Conditions and COLUMNS are SQL expressions over the variables
(a.name); each variable is a relation of that name. A label names an element table: by its name or one of
its labels. A variable without one gets the only table it can be: from the
edges next to it and their REFERENCES, or because the graph has one table
of that kind; otherwise the pattern is refused, never guessed.
Each variable reads its element table’s properties: every column, or what
its labels’ PROPERTIES clauses give, under their property names. An
undirected edge -[e]- matches both orientations of each edge (a self-loop
once): the match is a UNION ALL with one branch per orientation, so every
join stays an equality join.
A quantified edge, and the edge of a path with a path variable, a selector
or a mode, is not joined: it is a Segment, searched on the graph index
(see super::path_search), and joined to the nodes at its ends. A path
with a variable, a selector or a mode is one edge between two nodes for
now. Label expressions (|, &, !) and parenthesized path patterns are
refused with a message.
§Through the index
A node is bound when a condition on it alone limits its key to values
the query names: a.id = 7, a.id IN (1, 2) or a.id IN (SELECT …).
From a bound node, the fixed-length edges of its path are expanded
through the graph index too, one Segment of exactly one edge each,
outward from it: each segment starts from the keys the one before it
reached (Starts::After), so only the edges at the nodes reached are
read, never the whole edge table. A segment is a relation of edges as the
join’s is, one row per edge row, so the rows are the same. A node whose
query reads only its key, at the end of a segment whose index’s nodes are
that node’s table’s keys, is not joined to its table at all: its key is
the segment’s column (Lowered::aliases). Edges stay joins when no node
is bound, when the query reads an edge’s columns, or when
Usage::indexed does not list the edge table (its index could not be
kept between queries).
Structs§
- Alias
- A node not joined to its table: its key is a segment’s column.
- Lowered
- A pattern resolved against a graph: what to scan and join.
- Path
Pattern - One path of a
MATCH:[p =] [selector] [mode] (a)-[e]->…(b). - Pattern
- A parsed
GRAPH_TABLEbody. - Quantifier
- An edge’s quantifier: how many times it repeats,
{min,max}. - Segment
- An edge searched on the graph index rather than joined: a quantified
edge, or the edge of a path with a path variable, a selector or a mode.
It is a relation of paths, named
var, with the columns ofsuper::path_search: the path’s first and last node, its length, and its nodes and edges. - Source
- What a variable reads: an element table (or the graph’s
nodestable), all its columns orcolumnsas (column, property name). - Spec
- A node or edge:
[var] [:label] [WHERE condition]. - Usage
- What the query reads and binds, from its conditions and
COLUMNS: what decides which edges are expanded through the graph index (see the module docs). The default plans joins, as a pattern was planned before.
Enums§
- Direction
- Element
- One element of a path: nodes and edges alternate, starting with a node.
- Join
- A condition the lowering adds.
- Mode
- Which walks a path may be (SQL/PGQ’s path modes).
- Selector
- Which of a pair of nodes’ paths a path keeps.
- Starts
- Where a segment’s start nodes come from.
Constants§
- FUNCTION
- The table function Ursa’s parser rewrites
GRAPH_TABLE ( … )into.
Functions§
- lower
- Resolve
patternagainstgraph.schema_ofgives a table’s columns (for properties). - parse
- Parse a
GRAPH_TABLEbody:graph MATCH … [WHERE …] COLUMNS (…).
Type Aliases§
- VarColumn
- A column of a variable: (variable, column).