The Break Dancing Worm

Visa break dancing worm

Alex King brought up a good point this week asking why don’t companies make their commercials available online? Then I saw a commercial for Visa that had a break dancing worm in it. So I first went to their website to see if it was available, which it wasn’t. My next trip was to YouTube to see if someone had posted it. Sure enough it was there. So here it is, the Visa break dancing worm commercial.

UPDATE Tue 4 Apr 2006 @ 10:10am : I guess I didn’t look very hard at the Visa website because Lauren left a comment showing how to see their commercials in just a few steps. So here is a link to Visa commercials on their site. The break dancing worm spot is called ‘Recycling’.

Vista Versions

I have to wonder what makes Microsoft think that we need five different versions of Windows Vista:

I can understand having a server version that is different from a client/desktop/notebook system, but these are all client versions. Ug, sometimes too much choice just results in more pain.

Hey, speaking of a server version, what is the next Windows server OS going to be? Will there be a Windows Vista Server to replace Windows 2003 server?

Google Blog Problem

Several folks noticed a problem with the Official Google Blog recently. I ran into this via Bloglines with the post Google, fix your blog pleeasssee! <3 (P.S. Just t… by trey. Since that post has since been removed (returns a 404 page not found error) I took the screen shot shown above to preserve the moment :-)

Turns out that Google had deleted their own blog.

Cool, the folks at Search Engine Watch have a screen shot of the full post.

Akismet Problems

It has been about six weeks since I wrote my review of Akismet. Things had been going fine, but the last week or so has seen a large increase in the number of comment spam items that are not being caught, especially yesterday and today. I’ve asked about this via their contact form to see if this is something unique to me or if there is something going on at Akismet.

UPDATE Fri 24 Mar 2006 @ 4:30pm: I suspect the problems I’ve been having are related to Akismet database problem that was just reported. Interesting that the problem seems to involve taking too long to get a response back for free users.

Sequence vs Auto_Increment/Identity

At the risk of turning this into a SQL Server blog I have to bring up one more issue that I came across. I was looking at the Microsoft SQL Server functions in PHP trying to figure out how how to get the last inserted id from an identity field. With MySQL you can use mysql_insert_id() in PHP.

A little more time on Google turned up the SELECT @@IDENTITY method. Then I came across this “Alternatives to @@IDENTITY in SQL Server 2000” page. This revealed that there are three different ways to get the value of an identity field back, each one provides a potentially different answer depending on the conditions:

SELECT @@IDENTITY
SELECT IDENT_CURRENT('tablename')
SELECT SCOPE_IDENTITY()

If you want the details on how each one works go back and read the article. The one that I’m interested in is SELECT SCOPE_IDENTITY(), it will return the identity value scoped by the connection and statement. This avoids the possible scope changes (think triggers and multiple tables).

So far MySQL hasn’t had to deal with this level of complexity for auto_increment allowing mysql_insert_id() to ignore the scope issues that SQL Server 2000 has. This is already changing though with the introduction of triggers in MySQL 5.0. It isn’t clear any more what mysql_insert_id() is going to do under these conditions. Perhaps they’ll add another function or an option to mysql_insert_id() to make it explicit.

All of this research into identity and auto_increment fields got me to wondering why they don’t just implement sequences like PostgreSQL and Oracle have. Instead of getting the id value after inserting data, you get it before hand by requesting the next value from the sequence. In Oracle you get a new value via something like this:

SELECT sequence_name.nextval FROM dual

PostgreSQL provides a similar method:

SELECT nextval('sequence.name')

To go the extra mile you can use these methods as the default value for your id field which makes it work similar to auto_increment/identity. In PostgreSQL there is a short cut for doing this via the serial data type.

Just in case this wasn’t enough to sell you on the idea of sequences there is more. You can the start value, minimum value, maximum value and increment values. In PostgreSQL you can also indicate some rules on what to do about cycling values. In Oracle the default maximum value for a sequence is 999999999999999999999999999, or if you prefer

nine hundred ninety-nine septillion.
nine hundred ninety-nine sextillion.
nine hundred ninety-nine quintillion.
nine hundred ninety-nine quadrillion.
nine hundred ninety-nine trillion.
nine hundred ninety-nine billion.
nine hundred ninety-nine million.
nine hundred ninety-nine thousand.
nine hundred ninety-nine.

The default maximum value for a sequence is slightly smaller at 9223372036854775807, or

nine quintillion.
two hundred twenty-three quadrillion.
three hundred seventy-two trillion.
thirty-six billion.
eight hundred fifty-four million.
seven hundred seventy-five thousand.
eight hundred seven.

Not bad. Both of those are very large numbers and if you are incrementing by one (which is the default) then you could go for quite awhile before you hit the wall.

So the title of this entry is sequence vs. auto_increment/identity and hopefully you’ll agree that while auto_increment and identities are simpler, their lack of features and problems with scope make them inferior to sequences. With sequences you get more features and less confusion about what they are doing (remember triggers?).

What I’d like to see is MySQL and SQL Server convert over to sequences, but continue to expose the post insert values using the same methods and functions that they do now for auto_increment/identity. They could even use a similar shortcut to PostgreSQL’s serial data type to allow for backwards compatibility when creating tables. This approach would give them the greater functionality of sequences, make them more compatible with PostgreSQL and Oracle (which would making porting apps easier) and retain backwards compatibility with their previous versions.

Any bets on how long it will take for this to happen? Is there a proposed feature list for MySQL 6.0 and SQL Server 2010 :-)

Overcoming The Limitation Of Information_Schema.Views In SQL Server 2000

This morning I went on a hunt to find out where SQL Server 2000 keeps the view definitions for a database. I quickly came across information_schema feature (seems that having information_schema is part of the SQL92 standard) which exposes view details via information_schema.views. I was hoping that would be the end of my journey, but then I ran into a problem.

Go back and look at the details for the Information_Schema.Views, pay close attention to the VIEW_DEFINITION column. It turns out that if the view definition is more than 4000 characters then it returns NULL. Why they didn’t just make it a TEXT field I do not know. Of course one of the two view definitions that I was looking for was returning NULL. At least I had figured out why, now I needed to know how to get around it.

I knew I could not have been the only one to run into this, so it was back to searching for a solution. I eventually came across a post about sp_helptext that gets around the 4000 character limit. It turns out that sp_helptext will not only give you a view definition, but also triggers, functions, check constraints and stored procedures. Quite handy to have around. So I was able to get the view definition I was looking for (broken up across multiple rows) with:


EXEC sp_helptext 'my_view_name'

You’ll still have to put all the rows back together to get the complete view definition, but that it much better than just getting NULL. Of course if I could figure out what the Information_Schema.Views or sp_helptext is looking at to get the actual view definition I could do it myself. So far I haven’t been able to find that information, and I’m not sure that I’m going to spend much time looking since I have a workable solution at this point.

As an added bonus, go back to the Information_Schema.Views page again and take a look at the IS_UPDATABLE column notes. Turns out that it always returns NO.

While it was nice of Microsoft to include the Information_Schema.Views as part of SQL Server 2000, don’t depend on the data they provide, in some cases it will be wrong. I haven’t looked to see if this is something that has been fixed in SQL Server 2005.

UPDATE Tue 21 Mar 2006 @ 4:00pm: Turns out that getting the definitions of the Information_Schema.Views and sp_helptext is fairly simple. They are kept in the master database in SQL Server 2000. Connect to the master database and take a look at the views, you’ll see several that are owned by INFORMATION_SCHEMA. Then take a look at the listing for Stored Procedures. There are tons of sp_* procedures, one of which is sp_helptext. This lead me to running exec sp_helptext 'sp_helptext' to get the definition of sp_helptext. You can also look at it by looking at the properties of sp_helptext, but you’ll be doing a lot scrolling in a little tiny window. Ick.

After looking at the definitions of both I think I’m going to stick with sp_helptext.

UPDATE Tue 21 Mar 2006 @ 4:40pm: Here is the MSDN info on INFORMATION_SCHEMA and more specifically INFORMATION_SCHEMA.VIEWS which includes notes about the limit of 4000 characters to view_definition and that is_updatable always returns no.

Paul Graham Was Right

Adam Kalsey reminded me of an essay that Paul Graham posted last summer called Hiring is Obsolete (May 2005). The short version, Paul Graham was right.

Most folks have been trying to figure out what Yahoo, Google and to a lesser extent Microsoft are up to, especially with all of the purchases that have been going on lately. For instance, Yahoo bought Flickr, but from all reports Yahoo Photos is several times bigger than Flickr. Yahoo also bought Del.icio.us even though their MyWeb 2.0 was starting to offer similar services. A more recent example would be the purchase of Writely by Google. There is no doubt that Google has the money, time and people resources to build such a service themselves, but they didn’t.

Before I go on, if you haven’t read Paul Graham’s Hiring is Obsolete go do it now.

Okay, so back to the question of what the heck is going on with all of these folks being bought up by companies that have the resources do the same thing themselves. Honestly part of my gut says that this helps a lot with the open source, web head street cred crowd; but that certainly isn’t all of it. For one reason or another, larger companies don’t usually get around to developing the cool new “thing”. Paul lists some reasons for this under the product development portion of his essay: protecting existing turf, allowing their own people to experiment, the difficulty of project management for every project you could think of trying and big companies get in the way of themselves sometimes.

Yahoo and Google are buying these folks up because they get people who have demonstrated that they can come up with cool things. By bringing them into the fold they’ll get a chance to own any new ideas that they come up with and they’ll hopefully be able to make their existing products and services better as well. And by doing all this before they get really big (or go public) they can do it fairly inexpensively. Hard to believe that I just mentioned transactions in the millions of dollars as inexpensive.

So talk of a Web 2.0 bubble isn’t the same as the original bubble. I don’t expect many of these companies to reach the stage of going public, more likely that the good ones will just get purchased. Creating your own Web 2.0 app has become a resume for these talented folks. As for the future, I think Paul does a great job of predicting that:

I think the trend of big companies buying startups will only accelerate. One of the biggest remaining obstacles is pride. Most companies, at least unconsciously, feel they ought to be able to develop stuff in house, and that buying startups is to some degree an admission of failure. And so, as people generally do with admissions of failure, they put it off for as long as possible. That makes the acquisition very expensive when it finally happens.

What companies should do is go out and discover startups when they’re young, before VCs have puffed them up into something that costs hundreds of millions to acquire. Much of what VCs add, the acquirer doesn’t need anyway.

If you’ve made it this far you may be interested to know that Paul Graham has a blog now.

NVL, ISNULL, IFNULL and COALESCE

Welcome to a brief stop in the twilight zone of database functions.

If you want to check two (or more) fields and get the value of the first non-null field in Oracle you would use nvl. I needed to do the same thing in SQL Server 2000, which doesn’t have the function nvl (of course). After looking around SQL Server has a function that does the same exact thing called isnull.

By this point I figured I’d better be complete and find out if MySQL had a function called nvl or if they called it something else. If you guessed that it is called something else then you would be right, MySQL calls it ifnull. I was already familiar with the PostgreSQL equivalent which is called coalesce. Unlike all of the other functions mentioned above though, coalesce takes a list of fields/values/expressions instead of just two. Although the name sounds a little strange (nvl just rolls of the tongue so nicely) it certainly made more sense to have a more generalized function that would accept a list. As an additional reference the mysql compatibility project includes a ifnull function for folks porting SQL from MySQL to PostgreSQL.

So do you feel a little more enlightened now? Don’t stop now, it gets even stranger.

I got to thinking more about how much better the coalesce approach seems to be than nvl, isnull and ifnull so I did some more research to see what other databases besides PostgreSQL supported it. Guess what I found out. There is a coalesce in Oracle, a coalesce in SQL Server and a coalesce in MySQL. Huh? Why do folks even bother writing SQL that includes the use of nvl, isnull and ifnull?

That concludes our brief tour through the twilight zone of database functions for now.