Click here to monitor SSC

Phil Factor's Phrenetic Phoughts

Simple-Talk columnist
The wilder shores of Transact SQL    Phil on Twitter   Phil on SQL Server Central  Phil on BOS

Had Tennyson been a technical Author...

Published Sunday, July 16, 2006 12:20 PM

The Index: An Elegy

(I have always wondered why nobody has written a book on SQL Server in verse.  To correct this lamentable gap in the market, I have been penning some stanzas.
Here, as a sample, is a short verse on indexing)

An index is used as a short-cut to data
a table will warrant one sooner or later
Because only one can be clustered, beware
and ponder the index you cluster with care
the issues are clearer than you might suppose
this index determines the order of rows
so searching the index requires less I/O.
Selecting the column on which it should go
depends on the way that the rows are selected,
which should become clear if the Schema's inspected.
One problem, however, I think you should know,
retrieving a range can be horribly slow.

A non-clustered index is almost as good
once ordering keys can be well understood
make sure that the columns you use are selective
for if too few values, it's most ineffective
if data is changing or updating too
with frequent insertions, keep indexes few.
from 2000 on you can index a view
(but then there's restrictions on what you can do)
and even on computed columns as well
but only if deterministic as hell
For reasons which often are misunderstood
a non-clustered covering index is good
when composite columns are used with some care
they outperform anything else that's out there

Comments

 

Louis Davidson said:

Wow, that's prety good. I would pay for the full version :)  Did it take as long as it seems it would?
July 16, 2006 4:25 PM
 

Phil Factor said:

The more you do the quicker it gets. I'm glad you like it. It was inspired by the old bible-learning and history rhymes. There were a lot of verses to teach children the kings of England and what happened in each reign. Of the bible rhymes, my favourite verse was...

The world was made in six days
and finished on the seventh.
According to the contract,
it should have been the eleventh
but the painters wouldn't paint
and the workers wouldn't work
so the quickest thing to do
was to fill it in with dirt.
July 16, 2006 5:26 PM
 

Patrick Index said:

What about....

To write a SELECT statement here's what you do
Start with SELECT * if you haven't a clue
Then put the FROM clause with a table by name
You can use an alias as it amounts to the same
A WHERE clause should follow to filter the data
Perhaps use a function to return records no later
In order to sort use an ORDER BY clause
Then press F5 to execute of course.

Yours
Paddy Index


July 17, 2006 11:45 AM
 

Phil Factor said:

It is as if Lord Byron had been reincarnated!  

I've been working on a technical exposition on locking. it seems to naturally run to the rhythm of 'Sixteen Tons'.(George Davis/Merle Travis) If it works out, I'll reveal it to the world.
July 17, 2006 1:42 PM
 

Phil Factor said:

In the style of Rudyard Kipling, we have the start of the chapter on the Query Optimser

When you execute a query you expect it to be quick
a database is useless if retrieval  isn't slick
and the Query Optimiser is the bit that does the trick

The Query Optimiser tries to minimise the reads
with the index and the query tree it generally succeeds
The tables size and rows per page are also things it needs.

Chorus .... etc etc.
August 6, 2006 4:30 PM
 

WBrewer said:

The query optimiser chorus could be something like....

Oh! The road to slick IT
is the place we'd like to be
where the wind blows softly through the leaves
of the standardised query tree
August 7, 2006 4:03 AM
You need to sign in to comment on this blog
<July 2006>
SuMoTuWeThFrSa
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345
Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Converting String Data to XML and XML to String Data
 We all appreciate that, in general, XML documents or fragments are held in strings as text markup. In... Read more...

Geek of the Week: Don Syme
 With the arrival of F# 3.0 Microsoft announced a wide range of improvements such as type providers that... Read more...

How to Document and Configure SQL Server Instance Settings
 Occasionally, when you install identical databases on two different SQL Server instances, they will... Read more...

What's the Point of Using VARCHAR(n) Anymore?
 The arrival of the (MAX) data types in SQL Server 2005 were one of the most popular feature for the... Read more...