The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.

Index

Last updated: 2024-10-15 17:12:34

Index Overview

You can create an index for a table and use it to quickly get desired data from a database, which delivers higher flexibility in data query for your application.
TcaplusDB supports two types of indexes:
Local index: it must be composed of primary key fields and allows you to quickly query data by using a primary key as a filter.
Global Index: Supports fields composed of any types except message type, and allows for fast query using the configured fields in the global index as conditions.
TcaplusDB supports up to 8 local indexes.

Local index

Features

Local Index is a real-time index, which updates index data simultaneously when inserting or deleting data.
The fields of a Local Index must be included in the Primary Key Fields and must include the Sharding Field; thus, the query will ultimately be performed on a single data shard.
Local Index only supports Equi-join Query.
A table can have multiple Local Indexes; the query must include all fields of one of the Local Indexes.
Currently, only Generic Table supports Local Index.
Local Index can only be defined during table creation and must be composed of Primary Key Fields. The intersection of all Index Field Collections cannot be empty.

Example

For example, a table may have 4 Primary Key Fields, as shown in the following HeroInfo table: heroId, heroName, heroFightingType, and heroQuality are the Primary Key Fields of this table.
{
heroId:1,
heroName:"Arthur",
heroFightingType:1,
heroQuality:3
heroSkill:{
BasicSkill1:1,
BasicSkill2:2,
SpecialSkill:3
},
heroLevel:12,
heroskin:2,
heroAttackpower:141,
heroPhysicalDefense: 283,
heroMagicdefense:124
}
{
heroId:4,
heroName:"Shooter",
heroFightingType:3,
heroQuality:4
heroSkill:{
BasicSkill1:1,
BasicSkill2:2,
SpecialSkill:3
},
heroLevel:11,
heroskin:1,
heroAttackpower:225,
heroPhysicalDefense: 57,
heroMagicdefense:41
}
For the above table, you can freely combine the 4 Primary Key Fields to create indexes, but the created indexes' intersection must not be empty. For example, using heroId as the intersection field, you have the following combination options for index design:
heroId,heroName
heroId,heroFightingType
heroId,heroQuality
heroId,heroName,heroFightingType
heroId,heroFightingType,heroQuality
heroId,heroName,heroFightingType,heroQuality
Additionally, you can query data based on the above-created index fields. When creating indexes, please do so according to the actual requirements of your business; otherwise, performance will be reduced due to Index Redundancy.

Global Index

In the previously displayed HeroInfo table, you can query data items based on the fields contained in the already created Local Indexes. If you also want to query data based on information such as heroLevel and heroSkin, you can add heroLevel and heroSkin fields to the Global Index, then query the data using the fields contained in the Global Index.
Please note that Global Indexes also do not support Nested Types, such as the heroSkill field in the example table above.

Use Limits

Local Index Use Limits

Once created, Local Indexes cannot be modified, deleted, added, or deleted during use; they are deleted with the table.
The number of Local Indexes cannot exceed 8.
Local Indexes only support Exact Match. That is, when using local index fields as query conditions, you can only exactly match specific values; Fuzzy and Range Matching are not supported.

Global Secondary Index Use Limits

Global Secondary Indexes only support Table-level Fields. Nested Fields and Array List Type Fields do not support the creation of secondary indexes.
Global Secondary Indexes only support Generic Type Tables and do not support List Type Tables.
Global Secondary Indexes can only be used in the tcaplus_client Tool, C++ SDK (TDR Protocol Table & PB Protocol Table), and are currently not supported at the API Level for non-C++ languages.