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

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

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

問題描述

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

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 不會影響結果.我一直認為添加 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.

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

【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(liá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(表與臨時表性能)
主站蜘蛛池模板: 国产精品久久久久久久久久久久久久久 | 午夜激情网 | 黄色欧美大片 | 欧美一级黄| 91福利网 | 日日av| 免费一级a毛片 | 国产无限资源 | 日韩黄色在线观看 | xxxxx黄色| 69成人网 | 夜夜操天天操 | 久久在线免费视频 | 一区二区三区网站 | 中文在线字幕免费观看 | 欧美黑人性猛交 | 青娱乐99| 日本婷婷| 日本久久网站 | 精品国产成人 | 免费视频国产 | 黄色大片免费观看 | 亚洲激情一区二区 | 免费一区二区三区 | 免费啪视频 | 久色91| 久久午夜精品 | 日韩欧美综合 | 青娱乐福利视频 | 天天爽天天操 | 91麻豆精品一区二区三区 | 亚洲午夜视频在线观看 | 国产91免费| 亚洲精品乱码久久久久久 | 欧美日本国产 | 精品免费视频 | 一区免费视频 | www.四虎在线 | 91亚洲国产成人久久精品麻豆 | 国产精品久久一区二区三区 | 久久精品国产一区 |