Sql server not in最佳化

來源:互聯網
上載者:User

標籤:campaign   open   code   blog   rom   let   div   category   from   

使用EXISTS(或NOT EXISTS)通常將提高查詢的效率,由於NOT IN子句將對子查詢中的表執行了一個全表遍曆。

oracle在執行IN子查詢過程中,先執行子查詢結果放入暫存資料表再進行主查詢; 而exists先運行主查詢,再執行子查詢查到第一個匹配項如:查詢 A表中沒有和B表或C表相連的資料  select A.id,A.reads,A.addtime from A where A.person_id  not in (select user_id from B ) or A.worksite_id not in (select id from C) order by A.addtime desc 程式執行時間:40109.38毫秒  select A.id,A.reads,A.addtimefrom A where  not exists (select  id FROM B where B.user_id=A.person_id) or  not exists (select  id FROM C where C.id=A.worksite_id) order by Sendorder.addtime desc 程式執行時間:8531.25毫秒 

 

ms ssql 執行個體:

select subscriber_idfrom NewsLetterSystem_CampaignCategorySubscriber ccs WITH ( NOLOCK )where NOT EXISTS(SELECT  distinct subscriber_idFROM    NewsLetterSystem_OpenTracking ot WITH ( NOLOCK ) WHERE  ot.subscriber_id=ccs.subscriber_id and ot.campaign_id = 52801)and ccs.campaign_id = 52801 and ccs.status_id = 1

 

Sql server not in最佳化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.