I wanted to see the effects of having indexes on calculated columns, so I created a table like so:
CREATE TABLE [Domain\UserName].[CompColIndexing](
[a] [int] NOT NULL,
[nonIndexedNonPersisted] AS ([a]+(1)),
[nonIndexedPersisted] AS ([a]+(1)) PERSISTED,
[IndexedNonPersisted] AS ([a]+(1)),
[IndexedPersisted] AS ([a]+(1)) PERSISTED
) ON [DATA]
I've added 800,000 rows to this, with the value for a cycling through 0 to 9.
The following indexes were added:
CREATE NONCLUSTERED INDEX [IX_DJB_CompNonPersisted] ON [Domain\UserName].[CompColIndexing]
(
[IndexedNonPersisted] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [DATA]
GO
CREATE NONCLUSTERED INDEX [IX_DJB_CompPersisted] ON [Domain\UserName].[CompColIndexing]
(
[IndexedPersisted] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [DATA]
GO
Than I ran some ORDER BY clauses to see what performance differences I would get, plannign afterwards to see how changing values of a would affect things.
SELECT *
FROM [EMEA\BanksD].[CompColIndexing]
ORDER BY a
SELECT *
FROM [EMEA\BanksD].[CompColIndexing]
ORDER BY nonIndexedNonPersisted
SELECT *
FROM [EMEA\BanksD].[CompColIndexing]
ORDER BY IndexedNonPersisted
SELECT *
FROM [EMEA\BanksD].[CompColIndexing]
ORDER BY nonIndexedPersisted
SELECT *
FROM [EMEA\BanksD].[CompColIndexing]
ORDER BY IndexedPersisted
Unexpectedly though, I find that I get exactly the same result for each of the queries:
I was at least expecting the SORT operation on the first query to be slower as that one is unindexed.
What's happening here?
The cardinality is low on purpose, in reality, I actually need to sort on three different values.
I'm using Microsoft SQL Server 2008 R2 (SP2) - 10.50.4042.0 (X64)
Actual execution plans available at: https://www.brentozar.com/pastetheplan/?id=S10MTuxGg


