一个表如何与两个表交错?
How can one interleave with two tables?
假设我有架构
CREATE TABLE Account (
AccountId BYTES(MAX),
Foo STRING(1024)
) PRIMARY KEY (AccountId);"
CREATE TABLE Customer (
CustomerId BYTES(MAX),
Bar STRING(1024)
) PRIMARY KEY (CustomerId);"
然后我创建一个新的 table:
CREATE TABLE Order (
AccountId BYTES(MAX),
CustomerId BYTES(MAX),
Baz STRING(1024)
) PRIMARY KEY (AccountId, CustomerId);"
我想 INTERLEAVE
与 Account
和 Customer
。如何做到这一点?我熟悉在构建层次结构时如何使用一个 table INTERLEAVE
,但不确定如何使用两个 table 实现此目的。
您不能将一个 table 交错在另外两个 table 中,但您可以创建交错 table 的层次结构。在您的示例中,这意味着 Account
table 中的 Customer
table 和 [=11= 中的 Order
table 交错] table 像这样:
CREATE TABLE Account (
AccountId BYTES(MAX),
Foo STRING(1024)
) PRIMARY KEY (AccountId);
CREATE TABLE Customer (
AccountId BYTES(MAX),
CustomerId BYTES(MAX),
Bar STRING(1024)
) PRIMARY KEY (AccountId, CustomerId),
INTERLEAVE IN PARENT Account;
CREATE TABLE Order (
AccountId BYTES(MAX),
CustomerId BYTES(MAX),
OrderId BYTES(MAX),
Baz STRING(1024)
) PRIMARY KEY (AccountId, CustomerId, OrderId),
INTERLEAVE IN PARENT Customer;
您不能按照您要求的方式在另外两个 table 中交错一个 table 的原因是,交错 table 实际上意味着 Cloud Spanner 将存储交错子行 table 与父行 table 物理在一起。如果要将 table 与两个不同的、不相关的父 table 交错,则无法确定子行的存储位置。
假设我有架构
CREATE TABLE Account (
AccountId BYTES(MAX),
Foo STRING(1024)
) PRIMARY KEY (AccountId);"
CREATE TABLE Customer (
CustomerId BYTES(MAX),
Bar STRING(1024)
) PRIMARY KEY (CustomerId);"
然后我创建一个新的 table:
CREATE TABLE Order (
AccountId BYTES(MAX),
CustomerId BYTES(MAX),
Baz STRING(1024)
) PRIMARY KEY (AccountId, CustomerId);"
我想 INTERLEAVE
与 Account
和 Customer
。如何做到这一点?我熟悉在构建层次结构时如何使用一个 table INTERLEAVE
,但不确定如何使用两个 table 实现此目的。
您不能将一个 table 交错在另外两个 table 中,但您可以创建交错 table 的层次结构。在您的示例中,这意味着 Account
table 中的 Customer
table 和 [=11= 中的 Order
table 交错] table 像这样:
CREATE TABLE Account (
AccountId BYTES(MAX),
Foo STRING(1024)
) PRIMARY KEY (AccountId);
CREATE TABLE Customer (
AccountId BYTES(MAX),
CustomerId BYTES(MAX),
Bar STRING(1024)
) PRIMARY KEY (AccountId, CustomerId),
INTERLEAVE IN PARENT Account;
CREATE TABLE Order (
AccountId BYTES(MAX),
CustomerId BYTES(MAX),
OrderId BYTES(MAX),
Baz STRING(1024)
) PRIMARY KEY (AccountId, CustomerId, OrderId),
INTERLEAVE IN PARENT Customer;
您不能按照您要求的方式在另外两个 table 中交错一个 table 的原因是,交错 table 实际上意味着 Cloud Spanner 将存储交错子行 table 与父行 table 物理在一起。如果要将 table 与两个不同的、不相关的父 table 交错,则无法确定子行的存储位置。