Here is my request:
SELECT TOP 10 * FROM BigTable WHERE Value <> 2;
BigTable is little specific, since the column Valuecontains the same value for each row: 2. In real cases, there may be several lines that have a different meaning, but not so much. I really need to find these rogue lines. However, I do not know what value (2 is just an example) during development (but I know at the time of the request).
The request is slow (about 5 minutes); BigTable contains 10 million rows.
So, I added an index to the column Value, which is of type smallint. After 10 minutes, the index was built, and I again requested a query. It is still very slow.
: http://sqlfiddle.com/#!6/6ce0f/1
, SQL Server <>, , ? , 2 : SELECT TOP 10 Value FROM BigTable GROUP BY Value ( 2, ).
: , - -, SELECT TOP 10 * FROM BigTable WHERE Value = x .. ( , 2), ?
EDIT:
, , , . , . , , ( ). , , . , , , .
( Entity Framework Core, ):
CREATE NONCLUSTERED INDEX [IX_Value] ON [dbo].[BigTable]
(
[Value] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
2:
SSMS ( , , , , , )
Value <> 2

, IX_Establishments_UpdateTag ( ). : 5 18 ( , Value/UpdateTag 2)
Value < 2

IX_Establishments_UpdateTag. 1 (SSMS- 0s).