slal
slal

Reputation: 2867

Composite Index using JPA

I am new to JPA and the concept of Indexing.

I have defined composite index using JPA:

 @Table(name = "table_name", indexes = { @Index(name = "my_index", columnList = "id, user_id") })

My question is can I use the index to retrieve data from database using a service.

Upvotes: 1

Views: 1770

Answers (1)

J-Alex
J-Alex

Reputation: 7107

Lets shortly clarify what's index and why it's used:

  • Index is used to increase performance of select statements by using binary search on additionally created data structure which stores values and pointer to original record.

Cons:

  • Slowdowns the create, update, delete queries if you're updating the indexed column, because index is also updated with the data.
  • Requires additional disk space.

The primary key of the table is always indexed by default.

Therefore, cannot explicitly use indexes, but your database does.

You can find excellend explanation of indexing here

Upvotes: 1

Related Questions