Set a database index
To improve query efficiency and retrieve information faster from your database, create an index on fields that are used in query conditions. By default, a non-unique index is created on the _id_ field.
Prerequisites
Log on to the EMAS console. Select Serverless and click Enter to open the Serverless console.
In the navigation pane on the left, select ApsaraDB.
On the ApsaraDB page, click the target data table, and then click the Index tab.
Click Add Index.
Enter an index name, and set the index properties and index fields.
Index property: Specify whether the index is unique or non-unique.
A unique index prevents different records from having the same value for an indexed field.
ImportantIf a record does not have a value for a field in a unique index, the index stores a null value for that record. Because of the UNIQUE constraint, only one record can have a null value for the indexed field. If more than one record is missing a value for the indexed field, the index build fails and a duplicate key error is reported.
Index fields: Create a single-key or compound index, and sort the fields in ascending or descending order.
A single-key index is the most common type. It is an index on a single field. For single-key indexes, ascending and descending orders provide the same query performance.
A compound index is an index on multiple fields. Records are sorted first by the first field. Records with the same value in the first field are then sorted by the second field, and so on.
To save the index settings, click Save.