如果我在维护计划中运行重建索引任务,我是否必须使用更新统计任务来更新统计信息?
答案1
是的
不重建列统计信息,仅重建索引统计信息
--random data
CREATE TABLE dbo.foo (bar int PRIMARY KEY, humbug char(2000))
INSERT dbo.foo (bar, humbug) VALUES (1, 'aaa')
INSERT dbo.foo (bar, humbug) VALUES (2, 'bbb')
INSERT dbo.foo (bar, humbug) VALUES (3, 'ccc')
INSERT dbo.foo (bar, humbug) VALUES (4, 'aaa')
INSERT dbo.foo (bar, humbug) VALUES (5, 'bbb')
INSERT dbo.foo (bar, humbug) VALUES (6, 'ccc')
INSERT dbo.foo (bar, humbug) VALUES (7, 'ccc')
INSERT dbo.foo (bar, humbug) VALUES (8, 'ccc')
INSERT dbo.foo (bar, humbug) VALUES (9, 'ccc')
INSERT dbo.foo (bar, humbug) VALUES (10, 'cc')
INSERT dbo.foo SELECT bar+10, humbug FROM dbo.foo
--generate index stats + column stats
SELECT * FROM foo WHERE bar = 12
SELECT * FROM foo WHERE humbug = 'bbb'
--created date
SELECT
OBJECT_SCHEMA_NAME([id]) + '.' + OBJECT_NAME([id]),
NAME,
STATS_DATE ([id], indid)
FROM
dbo.sysindexes
WHERE
OBJECT_NAME([id]) = 'foo'
ORDER BY
STATS_DATE ([id], indid) DESC
--Relax, have a coffee
--rebuild
ALTER INDEX ALL ON dbo.foo REBUILD WITH (FILLFACTOR = 90)
--check again
SELECT
OBJECT_SCHEMA_NAME([id]) + '.' + OBJECT_NAME([id]),
NAME,
STATS_DATE ([id], indid)
FROM
dbo.sysindexes
WHERE
OBJECT_NAME([id]) = 'foo'
ORDER BY
STATS_DATE ([id], indid) DESC
--only index stats were updated
答案2
不会。重建索引将“免费”生成新的统计数据。