This topic describes the terms, limits, and precautions for global secondary indexes.

Terms

Term Description
index You can create read-only indexes for certain columns in base tables.
predefined column Tablestore uses a schema-free model. You can write an unlimited number of columns to a row and do not need to specify a fixed number of predefined columns in a schema. When you create a table, you can also predefine certain columns and specify their data types.
single-column index You can create an index for a single column.
compound index You can create an index for multiple columns in a table. A compound index can have indexed columns 1 and 2.
indexed attribute column You can map predefined columns in a base table to non-primary key columns in an index.
autocomplete Tablestore automatically adds all primary key columns of the base table to the index.

Limits

  • You can create a maximum of 64 tables in an instance including the base table and indexes.
  • The index names must be unique within an instance.
  • You can create a maximum of five indexes in a base table. If you have reached this limit, you cannot create any more indexes.
  • You can create a maximum of 15 predefined columns in a base table. If you have reached this limit, the base table will fail to be created.
  • An index can contain a maximum of four indexed columns. These indexed columns include a combination of primary key columns and predefined columns of the base table. If you specify more than four indexed columns, the index will fail to be created.
  • An index can contain a maximum of eight attribute columns. If you have reached this limit, the index will fail to be created.
  • You can specify the data type of an indexed column as INTEGER, STRING, or BINARY. The limits for indexed columns are the same as those for primary key columns of the base table.
  • If an index contains multiple columns, the size limit for the columns is the same as that for primary key columns of the base table.
  • If you specify a column of the STRING or BINARY type as an attribute column of an index, the limits for attribute columns are the same as those for attribute columns of the base table.
  • You cannot create an index on a table that has the time to live (TTL) parameter configured. If you want to create indexes on a table that has the TTL parameter configured, use DingTalk to request technical support.
  • You cannot create an index in a table that has the Max Versions parameter configured. If a table has the Max Versions parameter configured, indexes will fail to be created for the table. You cannot configure the Max Versions parameter for an indexed base table.
  • You cannot customize versions when writing data to an indexed base table. Otherwise, the data write will fail.
  • You cannot use the Stream feature in an index.
  • An indexed base table cannot contain repeated rows that have the same primary key during the same BatchWrite operation. Otherwise, the data write will fail.
  • You cannot specify an auto-increment primary key column as the first primary key column of an index.

Precautions

  • Tablestore automatically adds all primary key columns of the base table to the index. When you scan an index, you must specify the range of primary key columns. The range can be anywhere from negative infinity to positive infinity.
    When you create an index, you can only specify the columns that you want to index. Tablestore automatically adds all primary key columns of the base table to the index. For example, a base table contains the primary key columns PK0 and PK1 and a predefined column Defined0.
    • When you create an index for the Defined0 column, Tablestore generates the index that has the primary key columns Defined0, PK0, and PK1.
    • When you create an index for the Defined0 and PK1 columns, Tablestore generates the index that has the primary key columns Defined0, PK1, and PK0.
    • When you create an index for the PK1 column, Tablestore generates the index that has the primary key columns PK1 and PK0.
  • You can specify predefined columns as attribute columns in the base table. When you specify a predefined column of the base table as an attribute column of the index, you can search this index instead of the base table for the column value. However, this will increase storage costs. Otherwise, you will have to query the base table based on the index. You can choose between these methods based on your requirements.
  • We recommend that you do not specify a column whose values are date or time as the first primary key column of an index because it may slow down index updates. We recommend that you hash columns related to the time or date and create indexes for the hashed columns. If you have such requirements, use DingTalk to request technical support.
  • We recommend that you do not define a column of low cardinality or a column that contains enumerated values as the first primary key column of an index. For example, the gender column restricts the horizontal scalability of the index and leads to poor write performance.