_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › OPTIMIZEFORQueryHintOptionIncludeUNKNOWNVariableValue

Contents

1 襦貉覲
2 襷り覲

1 襦貉覲 #

OPTIMIZE FOR 貎朱Μ瑚 蟆朱. (2005 覯 危) OPTIMIZE FOR 襦貉覲襯 牛磯伎螳 襦貉覲 覿れ煙朱 豕 貎朱Μ螻 語一 覈詩 蟆曙 牛磯伎蟆 糾覲企ゼ 伎 襦 螳 螻牛蠍 . OPTIMIZE FOR 覈 螳 貎朱Μ 豕 襷 螻 ろ 讌 . (襦貉覲 覓語 Magic Density襯 谿瑚.)
USE AdventureWorks;
GO

EXEC sp_helpindex 'Person.Address';
/*
rowguid
AddressLine1, AddressLine2, City, StateProvinceID, PostalCode
StateProvinceID
AddressID
*/

create index nix_postal_code
on Person.Address(PostalCode);
go

DECLARE @city_name nvarchar(30);
DECLARE @postal_code nvarchar(15);
SET @postal_code = 86171;

--sql1
SELECT * FROM Person.Address
WHERE City = @city_name AND PostalCode = @postal_code
OPTION ( OPTIMIZE FOR (@city_name = 'Seattle', @postal_code UNKNOWN) );
optimize_for01.jpg

--sql2
SELECT * FROM Person.Address
WHERE City = @city_name AND PostalCode = @postal_code
OPTION ( OPTIMIZE FOR (@city_name = 'Seattle', @postal_code = 98028) );
optimize_for02.jpg

2 襷り覲 #

'optimize for ...'襯 蠎 襦貉覲襷 蟆 . sql server 蠍磯蓋朱 糾覲願 螳煙 旧 豈螻 . 讌襷 螳 蠍磯 糾覲伎 螳煙譯手鍵螳 觜襦 伎 蠍 覓語 螳 一危磯伎 糾覲願 螳煙讌 豕蠏殊 一危郁 豌襴 蟆曙 蠍磯 願 ろ螻 語企. 企 . れ螻 螳 覃 . (る(2011-07-06) 覦一 襭 螳 1螳 覦碁. 誤企慨 企 蟆曙磯)
create proc 企譟壱sp
as
select *
from 企
where std_dt between @bdt and @edt
option ( optimize for (@bdt = '20110601', @edt = '20110602'))
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:52

Youth is not a time of life but it is a state of mind. (覓伎碁)