February 25, 2014 at 5:05 pm
Using SQL 2008 R2 Enterprise
I am trying to partition a pair of existing 200 million row tables to improve reporting performance. As I understand it, I need to drop the existing clustered index and create a new one on the date stamp the partition funciton and scheme is based on. I don't want to dump the data into a new table because I want the existing reports to work without modification.
Here's my code:
CREATE PARTITION FUNCTION ByCreatedWhen_fn (DATETIME)
AS RANGE RIGHT FOR VALUES
('2011-01-01',
'2012-01-01',
'2012-07-01',
'2013-01-01',
'2013-07-01',
'2014-01-01',
'2014-07-01');
CREATE PARTITION SCHEME ByCreatedWhen_scm
AS PARTITION ByCreatedWhen_fn
ALL TO (ESP); -- existing filegroup that contains the tables
ALTER TABLE [dbo].[SXEvent] DROP CONSTRAINT [SXEventPK]
GO
CREATE CLUSTERED INDEX [ByCreatedWhen_idx] ON [dbo].[SXEvent]
([CreatedWhenUTC] ASC )
On ByCreatedWhen_scm
When I go to create the index I get the error:
Msg 2726, Level 16, State 1, Line 3
Partition function 'ByCreatedWhen_fn' uses 1 columns which does not match with the number of partition columns used to partition the table or index.
But I'm only using one column to partition the table & index. What does this mean?
February 25, 2014 at 5:14 pm
I believe you need to reference the column again on in the partition scheme. Seems redundant, but it does not need to match 100%.
CREATE CLUSTERED INDEX [ByCreatedWhen_idx] ON [dbo].[SXEvent]
([CreatedWhenUTC] ASC )
On ByCreatedWhen_scm (CreatedWhenUTC)
February 26, 2014 at 3:51 pm
Yes, not obvious why the column needs to be specified again, but it seems to be working.
Dan
February 26, 2014 at 4:05 pm
dan-572483 (2/26/2014)
Yes, not obvious why the column needs to be specified again, but it seems to be working.Dan
You can, and we do, create multi-column PK on a table, but only use one of the columns for partitioning. The only requirement for this example is that the partitioning column(s) are part of clustered index, which is usually the PK as well.
February 27, 2014 at 1:05 am
dan-572483 (2/25/2014)
I am trying to partition a pair of existing 200 million row tables to improve reporting performance.
Don't waste your time. Partitioning is not a performance tuning technique. While it is possible to get performance improvements out of partitioning, they don't necessarily come by default, queries usually have to be written to take advantage of partitioning.
https://www.simple-talk.com/sql/database-administration/gail-shaws-sql-server-howlers/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply