SQL SERVER 参数化查询后不走筛选索引,你让我很失望……
DROP TABLE T_TEST
CREATE TABLE T_TEST(
ID INT IDENTITY PRIMARY KEY,STATUS BIT
)
INSERT INTO T_TEST SELECT 0
GO 100000
INSERT INTO T_TEST SELECT 1
CREATE INDEX IXF_T_TEST_STATUS ON T_TEST(STATUS) WHERE STATUS=1
UPDATE STATISTICS T_TEST with fullscan
DBCC FREEPROCCACHE
--正常查询
SELECT * FROM T_TEST WHERE STATUS=1
CREATE TABLE T_TEST(
ID INT IDENTITY PRIMARY KEY,STATUS BIT
)
INSERT INTO T_TEST SELECT 0
GO 100000
INSERT INTO T_TEST SELECT 1
CREATE INDEX IXF_T_TEST_STATUS ON T_TEST(STATUS) WHERE STATUS=1
UPDATE STATISTICS T_TEST with fullscan
DBCC FREEPROCCACHE
--正常查询
SELECT * FROM T_TEST WHERE STATUS=1
--参数化查询
SP_EXECUTESQL N'SELECT * FROM T_TEST WHERE STATUS=@STATUS',N'@STATUS BIT',1
这让我情何以堪?