[Ruby] 【index】

less than 1 minute read

Indexing is a way to speed up the search for any column when searching for and pulling data from a table.

You can improve performance by setting columns that are frequently searched such as name and email.

The method of setting the index is described below.

index.png

Create a migration file as shown in the image above, and describe the columns you want to add to the index there.

In this case, I want to set an index in the name column of the table called scores, so I can set it with add_index: scores,: name.

If you want to set multiple indexes

index2.png

Describe in array format like this.
In this case, you’ve indexed the name and email columns.

After writing, migrate and reflect the changes to complete the setting.