database: reorder where conditions so that existing compound index is used, add user_id index
Created by: sashaostrikov
First I noticed that this query will not use the index. Reordering the predicates will fix it.
Then I recognised that another query will also full scan the table because user_id
index was deleted some time ago, but it should not be deleted as existing compound index "sub_repo_permissions_repo_id_user_id_version_uindex" UNIQUE, btree (repo_id, user_id, version)
is inefficient for user_id
or version
queries. That's why I returned the user_id
column index.