I have two tables
Account: AccountUID bigint (Primary Key) AccountID bigint Version smallint CustomerName varchar(50)
Note: AccountID and CurrentVersion are also part of the unique
AccountStatus: AccountID bigint (Primary Key) CurrentVersion smallint Filter1 varchar(10) Filter2 varchar(10))
To keep things simple, I currently have 100 lines, since each AccountID has only one version. I have values โโin the Filter1 and Filter2 tables, so when I do the following, I get 10 entries:
SELECT * FROM AccountStatus acs WHERE acs.Filter1=SomeValue1 and acs.Filter2=SomeValue2
Due to the fact that I have an index that has Filter1 and Filter2 in it, the actual execution plan shows an index search with only 10 rows selected in the value "Actual Rows".
When I join the Account table as follows, I get the same 10 records:
SELECT acs.* FROM AccountStatus acs INNER JOIN Account a ON acs.AccountID=a.AccountID AND acs.CurrentVersion=a.Version WHERE acs.Filter1=SomeValue1 and acs.Filter2=SomeValue2
However, when I look at the Actual Execution Plan, I still see the Index Seek in the AccountStatus table, as before, with 10 actual rows. However, above, I see an index index that includes the AccountID and Version the Account table. In addition, this โactionโ shows 100 in actual rows.
Below is detailed information about the indices used:
CREATE NONCLUSTERED INDEX [IX_Find] ON [dbo].[AccountStatus] ( [Filter1] ASC, [Filter2] ASC ) INCLUDE ( [AccountID], [CurrentVersion] ) 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 [PRIMARY] CREATE UNIQUE NONCLUSTERED INDEX [IX_Account_Status] ON [dbo].[Account] ( [AccountID] ASC, [Version] ASC ) INCLUDE ( [AccountUID]) 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 [PRIMARY]
While this is not too much for 100-line performance, it bothers me more when I get a million or several million lines. It will become very inefficient.
In any case, so that this type of query does not look at all the rows in the index in the Account table?
Any help would be greatly appreciated.