久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 SELECT 查詢中使用 TOP 1 的性能影響

Performance effect of using TOP 1 in a SELECT query(在 SELECT 查詢中使用 TOP 1 的性能影響)
本文介紹了在 SELECT 查詢中使用 TOP 1 的性能影響的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個用戶表,其中有用戶名和應(yīng)用程序列.用戶名可能會重復(fù),但用戶名 + 應(yīng)用程序的組合是唯一的,但我沒有在表上設(shè)置唯一約束(為了性能)

I have a User table where there are a Username and Application columns. Username may repeat but combination of Username + Application is unique, but I don't have the unique constraint set on the table (for performance)

問題:是否有任何區(qū)別(性能方面):

Question: will there be any difference (performance-wise) between :

SELECT * FROM User where UserName='myuser' AND Application='myapp'

AND -

SELECT TOP 1 * FROM User where UserName='myuser' AND Application='myapp'

由于 Username + Application 的組合是唯一的,因此兩個查詢將始終返回不超過一條記錄,因此 TOP 1 不會影響結(jié)果.我一直認(rèn)為添加 TOP 1 會真正加快速度,因為 sql server 會在找到匹配項后停止查找,但我最近在一篇文章中讀到,使用 TOP 實際上會減慢速度,建議避免使用,盡管它們沒有解釋原因.

As combination of Username + Application is unique, both queries will always return no more than one record, so TOP 1 doesn't affect the result. I always thought that adding TOP 1 will really speed things up as sql server would stop looking after it found one match, but I recently read in an article that using TOP will actually slow things down and it's recommended to avoid, though they haven't explained why.

有什么意見嗎?

謝謝!安德烈

推薦答案

您可能會因使用 top 而獲得一些性能差異,但使用索引可以獲得真正的性能.

You may get some performance difference from just using top, but the real performance you get by using indexes.

如果您有 UserName 和 Application 字段的索引,則數(shù)據(jù)庫在隔離單個記錄之前甚至不必接觸表.此外,它已經(jīng)從表統(tǒng)計信息中知道這些值是唯一的,因此使用 top 沒有區(qū)別.

If you have an index for the UserName and Application fields, the database doesn't even have to touch the table until it has isolated the single record. Also, it will already know from the table statistics that the values are unique, so using top makes no difference.

這篇關(guān)于在 SELECT 查詢中使用 TOP 1 的性能影響的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Sql server table usage statistics(Sql server 表使用情況統(tǒng)計)
Relative path in t sql?(t sql中的相對路徑?)
Getting the last record in SQL in WHERE condition(在 WHERE 條件下獲取 SQL 中的最后一條記錄)
Query to get XML output for hierarchical data using FOR XML PATH in SQL Server(在 SQL Server 中使用 FOR XML PATH 查詢以獲取分層數(shù)據(jù)的 XML 輸出)
T-SQL IF statement embedded in a sum() function(嵌入在 sum() 函數(shù)中的 T-SQL IF 語句)
Table vs Temp Table Performance(表與臨時表性能)
主站蜘蛛池模板: 久久久综合色 | 在线观看国产视频 | 精品美女久久久 | 日韩国产黄色片 | 亚洲一区av | 国产精品久久久久无码av | 欧美精品一区三区 | 自拍偷拍亚洲欧美 | 欧美精品在线一区二区三区 | 免费国产视频 | 黄色一级视频 | 久久一区 | 99国产精品99久久久久久粉嫩 | 中文av网站| 欧美日韩专区 | 99成人| 99精品久久久 | 久久精品欧美一区二区三区不卡 | 毛片在线免费 | 三级av在线 | 日韩av免费看 | 中文字幕二区三区 | 羞羞网站免费 | 午夜精品久久久久久久久久久久久 | 日韩黄 | 中文在线一区二区 | 国产成人精品免费视频大全最热 | 精品日韩一区二区 | xxxxx黄色片 欧美一区免费 | 亚洲三级在线观看 | 在线精品一区二区三区 | 欧美日韩在线一区 | 国产视频一区在线 | 成人免费小视频 | 欧美一二区 | 亚洲人人 | 超碰在线免费公开 | 中文字幕动漫成人 | 国产精品久久久久久影院8一贰佰 | 亚洲精品久久久久久久久久久久久 | 国产精品免费在线 |