Partition split

will 1 Reputation point
2020-12-11T20:18:43.64+00:00

The problem involves trying to split a partition table which did not as an empty partition at the end. The table also has a columnstore index. Though it was dropped prior to trying to split the partition and the last partition was switch out.

When trying to split a heap table, it will fail with the following error. Is it because there is another partition table2 using the same filegroup? table2 has it own partition function and scheme. What is preventing the split?

SPLIT clause of ALTER PARTITION statement failed because the partition is not empty.  Only empty partitions can be split in when a columnstore index exists on the table. Consider disabling the columnstore index before issuing the ALTER PARTITION statement, then rebuilding the columnstore index after ALTER PARTITION is complete.
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,955 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,651 questions
0 comments No comments
{count} votes

9 answers

Sort by: Most helpful
  1. David Browne - msft 3,851 Reputation points
    2020-12-11T20:33:23.967+00:00

    ALTER PARTITION FUNCTION SPLIT is an operation on a Partition Function, and will affect all Partition Schemes using that function, and all tables and indexes residing on those Partition Schemes.

    Here's a function to list all the partitions with their boundary values and row counts:

    SELECT   
      tbl.name table_name,  
      indx.name index_name,  
      pf.name partition_function,  
      ps.name partition_scheme,  
      prt.value boundary_value,  
      p.partition_number,  
      prt.boundary_id,  
      prt.value boundary_value,  
      p.rows  
    FROM   
      sys.tables AS tbl  
      JOIN sys.indexes AS indx   
        ON indx.object_id = tbl.object_id  
      JOIN sys.partition_schemes ps   
        ON indx.data_space_id = ps.data_space_id  
      JOIN sys.partition_functions pf   
        ON ps.Function_id = pf.Function_id   
      JOIN sys.partitions p   
        on p.object_id = indx.object_id  
        and p.index_id = indx.index_id  
      LEFT JOIN sys.partition_range_values prt   
        on prt.function_id = pf.function_id  
        and prt.boundary_id + case when pf.boundary_value_on_right = 1 then 1 else 0 end = p.partition_number   
    
    0 comments No comments

  2. will 1 Reputation point
    2020-12-11T21:44:51.847+00:00

    Both tables are using different partion functions and schemes. They only share filegroups. Does it matter in this case?


  3. Ben Miller (DBAduck) 956 Reputation points
    2020-12-12T00:24:33.433+00:00

    The error pertains to having a Columnstore index on your table. There is a limitation when you have a columnstore index on the table and it is that you cannot have data in the partition that you are splitting (1 of them has to be empty and the other can have data).

    So basically if you have a Columnstore index and you are trying to split a partition in the middle of a table and not on the ends of a table, you will get an error because you have to have 1 empty partition on the side of the split.

    Partition 1 - data
    Partition 2 - data -- want to split this one
    Partition 3 - data
    Partition 4 - no data

    If you want to do like above, you can if you do NOT have a Columnstore index on your table. If you do, you will get the error message you have above. (This will work if you drop the columnstore and split and then put the columnstore back on)

    Partition 1 - data
    Partition 2 - data
    Partition 3 - data -- want to split
    Partition 4 - no data

    If you want to do this, then you can even with a Columnstore, because there is one empty partition on the side of the split. (this will work with or without Columnstore indexes on the table)

    Hope that makes sense.

    0 comments No comments

  4. will 1 Reputation point
    2020-12-12T01:41:26.503+00:00

    Just to be clear, columnstore index had been dropped and the last partition had been switched out. so its empty.

    The table is now a heap table (partitioned).

    Partition 1 - data
    Partition 2 - data 2017-10-01
    Partition 3 - data 2017-11-01
    Partition 4 - no data (empty - switched out) 2017-12-01
    New Partition - Failed adding new 2018-01-01


  5. will 1 Reputation point
    2020-12-15T05:05:39.457+00:00

    Here are the results. As you can see partition 28 is empty, trying to add another partition after 28 is failing.

    partition_number    row_count
    1   0
    2   764365
    3   1947913
    4   9557952
    5   27624757
    6   50458571
    7   44443201
    8   61740713
    9   87396953
    10  58255125
    11  80414892
    12  44353571
    13  41169213
    14  37814501
    15  47813687
    16  63350026
    17  48993126
    18  50130871
    19  63185287
    20  60620138
    21  53509630
    22  57301035
    23  58564594
    24  60276995
    25  54829324
    26  50389878
    27  59874418
    28  0
    
    
    boundary_id rows_per_boundary
    1   6
    2   6
    3   6
    4   6
    5   6
    6   6
    7   6
    8   6
    9   6
    10  6
    11  6
    12  6
    13  6
    14  6
    15  6
    16  6
    17  6
    18  6
    19  6
    20  6
    21  6
    22  6
    23  6
    24  6
    25  6
    26  6
    27  6
    28  1
    29  1
    30  1
    31  1
    32  1
    33  1
    34  1
    35  1
    36  1
    37  1
    38  1
    39  1
    40  1
    41  1
    42  1
    43  1
    44  1
    45  1
    46  1
    47  1
    48  1
    49  1
    50  1
    51  1
    52  1
    53  1
    54  1
    55  1
    56  1
    57  1
    58  1
    59  1
    60  1
    61  1
    62  1
    63  1
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.