久久久久久久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é)果.我一直認為添加 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(表與臨時表性能)
主站蜘蛛池模板: 国产中文字幕在线观看 | www日韩欧美 | 97人人干 | 人人插人人 | 亚洲免费在线 | 日本精品久久 | 日韩精品一区二区三区在线观看 | 久久99国产精一区二区三区 | 国产一区二区三区在线看 | 国产亚洲一级 | 欧美精品一区二区三区在线播放 | 成人网在线观看 | 国产在线观看 | 精品欧美一区二区在线观看 | 免费一区 | 亚洲一区二区三区四区五区午夜 | 精品国产免费一区二区三区演员表 | 午夜视频在线观看一区二区 | 青青久草 | 久久精品免费 | 久久久久久国产精品 | 亚洲福利视频网 | 欧美日本在线 | 国产一区二区三区四区在线观看 | 日韩a视频| 国产精品成人一区二区三区 | 欧美日本在线观看 | 剑来高清在线观看 | 美日韩精品 | 国产一区二区视频免费在线观看 | 日韩欧美一区二区三区在线播放 | 成人污污视频 | 国产精品一区二区在线 | 日韩综合在线 | 成人免费在线观看视频 | 久久丝袜视频 | 天天干天天干 | 亚洲精品一区中文字幕乱码 | 日韩快播电影网 | 亚洲91视频 | 亚洲国产精品人人爽夜夜爽 |