2016年9月19日 星期一

Distributed query vs OPENQUERY

Distributed query vs OPENQUERY
from my MSDN blog - September 19, 2016

Distributed query (Four-part name) and OPENQUERY

OpenQueryDistributed Query
速度一般來說 OPENQUERY較快一點也很快
Query optimizer遠端產生執行計畫本地產生執行計畫 產生local query與remote query
連線數量只會產生1條連線到遠端取回資料會產生2條連線
第1條連線先取回統計資訊
第2條連線再取回資料
優點可以在一個Query裡面JOIN多個不同SQL Server的Table
可能出現issue如果太多連線使用Distributed Query,則會造成大量等待SOSHOST_MUTEX wait
缺點雖然有WHERE條件,但SQL Server可能會送出SELECT * FROM the remote table,然後等資料回到本地端才進行filter
權限只需要設定SELECT資料表的權限為了產生最佳執行計畫,remote login account必須有以下權限,才能取得完整的統計資訊,若沒有以下權限,則查詢效能則會比較差 To create the best query plans the user must own the table or be a member of the sysadmin fixed server role, the db_owner fixed database role, or the db_ddladmin fixed database role on the linked server. https://msdn.microsoft.com/en-us/library/ms175537.aspx 但SQL 2012開始則不需要此權限

Best Performer: Distributed query (Four-part) or OPENQUERY when executing linked server queries in SQL Server
https://blogs.msdn.microsoft.com/sqlsakthi/2011/05/08/best-performer-distributed-query-four-part-or-openquery-when-executing-linked-server-queries-in-sql-server/
Security for Linked Servers
http://msdn.microsoft.com/en-us/library/ms175537.aspx
Guidelines for Using Distributed Queries
https://msdn.microsoft.com/en-us/library/ms175129.aspx
OPENQUERY (Transact-SQL)
https://msdn.microsoft.com/en-us/library/ms188427.aspx
Optimizing Distributed Queries
https://technet.microsoft.com/en-us/library/ms180972(v=sql.105).aspx
Improving the Performance of Distributed Queries
http://sqlmag.com/database-performance-tuning/improving-performance-distributed-queries


沒有留言:

SQL Server Planning, Pricing and License

  Server-CALs授權模式 1.需購買的量應該是所有終端用戶的電腦 例如:一台Data warehouse主機 與 一台Web報表主機,但公司有50人或電腦會連進Web報表主機開啟報表,則應該每一台用戶端電腦都需要有CALs授權,Data warehouse主機購買Ser...