Database / Google Spanner Database Interview questions
Define interleaved tables in Google Spanner?
An interleaved table is a child table whose rows are physically stored next to the parent row they belong to, based on a shared primary key prefix. You declare the relationship with INTERLEAVE IN PARENT, and the child's primary key must start with the parent's primary key columns.
CREATE TABLE Orders ( CustomerId INT64 NOT NULL, OrderId INT64 NOT NULL, OrderDate DATE ) PRIMARY KEY (CustomerId, OrderId), INTERLEAVE IN PARENT Customers ON DELETE CASCADE;
Because parent and child rows sit in the same storage split, fetching a customer and their orders together avoids extra network hops, which is far cheaper than a traditional join across separately sharded tables. It also lets Spanner co-locate related data as it splits and moves ranges for load balancing.
More Related questions...