<?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>Joseph Piché &#187; optimization</title>
	<atom:link href="http://jpiche.com/tags/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://jpiche.com</link>
	<description>Web development professional with expertise in PHP, MySQL query optimization, Ajax, and XHTML</description>
	<lastBuildDate>Tue, 20 Jul 2010 04:04:51 +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>The Importance of EXPLAIN and SQL_NO_CACHE in Query Development</title>
		<link>http://jpiche.com/2009/10/the-importance-of-explain-and-sql_no_cache-in-query-development/</link>
		<comments>http://jpiche.com/2009/10/the-importance-of-explain-and-sql_no_cache-in-query-development/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 04:17:15 +0000</pubDate>
		<dc:creator>Joseph Piché</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[query]]></category>

		<guid isPermaLink="false">http://jpiche.com/?p=299</guid>
		<description><![CDATA[On average, I guess 35% of my over time at work involves MySQL query building, optimizing and re-writing. I find it an enjoyable challenge, and recently I re-worked an existing framework for a new site which put my focus almost solely on SQL, queries, and the schema.
With a normalized database schema, SQL optimization tends to [...]]]></description>
			<content:encoded><![CDATA[<p>On average, I guess 35% of my over time at work involves MySQL query building, optimizing and re-writing. I find it an enjoyable challenge, and recently I re-worked an existing framework for a new site which put my focus almost solely on SQL, queries, and the schema.</p>
<p>With a normalized database schema, SQL optimization tends to focus on aspects outside the query, like making sure indexes get put in the currect locations. But I happen to be stuck with large and slightly-non-normalized tables. So, in order to write queries against these tables for a site that averages 30k hits per month, I need to be able to see what MySQL is doing with each query. For this I would be lost without <code><a href="http://dev.mysql.com/doc/refman/5.1/en/using-explain.html">EXPLAIN</a></code> and <code><a href="http://dev.mysql.com/doc/refman/5.1/en/query-cache-in-select.html">SQL_NO_CACHE</a></code>.</p>
<p>I don&rsquo;t like writing tutorials, and I don&#8217;t really have time. But I love linking to <a href="http://dev.mysql.com/doc/">great documentation</a>. Most of what I know about MySQL I learned from their documentation, and I encourage even experienced query writers to make sure they know the importance of testing query times with <code>SQL_NO_CACHE</code> or using a development environment with caching completely disabled. When it comes to web applications, even microseconds can hurt in the long run.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpiche.com/2009/10/the-importance-of-explain-and-sql_no_cache-in-query-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Page Load Times Are Very Important</title>
		<link>http://jpiche.com/2009/08/page-load-times-are-very-important/</link>
		<comments>http://jpiche.com/2009/08/page-load-times-are-very-important/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 19:00:43 +0000</pubDate>
		<dc:creator>Joseph Piché</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[pageload]]></category>
		<category><![CDATA[remember-the-users]]></category>

		<guid isPermaLink="false">http://jpiche.com/?p=223</guid>
		<description><![CDATA[We&#8217;ve progressed pretty far since 56k dial-up days; no more waiting for pages to load in order to access information, almost everything is immediately accessible via multi-megabyte per second internet connections. But we would be naive to think that there have not been growing pains. In the IT industry, high turnover is both frequent and [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve progressed pretty far since 56k dial-up days; no more waiting for pages to load in order to access information, almost everything is immediately accessible via multi-megabyte per second internet connections. But we would be naive to think that there have not been growing pains. In the IT industry, high turnover is both frequent and expected due to the constantly changing environment. (The exception is highly specialized fields.) Improving technologies changes the needs of the people and their expectations.</p>
<p>Reading <a href="http://www.percona.com/">Percona</a>&#8217;s Web Scaling Blog, I saw a page on <a href="http://www.webscalingblog.com/front-end-performance">Front End Performance</a> which outlined why web developers need to be conscious of users.</p>
<blockquote><p>Web Site Speed Affects your bottom line. [...] Amazon&rsquo;s experiment: Slowing pages by 100ms decreased sales by 1%</p>
</blockquote>
<p>Highly-available internet access shifted our needs to security and privacy, but now we expect websites to be uber-fast. As a web developer, I need to listen to the needs of the user. The studies presented here show that those who do not develop sites up to user expectations will not get the traffic and revenue they desire.</p>
<p>This argument is very similar to the business scenario of the credit card purchase. Using a credit card is convenient to users, and even though it presents cost to a business to accept credit card purchases, if they do not accept them, they will lose business because customers expect it. Also, if a business abuses the power of the credit card by throwing in additional charges that are unnecessary (or unethical) customers will either not make purchases or not return for additional business.</p>
<p>So while producing a high-performance website&mdash;or trimming an existing one&mdash;may be costly, it is an important gesture, and will probably pay off.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpiche.com/2009/08/page-load-times-are-very-important/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;New&#8221; MySQL features</title>
		<link>http://jpiche.com/2009/08/new-mysql-features/</link>
		<comments>http://jpiche.com/2009/08/new-mysql-features/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 06:34:47 +0000</pubDate>
		<dc:creator>Joseph Piché</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://jpiche.com/?p=173</guid>
		<description><![CDATA[The more I use MySQL, the more I love it. I recently reviewed documentation for triggers when I ran into a pickle that needed to be solved in a short amount of time: ordering a query by TIMESTAMP.
I had a table with approx. 70k rows which had data continually inserted into it via cron job. [...]]]></description>
			<content:encoded><![CDATA[<p>The more I use MySQL, the more I love it. I recently reviewed documentation for <a href="http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html">triggers</a> when I ran into a pickle that needed to be solved in a short amount of time: ordering a query by <code>TIMESTAMP</code>.</p>
<p>I had a table with approx. 70k rows which had data continually inserted into it via cron job. I needed to query this table for the most recently inserted data given certain values. After re-organizing indexes and converting the table to <a href="http://en.wikipedia.org/wiki/InnoDB">InnoDB</a> from <a href="http://en.wikipedia.org/wiki/MyISAM">MyISAM</a> I was about to give up since (surprisingly) none of it gave any real improvement. The fundamental part of this query (the subquery in the <code>SELECT</code> expression which was ran over and over) was taking on average 0.022 seconds when ordering by a <code>TIMESTAMP</code> field which was automatically inserted by MySQL. When I used <code>ORDER BY UNIX_TIMESTAMP(`field`) DESC LIMIT 1</code> instead, the query took 0.001 seconds on average. Since I didn&#8217;t wan&#8217;t MySQL converting it every time (really I don&#8217;t know what it does with times internally), I looked up some documentation and saw triggers. It saved my query and the table. I was able to make an additional integer field in the table and set a trigger on insert that did the conversion and stored the unix timestamp in the new field, then I could query the new unix timestamp field all I want and speed up this query even more.</p>
<p>It was an epiphany. Suddenly I saw SQL problems under a different light. I was even able to solve another complex problem by creating an <a href="http://dev.mysql.com/doc/refman/5.1/en/create-event.html">event</a> which would build rebuild a <code>VIEW</code> every hour. It was awesome until I discovered the production MySQL server was running 5.0 which doesn&#8217;t have events and I suspect handles <code>VIEW</code>s much more poorly than 5.1 which I was running locally. Of course I have no control over this server, and it handles uber-important data, so there is absolutely nothing I can do about it. So unfortunately I had to go back to the drawing board with that one.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpiche.com/2009/08/new-mysql-features/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Static vs Generated HTML and Content-Length</title>
		<link>http://jpiche.com/2009/07/static-vs-generated-html-and-content-length/</link>
		<comments>http://jpiche.com/2009/07/static-vs-generated-html-and-content-length/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 14:55:39 +0000</pubDate>
		<dc:creator>Joseph Piché</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://jpiche.com/?p=151</guid>
		<description><![CDATA[A frustrating aspect of writing in PHP is that almost all HTML is generated from PHP and is offered to the client after some processing is done. Under Ideal conditions, the amount of processing would be minimal, but in the case of the code I am currently working on at my job, it is not. [...]]]></description>
			<content:encoded><![CDATA[<p>A frustrating aspect of writing in PHP is that almost all HTML is generated from PHP and is offered to the client after some processing is done. Under Ideal conditions, the amount of processing would be minimal, but in the case of the code I am currently working on at my job, it is not. I believe the root of the problem though is probably something most professional PHP programmers experience: the code they are working on is apart of a collaboration and being under a tight schedule, they cannot afford the resources to change what they would like.</p>
<p>The answer I most often get is &#8220;since it already works, let&#8217;s focus on something else.&#8221; With static HTML files on the server, apache can easily send the Content-Length, but even with PHP generated HTML, I could store all HTML in variables, then calculate the size and use apache&#8217;s Content-Length header to speed up page load times. Time is a valuable resource though, and being a good employee, I&#8217;m gonna (try to) do what I&#8217;m told.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpiche.com/2009/07/static-vs-generated-html-and-content-length/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using LIMIT</title>
		<link>http://jpiche.com/2009/04/using-limit/</link>
		<comments>http://jpiche.com/2009/04/using-limit/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 18:08:37 +0000</pubDate>
		<dc:creator>Joseph Piché</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://jpiche.com/?p=35</guid>
		<description><![CDATA[The last couple weeks I&#8217;ve had to focus on building and optimizing MySQL select statements. It&#8217;s been an interesting journey as I&#8217;ve learned about choosing optimal field types when building tables, when to use a subquery over a left join, and how to use the information procedure analyse() gives. But the one thing I did [...]]]></description>
			<content:encoded><![CDATA[<p>The last couple weeks I&#8217;ve had to focus on building and optimizing MySQL <code>select</code> statements. It&#8217;s been an interesting journey as I&#8217;ve learned about choosing optimal field types when building tables, when to use a subquery over a left join, and how to use the information <code>procedure analyse()</code> gives. But the one thing I did not expect was the extreme performance increase LIMIT gives when used appropriately. Looking back, I should have guessed it, since when you limit a query to only retrieving a specified amount of rows instead of an indefinite amount, MySQL has to do a lot less work.</p>
<p>Today&#8217;s challenge though is a little different; I&#8217;m working with an existing table which has text fields as indexes along with integer indexes and primary key. This quarter million row table needs to be checked against for data, but I am only able to check against indexes on <code>varchar(80)</code> fields and not unique keys, so those queries are running orders of magnitude slower than the others. Unfortunately, this data is used in many other locations, so I am not able to do anything with it right now.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpiche.com/2009/04/using-limit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
