I have two tables
homes_info
with 4 columns
home_id (primary_key)
title (varchar)
price (double)
location_id (foreign key)
And I have another table
locations
with 3 columns
location_id (primary key)
location_name (varchar)
location_state (varchar)
I just want to make these two queries
SELECT * FROM homes_info WHERE title = 'xxxxx' && price = 'xxxx'
SELECT * FROM homes_info LEFT JOIN locations on homes_info.location_id = locations.location_id WHERE title = 'xxx' && price = 'xxxxx' && location_name = 'xxxx'
are the following the best way to use indexes on above tables for optimizing above two queries?
ALTER TABLE homes_info ADD INDEX(title, price)
ALTER TABLE locations ADD INDEX(location_name)
I know for the first query the composite index INDEX(title, price)
is better than separate indexes, But what about the second query (where I used LEFT JOIN
)? would using separate indexes on title
and price
columns be better for the second query
In simple words, what would be the best use of indexes on those two tables for optimizing above two queries?
Thanks!