Ho alcuni sproc che necessitano di una tabella temporanea. Per non codificare i tipi di colonna (che sono varchar con una certa lunghezza), quindi non devo modificare le dichiarazioni quando lo schema della tabella di riferimento cambia (cioè i campi diventano più lunghi). Faccio questo (invece di creare una chiamata tabella):Viene chiamato 1 = 2 per ogni riga?
select orderId
into #sometmptbl
from orders
where 1=2
Tuttavia, quando si esegue una showplan su questo in realtà sembra andare al tavolo/index: PIANO
query per DICHIARAZIONE 1 (in linea 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.
totale stimato costi/O per dichiarazione 1 (at line 1): 632082.
significa 1 = 2 viene valutato per ogni ingresso nell'indice? C'è un modo per farlo in un tempo costante?
Aggiornamento:
Ecco il costo effettivo di I/O dopo il eseguire così sembra che l'attuale legge sono infatti 0 quindi non c'è alcun impatto sulle prestazioni:
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.
Sembra che tu abbia ragione - le letture effettive sono 0 – naumcho