The query optimizer fails to recognize partitioning function involving
modulus function. For example a partitioned view over tables partitioned as
follows is not optimized correctly:
CREATE TABLE Table_0 (
ID int NOT NULL CHECK (ID%10 = 0),
FirstName varchar (60) NOT NULL ,
LastName varchar (60) NOT NULL ,
GenderID tinyint NOT NULL ,
CONSTRAINT xPKTable_0 PRIMARY KEY CLUSTERED (ID)
)
But does work correctly with this
CREATE TABLE Table_0 (
ID int NOT NULL CHECK (ID between 0 and 10000),
FirstName varchar (60) NOT NULL ,
LastName varchar (60) NOT NULL ,
GenderID tinyint NOT NULL ,
CONSTRAINT xPKTable_0 PRIMARY KEY CLUSTERED (ID)
)
When the partitioned view is build over tables using the modulus function,
the optimizer will access each table in the view to satisfy a SELECT query
(select * from Table_View where ID = 25). When the view is built over the
BETWEEN comparison, the optimizer will only reference the relevant table.
This can be seen by setting statistics io on.
Is this a bug? I see nothing in BOL that indicates that the first check
constraint should not work. Is there a way to make this work? Having a
dynamic partitioning function is much more flexible that hard-coded ranges.
All the examples I have seen have been hard-coded, typically to a date
range.
Thanks,
Seth