No, it's not aligned.
Your quote is just the portion that seeks to clarify the potential equivalence of different partition functions.
The following sections speak only of a common partitioning column.
When partitioning a clustered index, the clustering key must contain the partitioning column. When partitioning a nonunique clustered index and the partitioning column isn't explicitly specified in the clustering key, the database engine adds the partitioning column by default to the list of clustered index keys. If the clustered index is unique, you must explicitly specify that the clustered index key contain the partitioning column. For more information on clustered indexes and index architecture, see Clustered Index Design Guidelines.
When partitioning a unique nonclustered index, the index key must contain the partitioning column. When partitioning a nonunique, nonclustered index, the database engine adds the partitioning column by default as a nonkey (included) column of the index to make sure the index is aligned with the base table. The database engine doesn't add the partitioning column to the index if it's already present in the index. For more information on nonclustered indexes and index architecture, see Nonclustered Index Design Guidelines.
An attempt to SWITCH out a partition of your table will fail with the error:
Msg 4912, Level 16, State 1
'ALTER TABLE SWITCH' statement failed.
The columns set used to partition the table 'dbo.Partitioned' is different from the column set used to partition index 'PartitionedDifferent'.
The documentation could be more explicit about this.
"Aligned" is a convenient shorthand for the idea that each partition (rowset) forming the indexes (and base table) should contain the same rows.
In other words, partition n of the base table should be guaranteed to contain the same rows as partition n of all secondary indexes. This is what allows things like SWITCH to work correctly as a metadata-only operation without physical data movement.
Older versions of the documentation were clearer about this (emphasis added):
Although partitioned indexes can be implemented independently from their base tables, it generally makes sense to design a partitioned table and then create an index on the table. When you do this, SQL Server automatically partitions the index by using the same partition scheme and partitioning column as the table. As a result, the index is partitioned in essentially the same manner as the table. This makes the index aligned with the table.
and in General Requirements for Switching Partitions:
Partitions must be on the same column. If you are switching a partition from one partitioned table to another, both tables must be partitioned on the same column.
Older documentation also stated the requirements when indexed views are present. This information has simply been lost in modern versions due to consolidation.
An indexed view is partition-aligned with the table it references if the following conditions are true:
Selective truncate bug
As a side note, Dan Guzman noticed that the new TRUNCATE TABLE syntax allowing only certain partitions to be truncated has a bug with non-aligned partitions, which will corrupt the structures involved (unless all partitions are specified).
The command should only be allowed with aligned indexes. Unfortunately, the documentation suggests an incomplete test is used:
To truncate a partitioned table, the table and indexes must be aligned (partitioned on the same partition function).
As discussed, being partitioned using an equivalent partition function is not sufficient.
Demo
INSERT dbo.Partitioned
(TablePartitioningColumn, IndexPartitioningColumn)
VALUES
('1999-07-01', '2000-07-01'),
('2000-07-01', '2001-07-01'),
('2001-07-01', '2002-07-01');
-- Check partitions
SELECT *,
PF1 = $PARTITION.ByYear(TablePartitioningColumn),
PF2 = $PARTITION.ByYear(IndexPartitioningColumn)
FROM dbo.Partitioned AS P;
| Junk |
TablePartitioningColumn |
IndexPartitioningColumn |
PF1 |
PF2 |
| NULL |
1999-07-01 00:00:00 |
2000-07-01 00:00:00 |
1 |
2 |
| NULL |
2000-07-01 00:00:00 |
2001-07-01 00:00:00 |
2 |
3 |
| NULL |
2001-07-01 00:00:00 |
2002-07-01 00:00:00 |
3 |
4 |
TRUNCATE TABLE dbo.Partitioned WITH (PARTITIONS (1));
DBCC CHECKTABLE (Partitioned);
Msg 8952, Level 16, State 1
Table error: table 'Partitioned' (ID 260248032).
Index row in index 'PartitionedDifferent' (ID 2)
does not match any data row. Possible extra or invalid keys for:
Msg 8956, Level 16, State 1, Line 46
Index row (1:341560:0) with values (
IndexPartitioningColumn = '2000-07-01 00:00:00' and
TablePartitioningColumn = '1999-07-01 00:00:00' and
HEAP RID = (1:333464:0)) pointing to the data row
identified by (HEAP RID = (1:333464:0)).
DBCC results for 'Partitioned'.
There are 2 rows in 2 pages for object "Partitioned".
CHECKTABLE found 0 allocation errors and 1 consistency errors
in table 'Partitioned' (object ID 260248032).
repair_rebuild is the minimum repair level for the errors
found by DBCC CHECKTABLE (dbo.Partitioned).
DBCC execution completed.
Feedback site bug report