NEWID Vs NEWSEQUENTIALID

When GUIDs got introduced, people started using them as primary keys (which is ok) and, because of default, most of those GUIDs ended up as clustered index.

Clustered index itself tries to keep values that are close to each other in binary form also close in physical order. This is fine for data that is usually just increasing (like integer identity column) but it is not as good when you have random data. Unfortunately GUIDs (as created with NewId function) are closer to random than to any other order.

NewSequentialId function was introduced to solve this exact problem. It will return values in increasing order but with small catch - it is guarantied only until you restart Windows. Once you reboot Windows starting value might be lower than last one inserted.

Shit really hits the fan if you need to combine date from more than one server. Each one will generate completely different set of increasing GUIDs. This will wreak havoc for your clustered index. Fragmentation, here we come.

And what is result of this “fight”? Should one use NewId or NewSequentialId function?

It simply does not matter. Once you remove clustered index issue from decision process, either function works fine. And I cannot say that I see any scenario where clustered index on GUID is appropriate.

Am I missing something?

P.S. Personally, I would go for NewId - it is shorter to write and it is more user-friendly.

Straw That Broke the Camel's Back

I loved Windows Mobile 6.5 so at first I was looking forward to Windows Phone 7. Than rumors started that it will not support legacy applications. Fine I thought, I will just rewrite them as I need and at least I will get to do some refactoring.

Then multitasking was killed. Yes, platform does support it, Microsoft’s own applications can use it but mere third-party developers were not worthy of it. That also unfortunately meant that I would need to rethink some applications. I didn’t felt good about it but I still wanted to develop for it.

I thought that half of this things I hear around are just misunderstanding and everything will become clear once official development tools go out. This happened today. And it is clear…

Phone registration tool was last straw for me.

You see, once you buy phone, you cannot just do development on it - you MUST register it with Microsoft. They will than link your development phone to your MarketPlace account. That account costs $100 per year. This is little bit high but I was prepared to do it.

Only one small problem remains - I am from Croatia. That means that I CAN NOT register an account and I CAN NOT make any application for it. Even local debugging without any thoughts about selling is impossible for me.

I heard semi-official position on this: I should just find somebody that lives in “correct” country and he can apply instead of me. Never mind that I would break Windows Phone Marketplace Application Provider Agreement. This will just “result in possible revocation of your Marketplace Account, removal of your Applications from Marketplace, loss of Application ratings and reviews, and forfeiture of any associated Account Fee.”

I did my share of Windows Mobile development of both paid and freeware applications but love that started with Embedded Visual Basic and had it’s peek with C# and .NET Compact Framework is no longer there. And it is not because newest platform is bad. Technical aspects of Windows Phone 7 development allow for better things that any version before.

It is politics surrounding it that make me sad. Intentional crippling of platform, complicating development without any good reason and treating me as second class citizen are things I am not used to.

I cannot say anything for sure - life is too unpredictable for this - but I doubt that Windows Phone 7 will be visiting my pocket any time soon. So long, and thanks for all the fish.

P.S. No matter what tone of this post is, I will always value Microsoft’s programming tools. I can say, without any doubt, I’ve never had better working environment than Visual Studio and I will definitely continue to use .NET Framework. Microsoft did phenomenal job with them.

O Tempora

Illustration

Some time ago I had need for NTP server of my own. It was just quick and dirty solution for problem that probably affects only me.

I selected this small project as my venture into open source world. Project is hosted at GitHub. If you need it, you got it.

[2015-04-25: Project is moved to GitHub]

Error Validating the Default for Column...

Illustration

For one project of mine I needed to use GUID for column identification inside SQL Server 2008 R2. As usually, I expected everything to go fine. I just add new column (Id in my case) and set it’s data type to “uniqueidentifier”. After that just set that field’s default to whichever function generates new GUID. Since I am running SQL Server 2008 R2 I opted to use NEWSEQUENTIALID (I will explain why in some other post).

As I am programmer first and database administrator only when needed, my natural environment when dealing with database is right-clicking Design and doing changes in more visual way.

As soon as I changed “Default Value or Binding” property to “(NEWSEQUENTIALID())” I was greeted with “Error validating the default for column ‘id’. Do you want to cancel your changes?” After checking all documentation and rechecking it again, I just answered to this question “NO”.

After other fields were adjusted and I tried to save changes, I was greeted with another message: “Warnings were encountered during pre-save validation process, and might result in failure during save. Do you want to continue attempting to save?”. Correct answer here is “YES”.

Save went without hitch. After additional Internet searches I found that this is simple error in validation procedure. And it is in SQL Server since version 2005. Two versions after, it is still alive and kicking.

Until Microsoft fixes this in SQL Server 2020, just remember to hit first “NO” and second “YES”.

Keeping Screen on

When Android developer wants to keep screen on while application is running, it often ends up with him managing wake locks. Quite often this is not needed.

If only thing you want to do is to keep screen on while your application is running (e.g. video player) and you do not need more advanced power management control, you should just add another flag to existing window.

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
    setContentView(...); 
    ...2
}

System itself will now ensure that screen is kept turned on while your application is visible. As soon as your application is in background, everything returns back to normal. Added benefit of this approach is that no additional permissions are required.