<?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; mysql</title>
	<atom:link href="http://jpiche.com/tags/mysql/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>Dreamhost and MySQL</title>
		<link>http://jpiche.com/2009/11/dreamhost-and-mysql/</link>
		<comments>http://jpiche.com/2009/11/dreamhost-and-mysql/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 21:02:44 +0000</pubDate>
		<dc:creator>Joseph Piché</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://jpiche.com/?p=353</guid>
		<description><![CDATA[At the company I work for, any amount of downtime on a website means we lose money, no exceptions. We run thousands of websites off just 6 or 7 severs and each of our popular sites get thousands of visits per day on average. This is easily accomplished by using dedicated servers and having a [...]]]></description>
			<content:encoded><![CDATA[<p>At the company I work for, any amount of downtime on a website means we lose money, no exceptions. We run thousands of websites off just 6 or 7 severs and each of our popular sites get thousands of visits per day on average. This is easily accomplished by using dedicated servers and having a simple master-slave MySQL setup with writes only going to the master. Of course we went with a really cheap stupid company and absolutely no support, but we control our servers, so its all good.</p>
<p>For my personal sites, I do not have the luxury of having a dedicated sever; instead I use Dreamhost. Support at Dreamhost is phenomenal&mdash;I could not ask for anything better. But I feel ripped-off by their actual service. Using shared hosting is always a gamble, and not in an exciting way like Casino.com (<a href="http://www.casino.com/">http://www.casino.com/</a>), but Dreamhost goes one further. Web servers are physically separated from database servers.</p>
<p>From the perspective of a System Admin, separating web from DB is a great idea. Web servers need different setups than database servers, and management would be much easier with them separate. However, the web developer perspective looks at processing time more than anything else, and unless a network is setup to be super fast, latency is going to be killer. But since this is a respectable web hosting company I would not expect anything less.</p>
<p>So, assuming they know what they are doing, the only other explanation for why my page processing time is seconds instead of tenths of seconds is that server load is terrible, once again pointing to inadequacy of service.</p>
<p>Even so, I stay with them if nothing else because they are the cheapest web host to provide SSH access and the flexibility to use PHP, Python or whatever I want.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpiche.com/2009/11/dreamhost-and-mysql/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<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>&#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>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>
