Top 1 is faster if you select only one row

Is the database interrupting the allocation cycle as fast as it has one record when using Top 1?

So select top 1 * from customer where cusId = 1234

faster than select * from customer where cusId = 1234

cusId is unique, so does MSSql understand that it is "faster" without top 1 ?

+7
source share
2 answers

If cusId is the primary key, both should be the same: performance.

EDIT:

You only add overhead with TOP 1 if you have a unique index that will still return 1 result.

This will be different if you have an order for something that interests you in only one line.

MORE:

A cycle is not involved if table scanning is not used, and for cusId there is no index at all. In this case, TOP 1 still does not help.

+4
source

In my opinion, select * from customer where cusId = 1234 will be faster. b / c he has one operation less than the first ...

0
source

All Articles