Reputation: 2359
I have a query
select * from cp where customer_Id = ? order by date_created desc limit 1
I like to optimize execution of this query bu creating index for customer_Id
column.
Question: should my index contain date_created
column also ?
Upvotes: 0
Views: 48
Reputation: 1269623
In general, yes. If you can, include it as a descending column:
create index idx_cp_customerId_datecreated cp(customer_id, date_created desc)
Do note however:
desc
option on indexes.date_created
.Upvotes: 1