sqlindexing

is index to be used at the expressions?


-- INDEX 1
create index on post (owner_id, likes_count)

-- QUERY 1
select * from post where owner_id = ?

---------------

-- INDEX 2
create index on post (owner_id)
create index on post (likes_count)

-- QUERY 2
select * from post where owner_id = ? AND likes_count = ?

I think index is used in both, am I right?


Solution

  • Yes in the first scenario: the index is likely to be chosen by the optimizer. No in the second scennario: where only one of the two indexes will get used but not both.