久久久久久久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(表與臨時表性能)
主站蜘蛛池模板: 国产精品久久久久一区二区三区 | 国产视频精品视频 | 精品粉嫩aⅴ一区二区三区四区 | 成人午夜精品 | 亚洲精品在线视频 | 亚洲一区二区三区视频免费观看 | 精品国产乱码久久久久久88av | 蜜桃视频在线观看免费视频网站www | 国产免费一区二区 | 亚洲综合第一页 | 在线观看免费观看在线91 | 久色一区 | 成人国产在线视频 | 欧美二区三区 | 国产一区二区视频在线观看 | 91精品久久久久久久99 | 日本久久综合 | 午夜婷婷激情 | 久久伊人操 | 亚洲国产精品久久久久秋霞不卡 | 97色在线视频| 成人h片在线观看 | 亚洲视频中文字幕 | h免费观看| 美女久久久久久久久 | 日韩精品成人 | 国产精品久久久久久久免费大片 | 日韩欧美中文在线 | 福利网站导航 | 仙人掌旅馆在线观看 | 碰碰视频 | 国产精品无码专区在线观看 | 夜夜骑av | 一区二区三区在线观看视频 | 国产日韩欧美精品一区二区 | 黄色在线观看网站 | 国产日韩欧美在线观看 | 免费激情网站 | 亚洲欧美视频一区 | 久久久夜色精品亚洲 | 日本福利视频免费观看 |