<?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>nerdboy.co.uk &#187; sql</title>
	<atom:link href="http://www.nerdboy.co.uk/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nerdboy.co.uk</link>
	<description>nerdboy blog - web development stuff</description>
	<lastBuildDate>Thu, 03 Jun 2010 10:17:07 +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 and the Art of Sql</title>
		<link>http://www.nerdboy.co.uk/2009/07/mysql-and-the-art-of-sql/</link>
		<comments>http://www.nerdboy.co.uk/2009/07/mysql-and-the-art-of-sql/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 09:48:15 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[MySql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=122</guid>
		<description><![CDATA[I&#8217;ve been reading the The Art of SQL and it makes some very sensible suggestions regarding query performance. Here&#8217;s somewhere I&#8217;ve implemented 1 of the techniques. The task: return records for this month. Usually I&#8217;d write something like select * from results where month(dateadded) = month(now()) and year(dateadded) = year(now()) The problem with this is that [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been reading the <a href="http://www.amazon.co.uk/gp/product/0596008945?ie=UTF8&amp;tag=classicwarfil-21&amp;linkCode=as2&amp;camp=1634&amp;creative=6738&amp;creativeASIN=0596008945">The Art of SQL</a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.co.uk/e/ir?t=classicwarfil-21&amp;l=as2&amp;o=2&amp;a=0596008945" border="0" alt="" width="1" height="1" /> and it makes some very sensible suggestions regarding query performance.</p>
<p>Here&#8217;s somewhere I&#8217;ve implemented 1 of the techniques.</p>
<p>The task: return records for this month.</p>
<p>Usually I&#8217;d write something like</p>
<pre class="brush: sql;">select * from results where month(dateadded) = month(now()) and year(dateadded) = year(now())</pre>
<p>The problem with this is that 2 functions (month() and year()) need to be applied to every row to filter the results, this obviously requires overhead.  Also we&#8217;re missing out on any indexes that might be on the dateadded field.</p>
<p>A better approach is to use</p>
<pre class="brush: sql;">select * from results where dateadded &gt;= DATE_FORMAT(now() ,'%Y-%m-01')</pre>
<p>With this approach 1 function is run to find the first day of the month, and if the dateadded field is indexed we&#8217;ll benefit from this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2009/07/mysql-and-the-art-of-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
