Quantcast
Viewing all articles
Browse latest Browse all 12963

Table Size Increased after Column Store Index Rebuild (even though partition size decreased)

Hi,

I have a large table (about 60GB) with a Clustered Column Store Index (156 columns). The table is alsopartitioned (using SQL Server 2014 Developer Edition).

After the table was being populated with data for a while, I wanted to test the effects of Index Rebuild on the space used by the table.

I performed the test on a single partition.

I executed the following query to get an idea on how the segments are set up and how much disk space they take:

select object_name(object_id), partition_number, segment_id
, COUNT(DISTINCT column_id) AS NumOfColumns
, SUM(cs.row_count) AS Total_row_count
, AVG(cs.row_count) AS Avg_row_count
, MIN(cs.row_count) AS Min_row_count
, MAX(cs.row_count) AS Max_row_count
, SUM(cs.on_disk_size) AS Total_on_disk_size
, AVG(cs.on_disk_size) AS Avg_on_disk_size
, MIN(cs.on_disk_size) AS Min_on_disk_size
, MAX(cs.on_disk_size) AS Max_on_disk_size
from sys.column_store_segments as cs
inner join sys.partitions as p
on
	p.partition_id = cs.partition_id
where 1=1
and object_id = object_id('MyTable')
and partition_number = 10
GROUP BY object_name(object_id), partition_number, segment_id
ORDER BY segment_id

I also executed sp_spaceused on the table and noted its total size.

Then I executed an Index Rebuild on the one partition only of the clustered column store index:

ALTER INDEX [cci_MyTable] ON MyTable REBUILD PARTITION = 10

Then I executed the query above and sp_spaceused again and noted the changes.

The result was:

  • Two new segments were created.
  • The number of row counts per segment shuffled up (but the grand total remained the same).
  • The grand total of on_disk_size became smaller by ~26 MB.
  • The table size (from sp_spaceused) became BIGGER by ~12MB.

So my question is:

Why, even though the total partition size became smaller, the total table size became bigger?

Here are the detailed results of sp_spaceused before and after the rebuild:

namerowsreserveddataindex_sizeunused
MyTable12958714560867096 KB60729232 KB
7240 KB130624 KB
namerowsreserveddataindex_sizeunused
MyTable12958714560879504 KB60741712 KB
7240 KB130552 KB


Note that I executed the index rebuild on a single partition only (partition 10 in this case), and I'm executing sp_spaceused at the table level; the total number of rows in the table remained the same. But the reserved and data used increased, while the index_size remained the same.

This is all rather strange to me.

I would figure that the index rebuild would require some additional space as a working area, but when finished, this space will be marked as unused. So I would expect maybe the reserved column to increase, but the data column to decrease (since at the partition level, the total partition size actually decreased).

Any explanations? What could cause this?

Thanks


Eitan Blumin; SQL Server Consultant - Madeira SQL Server Services; http://www.madeira.co.il/author/eitan/


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>