-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Taggings Unique Index performance issue #509
Comments
I'll have to look at this and think a bit. If you think you can help, please do. This repo needs it! |
@jhirbour (mysql guru) and I took a more detailed look at this and couldn't figure out why the tags index is not getting used. We tried a few things to force the index but no joy. @jhirbour, if you have anything to add please do. Otherwise this is far beyond my mysql skill set and rolling back to the previous indexes fixed the perf issue. |
Hey I just got back from vacation. I'll look at this during this week. After some initial testing over IRC we determined that at first glance this isn't an issue with MySQL picking the right index (troubleshot by index hinting). @jnimety can you tell me how many rows you have in: tags and in taggings just so I'm testing at scale. |
Could this be related to #516 |
|
@bf4 great lead. I bet that's it, in our situation tagger_id and tagger_type are all NULL. |
We're seeing that same performance issue (page load has gone from 0.8 sec to 28 sec) for #tag_list and we have no tagger_id or tagger_type values that are NULL.
|
re: @avitus "page load has gone from 0.8 sec to 28 sec" holy moly. I'm assuming you've rolled back to the previous release? Do you feel comfortable helping debug this? I'm no longer working on the app that used the plugin when I wrote the new index code. |
@bf4 Yep, I did rollback for now. On the positive side I did clean up a lot of duplicate tags 😃 I can take another look. I did take a brief look and it wasn't clear to me why it would be so slow. |
Perhaps we should yank the last release and put a note in the README until we figure it out? OTOH, if you already ran the migration, and are running the previously version, then the slowness is likely in acts-as-taggable-on, not the migration.. |
I only rolled back the migration so I think the problem lies in the new index. I don't understand why it would be so slow, though. |
what database and rails version are you on? |
Rails 4.0.3 and MySQL 5.5 |
Any news about this issue? |
This is because the unique compound index on taggings has a left-most column of tag_id. Using the example query given earlier:
The query cannot use the index because none of the conditions include the tag_id column. This is intuitive if you try to find all words in the english dictionary where the second letter is 'a'. It cannot be done without scanning the entire dictionary; the index is no help at all because the start of the index is on the first letter. My solution to this is to add back the compound index that identifies the taggable in its left-most column(s):
I also included context in this index, although this won't make much difference in most cases assuming the cardinality is low. The practical effect of this, as with all indexes, is it will slightly slow table writes and use up slightly more storage space and tablespace memory. |
@pcai , do you mind sending a PR ? |
i dont know if it helps but i'm sucessfully using something like :
|
I've opened a pull request, but I only added back the index. Didn't do any testing, automated or otherwise. |
We ran into a performance issue after running the taggings unique index migration. We're using mysql and after the migration the query plan for #tag_list is performing a full table scan on the tags table.
With the unique index, full table scan of tags required:
Without the unique index:
The text was updated successfully, but these errors were encountered: