<?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>Data-Diggers.com &#187; index</title>
	<atom:link href="http://www.data-diggers.com/index.php/tag/index/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.data-diggers.com</link>
	<description>Zen Cart Optimization, Performance and A/B Split Testing Modules for Zen Cart</description>
	<lastBuildDate>Mon, 24 May 2010 18:56:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Speed up admin/orders.php page</title>
		<link>http://www.data-diggers.com/index.php/2009/06/speed-up-adminorders-php-page/</link>
		<comments>http://www.data-diggers.com/index.php/2009/06/speed-up-adminorders-php-page/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 05:38:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[Zen Cart]]></category>

		<guid isPermaLink="false">http://www.data-diggers.eu/?p=62</guid>
		<description><![CDATA[
			
				
			
		
There&#8217;s suboptimal query in admin/orders.php page which retrieves information about last orders. Unfortunately query is constructed in such way that MySQL scans whole orders, orders_products and orders_total table. As always it&#8217;s not a problem until orders table gets big ( for example 50 000 entries ). If You happen to have at least 10 000 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.data-diggers.com%2Findex.php%2F2009%2F06%2Fspeed-up-adminorders-php-page%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.data-diggers.com%2Findex.php%2F2009%2F06%2Fspeed-up-adminorders-php-page%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">There&#8217;s suboptimal query in admin/orders.php page which retrieves information about last orders. Unfortunately query is constructed in such way that MySQL scans whole orders, orders_products and orders_total table. As always it&#8217;s not a problem until orders table gets big ( for example 50 000 entries ). If You happen to have at least 10 000 orders ( I wish You that <img src='http://www.data-diggers.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ), You probably get impatient each time You request admin/orders.php page.</p>
<p style="text-align: justify;">Good news is that there is quick fix. Just add index on (orders_id, class) on orders_total table to speed up the query. Here&#8217;s MySQL statement which does that for You:</p>
<div style="text-align: justify;">
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;"><span class="kw1">ALTER</span> <span class="kw1">TABLE</span> orders_total <span class="kw1">ADD</span> <span class="kw1">INDEX</span> idx_oid_class<span class="br0">&#40;</span>orders_id<span class="sy0">,</span> class<span class="br0">&#41;</span></div>
</div>
</div>
<p style="text-align: justify;">The query is still suboptimal, but at least its quite fast until orders table gets really big (500 000 orders? It&#8217;ll depend on Your server).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.data-diggers.com/index.php/2009/06/speed-up-adminorders-php-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speed up &#8216;Order history&#8217; query by 50%-75%</title>
		<link>http://www.data-diggers.com/index.php/2009/06/speed-up-order-history-query-by-50-75/</link>
		<comments>http://www.data-diggers.com/index.php/2009/06/speed-up-order-history-query-by-50-75/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 14:46:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[Zen Cart]]></category>

		<guid isPermaLink="false">http://www.data-diggers.eu/?p=49</guid>
		<description><![CDATA[
			
				
			
		
I noticed that following query takes long time to execute:


SELECT DISTINCT op.products_id
FROM orders o, orders_products op, products p
WHERE o.customers_id = &#8216;2345&#8242;
AND o.orders_id = op.orders_id
AND op.products_id = p.products_id
AND p.products_status = &#8216;1&#8242;
GROUP BY products_id
ORDER BY o.date_purchased DESC
LIMIT 6


I noticed that there&#8217;s no index on orders table on customers_id field. Without it MySQL has to scan whole table [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.data-diggers.com%2Findex.php%2F2009%2F06%2Fspeed-up-order-history-query-by-50-75%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.data-diggers.com%2Findex.php%2F2009%2F06%2Fspeed-up-order-history-query-by-50-75%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">I noticed that following query takes long time to execute:</p>
<div style="text-align: justify;">
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;"><span class="kw1">SELECT</span> <span class="kw1">DISTINCT</span> op<span class="sy0">.</span>products_id<br />
<span class="kw1">FROM</span> orders o<span class="sy0">,</span> orders_products op<span class="sy0">,</span> products p<br />
<span class="kw1">WHERE</span> o<span class="sy0">.</span>customers_id <span class="sy0">=</span> <span class="st0">&#8216;2345&#8242;</span><br />
<span class="kw1">AND</span> o<span class="sy0">.</span>orders_id <span class="sy0">=</span> op<span class="sy0">.</span>orders_id<br />
<span class="kw1">AND</span> op<span class="sy0">.</span>products_id <span class="sy0">=</span> p<span class="sy0">.</span>products_id<br />
<span class="kw1">AND</span> p<span class="sy0">.</span>products_status <span class="sy0">=</span> <span class="st0">&#8216;1&#8242;</span><br />
<span class="kw1">GROUP</span> <span class="kw1">BY</span> products_id<br />
<span class="kw1">ORDER</span> <span class="kw1">BY</span> o<span class="sy0">.</span>date_purchased <span class="kw1">DESC</span><br />
<span class="kw1">LIMIT</span> <span class="nu0">6</span></div>
</div>
</div>
<p style="text-align: justify;">I noticed that there&#8217;s no index on <strong>orders </strong>table on <strong><em>customers_id</em></strong> field. Without it MySQL has to scan whole table to find orders by <strong><em>customers_id</em></strong><em> </em>(in this case &#8216;2345&#8242;). If <strong>orders </strong>table is small there&#8217;s no problem, but when it has 10 000 or more entries it can noticably slow down Zen Cart. So, let&#8217;s add index on that table</p>
<div style="text-align: justify;">
<div class="codesnip-container" >
<div class="sql codesnip" style="font-family:monospace;"><span class="kw1">ALTER</span> <span class="kw1">TABLE</span> <span class="st0">`orders`</span> <span class="kw1">ADD</span> <span class="kw1">INDEX</span> <span class="st0">`idx_cid_datepurchased`</span><span class="br0">&#40;</span><span class="st0">`customers_id`</span><span class="sy0">,</span> <span class="st0">`date_purchased`</span><span class="br0">&#41;</span>;</div>
</div>
</div>
<p style="text-align: justify;">I included <strong><em>date_purchased</em></strong> in index, because some pages in admin area will use it for searching all orders of given customer.</p>
<p style="text-align: justify;">In my case it decreased query time from 0.3 sec to 0.08 sec. It&#8217;s still too much, but it&#8217;s better then nothing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.data-diggers.com/index.php/2009/06/speed-up-order-history-query-by-50-75/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
