Archive

Archive for March, 2005

Albums you should listen to before you die

March 16th, 2005

Found this via My cummerbund fell in the toilet (another Pebble user). The idea is you take the list of albums, highlight the ones you’ve listened too and add three.

  • Sgt. Peppers Lonely Hearts Club Band - The Beatles
  • London Calling - The Clash
  • Blood Sugar Sex Magik - Red Hot Chilli Peppers
  • Think Tank - Blur
  • This is Hardcore - Pulp
  • Moon Safari - Air
  • Elastica - Elastica
  • OK Computer - Radiohead
  • The Kiss of Morning - Graham Coxon
  • The Wall - Pink Floyd
  • Setting Sons - The Jam
  • America Beauty - The Grateful Dead
  • Toxicity - System of a Down
  • Train a Comin’ - Steve Earle
  • Folksinger - Phranc
  • Come From the Shadows - Joan Baez
  • Bat out of Hell - Meatloaf
  • The River - Bruce Springsteen
  • The Very Best of Joan Armatrading - Joan Armatrading
  • Copperhead Road - Steve Earle
  • Dark Side of the Moon - Pink Floyd
  • Brothers In Arms - Dire Straits
  • Outside - David Bowie
  • Passionoia - Black Box Recorder
  • Version 2.0 - Garbage
  • Too Young To Die (Greatest Hits) - St. Etienne
  • The Complete Recordings - Robert Johnson
  • Absolution - Muse
  • Kind of Blue - Miles Davis
  • The Soft Bulletin - The Flaming Lips
  • Queens of the stone age - Songs for the Deaf
  • Ryan Adams - Heatbreaker
  • Doolittle - The Pixies
  • Speakerboxx/The Love Below - OutKast
  • Unknown Pleasures - Joy Division

My additions are:

  • The Killers - Hot Fuss
  • Interpol - Antics
  • The Cure - Disintegration

I could easily add a hundred more though…

Uncategorized

Deleting lots of data…

March 13th, 2005

This question came up recently and there was some discussion about it so I thought I’d summarise here…

Problem
How best to delete a large amount of data from a table. The database in question was Sybase so we’ll talk about that. The concepts are the same for all major databases though the syntax may differ.

Solution
As came out in the conversation there are several things you need to think about.

  • How many rows are there in the table?
  • How much data needs to be deleted?
  • What indexes are there on the table?
  • Is this a production database?
  • Is this a one off task?

Lets look at the effect each of these questions has on how you approach this task.

How many rows are there in the table?
This is the first question you need to answer.
SELECT count(*) from MyTable
< 5,000 - Probably not going to be any problems here.

< 5,000,000 - Pick your query carefully and take some time.

5,000,000 + - In the realms of large tables, this needs planning carefully.

How much data needs to be deleted?
This is the second question you need to answer.
All - Think about using Truncate, this is a very effient way of deleting all the rows in the table since it simply moves the “next row marker”.
Truncate has several side effects though:-

  1. It’s not logged, can cause problems with replication
  2. No space is reclaimed because no rows have actually been deleted

You could also consider dropping and re-creating the table.
Lots - (30%+) If you’re planning to delete the majority of the table it’s worth considering moving the rows you need to a temporary table, clearing the old table (using truncate or dropping it) and moving the rows you need back again.
Some - (<30%) This is where you should be thinking about deleting the rows you don’t want (carefully)
Those percentages are just a guide, please use your judgement when deciding what to do. You also need to combine how much data you’re deleting with the size of the table. Deleting most of the rows from a 10 million row table is not a small undertaking

What indexes are there on the table?
Having indexes on the table during a large delete operation will slow the delete enormously. Typically it is quicker to drop all the indexes, delete the data and then recreate the indexes.
Once the delete is complete it is vital that the statistics for the table and index(es) involved are updated. If the query optimiser has incorrect information it will not pick the best plan. It’s entirely possible a catastrophically bad plan could be chosen.

Is this a production database?
If the delete needs to be carried out on a production database it should be carried out by a DBA and out of hours. It’s probably worth having a DBA on hand even if it’s a development database just in case something goes wrong

Is this a one off task?
If this is a one off task then the simplest approach is best.

  1. Fire up your trusty SQL Execution tool
  2. Execute the following SQL until no rows are deleted

SET ROWCOUNT 100 — limits the number of rows affected
DELETE FROM MyTable WHERE [Clause]
SET ROWCOUNT 0 — removes the previous limit
Clearly this isn’t going to work well if you need to delete thousands of rows (you’ll be running it all day)
If this is a task that needs to be carried out frequently it should be wrapped up in a stored procedure

A better plan…
Of course you can avoid the vast majority of all these problems with the simple (but often overlooked) step of developing and implementing an archiving strategy during the development phase.

/Technology ,

Weird London Weather

March 4th, 2005

I honestly don’t think I’ve ever seen weather like this in Central London at this time of year. It’s freezing cold and chucking it down with snow at the moment. I’m certainly in the minority of people in my office in loving weather like this. I have to admit my excitement is tempered slightly by the worry I might not be able to get home tonight.

Uncategorized

A new Category…

March 2nd, 2005

Databases are a bit of a pet subject to me so I thought I’d create a whole new category about them. I’m in the process of creating a course about SQL Tuning so some of the content of that will find it’s way here. I’ll probably other random things about databases as they come to me.

I should mention I’m not a DBA, more of an interested developer so if you see anything wrong or that you disagree with please comment!

Uncategorized

Moblog 2

March 2nd, 2005

I have a plan to take Simon Brown’s excellent moblog and add some features I’d find handy.

  • Save blogs for later posting
  • Insertion of HTML chunks
  • Adding support for cameras and the File API (JSR-75)

I’ll have to chat to Simon next time I see him to see what he thinks.

Uncategorized