<?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>Jeremy Smyth's Blog &#187; Nulls</title>
	<atom:link href="http://jeremysmyth.com/tag/nulls/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeremysmyth.com</link>
	<description></description>
	<lastBuildDate>Tue, 10 Aug 2010 12:07:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SQL: Why nulls slow down some queries</title>
		<link>http://jeremysmyth.com/2009/06/19/sql-why-nulls-slow-down-some-queries/</link>
		<comments>http://jeremysmyth.com/2009/06/19/sql-why-nulls-slow-down-some-queries/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 21:56:46 +0000</pubDate>
		<dc:creator>Jeremy Smyth</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[Nulls]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://jeremysmyth.com/?p=32</guid>
		<description><![CDATA[Someone asked a question on StackOverflow today about why null values slow down certain queries. This is roughly what I answered.
The main issue with null values and performance is to do with forward lookups.
If you insert a row into a table, with null values, it&#8217;s placed in the natural page that it belongs to. Any [...]]]></description>
			<content:encoded><![CDATA[<p>Someone asked a question on StackOverflow today about why null values slow down certain queries. This is roughly what I answered.</p>
<p>The main issue with null values and performance is to do with forward lookups.</p>
<p>If you insert a row into a table, with null values, it&#8217;s placed in the natural page that it belongs to. Any query looking for that record will find it in the appropriate place. Easy so far&#8230;.</p>
<p>&#8230;but let&#8217;s say the page fills up, and now that row is cuddled in amongst the other rows. Still going well&#8230;</p>
<p>&#8230;until the row is updated, and the null value now contains something. The row&#8217;s size has increased beyond the space available to it, so the DB engine has to do something about it.</p>
<p>The fastest thing for the server to do is to move the row off that page into another, and to replace the row&#8217;s entry with a forward pointer. Unfortunately, this requires an extra lookup when a query is performed: one to find the natural location of the row, and one to find its current location.</p>
<p>So, the short answer to the question of performance is yes, making those fields non-nullable will help search performance. This is especially true if it often happens that the null fields in records you search on are updated to non-null.</p>
<p>Of course, there are other penalties (notably I/O, although to a tiny extent index depth) associated with larger datasets, and then you have application issues with disallowing nulls in fields that conceptually require them, but hey, that&#8217;s another problem!</p>
]]></content:encoded>
			<wfw:commentRss>http://jeremysmyth.com/2009/06/19/sql-why-nulls-slow-down-some-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
