GQL Essentials Data Model
PDF ↗

Core Model and Patterns

Chapter 06Data Model

This chapter fixes the abstract data model that underlies the semantics of GQL and serves as the common reference point for later chapters. It introduces the basic universes of identifiers, types, and values, defines the property-graph structure used for stored graphs, and explains how paths, lists, and records are treated as first-class values. The presentation is independent of any particular physical representation and is parameterized by the conformance options of the GQL standard (for example, with respect to supported property value types).

6.1 Universes and Notation

Let

𝔸 be a universe of identifiers used in GQL, including names of directories, schemas, catalog objects, labels, properties, and columns, 𝕃 ⊆ 𝔸be a universe of label names, 𝕂 ⊆ 𝔸be a universe of property names, 𝕀  be a universe of globally unique identifiers of graph elements, 𝕋 be a universe of types (static, dynamic, and base types), 𝕍 be a universe comprising material values and the distinguished null value null.

The abstract three-valued truth carrier used throughout is 𝔹3 = {⊤ ⁡,⊥,U}; its connection to GQL Boolean values is defined in Section 8.3. Types and their characteristics (material/nullable/immaterial) as well as the naming of types and base types are defined by the GQL specification. Availability of the null and empty immaterial value types and explicit nullability follows the standard’s conformance options; the empty type contains no value and therefore contributes no additional element to 𝕍. No cardinality assumption is imposed on these ambient universes; by contrast, the node and edge carriers of every concrete graph are finite, as is every binding table used below.

Notational convention. We reserve blackboard-bold symbols such as 𝕍 for universes (e.g., the universe of values), and we use plain symbols such as V only for graph-specific carriers (e.g., the node set of a concrete graph).

A partial function is written f : A ⇀ B. The powerset of X is P(X). Let ℕ denote the set of natural numbers. A multiset (bag) over X is identified with a multiplicity function B : X → ℕ. The set of all such multisets is denoted M(X), and its finite-support subset is denoted Mfin(X). We also write B(X) := Mfin(X) when a finite bag is used as a meta-level type. Pointwise bag sum is written B1 ⊎ B2, and ⊎ ⁡ iBi denotes its indexed iteration. For bags B′,B ∈M(X), B′ is a submultiset of B, written B′ ⊑ bagB, iff B′(x) ≤ B(x) for every x ∈ X. For a bag B, supp(B) := {x∣B(x) > 0} is its support, and 1[P] is 1 when proposition P holds and 0 otherwise.

Finite sequences over X are denoted X∗. Binding-table records use closed (material) record types: a record type is a total function τrec : fields(τrec) → 𝕋, where fields(τrec) ⊆ 𝔸 is its declared field set; a record over τrec is a total assignment r : fields(τrec) → 𝕍 (each declared field has a value; null is a value of an appropriate null-containing type). The set of well-typed records inhabiting τrec is

Recτrec := {r : fields(τrec) → 𝕍∣r(n) has type τrec(n) for every n ∈fields(τrec)}.

To retain the metadata of the GQL binding-table descriptor, we model a binding table as

T = ⟨τrec,B,ord,pcs⟩,B ∈Mfin(Recτrec),

where ord is either unordered or determines an ordering of the record occurrences of B, and pcs is either notSet or a preferred permutation of the field names of τrec. The effective column-name sequence is pcs when a preferred sequence is set and, otherwise, is the field names of τrec in ascending order. We write BT for this domain and bag(T) = ⟨τrec,B⟩ for the bag projection used by order-insensitive algebra. The unit binding table is the unordered table with the unit record ⟨⟩, an empty record type, and no preferred column-name sequence.

6.2 Property-Graph Structure

The term property graph has been used in the literature for several closely related graph models whose formalizations are not identical (Angles 2012; Angles 2018). Depending on the formalization, differences may concern, among other things, element identities, the cardinality and applicability of labels and properties, edge direction, and the treatment of parallel edges (Angles 2018; Francis et al. 2018; Deutsch et al. 2022). In this book, the term is used in a deliberately broad sense, while the concrete model adopted below is closely aligned with the property-graph data structures defined by the GQL standard (International Organization for Standardization 2024). We refer to an instance of this model as a GQL graph.

The tuple below models only a graph’s structural contents; its optional constraining graph type and graph constraint dictionary are descriptor-level information modeled by the graph entry in Section 15.5. A GQL graph is modeled as a 9-tuple

G = ⟨V,E,λV ,ρV ,λE,ρE,src,dst,dir⟩,

where:

V ⊆ 𝕀 is a finite set of globally identifiable nodes, E ⊆ 𝕀 is a finite set of globally identifiable edges (a multigraph is permitted), V ∩ E = ∅ (node and edge identities are disjoint), λV : V →P(𝕃) assigns to a node its set of labels, ρV : V → (𝕂 ⇀ 𝕍)is the node property map (names of node labels and node properties are in separate namespaces, so a label and a property may share the same identifier on a node), λE : E →P(𝕃) assigns to an edge its set of labels, ρE : E → (𝕂 ⇀ 𝕍)is the edge property map (names of edge labels and edge properties are in separate namespaces, so a label and a property may share the same identifier on an edge), src,dst : E → V yield the endpoints of an edge, dir : E →{→, ↔}encodes directedness (directed/undirected).

When dir(e) =↔, src(e) and dst(e) are only a representational ordering of the two endpoints; they do not assign source and destination semantics to an undirected edge. Loops are allowed (edges e ∈ E with src(e) = dst(e)), as are mixed graphs and multigraphs; each property name is unique within its carrier (node/edge), and property values belong to the supported value types. This abstract structure is instantiated by the library schema and graph instance introduced in Section 4.1.

For example, in that instance V = {r,a,c,l,b1,b2} and E contains the six displayed edges. For the OWNS edge eowns, λV (r) = {Reader}, ρV (r)(firstname) = ’Alice’, λE(eowns) = {OWNS}, src(eowns) = r, dst(eowns) = a, and dir(eowns) =→; the edge-property map is illustrated by ρE(einc,1)(late_fee) = 0.0 for the first INCLUDES edge.

Because property maps are partial, let absent∉𝕍 denote absence of a property, rather than a GQL value, and use the totalized lookup notation

ρ^X(x,k) = { ρX(x)(k),k ∈dom(ρX(x)), absent, k∉dom(ρX(x)), X ∈{V,E}.

Evaluation of a property reference is a separate operation: in particular, when its declared type is nullable, a reference to an absent property evaluates to null, as specified by GQL.

Remark on “openness/closedness”. If a graph has an associated graph type, it is closed (it permits only elements conforming to that type); otherwise it is open.

Modeling choices. Although the tuple definition already fixes the types of λV ,λE and ρV ,ρE, we make two conventional but important choices explicit: (i) Labels as sets. By typing λV : V →P(𝕃) and λE : E →P(𝕃) we treat labels as sets (unordered, without duplicates). Thus, label membership is the primitive notion (e.g., ℓ ∈ λV (v)), and adding/removing a label is idempotent at the semantic level. (ii) Properties as partial maps. By typing ρV : V → (𝕂 ⇀ 𝕍) and ρE : E → (𝕂 ⇀ 𝕍) we model properties as partial functions from keys to values. For a particular node or edge, a property key may be absent from its property map, that is, it may lie outside the domain of the corresponding partial function. This is semantically distinct from the property being present with value null, when null is supported.

6.3 Values and Types

Base universes. We use the single universes 𝔸, 𝕃, 𝕂, 𝕋, and 𝕍 fixed in Section 6.1; no second value or type universe is introduced here. Let ⊑⊆ 𝕋 × 𝕋 be a reflexive, transitive subtyping relation, where τ1 ⊑ τ2 is read as “τ1 is a subtype of τ2”, meaning that every value of type τ1 is also admissible as a value of type τ2.

Type constructors.

Scalars: Bool,Int,Real,String,DateTime,… ⁡ ∈ 𝕋. Composite: LIST⟨τ⟩,RECORD⟨ni:τi⟩,PATH ∈ 𝕋. We write Opt(τ) only as meta-level shorthand for a value type that contains the null value; it is not a GQL type constructor. Graph element references: NodeRef,EdgeRef ∈ 𝕋(reference value types whose referents are nodes and edges, respectively).
Conceptually, nullability is represented via the option notation: a site (that is, a typed read/write location such as a property slot or a variable binding; see

Chapter 17

for a precise definition) of type Opt(τ) admits the null value null.

Typing contexts. A type environment Ξ is a finite map from names to types (for properties, parameters, and binding variables). We write the standard judgment Ξ ⊢ e : τ for expressions. Subsumption: if Ξ ⊢ e : τ and τ ⊑ τ′, then Ξ ⊢ e : τ′.

Expression-evaluation interface. Let Err be an abstract carrier of error or exception-condition tokens. For an expression E and a record r, we reserve ⟦E⟧(r) ∈ 𝕍 ∪Err for evaluation in the row environment induced by r, with the store and global environment fixed by the surrounding execution context. For a Boolean expression φ, ⟦φ⟧tv(r) analogously denotes a member of 𝔹3 or an error. The complete evaluation judgment is given in Chapter 8.

6.4 Basics of Paths as Data

A path in a graph G is a finite sequence of graph elements of odd length that starts and ends at a node, i.e., a node–edge–… ⁡–edge–node sequence ⟨v0,e1,v1,… ⁡,en,vn⟩ of length 2n + 1; the orientation of each edge in the path is determined relative to the order of nodes in the sequence (→ to the left/right, or undirected). We distinguish the following classes: trail (no repeated edges), simple (no repeated nodes, except possibly first = last), and acyclic (no repeated nodes). Formally, w = ⟨v0,e1,v1,… ⁡,en,vn⟩ is simple iff vi≠vj for all 0 ≤ i < j ≤ n except possibly the pair (i,j) = (0,n), allowing v0 = vn. We write Path(G) for the set of all such paths in G. The full treatment of path values, concatenation, path modes, and result projection is given in Chapter 10.

Material path values and length. We write PathVal for the carrier of material path values. In accordance with the GQL value model, a path value encapsulates a path element list of graph-element reference values; whenever none of those references is invalidated, their referents identify a path, independently of the current working graph. Concretely, a material path value is written as

p = PATH [⟨n0,e1,n1,… ⁡,ek,nk⟩ ],

where k ≥ 0, each ni is a node reference value, each ei is an edge reference value, and the list alternates starting and ending with a node reference (hence has odd length 2k + 1). The path length is the number of edge references:

PATH_LENGTH(p) = k.

In particular, the length-zero path PATH[⟨n0⟩] is well-formed and satisfies

PATH_LENGTH(PATH[⟨n0⟩]) = 0.

Null-propagation. If p = null (i.e., p is the null value admitted by a nullable path value type), then PATH_LENGTH(p) = null. Malformed representations (that do not alternate or do not start/end in a node reference) are outside this well-formed path domain; the standard path-value constructions do not produce them. A full formalization of path values, path modes, finiteness and selection, and path accessors is given in Chapter 10.

6.5 Lists and Structural Access

List, record, and path types are constructed value types. They provide the abstract carriers for nested and structured values that occur as property values, as components of binding tables, and as results of expressions (including path-returning queries). By fixing their behavior here, we obtain a uniform basis for the typing and evaluation rules for structural accessors and functions in later chapters.

  • Lists. A list value is a finite sequence [v1,… ⁡,vn]. Conceptually we describe indexing in ordinal (1-based) terms: [v1,… ⁡,vn][i] = vi if 1 ≤ i ≤ n; the precise mapping from index expressions to positions (ordinal vs. offset indexing, from-end handling, and out-of-range behavior) follows the session’s list-behavior policy. The declared type of list concatenation is determined by GQL’s general combination of value types; evaluation then follows the standard null and maximum-cardinality rules.
  • Records. A record value is a finite mapping from field names to values, written r.n for the value in field n. For records with a closed record type τrec, a record value r supports field access r.n whenever n ∈dom(τrec). If the source record has no field named n, the reference returns null when its declared type is nullable; otherwise it raises data exception 22G03. Records model structured values such as rows of binding tables or compound results of expressions (e.g., a RETURN item with multiple named components), so that field access in the language can be defined once in terms of this generic record notion.
  • Paths. For the path values defined above, we use nodes(p), edges(p), and length(p) as meta-level shorthands derived from the standard accessors ELEMENTS(p) and PATH_LENGTH(p); both standard accessors return null when their path input is null. By treating paths as first-class values with these primitive operations, we can later give uniform typing and evaluation rules for path-returning patterns and path functions, independently of how paths are physically represented in an implementation.
GQL Essentials · Dominik Tomaszuk

Search chapters, definitions and examples.