Bri6ko
Bri6ko

Reputation: 1905

Index on unique field

I have a users table and there is an index on that table:

add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree

The index type is btree and email is a unique field.
Is it worth having this index or is it better to just remove it?

Upvotes: 0

Views: 101

Answers (2)

Erwin Brandstetter
Erwin Brandstetter

Reputation: 656744

If the column is defined UNIQUE, it is indexed with a unique btree index automatically anyway, because that's how Postgres implements a UNIQUE constraint.

An additional index would be redundant, dead freight. Delete it.

Details:

Upvotes: 1

Antarr Byrd
Antarr Byrd

Reputation: 26071

I would remove it first and then use lol_dba db:find_indexes from lol_dba to see if it recommends adding the index.

Upvotes: 1

Related Questions