<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>CounterMarch Systems Blog - databases</title>
			<link>http://www.countermarch.com/blog/index.cfm</link>
			<description>CounterMarch Systems is a software consulting firm specializing in Adobe technologies</description>
			<language>en-us</language>
			<pubDate>Tue, 07 Sep 2010 00:15:39 -0400</pubDate>
			<lastBuildDate>Thu, 28 Feb 2008 17:15:00 -0400</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>helpdesk@countermarch.com</managingEditor>
			<webMaster>helpdesk@countermarch.com</webMaster>
			
			<item>
				<title>SQL Profiler</title>
				<link>http://www.countermarch.com/blog/index.cfm/2008/2/28/SQL-Profiler</link>
				<description>
				
				&lt;p&gt;The absolute simplest thing you can do to save considerable time debugging your database-driven applications is start up SQL Profiler.&lt;/p&gt;

&lt;p&gt;I&apos;ll admit. I didn&apos;t even realize this existed until several years ago at CFUNITED when &lt;a href=&quot;http://www.carehart.org&quot;&gt;Charlie Arehart&lt;/a&gt; gave a presentation that somehow moved on to showing us the profiler.  I can&apos;t pick out which one of his &lt;a href=&quot;http://www.carehart.org/presentations.cfm&quot;&gt;many great presentations&lt;/a&gt; it was. but what a fortunate turn of events to have been in that room at the time!&lt;/p&gt;

&lt;p&gt;I&apos;ve found this to be most useful in our Ajax applications - situations where we would traditionally use a brute force CFDUMP to see what&apos;s going in to the db aren&apos;t always possible.  Hacking up your code to write the sql to a file or email is nasty and time consuming.  Why not just watch the wire instead? Here&apos;s how that&apos;s done:&lt;/p&gt;

&lt;p&gt;Let&apos;s start from square one.  Start-&gt;All Programs-&gt;Microsoft SQL Server -&gt; Profiler.&lt;/p&gt;

&lt;p&gt;Select &quot;New Trace&quot; from the dropdown menu or the leftmost icon on the toolbar. Connect to your desired database server.  In my case. I&apos;m using localhost and windows credentials.  YMMV.&lt;/p&gt;

&lt;img src=&quot;http://www.countermarch.com/blog/images//sqlprofile1.jpg&quot;&gt;
&lt;br /&gt;

&lt;p&gt;The next screen is the most important one: what do you want to see in the log?  The names are terrible and don&apos;t say enough.  Let&apos;s over-simplify for a moment and pick the &lt;strong&gt;SQLProfilerTSQL_SPs&lt;/strong&gt; template.  To be honest. this is the only one I have used so far.&lt;/p&gt;

&lt;img src=&quot;http://www.countermarch.com/blog/images//sqlprofile21.jpg&quot;&gt;
&lt;br /&gt;

&lt;p&gt;Don&apos;t do anything else - just hit &quot;Run&quot;.  You&apos;ll see some startup messages and what not.  Ignore them.&lt;/p&gt;

&lt;img src=&quot;http://www.countermarch.com/blog/images//sqlprofile3.jpg&quot;&gt;

&lt;br /&gt;
&lt;p&gt;Run a quick template on your site.  Not too much - you&apos;ll quickly overwhelm yourself (Ctrl-Shift-Del to clear the trace window).  You&apos;ll see stuff like this:&lt;/p&gt;

&lt;img src=&quot;http://www.countermarch.com/blog/images//sqlprofile4.jpg&quot;&gt;

&lt;br /&gt;

&lt;p&gt;Here&apos;s how you piece that together: the &quot;exec sp_execute...&quot; line is the params being passed in to the SQL statement defined on the following line (UPDATE. SELECT. whatever).  At that point it becomes trivially easy to stitch it back together and see what&apos;s going on.&lt;/p&gt;

&lt;p&gt;Of course. there&apos;s FAR more to profiler than this dinky little example. but in terms of getting started without messing with your code it can&apos;t be beat.  Use it to check security. run performance tests. log a problematic long-running query or simply get around having to touch your code for debugging.  If you find a particularly good resource for learning more about profiler. post it here in comments.&lt;/p&gt; 
				</description>
				
				<category>databases</category>				
				
				<pubDate>Thu, 28 Feb 2008 17:15:00 -0400</pubDate>
				<guid>http://www.countermarch.com/blog/index.cfm/2008/2/28/SQL-Profiler</guid>
				
			</item>
			
			<item>
				<title>Oracle query performance</title>
				<link>http://www.countermarch.com/blog/index.cfm/2007/4/24/Oracle-query-performance</link>
				<description>
				
				*sigh*

Another performance bottleneck to investigate...

&lt;code&gt;
getMyStuff (Datasource=*******. Time=103309ms. Records=14) 
&lt;/code&gt;

Thanks. Oracle.  Thanks a whole lot. 
				</description>
				
				<category>databases</category>				
				
				<pubDate>Tue, 24 Apr 2007 20:04:00 -0400</pubDate>
				<guid>http://www.countermarch.com/blog/index.cfm/2007/4/24/Oracle-query-performance</guid>
				
			</item>
			
			<item>
				<title>SQL Server Index Tuning Wizard</title>
				<link>http://www.countermarch.com/blog/index.cfm/2007/1/22/SQL-Server-Index-Tuning-Wizard</link>
				<description>
				
				We were doing a little bit of experimenting in the labs today with large SQL datasets and complex nested queries.  We&apos;re talking about 1.5 million rows of data in our primary source table. a few blocks of subselects in the query...

Running it straight up as a CFQUERY using CFQUERYPARAM we were seeing about 7 second response times.  Eh. not good enough.

Took the code. dropped it in a stored procedure...same result.

So we told Query Analyzer to show us the Execution Plan.  Saw about 80% of the cost was a series of index scans - typical. not a big deal. but I figured we could tweak the indexes a bit.  We added a couple extra ones manually but that actually increased response times from 7 to about 10 seconds.  Oops!

It was at this moment we figured we&apos;d see what happened when we let Microsoft drive.  There&apos;s an option on the toolbar for the Index Tuning Wizard.  We set it to run using the stored proc as the workload to be tuned.  A few seconds later it reported it was done with an estimated 99% improvement.  Yeah. right!

Imagine our surprise when running that proc was returning data in less than 1 second!

More experimenting will be done with other queries.  The hope is that we didn&apos;t kill performance for the rest of the (mostly unwritten) application just to meet this one need.  Either way. we&apos;re pleasantly surprised with how well this worked out.

Just goes to show you that we as developers have a LOT to benefit by learning more about proper database tuning.  I know we&apos;ve barely scratched the surface.  There&apos;s a reason a good DBA makes a lot of money! 
				</description>
				
				<category>databases</category>				
				
				<pubDate>Mon, 22 Jan 2007 22:11:00 -0400</pubDate>
				<guid>http://www.countermarch.com/blog/index.cfm/2007/1/22/SQL-Server-Index-Tuning-Wizard</guid>
				
			</item>
			
			<item>
				<title>SQL Fun</title>
				<link>http://www.countermarch.com/blog/index.cfm/2005/11/29/SQL-Fun</link>
				<description>
				
				Ever have one of those problems that you just *know* could be solved in one very clever (and not overly complicated) SQL statement?  Ever realize you&apos;re just not seeing it and as a result trying to write a ton of code to do the same thing?

I know there&apos;s a join of some sort that would make this data transfer thing pretty darn simple to do.  I just can&apos;t see it right now.  Guess I know what i&apos;ll be dreaming about tonight... 
				</description>
				
				<category>databases</category>				
				
				<pubDate>Tue, 29 Nov 2005 03:26:00 -0400</pubDate>
				<guid>http://www.countermarch.com/blog/index.cfm/2005/11/29/SQL-Fun</guid>
				
			</item>
			</channel></rss>