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
case_sensitive_equality_operator including BINARY is slow on MySQL #1399
Comments
I think I was the one who working on this patch. The blog posts are quite unrelated because the ability to validates uniqueness with case sensitive for MySQL was lost between 2.3.x and 3.0.x transition. I bought back the If you're going to do update your schema to something that will make MySQL always do case sensitive, I think you can already do @tenderlove, what is your thought on this ticket? |
Oh, I use both I use In the very early days after releasing the app, we removed every line of
IIRC, I found the noticeable performance degradation when we only have 10K users, so the problem should be pretty common, and people must be doing either:
And the current implementation only benefits people like 4 (and Postgres, maybe? but I guess Anyway, my suggestion for change is either:
|
…ils#1399 state:resolved] Signed-off-by: Joshua Peek <josh@joshpeek.com>
It's already '=' in current master. Closing this. |
…collation issues In MySQL, the default collation is case insensitive. Since the uniqueness validator enforces case sensitive comparison by default, it frequently causes mismatched collation issues (performance, weird behavior, etc) to MySQL users. https://grosser.it/2009/12/11/validates_uniqness_of-mysql-slow/ #1399 #13465 gitlabhq/gitlabhq@c1dddf8 huginn/huginn#1330 (comment) This extracts `default_uniqueness_comparison` to ease to handle the mismatched collation issues on the connection.
In MySQL, the default collation is case insensitive. Since the uniqueness validator enforces case sensitive comparison by default, it frequently causes mismatched collation issues (performance, weird behavior, etc) to MySQL users. https://grosser.it/2009/12/11/validates_uniqness_of-mysql-slow/ rails#1399 rails#13465 gitlabhq/gitlabhq@c1dddf8 huginn/huginn#1330 (comment) I'd like to deprecate the implicit default enforcing since I frequently experienced the problems in code reviews. Note that this change has no effect to sqlite3, postgresql, and oracle-enhanced adapters which are implemented as case sensitive by default, only affect to mysql2 adapter (I can take a work if sqlserver adapter will support Rails 6.0).
It's about time we should fix this - right now
ActiveRecord::ConnectionAdapters::MysqlAdapter
has this code block:which renders
validates_uniqueness_of
prohibitively slow. With 7M records, it takes 3+ seconds in our case. It really should be:That way, we benefit from MySQL's collation for case sensitivity in the index (like
utf8_unicode_ci
orutf8_bin
), which is FAST. Or we could add:case_sensitive => nil
as a new option particularly for that case.It's a known problem for a long time actually, and patches have been around:
The text was updated successfully, but these errors were encountered: