Reputation: 2867
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
Reputation: 7107
Lets shortly clarify what's index and why it's used:
select
statements by using
binary search on additionally created data structure which stores
values and pointer to original record.Cons:
create, update, delete
queries if you're updating the indexed column, because index is also updated with the data. 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