Partitioning Error

  • 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?

  • 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)

  • Yes, not obvious why the column needs to be specified again, but it seems to be working.

    Dan

  • 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.

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply