Top 1 faster if only selecting one row

Does the database break the selection loop as fast as it has got one record when using Top 1?

So that select top 1 * from customer where cusId = 1234

is faster than select * from customer where cusId = 1234 ?

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


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

EDIT:

You are only adding overhead with TOP 1 if you have unique index that will return 1 result anyway.

It will be different if you have order by something than you are interested in only one row.

MORE:

There is no looping involved, unless there is a table scan involved and there is no index at all for cusId . In that case, TOP 1 can't help you anyway.


在我看来, select * from customer where cusId = 1234会更快..它有一个操作比第一个操作更少...

链接地址: http://www.djcxy.com/p/53514.html

上一篇: 什么是mavenProjectBuilder在maven 3中被弃用的替代品?

下一篇: 如果只选择一行,则排名前1位更快