Linx Trix

September 19, 2007

Tricking MySQL to use index on binary search

Filed under: medium, mysql — admin @ 10:49 am

Did you know that this:

SELECT * FROM test WHERE binary login = ‘SomeCaseSensitiveLogin’

is million times slower then

SELECT * FROM test WHERE login = ‘SomeCaseSensitiveLogin’ AND binary login = ‘SomeCaseSensitiveLogin’

Of course the logical choice would be to have a binary index on login(like in this example of case sensitive searches in mysql), but sometimes the MySQL version is too old or buggy or you simply don’t have the permission to do so, and I even had a situation where this was faster then any other method, but as always it depends on the data you have.

In my example it was a 40.000 rows user database and the search was taking 0.21 secs with pure binary vs 0.00 with this trick above.

Share and Enjoy:
  • del.icio.us
  • Digg
  • Reddit
  • Slashdot
  • StumbleUpon
  • Live
  • Propeller
  • Technorati
  • Google Bookmarks
  • YahooMyWeb

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress