<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: MySQL Error: BLOB/TEXT used in key specification without a key length</title>
	<atom:link href="http:///blog/2009/10/mysql-error-blobtext-used-in-key-specification-without-a-key-length/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tnrglobal.com/blog/2009/10/mysql-error-blobtext-used-in-key-specification-without-a-key-length/</link>
	<description></description>
	<lastBuildDate>Thu, 20 May 2010 19:04:48 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jeff Peck</title>
		<link>http://www.tnrglobal.com/blog/2009/10/mysql-error-blobtext-used-in-key-specification-without-a-key-length/cpage/1/#comment-99</link>
		<dc:creator>Jeff Peck</dc:creator>
		<pubDate>Thu, 04 Feb 2010 02:40:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.tnrglobal.com/blog/2009/10/mysql-error-blobtext-used-in-key-specification-without-a-key-length/#comment-99</guid>
		<description>That&#039;s a really clever way to access fields in a database by a URL key.

Just thinking about it, I am noticing... to optimize this even further, you might want to store that MD5 hash in two BIGINT UNSIGNED fields with a single index over them (if you are not doing it that way already).

Storing them in CHAR(32) fields uses 256 bits per row whereas two BIGINTs are only 128 bits total, which is all that you need to store an MD5 hash.  The may not be a big deal for space, but should make a noticeable difference in the performance.

This would be the query to accomplish the insert in MySQL:

[code]
INSERT INTO `my_url_table` (`id_1`, `id_2`) VALUES (cast(conv(substring(md5(&quot;www.hugeurl.com&quot;),1,16),16,10) as unsigned integer),cast(conv(substring(md5(&quot;www.hugeurl.com&quot;),17,32),16,10) as unsigned integer))
[/code]

... where id_1 and id_2 are the primary keys.  Note the difference in substring() from 1 to 16 and from 17 to 32 to evenly slice the hash.

Another approach might be to use an CHAR(16) field and convert the hex md5 hash into ASCII.

Either way, I think the idea to access fields by their URL as a hash is a great idea!  Thanks.</description>
		<content:encoded><![CDATA[<p>That&#8217;s a really clever way to access fields in a database by a URL key.</p>
<p>Just thinking about it, I am noticing&#8230; to optimize this even further, you might want to store that MD5 hash in two BIGINT UNSIGNED fields with a single index over them (if you are not doing it that way already).</p>
<p>Storing them in CHAR(32) fields uses 256 bits per row whereas two BIGINTs are only 128 bits total, which is all that you need to store an MD5 hash.  The may not be a big deal for space, but should make a noticeable difference in the performance.</p>
<p>This would be the query to accomplish the insert in MySQL:</p>
<p>[code]<br />
INSERT INTO `my_url_table` (`id_1`, `id_2`) VALUES (cast(conv(substring(md5("www.hugeurl.com"),1,16),16,10) as unsigned integer),cast(conv(substring(md5("www.hugeurl.com"),17,32),16,10) as unsigned integer))<br />
[/code]</p>
<p>&#8230; where id_1 and id_2 are the primary keys.  Note the difference in substring() from 1 to 16 and from 17 to 32 to evenly slice the hash.</p>
<p>Another approach might be to use an CHAR(16) field and convert the hex md5 hash into ASCII.</p>
<p>Either way, I think the idea to access fields by their URL as a hash is a great idea!  Thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

