<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>damonparker.org &#187; Linux</title>
	<atom:link href="http://damonparker.org/blog/category/technical/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://damonparker.org</link>
	<description>code / ecommerce / life</description>
	<lastBuildDate>Mon, 14 Jun 2010 14:33:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-RC3</generator>
		<item>
		<title>MySQL Database Performance &#8211; ZenCart Sales Report</title>
		<link>http://damonparker.org/blog/2006/10/23/mysql-database-performance-zencart-sales-report/</link>
		<comments>http://damonparker.org/blog/2006/10/23/mysql-database-performance-zencart-sales-report/#comments</comments>
		<pubDate>Mon, 23 Oct 2006 19:13:36 +0000</pubDate>
		<dc:creator>damonp</dc:creator>
				<category><![CDATA[Ecommerce]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://damonparker.org/blog/2006/10/23/mysql-database-performance-zencart-sales-report/</guid>
		<description><![CDATA[One of my client&#8217;s ZenCart installs was loading the server down so much to generate sales reports with the Sales Report v1 contribution that the public side was noticeably less responsive for the couple of minutes it took to build the report. The site has been running for over three years and contains 9k orders, [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>One of my client&#8217;s ZenCart installs was loading the server down so much to generate sales reports with the <a href="http://www.zen-cart.com/index.php?main_page=product_contrib_info&#038;cPath=40_41&#038;products_id=83" rel="external">Sales Report v1</a> contribution that the public side was noticeably less responsive for the couple of minutes it took to build the report.  The site has been running for over three years and contains 9k orders, so there is a lot of data to weed through even for a weekly report.  A quick look at the <a href="http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html" rel="external">slow query log</a> listed the following query as the culprit:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> count<span style="color: #66cc66;">&#40;</span> op.products_id <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> attr_cnt, o.orders_id, opa.orders_products_id, opa.products_options, opa.products_options_values, opa.options_values_price, opa.price_prefix<br />
<span style="color: #993333; font-weight: bold;">FROM</span> orders_products_attributes opa, orders o, orders_products op<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> o.orders_id <span style="color: #66cc66;">=</span> opa.orders_id<br />
<span style="color: #993333; font-weight: bold;">AND</span> op.orders_products_id <span style="color: #66cc66;">=</span> opa.orders_products_id<br />
<span style="color: #993333; font-weight: bold;">AND</span> o.date_purchased <span style="color: #66cc66;">&gt;=</span> <span style="color: #ff0000;">'2006-10-18T00:00:00'</span><br />
<span style="color: #993333; font-weight: bold;">AND</span> o.date_purchased <span style="color: #66cc66;">&lt;</span> <span style="color: #ff0000;">'2006-10-19T00:00:00'</span><br />
<span style="color: #993333; font-weight: bold;">AND</span> op.products_id <span style="color: #66cc66;">=</span><span style="color: #cc66cc;">179</span><br />
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> products_options_values<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> orders_products_id;</div></div>
<p>Running this query through <a href="http://dev.mysql.com/doc/refman/5.0/en/explain.html" rel="external">EXPLAIN</a> <a href="http://damonparker.org/html/explain_sales_report.html#one">shows 20978 rows examined</a>.  In this case, thats 20978 rows per day included in the sales report.</p>
<p>The main problem with this query is the ORDER BY clause which cannot utilize an exisiting index.  Adding the following index:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">'orders_products_attributes'</span> <span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'orders_products_id'</span> <span style="color: #66cc66;">&#41;</span></div></div>
<p>limits the rows examined for each query to 68 (<a href="http://damonparker.org/html/explain_sales_report.html#two">results</a>).  </p>
<p>This simple change allows the sales report to load in seconds as opposed to minutes with no noticeable lag on the public side.</p>
<p>The create table SQL for the current version of ZenCart (v1.3.5) contains the following index in orders_products_attributes:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...<br />
<span style="color: #993333; font-weight: bold;">KEY</span> idx_orders_id_prod_id_zen <span style="color: #66cc66;">&#40;</span>orders_id,orders_products_id<span style="color: #66cc66;">&#41;</span><br />
...</div></div>
<p>This index is used in the query in question.  In my tests it was only slightly slower than the single column index above.  EXPLAIN showed about 270 rows examined with the two column index on my dataset while  the single column index only examined 68 rows.</p>
 <img src="http://damonparker.org/wp-content/plugins/feed-statistics.php?view=1&post_id=275" width="1" height="1" style="display: none;" /><img src="http://damonparker.org/?ak_action=api_record_view&id=275&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://damonparker.org/blog/2006/10/23/mysql-database-performance-zencart-sales-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Directory Shortcuts Using Bash Functions</title>
		<link>http://damonparker.org/blog/2006/06/15/directory-shortcuts-using-bash-functions/</link>
		<comments>http://damonparker.org/blog/2006/06/15/directory-shortcuts-using-bash-functions/#comments</comments>
		<pubDate>Thu, 15 Jun 2006 16:01:43 +0000</pubDate>
		<dc:creator>damonp</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://damonparker.org/blog/2006/06/15/directory-shortcuts-using-bash-functions/</guid>
		<description><![CDATA[Modify this snippet to match the directory shortcuts you need on your system and add into your .bashrc file: www &#40;&#41; &#123; if &#91; $1 == &#34;domain1&#34; &#93;; then &#160; &#160; cd /www/vhosts/domain1.com/htdocs elif &#91; $1 == &#34;domain2&#34; &#93;; then &#160; &#160; cd /www/vhosts/domain2.com/htdocs &#160; &#160; &#160; else &#160; &#160; cd /www/vhosts/$1 ; fi echo [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Modify this snippet to match the directory shortcuts you need on your system and add into your <em>.bashrc</em> file:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">www <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> $<span style="color: #cc66cc;">1</span> == <span style="color: #ff0000;">&quot;domain1&quot;</span> <span style="color: #66cc66;">&#93;</span>; <span style="color: #b1b100;">then</span><br />
&nbsp; &nbsp; <span style="color: #000066;">cd</span> <span style="color: #66cc66;">/</span>www<span style="color: #66cc66;">/</span>vhosts<span style="color: #66cc66;">/</span>domain1.com<span style="color: #66cc66;">/</span>htdocs<br />
<span style="color: #b1b100;">elif</span> <span style="color: #66cc66;">&#91;</span> $<span style="color: #cc66cc;">1</span> == <span style="color: #ff0000;">&quot;domain2&quot;</span> <span style="color: #66cc66;">&#93;</span>; <span style="color: #b1b100;">then</span><br />
&nbsp; &nbsp; <span style="color: #000066;">cd</span> <span style="color: #66cc66;">/</span>www<span style="color: #66cc66;">/</span>vhosts<span style="color: #66cc66;">/</span>domain2.com<span style="color: #66cc66;">/</span>htdocs &nbsp; &nbsp; &nbsp; <br />
<span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; <span style="color: #000066;">cd</span> <span style="color: #66cc66;">/</span>www<span style="color: #66cc66;">/</span>vhosts<span style="color: #66cc66;">/</span>$<span style="color: #cc66cc;">1</span> ; <br />
<span style="color: #b1b100;">fi</span><br />
<span style="color: #000066;">echo</span> `<span style="color: #000066;">pwd</span>`;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>To use:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">www domain1</div></div>
 <img src="http://damonparker.org/wp-content/plugins/feed-statistics.php?view=1&post_id=255" width="1" height="1" style="display: none;" /><img src="http://damonparker.org/?ak_action=api_record_view&id=255&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://damonparker.org/blog/2006/06/15/directory-shortcuts-using-bash-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Mac Line Endings</title>
		<link>http://damonparker.org/blog/2006/01/05/convert-mac-line-endings/</link>
		<comments>http://damonparker.org/blog/2006/01/05/convert-mac-line-endings/#comments</comments>
		<pubDate>Thu, 05 Jan 2006 16:02:59 +0000</pubDate>
		<dc:creator>damonp</dc:creator>
				<category><![CDATA[Apple / Mac]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Microsoft / Windows]]></category>

		<guid isPermaLink="false">http://damonparker.org/blog/?p=165</guid>
		<description><![CDATA[I wasted an hour last week messing with a CSV file I was massaging data in for import into a large SQL database only to find out the reason the import kept dying was because of the Mac line endings. There are many shell script, Perl scripts and shell one liners to convert line endings [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I wasted an hour last week messing with a CSV file I was massaging data in for import into a large SQL database only to find out the reason the import kept dying was because of the Mac line endings.  There are many shell script, Perl scripts and shell one liners to convert line endings but I found a program called <a href="http://ccrma-www.stanford.edu/~craig/utility/flip/" rel="external">flip</a> available for OSX, WinXP and Linux that can convert between all three. </p>
<div class="code">
Usage: flip [-t|-u|-d|-m] filename[s]<br />
   Converts ASCII files between Unix, MS-DOS/Windows, or Macintosh newline formats</p>
<p>   Options:<br />
      -u  =  convert file(s) to Unix newline format (newline)<br />
      -d  =  convert file(s) to MS-DOS/Windows newline format (linefeed + newline)<br />
      -m  =  convert file(s) to Macintosh newline format (linefeed)<br />
      -t  =  display current file type, no file modifications</p></div>
<p>They are linked here locally as well:</p>
<ul>
<li><a href="http://damonparker.org/files/flip.cpp">flip.cpp</a></li>
<li><a href="http://damonparker.org/files/flip.osx">Mac OSX</a></li>
<li><a href="http://damonparker.org/files/flip.exe">Windows XP</a></li>
<li><a href="http://damonparker.org/files/flip.linux">Linux libc6</a></li>
</ul>
 <img src="http://damonparker.org/wp-content/plugins/feed-statistics.php?view=1&post_id=165" width="1" height="1" style="display: none;" /><img src="http://damonparker.org/?ak_action=api_record_view&id=165&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://damonparker.org/blog/2006/01/05/convert-mac-line-endings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using xcache
Page Caching using xcache
Database Caching 20/44 queries in 0.009 seconds using xcache
Content Delivery Network via cdn.damonparker.org/q9i5a4w8/cds

Served from: damonparker.org @ 2010-07-30 14:01:00 -->