我有一些需要臨時表的sprocs。爲了不對列類型(具有一定長度的varchar)進行硬編碼,所以我不必在引用表模式更改時更改聲明(即字段變長),我這樣做(而不是create table調用):在哪裏1 = 2被調用每行?
select orderId
into #sometmptbl
from orders
where 1=2
但是,當你在這做一個顯示計劃實際上似乎是想表/索引:
查詢計劃語句1(以線 1)。
STEP 1 The type of query is CREATE TABLE. STEP 2 The type of query is INSERT. The update mode is direct. FROM TABLE orders Nested iteration. Index : orders_idx1 Forward scan. Positioning at index start. Index contains all needed columns. Base table will not be read. Using I/O Size 2 Kbytes for index leaf pages. With LRU Buffer Replacement Strategy for index leaf pages. TO TABLE #sometmptbl Using I/O Size 2 Kbytes for data pages.
估計總for語句 1(第1行)I/O成本:632082.
這是否意味着1 = 2被用於索引中的每個條目進行評估?有沒有辦法在一個固定的時間做到這一點?
更新:
下面是實際的I/O成本執行(Execute),所以它看起來後像實際讀取確實是0,所以沒有性能影響:
Table: orders scan count 0, logical reads: (regular=0 apf=0 total=0), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Table: #sometmptbl_____00002860018595346 scan count 0, logical reads: (regular=1 apf=0 total=1), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Total actual I/O cost for this command: 2.
Total writes for this command: 3
0 row(s) affected.
看起來你是對的 - 實際讀取爲0 – naumcho 2010-07-12 19:23:51