Wednesday 25 August 2010

R trick: plot data in one scale, label axes on the original scale

Here is the way to do it. First, get the data and plot it in the logarithmic scale, say, without the y axis:

x <- exp( rnorm( 100 ) )
plot( log( x ), yaxt="n" )

Create the labels:

a <- 1:ceiling( max( x ) )

Finally, draw the axis at the original scale and with your desired labels:

axis(2, at=log(a), label=a)

Wednesday 18 August 2010

How many rows assigns Teradata to each AMP for a given table?

Teradata distributes table rows to different AMP's according to a hash value calculated from its primary key. The following query indicates how many rows fall into each AMP for a given table.

SELECT
HASHAMP (HASHBUCKET(HASHROW( col1, col2, col3 ))) AS AMP_NUM,
COUNT(*) as NUM_ROWS_PER_AMP
FROM
mytable
GROUP BY 1
ORDER BY 1;


It is useful to check whether your table is properly distributed or not!

Tuesday 17 August 2010

PHP's "Fatal error: Call to undefined function: curl_init()" on Ubuntu

After Twitter changed its access settings for applications to tweet directly into it, I had some problems updating my WP to Twitter plugin. I got a "Fatal error: Call to undefined function: curl_init()". 

Problem? Missing php5-curl package on my Ubuntu server.

Solution?

sudo apt-get install php5-curl
sudo /etc/init.d/apache2 restart

Listing missing statistics from Teradata query optimizer

Teradata is a fine DBMS whose performance critically depends on whether the right table statistics are available to the query optimizer.

You can request it to hint you for the missing statistics that it would like to have on your tables running the code

diagnostic helpstats on for session;

before checking query plans. After running the command above, the query plan, at the end, will list those statistics that the end of the query plan.

Saturday 14 August 2010

Completely eliminate packages marked as rc in Ubuntu or Debian

Removing a package is not the same as purging it. Simply removing leaves some cruft behind. If you remove packages from your Ubuntu or Debian system using

apt-get remove mypackage

you will still see it when you run a

dpkg -l

comand. And it is the case because configuration files are not erased. In order to completely remove (i.e., purge) a package you need to run

apt-get --purge remove mypackage

But what if you removed it but you did not purge it? It will always show up in your system.

If you want to get rid of all those rc-status (removed but not purged) packages in your system you can run something like:

sudo dpkg --purge `dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs`