Wish: SUB-INSERT SQL statements

Sub-selects are nice:

INSERT INTO person
 (name, phone, city_id)
VALUES
 ( 
   'john',
   '555-1234',
   (SELECT id FROM city WHERE name = 'Los Angeles')
 )

It saves a DB roundtrip to find the city.id for ‘Los Angeles’.

But sometimes you encounter a new city and first have to assign an entry for it in the city table. Except that the row may already exist, so first you have to select the city, if it does not exist, create the city and finally store the person. MySQL has a nice pattern for storing rows that might already exist in the DB, allowing us to combine the select-if-not-found-store steps into one:

INSERT INTO city
  (name)
VALUES
  ('Palo Alto')
ON DUPLICATE KEY
  UPDATE id = LAST_INSERT_ID(id);

MySQL will return the correct city.id for the new city entry regardless of whether the row had to be inserted or it already existed.

Now, it would be sweet if INSERTs could be used the same way SUB-SELECTs are, allowing us to combine all three steps into a single statement:

INSERT INTO person
 (name, phone, city_id)
VALUES
  ( 
   'john',
   '555-1234',
   (
     INSERT INTO city
       (name)
     VALUES
      ('Palo Alto')
     ON DUPLICATE KEY
      UPDATE id = LAST_INSERT_ID(id);
   )
 )

This pattern happens all the time when storing complex records that span multiple tables. It would be very convenient if databases would support it natively.

Advertisements

Warehouse Robotics + Data Centers

Inspired by: The Building is the New Server by @w_scottweiss + Faster Than Overnight by @MarcusWohlsen + Amazon buys Kiva Systems

Our future overlords Google, Amazon, Apple, Facebook,… are all building new massive datacenters. Servers are custom designed for maximizing density, and ease of replacing failed components.

The next logical step is datacenters built similar to modern warehouses used by the likes of Amazon for order fulfillment. Modern warehouses are designed to allow robots to stock and retrieve all the goods from shelves. These warehouses acheive far higher efficiency and density than those operated by humans. Because of the structured nature of datacenters (racks upon rack of servers) robots could be similarly adapted to replace failed components, servers, etc… in datacenters. Designing with robots in mind might enable entirely new layouts, topologies and environments for increased density and cooling performance.

Credit Rolls for Software

Software should have credit rolls the way films do.

At the end of every film, there are the credit rolls that acknowledge the work of everyone who was involved in the making of the film:

Star Wars Episode IV Credit Roll

Why not the same for software? In the case of films, all sorts of people get credit for their contributions but in most software and software services, we don’t know the contributors and usually we can’t even find out. I use tons of online services but I have no idea who the true contributors really are. At most, if the service is very popular, I might know the name of the founders (Larry/Sergey, Jerry/David, Adam D’Angelo, …).

This opacity is a huge shame because people who write software should rightfully be recognized for their work.

It is even technically possible to produce a credit roll for the software that we use. Here is a version control log (svn -blame) of who the latest contributor for each line of code for a Polyvore js function:

 
  8358      kwyee // Monitor calls f every interval ms.  
  8358      kwyee // It fires a change event when f() changes.
  8482      kwyee // f() is passed to the trigger event handler.
  2073      pasha function Monitor(f, interval) {
  2623      pasha     var curr = f();
  2073      pasha     if (!interval) { interval = 100; }
  8656      kwyee     this.check = function() {
  2073      pasha         var now = f();
  2073      pasha         if (now != curr) {
  2073      pasha             curr = now;
  2073      pasha             Event.trigger(this, 'change', curr);
  2073      pasha         }
  8656      kwyee         return now;
  8656      kwyee     };
 17189      pasha     this.timer = new Interval(interval, this.check, this);
  2073      pasha }

It is possible to take this information and instrument the code such that each execution keeps track of all the people who contributed and produce an exhaustive credit roll of sorts. There could be a dialog that shows all the people whose code was executed to make this app / page / REST call etc… possible. I actually remember that old System 7 era Apple software used to have credits in the ‘About X…’ dialogs.

Smartphones + Free Online Education = Disruption

Ever since the industrial age, technology has been widening the gap between the rich and poor. You either fell on the side of the curve that benefits from technology, in which case you become more wealthy, or you fall below the threshold, in which case technology commoditizes you and you become poorer.

Actually, for a while, it was possible for people below the threshold to move up by learning new skills — farmers doing manual labor became more skilled factory workers. But the relentless improvement in technology pushed the bar higher and higher until people now have a hard time keeping up.  Where does the average person go once a computer can beat Kasporov in chess? Hence the erosion of the middle class.

There is however still room in high tech. If you are lucky and of above average intelligence, you can still be educated and secure one of the increasingly scarce jobs that are above the threshold of technological obsolescence. I say lucky because you have to be born in the developed world with access to higher education, etc.

With the advent of global Internet connectivity, affordable computing devices and free online education (information wants to be free), a few billion brains will soon have the potential to compete with the lucky few for the same increasingly scarce jobs.

I think something amazing is going to happen when all this comes to pass.  Either a weird dystopian future where everything is completely commoditized, or something amazingly wonderful, like all the brains working together to enable some breakthrough science that opens new frontiers for humanity.

My hope is for the latter.

Idea #7842

If one day I found myself running a big company where due to the sheer number of employees, a lot of people were leaving at any given time, I would institute this policy:

Employees would vest 5% of their options (or some other incentive) if they choose to leave at a time when their project has reached a stable state.

As far as I know, other than protecting their reputation, most employees have no incentive to leave at times that are “convenient” for their projects. The cost of someone  leaving at a critical phase of a project (eg: just before launch) is probably more than the incentives for persuading them to stay on until a less critical time.