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

TSQL:在 select with join 中使用替換函數

TSQL: Using replace function in select with join(TSQL:在 select with join 中使用替換函數)
本文介紹了TSQL:在 select with join 中使用替換函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

背景.我正在使用 SQL Server.我在數據庫中有兩個表:

Background. I'm using SQL Server. I have two tables in database:

Vendors(Id, Name, Description)
Products(Id, VendorId, Name, Description)

Id 列中的值使用 Vendor 表中的前綴 'ID_' 進行格式化.

Values in Id column are formatted with prefix 'ID_' in Vendor table.

VendorId 列中的值使用 Products 表中的前綴 'VE_' 進行格式化.

Values in VendorId column are formatted with prefix 'VE_' in Products table.

例如 Products中的'VE_001245'是指Vendors中的'ID_001245'>.

(請不要提議改變這個概念,不關心數據庫方案,不建議添加外鍵.只是為了說明.)

(Please, do not propose to change this concept, do not care about database scheme, do not suggest adding foreign key. All it is just for illustration.)

問題:以下哪個查詢在性能方面最好,為什么?

Question: which one of following queries is best in performance context and why?

  1. 在內部select中使用replace函數:

select v.* from Vendors v
inner join
(
    select distinct replace(VendorId, 'VE_', 'ID_') as Id
    from Products
) list
on v.Id = list.Id

  • on語句中使用replace函數:

    select v.* from Vendors v
    inner join
    (
        select distinct VendorId as Id
        from Products
    ) list
    on v.Id = replace(list.Id, 'VE_', 'ID_')
    

  • 編輯.每個表中只有聚集索引(按Id列).每個表可以包含數百萬行.

    Edit. There is only clustered index in each table (by Id column). Each table can contains millions rows.

    推薦答案

    兩個查詢在性能方面幾乎相同.在第一個查詢中,排序 進行了兩次,一次是在選擇不同記錄時,一次是在執行內部聯接時,最后是 合并聯接選擇最終結果集.而在第二個查詢中,排序只完成一次,但正在執行 Hash join,這比合并連接更昂貴.因此,在表上沒有任何索引的情況下,這兩個查詢在性能方面是相同的.

    Both the queries are almost same in terms of performance. In the first query sorting is done twice, once when you are selecting the distinct records and again when it is performing an inner join, and in the end a merge join is there to select the final result set. Whereas in second query sorting is done only once but Hash join is being performed which is more expensive then merge join. So both the queries are same performance wise in the scenario when you don't have any index on the table.

    這篇關于TSQL:在 select with join 中使用替換函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

    相關文檔推薦

    Modify Existing decimal places info(修改現有小數位信息)
    The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
    T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
    remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
    Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
    concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
    主站蜘蛛池模板: 97久久精品 | 国产视频福利在线观看 | 国产免费视频 | 国产一区二区三区在线 | 91就要激情| 日韩国产一区二区三区 | 午夜视频在线免费观看 | 国产91色在线 | 亚洲 | 亚洲一区二区在线电影 | 日韩综合| 91麻豆精品国产91久久久更新资源速度超快 | 国产精品久久久久久久久久免费看 | 国产亚洲精品区 | 日本三级视频 | 久久免费观看视频 | 神马久久春色视频 | 高清国产午夜精品久久久久久 | 伊人一区 | 久久精品视频一区二区 | 91精品一区| 久久精品国产久精国产 | 亚洲国产一区二区三区 | 亚洲欧美在线一区 | 91精品国产一区二区三区 | 黄a免费看| 精品一二三区视频 | 91成人在线 | 欧美精品在线免费 | 草草精品 | 日本成人三级电影 | 成年人在线视频 | 成人免费视频网 | 超碰91在线 | 日日av| 国产日韩欧美一区 | 国产精品特级毛片一区二区三区 | 波多野结衣中文字幕一区二区三区 | 欧美精品久久久久久 | 亚洲第一女人av | 成人动慢| 国产精品久久精品 |