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

TSQL:在 select with join 中使用替換函數(shù)

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

問題描述

背景.我正在使用 SQL Server.我在數(shù)據(jù)庫中有兩個(gè)表:

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

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

Id 列中的值使用 Vendor 表中的前綴 'ID_' 進(jìn)行格式化.

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

VendorId 列中的值使用 Products 表中的前綴 'VE_' 進(jìn)行格式化.

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

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

(請(qǐng)不要提議改變這個(gè)概念,不關(guān)心數(shù)據(jù)庫方案,不建議添加外鍵.只是為了說明.)

(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.)

問題:以下哪個(gè)查詢?cè)谛阅芊矫孀詈茫瑸槭裁?

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

  1. 在內(nèi)部select中使用replace函數(shù):

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函數(shù):

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

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

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

    推薦答案

    兩個(gè)查詢?cè)谛阅芊矫鎺缀跸嗤?在第一個(gè)查詢中,排序 進(jìn)行了兩次,一次是在選擇不同記錄時(shí),一次是在執(zhí)行內(nèi)部聯(lián)接時(shí),最后是 合并聯(lián)接選擇最終結(jié)果集.而在第二個(gè)查詢中,排序只完成一次,但正在執(zhí)行 Hash join,這比合并連接更昂貴.因此,在表上沒有任何索引的情況下,這兩個(gè)查詢?cè)谛阅芊矫媸窍嗤?

    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.

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

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

    相關(guān)文檔推薦

    Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
    The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱“CONVERT)
    T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
    remove duplicates from comma or pipeline operator string(從逗號(hào)或管道運(yùn)算符字符串中刪除重復(fù)項(xiàng))
    Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
    concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
    主站蜘蛛池模板: 超碰在线人人 | 亚洲三区在线播放 | 日韩一区二区三区在线视频 | 天堂一区二区三区四区 | 天天爽天天干 | 亚洲色综合 | 亚洲精品在线观 | 午夜免费影视 | 亚洲日本一区二区三区四区 | 91在线视频观看免费 | 操久久| 99re99| 91看片在线 | 一二三四在线视频观看社区 | 亚洲天堂久久新 | 91精品国产91久久久久久 | 999久久久 | 国产精品视屏 | av手机免费在线观看 | 9久久婷婷国产综合精品性色 | 久草免费在线视频 | 国产黄a一级 | 美女黄视频网站 | 成人在线视频网 | 日韩成年人视频在线 | 久久天天躁狠狠躁夜夜躁2014 | 一区二区三区网站 | 99re视频精品| 国产色| 久久久精品网站 | 羞羞午夜 | 日韩成人 | 日韩精品人成在线播放 | 成年人黄色一级片 | 精品国产乱码久久久久久图片 | 在线免费观看毛片 | 成人精品久久 | 在线婷婷 | 久久久亚洲综合 | 在线视频一区二区 | 国产精品1区2区3区 欧美 中文字幕 |