Reputation: 2424
Lets say I have three tables, Foo
, Bar
and Baz
CREATE TABLE Foo (
FooId BYTES(MAX)
) PRIMARY KEY (FooId);
CREATE TABLE Bar (
FooId BYTES(MAX),
BarId BYTES(MAX)
) PRIMARY KEY (FooId, BarId),
INTERLEAVE IN PARENT Foo on DELETE CASCADE;
CREATE TABLE Baz (
FooId BYTES(MAX),
BazId BYTES(MAX)
) PRIMARY KEY (FooId, BazId),
INTERLEAVE IN PARENT Foo on DELETE CASCADE;
This diagram demonstrates the INTERLEAVE
hierarchy:
+-----+ +-----+
| | | |
| Foo <---+ Bar |
| | | |
+--^--+ +-----+
|
+--+--+
| |
| Baz |
| |
+-----+
Cloud Spanner's documentation Describes INTERLEAVE
as
You can define hierarchies of parent-child relationships between tables up to seven layers deep, which means you can co-locate rows of seven logically independent tables.
Since we used INTERLEAVE
between Bar
and Foo
, I believe we're guaranteed that they are co-located, with the same keys. Just like how we INTERLEAVE
Baz
and Bar
, they should be co-located as well, with the same keys.
If that's true, then are we guaranteed that Bar
and Baz
are co-located, with the same keys, as well?
Upvotes: 3
Views: 80
Reputation: 371
In the scenario described, Bar and Baz are collocated (or in the same split) given a FooId key. Within a split, the rows from each table are grouped together.
Upvotes: 2