Lee Packham’s Corner
The rants of a software busy body
  • Home
  • Gallery
  • About
  • dtrace Stuff

Archive for September, 2008

Big table and changing indexes

MySQL No Comments »

MySQL sucks at large tables. Sorry if you’ve come here thinking that I, in any way, like MySQL. That said, I have to look after some sizeable databases which are on MySQL for various reasons - so needs must.

I recently needed to sort out an issue with indexes on a table. I needed to drop one, and add a couple more. Snag? The table has 3.6 million rows and as such I would call it a large table.

Normally, I guess, you would do something like:

ALTER TABLE foo ADD INDEX (my_column);
ALTER TABLE foo DROP INDEX old_index;

This doesn’t work when you have a lot of rows. Well, it does… if you have a few hours to spare. Let’s look at why.

When you add an index to a pre-existing table, MySQL has to go look through the entire table to populate the new index. When you drop an index on a pre-existing table, it loops through every row depopulating the index before finally dropping it.

So, here’s what I did to speed things up:

  1. SELECT * FROM foo INTO OUTFILE 'foo_outfile.dmp';
  2. CREATE TABLE foo_a LIKE foo;
  3. ALTER TABLE foo_a ADD INDEX (my_column);
  4. ALTER TABLE foo_a DROP INDEX old_index;
  5. LOAD DATA INFILE 'foo_outfile.dmp' INTO TABLE foo_a;
  6. TRUNCATE TABLE foo; DROP TABLE foo;
  7. ALTER TABLE foo_a RENAME foo;

Why TRUNCATE before DROP? That’s easy, DROP tries to delete each row. To delete each row the index has to be updated… 3.6M times! TRUNCATE trashes everything, then you’re dropping an empty table!


September 29th, 2008 |



The importance of tabs

Programming No Comments »

This sort of thing drives me barmy - why can’t people set a standard on tabs?

The above snippet is taken from eJabberd (a Jabber Server written in Erlang). Notice how some lines are soft tabs, others are hard. The causes havoc when dealing with merging in source control (I don’t care if you use a new fangled Git approach). Whitespace (both tabs and line endings) must be consistent on programming projects. Much pain ensues if they are not!

Personally I set rules in SVN commit hooks. This means that if a developer has anything ‘bad’ like Windows Line Endings on a Python project, then it is dealt with accordingly.

Saves a lot of merge pain!


September 27th, 2008 |



pkgsrc and OpenSolaris 2008.05 - made easy

Open Solaris 1 Comment »

This is something that’s been bugging me for ages. I could not easily make pkgsrc bootstrap and compile packages under OpenSolaris. Today I cracked it:

  1. Grab the latest stable tarball and gtar xzf it somewhere sensible (under /usr is good).
  2. pfexec pkg install SUNWgcc sunstudioexpress SUNWgmake
  3. pfexec pkg install SUNWxwinc
  4. pfexec pkg install SUNWcvs SUNWgnome-common-devel
  5. su
  6. cd /usr/pkgsrc/bootstrap
  7. export PATH=/usr/ccs/bin:$PATH
  8. ./bootstrap
  9. <patience>
  10. Edit your .bash_profile to make sure /usr/pkg is in your path

And you’re done! Working a charm for me here.


September 12th, 2008 |



OpenSolaris 2008.05 finally works properly on HP Proliant ML115 G5

Solaris No Comments »

Finally, OpenSolaris 2008.05 snv_97 is out! This includes the network driver for the network card on the HP Proliant ML115 G5 (the Broadcom BCM 5722). By surprise, it also includes the GFX driver for the onboard graphics card (some MGA 200 thing). This makes installation a lot easier than trying to do it via Text.

This is great news. I can finally drop running Solaris under ESXi 3.5u2 and get onto using the OpenxVM (which is really XEN, but packaged by Sun). Why is that good news? I prefer native ZFS. Speed being the main thing.

You can get the DVD directly from Genunix in both primary languages and all languages formats.


September 12th, 2008 |



Not so Genius iTunes

Mac / OSX No Comments »

The new iTunes 8 came out yesterday! Excellent. Loving the new features - especially the Genius playlist thingie. Apart from… It’s not ACTUALLY that good. Sorry. If you’re listening to a popular artist (Say Coldplay, Michael Jackson or similar), it’s great. If you’re listening to one of the reams of Christian music albums, forget it.

Genius just pops up a message saying “Tough” (see the image for the proper text) when I click the little Genius button while Tim Hughes is playing. Tim Hughes is one of the most popular worship leaders in the UK (and a top guy to boot). I was hoping it would find other inspirational songs when I hit the button. Alas, just the error.

The iTunes store had no trouble finding other Christian tracks for me to buy in the Genius sidebar! Figures. Pandora (although that’s no longer available) and last.fm don’t ever have this trouble. So why does iTunes. I put to you that Genius is truly not Genius.

EDIT: It can’t even handle the Mark Ronson - Version album. That’s far less obscure than some big religion thing!


September 10th, 2008 |



Debugging SMTP

Python 2 Comments »

I saw this today on djangosnippets and figured it’s useful enough for me to post! Sometimes when writing a webapp you need to debug the output of your e-mail sending. This can be quite hard as things have to, usually, go via an SMTP server. What you really want is a quick way to grab the output with all the headers that YOUR code is setting - you can, easily, with Python.

OSX/Unix/Linux

sudo /usr/lib/python2.5/smtpd.py \
    -n -c DebuggingServer localhost:25

(obviously on Solaris/OpenSolaris you want to use pfexec instead of sudo!)

Windows

c:\python25\python.exe c:\python25\lib\smtpd.py \
    -n -c DebuggingServer localhost:25

You then get an output in the terminal window you ran it in every time a message hits the server. Handy.


September 9th, 2008 |



Be* Mixes Toolbar

Web/Tech No Comments »

When we made Mixes at work, we made sure that we built it in a RESTful way. This has a few cool advantages. Not least because one of the guys I work with, Lloyd Pick, made a quick toolbar up for Firefox to view the status of current matches.

It’s a very simple affair. The grey men change to green men as the server fills up and you can click to go to the page and get yourself on that server.

I’m loving it during the beta. It means I don’t have to sit on the page waiting for a game to get going, I can see instantly as I browse round the web that something’s going on.

Good job Limi, let’s hope Mozilla Addons get it out of the Experimental bin.

Mixes Toolbar @ addons.mozilla.org


September 1st, 2008 |



  • Friend's Blogs/Sites

    • David Rickard
    • Lloyd Pick
    • Michael Smith
  • Recent Posts

    • Is it any wonder the world is infested with spam?
    • The Wowhead Christmas Wallpaper
    • Unibody Macbook Pro constantly waking up
    • How Warcraft reigned supreme in 2008
    • CRY vs. DRY
  • Archives

    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • November 2007
    • October 2007
    • August 2007
    • July 2007
    • June 2007
    • May 2007
    • January 2007
    • December 2006
    • October 2006
    • September 2006
  • Recent Tracks (last.fm)

    • Nickelback – Gotta Be Somebody 18 hours ago
    • Nickelback – Burn It to the Ground 18 hours ago
    • Nickelback – Something in Your Mouth 18 hours ago
    • Lisa Miskovsky – Still Alive (The Theme from Mirror's Edge) (Paul Van Dyk Mix) 18 hours ago
    • The Prodigy – Charly 22 hours ago
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
Copyright © 2009 Lee Packham’s Corner All Rights Reserved
RSS XHTML CSS Log in
Wp Theme by n Graphic Design
Powered by Wordpress