Use sp_helpFile and sp_helpFileGroup to see the allocations.
Index partitioning
If table and index use the same partitioning function and partitioning columns (in same order), they are said to be aligned.
If table and index use the same partitioning function and partitioning scheme, they are said to be storage aligned. In general, having the tables and indexes on the same file or filegroup can often benefit where multiple CPUs can parallelize an operation across partitions. In the case of storage alignment and multiple CPUs, SQL Server can have each processor work directly on a specific file or filegroup – and know that there are no conflicts in data access because all data required for a particular join or index lookup will be colocated on the same disk.
LEFT and RIGHT parititions
For a LEFT partition function, the extreme LEFT boundary point is fixed. For a RIGHT partition function, the extreme RIGHT boundary point is fixed. The other ends of the partitions will not have boundary points explicitly defined (ie, the extreme right will be ∞ for a left partition function, and the extreme left will be -∞ for a right partition function).
To easily remember the rules of LEFT and RIGHT partition functions, picture a number line and use just one boundary condition as an example.
In a LEFT partition function, any value that is on the LEFT of a boundary condition, is always <= the boundary condition, and any value that is on the right of the boundary condition is always > than the boundary condition. (Remember, that in the left partition function, the extreme right is open (∞), so towards right is always > and going towards infinity).
For e.g. if the first value (or boundary condition) of a partition function is ‘20001001’ then the values within the bordering partitions will be:
1st partition is all data <= ‘20001001’
2nd partition is all data > ‘20001001’
In a RIGHT partition function, any value that is on the RIGHT of a boundary condition, is always >= the boundary condition. Any value on the left of the boundary condition is always < than the boundary condition. (Remember, in the RIGHT partition function, the extreme left is open (-∞), so towards left is always < and going towards -∞.
For e.g. if the first value (or boundary condition) of a partition function is ‘20001001’ then the values within the bordering partitions will be:
1st partition is all data < ‘20001001’
2nd partition is all data => ‘20001001’
Process of partitioning a table, index, or indexed view is as follows:
1. Create a partition function.
2. Create a partition scheme mapped to a partition function
3. Create the table, index, or indexed view on the partition scheme.
PARTITION FUNCTION
A partition function defines the set of boundary points for which data will be partitioned.
e.g.
CREATE PARTITION FUNCTION myPartFunction (int)
AS RANGE LEFT
FOR VALUES (10,20,30,40,50)
PARTITION SCHEME
A partition scheme defines the storage structures and collection of filegroups that you want to use with a given partition function.
E,g,
CREATE PARTITION SCHEME myPartScheme
AS PARTITION myPartFunction
TO (fileGroup1, fileGroup2, fileGroup3, fileGroup4, fileGroup5
OR
CREATE PARTITION SCHEME myPartScheme
AS PARITION myPartFunction
ALL TO (fileGroup1)
Important: The filegroup must already be present in the database. SQL Server allows the use of the ALL keyword which allows you to create all paritions defined by the partition function within a single filegroup. If you do not use the “all” keyword, then the partition scheme must be defined in such a way as to contain a filegroup for each partition that is created by the partition function mapped to the partition scheme. ie, Each partition that is created in the partition function, must be associated with atleast one file group. If you use the “all” keyword, a maximum of only one filegroup can be specified.
CREATING PARTITIONED TABLE OR PARTITIONED INDEX
This is similar to creating a non partitioned table, index or indexed view. The ON clause is where the difference lies. Instead of specifying a filegroup on which to create the table, you specify a partition scheme.
CREATE TABLE Employee
(EmployeeID INT, Name varchar(100))
ON mypartscheme (employeeID)
You need to specify the column in the table, the partitioning key, to which the partition function will be applied. The partitioning key must match the data type, length and precision of the partition function. If the partition column is computed, the computed column must be PERSISTED (values must be physically stored)
Partitioned index is similar
CREATE NONCLUSTERED INDEX idx_employeeName ON dbo.Employee(name)
ON myPartScheme(EmployeeID).
When specifying partitioning key for an index, you are not limited to the columns that on which the index is defined.
SPLIT AND MERGE OPERATORS
The SPLIT operator introduces a new boundary point into a partition function. MERGE eliminates a boundary point from a partition function. You must be careful while using this because you are either adding or removing an entire partiton form the partition function. Data is not being removed – only partition. Because a partition can reside only in a single filegroup, these operations could cause significant amount of disk I/O as sql server relocates rows on disk.
ALTER PARTITION FUNCTION partition_function_name
{SPLIT RANGE (boundary_value)
| MERGE RANGE (boundary_value)} [;]
ALTERING A PARTITION SCHEME
You can add filegropus to an existing partition scheme to create more storage space for a partitioned table.
ALTER PARTITION SCHEME partition_Scheme_name
NEXT USED [file_group_name] [;]
The NEXT USED clause has two purposes
1. It adds a new filegroup to the partition scheme, if the specified filegroup is not already part of the partition scheme.
2. It marks the NEXT USED property for a filegroup. The filegroup that is marked with the NEXT USED flag is the filegroup that contains the next partition that is created when a SPLIT operation is executed.
Note: Partitioning can be done after it has been populated with data – although this causes significant disk IO. To partition an existing table, you need to drop the clustered index and re-create the clustered index on the partition scheme. To partition an existing index or indexed view, drop the index and recreate the index on a partition scheme.
SWITCH OPERATOR
The basic idea is that SWITCH allows you to exchange partitions between tables in a perfectly scalable manner with no locking, blocking or deadlocking. SWITCH has severala requirements to ensure that the operation is perfectly scalabale. Th emost important are as follows
- The data and index for the source and target tables must be aligned.
- Source and target tables must have the same structure.
- Data cannot be moved from one file group to another
- Two partitions with data cannot be exchanged
- The target partition must be empty
- The source or target table cannot participate in replication.
- The source or target tables cannot have full text indexes or FILESTREAM data type defined..
Points to Remember:
1. You cannot use columns which are of text, ntext, image, sml, varbinary(max), varchar(max) or any CLR data types for partitioning. Any column that are used for partitioning should be deterministic.
2. Maximum number of partitions for a table is 1000.
3. There fore you are allowed to specify a maximum of 999 boundary points.
4. A computed column must be PERSISTED
5. SPLIT is used to introduce a new boundary point to a partition function
6. MERGE is used to remove a boundary point from a partition function
7. SWITCH is used to move partition between tables.
8.In a SWITCH operation, You cannot move data from one filegroup to another , nor exchange two partitions with data – ie, only one partition may contain data.
List out which tables are partitioned, and what partition scheme and partition function they use:
SELECT DISTINCT object_name(o.object_id), pf.name AS function_name, ps.name AS scheme_name
FROM
sys.objects o
INNER JOIN
sys.indexes i ON o.object_id = i.object_id
INNER JOIN
sys.partition_schemes ps ON ps.data_space_id = i.data_space_id
INNER JOIN
sys.partition_functions pf ON ps.function_id = pf.function_id
WHERE i.index_id < 2
LIST which column the table is being partitioned on
SELECT b.name
FROM
sys.index_columns a
inner join
sys.columns b on
a.column_id= b.column_id
WHERE
OBJECT_NAME(a.OBJECT_ID)='<tableName>’ and
a.partition_ordinal = 1 and OBJECT_NAME(b.OBJECT_ID)='<tableName>’;
*If partition_ordinal = 0, it is not a partitioned column
SOURCE: MCTS Training kit (chapter 6)
http://www.sqlskills.com/resources/whitepapers/partitioning%20in%20sql%20server%202005%20beta%20ii.htm#_Toc79339948