Creating an index on ARRAY<string(max)> in Google Cloud Spanner

时间:2017-03-22 18:40:26

标签: google-cloud-platform google-cloud-spanner

I'm trying to create an index on the AlbumTokens column in my Google Cloud Spanner test database and I get a mysterious error referencing an index option that is not currently documented:

CREATE INDEX AlbumTokens 
ON Albums (
    AlbumTokens
)

>>> Index AlbumTokens references ARRAY AlbumTokens, but is not declared as DISTINCT_ARRAY_ELEMENT index.

Is it possible to do this? If so, how?

I'm using the sample schema with an ARRAY<STRING> column added on:

CREATE TABLE Singers (
    SingerId INT64 NOT NULL,
    FirstName STRING(1024),
    LastName STRING(1024),
    SingerInfo BYTES(MAX),
) PRIMARY KEY (SingerId)

CREATE TABLE Albums (
    SingerId INT64 NOT NULL,
    AlbumId INT64 NOT NULL,
    AlbumTitle STRING(MAX),
    AlbumTokens ARRAY<STRING(MAX)>,
) PRIMARY KEY (SingerId, AlbumId),
INTERLEAVE IN PARENT Singers ON DELETE CASCADE

1 个答案:

答案 0 :(得分:1)

您无法使用Array作为关键字创建索引:

  

不允许的类型

     

这些不能是ARRAY类型:

     

表格的关键列。

     

索引的关键列。

您可以通过STORING关键字在索引中包含数组,以返回数组而无需加入主表,但您无法在i上扫描