Reputation: 187
Can a Cloud Spanner child table define the same primary key that the parent table uses (with the child is interleaved in the parent)? I know the child's primary key must use the parent's primary key as a prefix, but is the child key required to use at least one additional column? If it's permitted to use the same key, is it bad practice? And if it's not permitted, why not?
For example:
CREATE TABLE Furniture (
FurnitureId STRING(MAX) NOT NULL,
MakerId INT64 NOT NULL,
// additional fields here...
) PRIMARY KEY (FurnitureId, MakerId);
CREATE TABLE FurnitureHistory (
FurnitureId STRING(MAX) NOT NULL,
MakerId INT64 NOT NULL,
// additional fields here...
) PRIMARY KEY (FurnitureId, MakerId),
INTERLEAVE IN PARENT Furniture;
Thanks! Peter
Upvotes: 0
Views: 363
Reputation: 3512
It is permitted, but it seems a little bit strange at first hand. This data model will allow you to insert at most one child row for each parent row. This is quite similar to adding a couple of optional fields to the parent table, but with these optional fields logically separated from the parent table. So I guess this makes sense if:
And/or
Upvotes: 1