Hello.

On Thu 2002-10-31 at 13:54:18 -0500, [EMAIL PROTECTED] wrote:
> Am I right in assuming that comparing two md5 strings would be faster 
> if they were compared as two hexadecimal numbers than if they were 
> compared as two strings?
> 
> If so, is there any way to insist on this in a SQL query? I am using 
> PHP, and would like to know from that perspective if it makes any 
> difference. Single-quoted variable name versus double-quoted, for 
> example? Any magic words to force the comparison to be done in the 
> numerical space?

Single and double quotes have the same meaning in MySQL.

You can force a variable to a number by adding 0, e.g.

  SELECT "00001"+0 = "1"+0

will be true. Without the "+0", it wouldn't. For forcing a hexadecimal
representation (which md5 strings usually are displayed as) you would
use the CONV() function:

  SELECT CONV("a2da", 16, 10)


But forcing evaluation to numeric values doesn't help speed in any
significant way. It could even slow down retrieval.

What matters is how you store the md5 string. If you could store them
as numeric values and then use index by specifying numbers, this will
be faster than storing strings representations.

Your problem will be that md5 hashes usually are 128 bit and larger
and MySQL's biggest numeric type is BIGINT which is 64 bit.

So what's left is that you save the real md5 string instead of it's
hex representation, e.g. in a CHAR BINARY. That's easiest if you have
the binary representation on the client side. I see no easy way of
doing it in MySQL if you only have the hex rep (you could split it
into two strings and use CONV on each of it - but then you could go
and save them as two BIGINTs to begin with).

Considering all the possible hassle, I would start with saving the hex
representations as strings and worry about performance, when you see
that it really becomes a problem.

Regards,

        Benjamin.


-- 
[EMAIL PROTECTED]

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to