Spanner's Data Model

Let's study the data model of Spanner.

Spanner is a distributed data store initially developed internally by J. C. Corbett et al.J. C. Corbett et al., “Spanner: Google’s Globally-Distributed Database,” in Proceedings of OSDI 2012, 2012. and D. F. Bacon et al.D. F. Bacon et al., “Spanner: Google’s Globally-Distributed Database,” in Proceedings of the 2017 ACM International Conference on Management of Data, 2017. at Google and was subsequently released publicly as part of the Google platform.

The data model of Spanner is very close to the data model of classical relational databases.

A database in Spanner can contain one or more tables, which can contain multiple rows. Each row contains a value for each column that is defined, and one or more columns are defined as the primary key of the table, which must be unique for each row. Each table contains a schema that defines the data types of each column.

Data partitioning

Spanner partitions the data of a table using horizontal range partitioning.

The rows of a table are partitioned in multiple segments, called splits.

Split

A split is a range of contiguous rows, where the rows are ordered by the corresponding primary key.

Dynamic load-based splitting

Spanner can perform dynamic load-based splitting, so any split that receives an extreme amount of traffic can be partitioned further and stored in servers with less traffic.

Parent-child relationship

The user can define parent-child relationships between tables so that related rows from the tables are collocated, making join operations much more efficient.

For example, a table “C” can be declared as a child table of “A”, using the INTERLEAVE keyword. We must also ensure that the primary key of the parent table is a prefix of the primary key of the child table.

An example in the following illustration shows a parent table Singers interleaved with a child table, called Albums.

Note: Spanner guarantees that the row of a parent table and the associated rows of the child table will never be assigned to a different split.

Get hands-on with 1400+ tech skills courses.