OT using crc32 as key for objects

Jed Reynolds lists at benrey.is-a-geek.net
Fri Oct 6 07:42:29 UTC 2006

Sorry if this is too far off topic, but since memcached is essentially a 
very large hash table, discussion of hashing might be appropriate here.

When caching query results, mysql uses the query as the key in its query 
cache. Since a sql query is not a legal memcache key, nor is the base64 
of a query legal (often too long), the hash of the query is the next 
logical choice.

I'd like to avoid using truncated MD5 or SHA1 hashes of queries as that 
seems overkill. Using a crc32 of a query is more risky but still 
improbable to collide within a hundred thousand queries, but I don't 
know the math that well. It would seem to me that concatenating the 
crc32s of a query and a salted version of the query would very likely 
yield a pretty unique key for a sql query. By the same logic, 
concatenating the crc32 of the base64 encoding of a query seems 
reasonably safe, too.

Any opinions?

Jed Reynolds

More information about the memcached mailing list