A
A
artshelom2021-06-14 21:53:42
SQL Server
artshelom, 2021-06-14 21:53:42

How can I increase the query speed?

I make a simple request:

SELECT top 500 * 
  FROM [dbo].[table1] 
  WHERE ([Id] NOT IN (select [ClientTableId] from [Entities] where [column] = '2'))

Execution speed: 23 seconds I execute
in Sql Server
[dbo].[table1] - 20541 records
[dbo].[Entities] with where is - 4500 records

How can I increase the speed, then 23 seconds does not suit at all (?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Akina, 2021-06-14
@artshelom

SELECT TOP 500 * 
FROM [table] 
WHERE  NOT EXISTS ( SELECT NULL 
                    FROM [Entities] 
                    WHERE [column] = '2' 
                      AND [table1].[Id] = [ClientTableId] )

PS. The presence of an index Entities (column, ClientTableId) is welcome. However, maybe Entities (ClientTableId, column) will be better - it depends on the statistics of the data.
P.P.S. TOP 500 without specifying ORDER BY is a little meaningful thing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question