If user_id
is the primary key column and indexed, that is sufficient.
You should only consider making a composite index on user_id
and user_email_confirmed
if both the following conditions are satisfied:
Your DBMS supports unique indexes with additional columns (DB2 does; I'm not sure which others do).
CREATE UNIQUE INDEX pkx_user ON User(User_ID) INCLUDE(User_Email_Confirmed); -- DB2
Many of your queries are going to include the user_email_confirmed
column.
Otherwise, the index is wasted space. Given that you have to get the data for the row to retrieve the user_email
value, there's no real cost to checking the user_email_confirmed
column too. If your composite index included the user_email
column too, you'd have a less efficient index (because the data for each row in the index would be larger), but you'd be able to avoid fetching the data row (it becomes an index-only query). Whether that matters is hard to judge — I doubt if the gain from not fetching the row is outweighed by the loss of efficiency in the index.