<?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 Blob Compression performance benefits</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:23:57 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: zlib</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-664100</link>
		<dc:creator>zlib</dc:creator>
		<pubDate>Mon, 12 Oct 2009 15:44:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-664100</guid>
		<description>conversely, il you happen to store zlib-compressed data in a blob and want to be able to decompress for a quick check, you can

  select uncompress(concat(x&#039;00000100&#039;,myblob)) from mytable where id=2121;

(the value must be chosen so that it&#039;s not too big but still can contain the output buffer)</description>
		<content:encoded><![CDATA[<p>conversely, il you happen to store zlib-compressed data in a blob and want to be able to decompress for a quick check, you can</p>
<p>  select uncompress(concat(x&#8217;00000100&#8242;,myblob)) from mytable where id=2121;</p>
<p>(the value must be chosen so that it&#8217;s not too big but still can contain the output buffer)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Burton</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-238679</link>
		<dc:creator>Kevin Burton</dc:creator>
		<pubDate>Mon, 04 Feb 2008 07:52:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-238679</guid>
		<description>Agreed.  This is valuable information. I&#039;m probably going to write an implementation for Java.

Better yet.... it would be nice if the JDBC driver had a (de)compress BLOBs on the client option that was compatible with the internal MySQL compress/uncompress functions.

I think I might just submit a patch for that when I get around to it.

Kevin</description>
		<content:encoded><![CDATA[<p>Agreed.  This is valuable information. I&#8217;m probably going to write an implementation for Java.</p>
<p>Better yet&#8230;. it would be nice if the JDBC driver had a (de)compress BLOBs on the client option that was compatible with the internal MySQL compress/uncompress functions.</p>
<p>I think I might just submit a patch for that when I get around to it.</p>
<p>Kevin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-238678</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Mon, 04 Feb 2008 07:49:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-238678</guid>
		<description>Thanks Sergei for looking into it. So there is some extra data conversion with &quot;.&quot; added for data ending with space besides the size value.  Anyway this should not make it hard to implement compatible compression for other languages so you can uncompress on the application when desired.</description>
		<content:encoded><![CDATA[<p>Thanks Sergei for looking into it. So there is some extra data conversion with &#8220;.&#8221; added for data ending with space besides the size value.  Anyway this should not make it hard to implement compatible compression for other languages so you can uncompress on the application when desired.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergei Golubchik</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-238509</link>
		<dc:creator>Sergei Golubchik</dc:creator>
		<pubDate>Sun, 03 Feb 2008 23:28:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-238509</guid>
		<description>Dug up old emails...

============
Vva (the implementor):

3. As I understand, Zlib doesn&#039;t provide function for calculation of
   size of packet after uncomppress..
============
Peter:

I&#039;ve used this library (also LZO/BZIP2) for my own application and I
used a bit different approach - storing original size in the header.
This allows to avoid uncompress in the loop which is really bad
performance wise.
Thus I did not needed compatibility with existing data, which we likely
need in our case.
============
Monty:

No, we don&#039;t need to be compatible in this case.  We can define that
our compressed string starts with a 4 byte length header + the
compressed data.  Anyone that needs to access the compress data can
simply use RIGHT().

The 2 highest bits should be masked when reading the data as we
want to use this to store the compress method used.
(This will limit compressed data to 1 G, but this is ok for now)
============

At the moment, there&#039;s only one &quot;compress method used&quot;, so two highest bits are always 0.</description>
		<content:encoded><![CDATA[<p>Dug up old emails&#8230;</p>
<p>============<br />
Vva (the implementor):</p>
<p>3. As I understand, Zlib doesn&#8217;t provide function for calculation of<br />
   size of packet after uncomppress..<br />
============<br />
Peter:</p>
<p>I&#8217;ve used this library (also LZO/BZIP2) for my own application and I<br />
used a bit different approach &#8211; storing original size in the header.<br />
This allows to avoid uncompress in the loop which is really bad<br />
performance wise.<br />
Thus I did not needed compatibility with existing data, which we likely<br />
need in our case.<br />
============<br />
Monty:</p>
<p>No, we don&#8217;t need to be compatible in this case.  We can define that<br />
our compressed string starts with a 4 byte length header + the<br />
compressed data.  Anyone that needs to access the compress data can<br />
simply use RIGHT().</p>
<p>The 2 highest bits should be masked when reading the data as we<br />
want to use this to store the compress method used.<br />
(This will limit compressed data to 1 G, but this is ok for now)<br />
============</p>
<p>At the moment, there&#8217;s only one &#8220;compress method used&#8221;, so two highest bits are always 0.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergei Golubchik</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-238498</link>
		<dc:creator>Sergei Golubchik</dc:creator>
		<pubDate>Sun, 03 Feb 2008 23:10:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-238498</guid>
		<description>To be able to allocate buffers before uncompressing. And for UNCOMPRESSED_LENGTH() function.

Besides, the manual

http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function-compress

says &quot;The compressed string contents are stored the following way:
    * Empty strings are stored as empty strings.
    * Non-empty strings are stored as a four-byte length of the uncompressed string (low byte first), followed by the compressed string. If the string ends with space, an extra ‘.’ character is added to avoid problems with endspace trimming should the result be stored in a CHAR or VARCHAR column. (Use of CHAR or VARCHAR to store compressed strings is not recommended. It is better to use a BLOB column instead.)&quot;

Looks pretty clear to me, no need to guess or read the code.</description>
		<content:encoded><![CDATA[<p>To be able to allocate buffers before uncompressing. And for UNCOMPRESSED_LENGTH() function.</p>
<p>Besides, the manual</p>
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function-compress" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function-compress</a></p>
<p>says &#8220;The compressed string contents are stored the following way:<br />
    * Empty strings are stored as empty strings.<br />
    * Non-empty strings are stored as a four-byte length of the uncompressed string (low byte first), followed by the compressed string. If the string ends with space, an extra ‘.’ character is added to avoid problems with endspace trimming should the result be stored in a CHAR or VARCHAR column. (Use of CHAR or VARCHAR to store compressed strings is not recommended. It is better to use a BLOB column instead.)&#8221;</p>
<p>Looks pretty clear to me, no need to guess or read the code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Breaking Eggs And Making Omelettes &#187; Blog Archive &#187; It&#8217;s The Little Things</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-233538</link>
		<dc:creator>Breaking Eggs And Making Omelettes &#187; Blog Archive &#187; It&#8217;s The Little Things</dc:creator>
		<pubDate>Thu, 24 Jan 2008 06:48:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-233538</guid>
		<description>[...] little googling turns up this recent blog post discussing the matter. It seems that MySQL prepends standard zlib data with a 30-bit [...]</description>
		<content:encoded><![CDATA[<p>[...] little googling turns up this recent blog post discussing the matter. It seems that MySQL prepends standard zlib data with a 30-bit [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Burton</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-230836</link>
		<dc:creator>Kevin Burton</dc:creator>
		<pubDate>Mon, 14 Jan 2008 10:05:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-230836</guid>
		<description>Hey Jim.

Thanks for the clarification.  How can compress() use a prefix of only 4 bytes since the compressed data could in theory be up to 2^32?

The uncompress makes sense.

What&#039;s the reason for the change in format?  So that LENGTH() works?</description>
		<content:encoded><![CDATA[<p>Hey Jim.</p>
<p>Thanks for the clarification.  How can compress() use a prefix of only 4 bytes since the compressed data could in theory be up to 2^32?</p>
<p>The uncompress makes sense.</p>
<p>What&#8217;s the reason for the change in format?  So that LENGTH() works?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jim</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-230453</link>
		<dc:creator>jim</dc:creator>
		<pubDate>Sat, 12 Jan 2008 20:15:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-230453</guid>
		<description>the COMPRESS() function uses the underlying zlib compress() function, but prepends four bytes with the original length of the data &amp; 0x3FFFFFFF using the int4store() macro. for UNCOMPRESS(), it passes the compressed data after the first four bytes to the zlib uncompress() function.</description>
		<content:encoded><![CDATA[<p>the COMPRESS() function uses the underlying zlib compress() function, but prepends four bytes with the original length of the data &amp; 0&#215;3FFFFFFF using the int4store() macro. for UNCOMPRESS(), it passes the compressed data after the first four bytes to the zlib uncompress() function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ron ald Bradford</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-230251</link>
		<dc:creator>Ron ald Bradford</dc:creator>
		<pubDate>Sat, 12 Jan 2008 06:25:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-230251</guid>
		<description>Kevin,

FYI, after reading this blog entry today, I was actually just compiling MySQL 5.0.51 on a new machine and look what message popped up.

checking for zlib compression library... system-wide zlib not found, using one bundled with MySQL

Interesting isn&#039;t it?</description>
		<content:encoded><![CDATA[<p>Kevin,</p>
<p>FYI, after reading this blog entry today, I was actually just compiling MySQL 5.0.51 on a new machine and look what message popped up.</p>
<p>checking for zlib compression library&#8230; system-wide zlib not found, using one bundled with MySQL</p>
<p>Interesting isn&#8217;t it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/comment-page-1/#comment-230115</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sat, 12 Jan 2008 00:52:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2008/01/11/mysql-blob-compression-performance-benefits/#comment-230115</guid>
		<description>Well if it is not the problem go ahead and &quot;copy paste&quot; COMPRESS implementation from MySQL source :)</description>
		<content:encoded><![CDATA[<p>Well if it is not the problem go ahead and &#8220;copy paste&#8221; COMPRESS implementation from MySQL source <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
