<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>in Chris Velazquez's words... - database</title>
    <link>http://www.chrisvelazquez.com/blog/</link>
    <description>a blog fertilized by my mental droppings</description>
    <language>en-us</language>
    <copyright>Christopher S. Velazquez</copyright>
    <lastBuildDate>Mon, 26 Feb 2007 15:43:05 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>chris@chrisvelazquez.com</managingEditor>
    <webMaster>chris@chrisvelazquez.com</webMaster>
    <item>
      <trackback:ping>http://www.chrisvelazquez.com/blog/Trackback.aspx?guid=534833ac-2fde-4f22-b4ed-740a83762c2b</trackback:ping>
      <pingback:server>http://www.chrisvelazquez.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisvelazquez.com/blog/PermaLink,guid,534833ac-2fde-4f22-b4ed-740a83762c2b.aspx</pingback:target>
      <dc:creator>Chris V.</dc:creator>
      <wfw:comment>http://www.chrisvelazquez.com/blog/CommentView,guid,534833ac-2fde-4f22-b4ed-740a83762c2b.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisvelazquez.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=534833ac-2fde-4f22-b4ed-740a83762c2b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Curious as it sounds, Microsoft's open source lab has published an article on <a href="http://port25.technet.com/archive/2007/02/22/postgresql-on-windows-a-primer.aspx">how
to install and configure PostgreSQL on a Windows Server system</a>.  This
is very interesting, considering how PostgreSQL can be considered a competitor to
Microsoft's own SQL Server 2005.
</p>
        <p>
For those of you not familiar with <a href="http://www.postgresql.org/">PostgreSQL</a>,
it is an open-source, industrial-strength relational database with most of the features
you'd find in a mature database server.  It has triggers, stored procedures and
views, and can handle a variety of stored procedure languages, including Java, PHP
and Ruby.  On the client side, PostgreSQL ships with both OLEDB and a .NET data
providers.  One of the fascinating features of PostgreSQL is its ability
to have inherited tables.  I can see where this could dovetail with OR mappings
for subclasses.
</p>
        <img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=534833ac-2fde-4f22-b4ed-740a83762c2b" />
      </body>
      <title>Microsoft publishes PostgreSQL how-to</title>
      <guid isPermaLink="false">http://www.chrisvelazquez.com/blog/PermaLink,guid,534833ac-2fde-4f22-b4ed-740a83762c2b.aspx</guid>
      <link>http://www.chrisvelazquez.com/blog/PermaLink,guid,534833ac-2fde-4f22-b4ed-740a83762c2b.aspx</link>
      <pubDate>Mon, 26 Feb 2007 15:43:05 GMT</pubDate>
      <description>&lt;p&gt;
Curious as it sounds, Microsoft's open source lab has published an article on &lt;a href="http://port25.technet.com/archive/2007/02/22/postgresql-on-windows-a-primer.aspx"&gt;how
to install&amp;nbsp;and configure PostgreSQL on a Windows Server system&lt;/a&gt;.&amp;nbsp; This
is very interesting, considering how PostgreSQL can be considered a competitor to
Microsoft's own SQL Server 2005.
&lt;/p&gt;
&lt;p&gt;
For those of you not familiar with &lt;a href="http://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt;,
it is an open-source, industrial-strength relational database with most of the features
you'd find in a mature database server.&amp;nbsp; It has triggers, stored procedures and
views, and can handle a variety of stored procedure languages, including Java, PHP
and Ruby.&amp;nbsp; On the client side, PostgreSQL ships with both OLEDB and a .NET data
providers.&amp;nbsp; One of the fascinating features of PostgreSQL is&amp;nbsp;its ability
to have inherited tables.&amp;nbsp; I can see where this could dovetail with OR mappings
for subclasses.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=534833ac-2fde-4f22-b4ed-740a83762c2b" /&gt;</description>
      <comments>http://www.chrisvelazquez.com/blog/CommentView,guid,534833ac-2fde-4f22-b4ed-740a83762c2b.aspx</comments>
      <category>database</category>
    </item>
    <item>
      <trackback:ping>http://www.chrisvelazquez.com/blog/Trackback.aspx?guid=1ade8044-e7b5-45f3-b1c5-9099b0e29257</trackback:ping>
      <pingback:server>http://www.chrisvelazquez.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisvelazquez.com/blog/PermaLink,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</pingback:target>
      <dc:creator>Chris V.</dc:creator>
      <wfw:comment>http://www.chrisvelazquez.com/blog/CommentView,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisvelazquez.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1ade8044-e7b5-45f3-b1c5-9099b0e29257</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have this habit of underestimating Microsoft, especially when it comes to the Office
product line. At first blush, I was unimpressed with Office 2007.  To the average
user, on first glance, it looks like Microsoft has traded one set of GUI widgets for
another set of more complicated GUI widgets.  Combining this with the IT pundits
declaring Office 2007 dead on arrival, I ignored it.  It's hard for me to get
very excited about new widgets.
</p>
        <p>
But last night I chanced upon the <a href="http://msdn2.microsoft.com/en-us/office/aa905543.aspx">VSTO
site</a> (Visual Studio Tools for Office), and took a peek at <a href="http://wm.microsoft.com/ms/msdn/office/vsto2005seintro/vsto2005seintro.wmv">this
video</a>.  I was amazed, and had to concede that Microsoft had pulled it
off once again.  They have raised the bar for us programmers and expectations
of users.  Briefly, your WinForms user controls can plug right into the Office
environment, into either the ribbon or in the side docking panel.  Having worked
on a system in C# that emulates a similar behavior, I was very interested,
and a little disappointed that my craftily written code would soon be obsolete.
</p>
        <p>
The thing about Office, and Word and Excel in particular, is that everyone uses it. 
People get a warm fuzzy from software they use frequently and have some understanding
of.  The number one feature request I get is to be able to download data into
an Excel spreadsheet.  And VSTO 2005 SE (Second Edition) makes the job for programmers
integrating into Office a whole lot better.  And it gives a compelling reason
to upgrade to Office 2007.  This is only a minor upgrade for the end-user, but
this is a sea-change upgrade for the Office developer.
</p>
        <p>
VSTO 2005 SE will also allow Office programmers to achieve the type of service-oriented
architecture that was difficult to achieve with our previous tools.  Since your
user controls can do all those wonderful things like consume web services, chat over
networks, query databases, access the file system, etc., the integration possibilities
are nearly endless.  And the ability to dock your components right at the user's
fingertips within the Office application makes the software convenient to summon for
the end-user.
</p>
        <p align="right">
          <img src="http://www.chrisvelazquez.com/blog/content/binary/aa905543_NewVSTOlogo(en-us,MSDN_10).jpg" border="0" />
        </p>
        <p>
Now to work on my "reasons to upgrade" spiel for my clients...
</p>
        <img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=1ade8044-e7b5-45f3-b1c5-9099b0e29257" />
      </body>
      <title>Why Office 2007 Really Does Rock</title>
      <guid isPermaLink="false">http://www.chrisvelazquez.com/blog/PermaLink,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</guid>
      <link>http://www.chrisvelazquez.com/blog/PermaLink,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</link>
      <pubDate>Wed, 31 Jan 2007 17:13:09 GMT</pubDate>
      <description>&lt;p&gt;
I have this habit of underestimating Microsoft, especially when it comes to the Office
product line. At first blush, I was unimpressed with Office 2007.&amp;nbsp; To the average
user, on first glance, it looks like Microsoft has traded one set of GUI widgets for
another set of more complicated GUI widgets.&amp;nbsp; Combining this with the IT pundits
declaring Office 2007 dead on arrival, I ignored it.&amp;nbsp; It's hard for me to get
very excited about new widgets.
&lt;/p&gt;
&lt;p&gt;
But last night I chanced upon the &lt;a href="http://msdn2.microsoft.com/en-us/office/aa905543.aspx"&gt;VSTO
site&lt;/a&gt; (Visual Studio Tools for Office), and took a peek at &lt;a href="http://wm.microsoft.com/ms/msdn/office/vsto2005seintro/vsto2005seintro.wmv"&gt;this
video&lt;/a&gt;.&amp;nbsp; I was amazed, and had to concede that Microsoft had&amp;nbsp;pulled it
off once again.&amp;nbsp; They have raised the bar for us programmers and expectations
of users.&amp;nbsp; Briefly, your WinForms user controls can plug right into the Office
environment, into either the ribbon or in the side docking panel.&amp;nbsp; Having worked
on a system&amp;nbsp;in C#&amp;nbsp;that emulates a similar behavior, I was very interested,
and a little disappointed that my craftily written code would soon be obsolete.
&lt;/p&gt;
&lt;p&gt;
The thing about Office, and Word and Excel in particular, is that everyone uses it.&amp;nbsp;
People get a warm fuzzy from software they use frequently and have some understanding
of.&amp;nbsp; The number one feature request I get is to be able to download data into
an Excel spreadsheet.&amp;nbsp; And VSTO 2005 SE (Second Edition) makes the job for programmers
integrating into Office a whole lot better.&amp;nbsp; And it gives a compelling reason
to upgrade to Office 2007.&amp;nbsp; This is only a minor upgrade for the end-user, but
this is a sea-change upgrade for the Office developer.
&lt;/p&gt;
&lt;p&gt;
VSTO 2005 SE will also allow Office programmers to achieve the type of service-oriented
architecture that was difficult to achieve with our previous tools.&amp;nbsp; Since your
user controls can do all those wonderful things like consume web services, chat over
networks, query databases, access the file system, etc., the integration possibilities
are nearly endless.&amp;nbsp; And the ability to dock your components right at the user's
fingertips within the Office application makes the software convenient to summon for
the end-user.
&lt;/p&gt;
&lt;p align=right&gt;
&lt;img src="http://www.chrisvelazquez.com/blog/content/binary/aa905543_NewVSTOlogo(en-us,MSDN_10).jpg" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Now to work on my "reasons to upgrade" spiel for my clients...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=1ade8044-e7b5-45f3-b1c5-9099b0e29257" /&gt;</description>
      <comments>http://www.chrisvelazquez.com/blog/CommentView,guid,1ade8044-e7b5-45f3-b1c5-9099b0e29257.aspx</comments>
      <category>.net;database;office</category>
    </item>
    <item>
      <trackback:ping>http://www.chrisvelazquez.com/blog/Trackback.aspx?guid=c98968e6-c0eb-4e5b-b99f-9241f4c9fc7c</trackback:ping>
      <pingback:server>http://www.chrisvelazquez.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisvelazquez.com/blog/PermaLink,guid,c98968e6-c0eb-4e5b-b99f-9241f4c9fc7c.aspx</pingback:target>
      <dc:creator>Chris V.</dc:creator>
      <wfw:comment>http://www.chrisvelazquez.com/blog/CommentView,guid,c98968e6-c0eb-4e5b-b99f-9241f4c9fc7c.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisvelazquez.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=c98968e6-c0eb-4e5b-b99f-9241f4c9fc7c</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I found an interesting alternative data access layer (DAL) to NHibernate called <a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=actionpack" target="_blank">SubSonic</a>. 
It was formerly called "ActionPack", but I guess there must be enough confusion with
Microsoft's "<a href="http://oem.microsoft.com/script/sites/public/action_pack.htm" target="_blank">Action
Pack</a>" that they changed the name.  SubSonic is open-source (MPL) 
</p>
        <p>
SubSonic has been hailed as "Ruby on Rails" for .NET developers.  There is a
screencast of it <a href="http://www.wekeroad.com/actionpackintro.html" target="_blank">here</a>,
prepare to be amazed.  It works kind of like this:
</p>
        <p>
1) Add a reference to the SubSonic DLL<br />
2) Modify your web.config with connection string info and SubSonic build provider
info<br />
3) Build the project<br />
4) ...<br /><img src="http://www.chrisvelazquez.com/blog/content/binary/miracle3.gif" border="0" />Copyright
(C) Sidney Harris.
</p>
        <p>
5) Amazing!  Domain objects and data access layer have been automagically created!
</p>
        <p>
I foresee this as a great way to quickly get a data-driven site up with a minimum
of development effort.  Realizing this is not the end-all and be-all of data
access, you are still free to use "traditional" ADO.NET techniques.  A recent
benefit is that CodePlex has come out with an XmlProvider, so that if you would rather
persist to XML instead of a database, it can handle that data access layer, too. 
This thing keeps getting better and better.
</p>
        <img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=c98968e6-c0eb-4e5b-b99f-9241f4c9fc7c" />
      </body>
      <title>SubSonic - The Zero Code DAL</title>
      <guid isPermaLink="false">http://www.chrisvelazquez.com/blog/PermaLink,guid,c98968e6-c0eb-4e5b-b99f-9241f4c9fc7c.aspx</guid>
      <link>http://www.chrisvelazquez.com/blog/PermaLink,guid,c98968e6-c0eb-4e5b-b99f-9241f4c9fc7c.aspx</link>
      <pubDate>Wed, 03 Jan 2007 16:27:55 GMT</pubDate>
      <description>&lt;p&gt;
I found an interesting alternative data access layer (DAL)&amp;nbsp;to NHibernate called &lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=actionpack" target=_blank&gt;SubSonic&lt;/a&gt;.&amp;nbsp;
It was formerly called "ActionPack", but I guess there must be enough confusion with
Microsoft's "&lt;a href="http://oem.microsoft.com/script/sites/public/action_pack.htm" target=_blank&gt;Action
Pack&lt;/a&gt;" that they changed the name.&amp;nbsp; SubSonic is open-source (MPL) 
&lt;/p&gt;
&lt;p&gt;
SubSonic has been hailed as "Ruby on Rails" for .NET developers.&amp;nbsp; There is a
screencast of it &lt;a href="http://www.wekeroad.com/actionpackintro.html" target=_blank&gt;here&lt;/a&gt;,
prepare to be amazed.&amp;nbsp; It works kind of like this:
&lt;/p&gt;
&lt;p&gt;
1) Add a reference to the SubSonic DLL&lt;br&gt;
2) Modify your web.config with connection string info and SubSonic build provider
info&lt;br&gt;
3) Build the project&lt;br&gt;
4) ...&lt;br&gt;
&lt;img src="http://www.chrisvelazquez.com/blog/content/binary/miracle3.gif" border=0&gt;Copyright
(C) Sidney&amp;nbsp;Harris.
&lt;/p&gt;
&lt;p&gt;
5) Amazing!&amp;nbsp; Domain objects and data access layer have been automagically created!
&lt;/p&gt;
&lt;p&gt;
I foresee this as a great way to quickly get a data-driven site up with a minimum
of development effort.&amp;nbsp; Realizing this is not the end-all and be-all of data
access, you are still free to use "traditional" ADO.NET techniques.&amp;nbsp; A recent
benefit is that CodePlex has come out with an XmlProvider, so that if you would rather
persist to XML instead of a database, it can handle that data access layer, too.&amp;nbsp;
This thing keeps getting better and better.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=c98968e6-c0eb-4e5b-b99f-9241f4c9fc7c" /&gt;</description>
      <comments>http://www.chrisvelazquez.com/blog/CommentView,guid,c98968e6-c0eb-4e5b-b99f-9241f4c9fc7c.aspx</comments>
      <category>database;web development;.net</category>
    </item>
    <item>
      <trackback:ping>http://www.chrisvelazquez.com/blog/Trackback.aspx?guid=319fba36-e3b2-476d-b607-71ab21d80854</trackback:ping>
      <pingback:server>http://www.chrisvelazquez.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisvelazquez.com/blog/PermaLink,guid,319fba36-e3b2-476d-b607-71ab21d80854.aspx</pingback:target>
      <dc:creator>Chris V.</dc:creator>
      <wfw:comment>http://www.chrisvelazquez.com/blog/CommentView,guid,319fba36-e3b2-476d-b607-71ab21d80854.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisvelazquez.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=319fba36-e3b2-476d-b607-71ab21d80854</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just recently started using <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796">Microsoft
SQL Server Management Studio Express</a> (SSMSE).  This free tool is intended
for SQL Server 2005 databases, but it works just fine with MSDE and SQL 2000 databases,
as far as I can tell.  SSMSE obsoletes the tools I have been using up to this
point, namely Enterprise Manager and Query Analyzer.
</p>
        <p>
Enterprise Manager is slow to open on most systems I've used.  I have a server
instance with 20 databases and I can take a nap before the thing finishes opening
up.  SSMSE uses demand loading of the tree nodes, so performance is a lot better.
</p>
        <p>
The whole integration between Enterprise Manager and Query Analyzer has a more natural
feel.  Nice job, MS!
</p>
        <img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=319fba36-e3b2-476d-b607-71ab21d80854" />
      </body>
      <title>Good Riddance, Query Analyzer!</title>
      <guid isPermaLink="false">http://www.chrisvelazquez.com/blog/PermaLink,guid,319fba36-e3b2-476d-b607-71ab21d80854.aspx</guid>
      <link>http://www.chrisvelazquez.com/blog/PermaLink,guid,319fba36-e3b2-476d-b607-71ab21d80854.aspx</link>
      <pubDate>Tue, 02 Jan 2007 22:25:55 GMT</pubDate>
      <description>&lt;p&gt;
I just recently started using &lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796"&gt;Microsoft
SQL Server Management Studio Express&lt;/a&gt;&amp;nbsp;(SSMSE).&amp;nbsp; This free tool is intended
for SQL Server 2005 databases, but it works just fine with MSDE and SQL 2000 databases,
as far as I can tell.&amp;nbsp; SSMSE obsoletes the tools I have been using up to this
point, namely Enterprise Manager and Query Analyzer.
&lt;/p&gt;
&lt;p&gt;
Enterprise Manager is slow to open on most systems I've used.&amp;nbsp; I have a server
instance with 20 databases and I can take a nap before the thing finishes opening
up.&amp;nbsp; SSMSE uses demand loading of the tree nodes, so performance is a lot better.
&lt;/p&gt;
&lt;p&gt;
The whole integration between Enterprise Manager and Query Analyzer has a more natural
feel.&amp;nbsp; Nice job, MS!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=319fba36-e3b2-476d-b607-71ab21d80854" /&gt;</description>
      <comments>http://www.chrisvelazquez.com/blog/CommentView,guid,319fba36-e3b2-476d-b607-71ab21d80854.aspx</comments>
      <category>database</category>
    </item>
    <item>
      <trackback:ping>http://www.chrisvelazquez.com/blog/Trackback.aspx?guid=a2b89d33-dd8d-49d8-9c15-8c67ee7a1861</trackback:ping>
      <pingback:server>http://www.chrisvelazquez.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.chrisvelazquez.com/blog/PermaLink,guid,a2b89d33-dd8d-49d8-9c15-8c67ee7a1861.aspx</pingback:target>
      <dc:creator>Chris V.</dc:creator>
      <wfw:comment>http://www.chrisvelazquez.com/blog/CommentView,guid,a2b89d33-dd8d-49d8-9c15-8c67ee7a1861.aspx</wfw:comment>
      <wfw:commentRss>http://www.chrisvelazquez.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=a2b89d33-dd8d-49d8-9c15-8c67ee7a1861</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
OK, I'm definitely not the first person in the world to figure this out, but it bit
me in the behind last week.  So I figured I would share this bit of wisdom with
you so it doesn't happen to you.
</p>
        <p>
Most of the data that's stored in this MSDE (SQL Server) database lives in an
"engineering variable data" table.  In this parallel universe, the term "variable"
doesn't mean quite what we programmers think it should mean, so I'll call it a "datum" 
A "datum" can have a value, a specification (that determines how it is used in a calculation),
upper and lower limits, residuals, bound type, and other properties of interest to
engineers.
</p>
        <p>
I experienced a dreadful performance problem in the production system.  Out of
necessity, the program would sometimes have to delete 10,000 records from the VariableData
table and insert a new copy of those records.  In the development system with
a much smaller database, this worked as intended.  However, when we started getting
upwards of a million records in the table, this data replacement step would bring
the program to its knees for 30-120 seconds.  Sometimes the queries would time
out, gobble up RAM like candy on Halloween, or both.  I tried various hacks and
workarounds to improve performance, including using a bulk insert, but to no avail.
</p>
        <p>
We finally took a look at the indexes:
</p>
        <p>
IX_SolutionCaseID: key to an integer in SolutionCase table<br />
IX_Specification: key to a varchar(7), whose value can be one of 7 possibilities<br />
IX_Guid: unique key for a uniqueidentifier<br />
IX_VariableID: key to an integer in Variable table<br />
IX_VariableVariableID: a redundant key
</p>
        <p>
I realized that the way I get data out of the database is by SolutionCaseID and VariableID,
which uniquely identifies a datum.  So the queries I was currently running were
using one of the existing indexes and then doing a table scan to find the record I
actually wanted. Ick.  So I added a new two-field key:
</p>
        <p>
IX_SolutionCaseIDVariableID: <font color="#008000">added</font> key for
both SolutionCaseID and VariableID
</p>
        <p>
Adding this index to a populated table only took a few seconds and it cut the wait
time in half!
</p>
        <p>
Next I started hacking away indexes that I never use.
</p>
        <p>
IX_VariableVariableID: <font color="#ff0000">deleted</font> - this had no noticeable
effect on performance.<br />
IX_Specification : <font color="#ff0000">deleted</font> - this improved performance. 
This is analogous to have an index on sex "M" or "F", which is always a bad idea.<br />
IX_Guid: <font color="#ff0000">deleted</font> - I never look up data by Guid, this
is for UI magic only.  This had a huge benefit on performance
</p>
        <p>
So the conclusions can be:
</p>
        <ul>
          <li>
Avoid indexes on GUID columns, unless they are primary keys and that's how you look
things up 
</li>
          <li>
If you look up on two fields a lot, make sure you have an index that contains both
fields 
</li>
          <li>
Don't index on columns that have lots of repetitive data.  You might actually
win with a table scan on this one!</li>
        </ul>
        <p>
And if you didn't know this already, you can always force an index to be used in a
select query (use at your own discretion):
</p>
        <p>
          <font face="Courier New">SELECT Field1, Field2, Field3 FROM TableName <strong><font color="#0000ff">WITH
(INDEX = MyIndexName)</font></strong> WHERE Field4 = 42</font>
        </p>
        <p>
And now my client is much happier, and there was much rejoicing!
</p>
        <img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=a2b89d33-dd8d-49d8-9c15-8c67ee7a1861" />
      </body>
      <title>Bad Indexing Can Degrade Database Performance</title>
      <guid isPermaLink="false">http://www.chrisvelazquez.com/blog/PermaLink,guid,a2b89d33-dd8d-49d8-9c15-8c67ee7a1861.aspx</guid>
      <link>http://www.chrisvelazquez.com/blog/PermaLink,guid,a2b89d33-dd8d-49d8-9c15-8c67ee7a1861.aspx</link>
      <pubDate>Tue, 02 Jan 2007 20:19:36 GMT</pubDate>
      <description>&lt;p&gt;
OK, I'm definitely not the first person in the world to figure this out, but it bit
me in the behind last week.&amp;nbsp; So I figured I would share this bit of wisdom with
you so it doesn't happen to you.
&lt;/p&gt;
&lt;p&gt;
Most of the data that's stored in this MSDE (SQL Server)&amp;nbsp;database lives in an
"engineering variable data" table.&amp;nbsp; In this parallel universe, the term "variable"
doesn't mean quite what we programmers think it should mean, so I'll call it a "datum"&amp;nbsp;
A "datum" can have a value, a specification (that determines how it is used in a calculation),
upper and lower limits, residuals, bound type, and other properties of interest to
engineers.
&lt;/p&gt;
&lt;p&gt;
I experienced a dreadful performance problem in the production system.&amp;nbsp; Out of
necessity, the program would sometimes have to delete 10,000 records from the VariableData
table and insert a new copy of those records.&amp;nbsp; In the development system with
a much smaller database, this worked as intended.&amp;nbsp; However, when we started getting
upwards of a million records in the table, this data replacement step would bring
the program to its knees for 30-120 seconds.&amp;nbsp; Sometimes the queries would time
out, gobble up RAM like candy on Halloween, or both.&amp;nbsp; I tried various hacks and
workarounds to improve performance, including using a bulk insert, but to no avail.
&lt;/p&gt;
&lt;p&gt;
We finally took a look at the indexes:
&lt;/p&gt;
&lt;p&gt;
IX_SolutionCaseID: key to an integer in SolutionCase table&lt;br&gt;
IX_Specification: key to a varchar(7), whose value can be one of 7 possibilities&lt;br&gt;
IX_Guid: unique key for a uniqueidentifier&lt;br&gt;
IX_VariableID: key to an integer in Variable table&lt;br&gt;
IX_VariableVariableID: a redundant key
&lt;/p&gt;
&lt;p&gt;
I realized that the way I get data out of the database is by SolutionCaseID and VariableID,
which uniquely identifies a datum.&amp;nbsp; So the queries I was currently running were
using one of the existing indexes and then doing a table scan to find the record I
actually wanted. Ick.&amp;nbsp; So I added a new two-field key:
&lt;/p&gt;
&lt;p&gt;
IX_SolutionCaseIDVariableID: &lt;font color=#008000&gt;added&lt;/font&gt;&amp;nbsp;key&amp;nbsp;for both
SolutionCaseID and VariableID
&lt;/p&gt;
&lt;p&gt;
Adding this index to a populated table only took a few seconds and it cut the wait
time in half!
&lt;/p&gt;
&lt;p&gt;
Next I started hacking away indexes that I never use.
&lt;/p&gt;
&lt;p&gt;
IX_VariableVariableID: &lt;font color=#ff0000&gt;deleted&lt;/font&gt; - this had no noticeable
effect on performance.&lt;br&gt;
IX_Specification : &lt;font color=#ff0000&gt;deleted&lt;/font&gt; - this improved performance.&amp;nbsp;
This is analogous to have an index on sex "M" or "F", which is always a bad idea.&lt;br&gt;
IX_Guid: &lt;font color=#ff0000&gt;deleted&lt;/font&gt; - I never look up data by Guid, this is
for UI magic only.&amp;nbsp; This had a huge benefit on performance
&lt;/p&gt;
&lt;p&gt;
So the conclusions can be:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Avoid indexes on GUID columns, unless they are primary keys and that's how you look
things up 
&lt;li&gt;
If you look up on two fields a lot, make sure you have an index that contains both
fields 
&lt;li&gt;
Don't index on columns that have lots of repetitive data.&amp;nbsp; You might actually
win with a table scan on this one!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
And if you didn't know this already, you can always force an index to be used in a
select query (use at your own discretion):
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;SELECT Field1, Field2, Field3 FROM TableName &lt;strong&gt;&lt;font color=#0000ff&gt;WITH
(INDEX = MyIndexName)&lt;/font&gt;&lt;/strong&gt; WHERE Field4 = 42&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
And now my client is much happier, and there was much rejoicing!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.chrisvelazquez.com/blog/aggbug.ashx?id=a2b89d33-dd8d-49d8-9c15-8c67ee7a1861" /&gt;</description>
      <comments>http://www.chrisvelazquez.com/blog/CommentView,guid,a2b89d33-dd8d-49d8-9c15-8c67ee7a1861.aspx</comments>
      <category>database</category>
    </item>
  </channel>
</rss>