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
EppO
merged 2 commits into
RolifyCommunity:master
from
sergey-alekseev:sergey-alekseev-patch-1
Nov 18, 2017
Merged
remove a separate index for the name column #467
EppO
merged 2 commits into
RolifyCommunity:master
from
sergey-alekseev:sergey-alekseev-patch-1
Nov 18, 2017
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*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)`
1 similar comment
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. |
2 similar comments
EppO
approved these changes
Nov 18, 2017
There was a problem hiding this 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: I tested with Postgres only. Run an
EXPLAIN
query: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)