Using the StackOverflow2010 database, I can create an index on the users table as follows:
CREATE INDEX IX_DisplayName ON dbo.Users ( DisplayName, UpVotes ) And then run an inequality search on the key of the index:
SELECT DisplayName, UpVotes FROM Users WHERE DisplayName <> 'Alex' I get the plan here
I am trying to work out how SQL Server has gone about getting the results for this query.
The plan begins with some constant scans but the Output list is blank so it isn't clear to me what they are for. The two computer scalars which follow output Expr1003-1008 which are used by the Concatenate operator but that is also using Expr1009 and Expr1010 which I can't see the origin of. I am also not sure why the TOP N sort is required
The Index seek makes sense - it is looking for > Expr1011 and < Expr1012. I would assume that this is basically something like
>= 'a' AND < 'Alex' or
> 'Alex' AND <= 'zzzzzzzzzzzzzz' or similar.
Can someone explain to me step by step, how this plan is working and how I can understand the values of Expr1011 and Expr1012 (used in the index seek) which are produced by the concatenation operator