Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove a separate index for the name column #467

Merged
merged 2 commits into from Nov 18, 2017

Conversation

sergey-alekseev
Copy link
Contributor

Note: I tested with Postgres only. Run an EXPLAIN query:

> Role.where(name: 'Admin').explain
  Role Load (0.5ms)  SELECT "roles".* FROM "roles" WHERE "roles"."name" = $1  [["name", "Admin"]]
 => EXPLAIN for: SELECT "roles".* FROM "roles" WHERE "roles"."name" = $1 [["name", "Admin"]]
                                                     QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on roles  (cost=4.17..11.28 rows=3 width=96)
   Recheck Cond: ((name)::text = 'Admin'::text)
   ->  Bitmap Index Scan on index_roles_on_name_and_resource_type_and_resource_id  (cost=0.00..4.17 rows=3 width=0)
         Index Cond: ((name)::text = 'Admin'::text)
(4 rows)

https://github.com/ankane/pghero adds this index to the Duplicate Indexes section.

On roles
index_roles_on_name (name)
is covered by
index_roles_on_name_and_resource_type_and_resource_id (name, resource_type, resource_id)

*Note:* I tested with Postgres only. Run an `EXPLAIN` query:  
```
> Role.where(name: 'Admin').explain
  Role Load (0.5ms)  SELECT "roles".* FROM "roles" WHERE "roles"."name" = $1  [["name", "Admin"]]
 => EXPLAIN for: SELECT "roles".* FROM "roles" WHERE "roles"."name" = $1 [["name", "Admin"]]
                                                     QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on roles  (cost=4.17..11.28 rows=3 width=96)
   Recheck Cond: ((name)::text = 'Admin'::text)
   ->  Bitmap Index Scan on index_roles_on_name_and_resource_type_and_resource_id  (cost=0.00..4.17 rows=3 width=0)
         Index Cond: ((name)::text = 'Admin'::text)
(4 rows)
```

https://github.com/ankane/pghero adds this index to the Duplicate Indexes section.

On roles  
`index_roles_on_name (name)`  
is covered by  
`index_roles_on_name_and_resource_type_and_resource_id (name, resource_type, resource_id)`
@coveralls
Copy link

coveralls commented Oct 20, 2017

Coverage Status

Coverage remained the same at 93.089% when pulling 7ecaa08 on sergey-alekseev:sergey-alekseev-patch-1 into 3b85e92 on RolifyCommunity:master.

1 similar comment
@coveralls
Copy link

coveralls commented Oct 20, 2017

Coverage Status

Coverage remained the same at 93.089% when pulling 7ecaa08 on sergey-alekseev:sergey-alekseev-patch-1 into 3b85e92 on RolifyCommunity:master.

@sergey-alekseev
Copy link
Contributor Author

I tested with other databases and it appears the index is not needed with Postgres only. Look at https://github.com/sergey-alekseev/test-rolify.

@coveralls
Copy link

coveralls commented Oct 22, 2017

Coverage Status

Coverage remained the same at 93.089% when pulling d0da8c6 on sergey-alekseev:sergey-alekseev-patch-1 into 3b85e92 on RolifyCommunity:master.

2 similar comments
@coveralls
Copy link

coveralls commented Oct 22, 2017

Coverage Status

Coverage remained the same at 93.089% when pulling d0da8c6 on sergey-alekseev:sergey-alekseev-patch-1 into 3b85e92 on RolifyCommunity:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 93.089% when pulling d0da8c6 on sergey-alekseev:sergey-alekseev-patch-1 into 3b85e92 on RolifyCommunity:master.

Copy link
Member

@EppO EppO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Sometimes, too many indexes are not that good.
Thanks for your PR

@EppO EppO merged commit 9756943 into RolifyCommunity:master Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants