When the code flat out lies to you

time to read 1 min | 154 words

Take a look at the following snippet. This is a table definition using Esent.


At a glance, this looks fine. It defines a table with a primary key that is auto incrementing whose type is long. Everything seems fine and dandy.

Unfortunately, there is a horrible bug in this code. The Long type here refers to Win32 long type in C which is… 32 bits. When I wrote this code, I assumed that this is C#’s long type, which is 64 bits in size.

The difference matters, because after just over 2 billion inserts to this table, everything is going to break in a horrible horrible horrible manner. At which point the only fix is to run a schema upgrade on the internal data structure, which is… an interesting experience when you have literally billions of records there.