<?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>Web Development&#187; SQL</title>
	<atom:link href="http://webdevelopment.kerryjones.net/c/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://webdevelopment.kerryjones.net</link>
	<description>Web Development Tips &#38; Tricks, the things that you don't want to figure out.</description>
	<lastBuildDate>Wed, 05 Aug 2009 17:03:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MySQL INNER JOIN &#8211; A Real Time Saver</title>
		<link>http://webdevelopment.kerryjones.net/web-development/mysql-inner-join-a-real-time-saver/</link>
		<comments>http://webdevelopment.kerryjones.net/web-development/mysql-inner-join-a-real-time-saver/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 00:28:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[time saver]]></category>

		<guid isPermaLink="false">http://webdevelopment.kerryjones.net/?p=75</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><img src="http://webdevelopment.kerryjones.net/wp-content/uploads/2009/01/mysql_logo.jpg" alt="MySQL" width="230" height="117" align="left" style="padding-right: 10px;" />Ok, so the story behind this post is one of my sites, <a title="SendArticles.com Article Submission" href="http://www.sendarticles.com/">SendArticles.com</a>. It is an article submission service, and one page, the reports page, was taking 10-15 second to load. I cannot stand waiting that long, it makes me not want to go to the page, yet I have to all the time. This is a dedicated server and it was nowhere near its max capacity, so I knew it had to be something else.</p>
<p>So, I decided to debug it. I removed a small piece of code, and BAM! Loaded in about half a second. I was confused, I put the code back in. 10-15 second delay was back. Ok, that was definitely it. So, it came down to a SQL (despite technically using MySQL, I&#8217;m just going to refer to it as the code is the same) query, which was essentially the following:<br />
<fieldset>
<legend>SQL</legend>
<p>SELECT col FROM table WHERE col2 IN (SELECT col2 FROM table2 WHERE col3 = XX AND col4 = XX)<br />
</fieldset>
<p>
I apologize for the anonymity, but I do feel it&#8217;s necessary. Anyway, the main essence of the statement was that it was making a column (col2) match what another SELECT statement found. So, I decided to replace it with an INNER JOIN (I wasn&#8217;t in the practice of using them when I first wrote the code).</p>
<fieldset>
<legend>SQL</legend>
<p>SELECT a.col FROM table AS a INNER JOIN table2 AS b ON (a.col2 = b.col2) WHERE b.col3 = XX AND b.col4 = XX</fieldset>
<p>
It produces the exact same results, but in about half a second. Almost no time at all, just instant results. So, I&#8217;ve resolved to go through every SQL statement in the hundreds of pages of files (luckily nearly all of them are contained in a handful of classes), and change any SQL IN statements to INNER JOIN.</p>
<p>Hope this helped,</p>
<p>Kerry</p>
]]></content:encoded>
			<wfw:commentRss>http://webdevelopment.kerryjones.net/web-development/mysql-inner-join-a-real-time-saver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

