Should you use HASH index?

Today, Mattias|farm on IRC asked how to create primary key using HASH index. After some talk, he said that in some books it said that for “=" (equality) hash indexes are better.

So, I digged a bit deeper.

IMPORTANT UPDATE: As of PostgreSQL 10 hash indexes are WAL logged. As such, main point against them is gone.

Continue reading Should you use HASH index?

Getting random interfacelift wallpaper

Just thought I'll share it – maybe somebody else will use it.

I'm using KDE 3.5, so the final “dcop …" command, simply sets the file as current wallpaper.

I also use 1680×1050 resolution – which you can probably guess from the code 🙂

#!/usr/bin/perl -w
use strict;
use English qw( -no_match_vars );
use WWW::Mechanize;
 
my $agent = WWW::Mechanize->new();
 
$agent->get("http://interfacelift.com/wallpaper_beta/downloads/random/widescreen/1680x1050/");
exit unless 200 == $agent->res->code;
 
my @links = $agent->find_all_links(
    'url_regex' => qr{1680x1050.jpg},
);
exit if 0 == scalar @links;
 
$agent->get( $links[ rand @links ] );
exit unless 200 == $agent->res->code;
 
my $username = getpwuid( $REAL_USER_ID );
my $filename = '/tmp/interfacelift.' . $username . '.jpg';
 
open my $fh, '>', $filename or exit;
binmode $fh;
print $fh $agent->res->decoded_content;
close $fh;
 
$ENV{"DISPLAY"} = ':0';
system( qw( /usr/bin/dcop kdesktop KBackgroundIface setWallpaper ), $filename, 4 );
 
exit;

Pretty simplistic, but it does the job. Now, I add this line to my crontab:

*/5  * * * * /home/depesz/bin/interfacelift.pl

And enjoy new, nice wallpaper every 5 minutes 🙂

explain.depesz.com – update

I just updated explain.depesz.com with 2 new interface features:

  • When you put mouse cursor over node, it will mark direct child nodes with
  • When you click on node, all child nodes (even indirect) will be hidden, and the node you clicked on will be marked with

Both features are directed towards people who analyze longer plans – ability to hide parts or just visually see what the Nested Loop is calling in 2nd stage greatly helps me see the flow of query – you can test it, for example, here.

By the way – BIG THANK YOU for Metys for help on it (well, actually, for doing it).

explain.depesz.com – update

I just modified the internals of explain.depesz.com. Now, it finally stores the plans in database (previously it stored the plans as files in dedicated directory).

Effect for enduser is just that history page should load faster.

But, having the data in database makes it possible to add more features.

One such feature is already added – ability to explain plan, but not list it on history page.

Right now, when you add new plan, you can specify if you want it to be listed with other previous explains – default value is “yes". But if you don't want just anybody to be able to click his way to your plan – there is option for it.

For obvious reasons all previous plans are marked as public now. If you want it to be changed, please contact me – we can probably do something about it.

And as last thing: I would like to express my big THANK YOU to all of you who use explain.depesz.com.

(side note: Catalyst is really cool)

explain.depesz.com – update

I just updated explain.depesz.com with the newest explain-parsing library version (Pg::Explain v 0.09).

This version will hit CPAN mirrors in next couple of hours.

Changes:

  • Fix exclusive time calculations
  • Make PE::Node understand Bitmap scans (heap and index)
  • Add proper handling of nodes that were “never executed"
  • Add ->is_analyzed method to PE::Node to make it easy to distinguish between EXPLAIN and EXPLAIN ANALYZE nodes

Learning POE: HTTP-2-MUD proxy

Some years ago I learned of existence of (supposedly cool) POE framework for Perl. I tried to use it for some projects, but the learning curve proved to be fatal for my interest.

All the time I felt that POE is great, it's just that I'm too stupid to be able to actively use it.

Time passed by. Something like half a year ago, friend asked me if it would be possible for me to write a cool program – HTTP proxy for their MUD.

Continue reading Learning POE: HTTP-2-MUD proxy

find.best.tablespace.split.pl

Robert Treat reported an error with find.best.tablespace.split.pl. In some cases it could die with ‘division by zero' error.

Problem was solved using patch from Robert, which simply treats “0" in number of rows fetched or written, as ‘0.001'.

Additionally, I added a simpler way to specify multiple schemas to use tables from.

Code is available in svn repository.