<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Optimize this?</title>
	<atom:link href="http://blog.xcski.com/2008/04/13/optimize-this/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.xcski.com/2008/04/13/optimize-this</link>
	<description>Everything I used to bore people on newsgroups and mailing lists with, now in one inconvenient place.</description>
	<pubDate>Fri, 22 Aug 2008 00:39:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Joe D</title>
		<link>http://blog.xcski.com/2008/04/13/optimize-this#comment-85641</link>
		<dc:creator>Joe D</dc:creator>
		<pubDate>Mon, 14 Apr 2008 03:40:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xcski.com/?p=1321#comment-85641</guid>
		<description>No idea if this will have any effect, but try changing that "a.type in (blah)" to "b.type in (blah)".</description>
		<content:encoded><![CDATA[<p>No idea if this will have any effect, but try changing that &#8220;a.type in (blah)&#8221; to &#8220;b.type in (blah)&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: richard</title>
		<link>http://blog.xcski.com/2008/04/13/optimize-this#comment-85637</link>
		<dc:creator>richard</dc:creator>
		<pubDate>Sun, 13 Apr 2008 23:18:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xcski.com/?p=1321#comment-85637</guid>
		<description>yes, as soon as you apply a function to a column in (most) databases you will force a tablescan. The inequality may also force a tablescan. I think the way around this is to precompute the column (i.e. have a column whose value is 1 if ((chart_map &#38; 7) != 0) ). (Oracle, at least, allows function indexes). I don't know which parts of the query are constants, and which parts are inputs, so that's my best suggestion for now. If this column really is a bitmap, think about exploding it into separate columns of type char(1).

The other thing to be aware of is that if you're going to hit multiple indexes with your comparators then the optimizer may also decide that it's faster to simply do a tablescan because hitting multiple indexes, and merging the results is slower than accessing the base data.

On a point of style you should always qualify which table the columns come from; you might know that category is in b and chart_map is in a, but the programmer that comes after you might not (and by creating a column of the same name in one of the other tables will break your code without even touching it).

final thought... if some of the comparators radically restrict the data set, then you might try using subselects.</description>
		<content:encoded><![CDATA[<p>yes, as soon as you apply a function to a column in (most) databases you will force a tablescan. The inequality may also force a tablescan. I think the way around this is to precompute the column (i.e. have a column whose value is 1 if ((chart_map &amp; 7) != 0) ). (Oracle, at least, allows function indexes). I don&#8217;t know which parts of the query are constants, and which parts are inputs, so that&#8217;s my best suggestion for now. If this column really is a bitmap, think about exploding it into separate columns of type char(1).</p>
<p>The other thing to be aware of is that if you&#8217;re going to hit multiple indexes with your comparators then the optimizer may also decide that it&#8217;s faster to simply do a tablescan because hitting multiple indexes, and merging the results is slower than accessing the base data.</p>
<p>On a point of style you should always qualify which table the columns come from; you might know that category is in b and chart_map is in a, but the programmer that comes after you might not (and by creating a column of the same name in one of the other tables will break your code without even touching it).</p>
<p>final thought&#8230; if some of the comparators radically restrict the data set, then you might try using subselects.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
