tags:

views:

195

answers:

1

How are non-deterministic functions used in SQL partitioning functions and are they useful?

+2  A: 

MsSql allows non-deterministic functions in partitioning functions:

CREATE PARTITION FUNCTION MyArchive(datetime)
AS RANGE LEFT FOR VALUES (GETDATE() – 10)
GO

Does that mean that records older then 10 days are automatically moved to the archive (first) partition? Of course not.

The database stores the date when the partitioning schema was set up and uses it in the most (logical) way. Lets say one sets the above schema on 2000 -01-11 which makes the delimiting date 2000-01-01. When you are querying for data with date lower then the initial delimiting date (boundary_value - 2000-01-01) you will use only the archive partition. When you are querying for data with date higher then the current day minus 10 days (GETDATE() – 10) you will be using only the current partition. All other queries will use both partitions ie querying for data with date lower then current date minus 10 days but higher then the delimiting date (2000-01-01).

This means that with each passing day, the range of dates for which both partitions are used is growing. And you would have been better of setting the partition to the delimiting date deterministically.

I don't forsee any scenario where this is useful.

Goran