在阅读《Inside Microsoft SQL Server 2005 T-SQL Querying》一书时,碰到一段这样的示例代码:-- the purpose of this statement is
-- to create the temporary table tempdb..OptStats
SELECT 0 AS Run, *
INTO tempdb..OptStats
FROM sys.dm_exec_query_optimizer_info;
GO
-- this will populate the procedure cache
-- with this statement's plan so that it will not
-- generate any optimizer events when executed
-- next time
-- the following GO is intentional to ensure
-- the query plan reuse will happen for the following
-- INSERT for its next invocation in this script
GO
INSERT INTO tempdb..OptStats
SELECT 1 AS Run, *
FROM sys.dm_exec_query_optimizer_info;
GO
-- same reason as above; observe the "2" replaced "1"
-- therefore, we will have a different plan
GO
INSERT INTO tempdb..OptStats
SELECT 2 AS Run, *
FROM sys.dm_exec_query_optimizer_info;
GO哪位能针对这段代码,谈谈红色注释部分究竟是什么含义,特别是the following GO is intentional to ensure
the query plan reuse will happen for the following INSERT for its next invocation in this script
一句。 the following GO 究竟指哪个GO,好像有些语句后都跟了两个GO,为何要这样做?
-- to create the temporary table tempdb..OptStats
SELECT 0 AS Run, *
INTO tempdb..OptStats
FROM sys.dm_exec_query_optimizer_info;
GO
-- this will populate the procedure cache
-- with this statement's plan so that it will not
-- generate any optimizer events when executed
-- next time
-- the following GO is intentional to ensure
-- the query plan reuse will happen for the following
-- INSERT for its next invocation in this script
GO
INSERT INTO tempdb..OptStats
SELECT 1 AS Run, *
FROM sys.dm_exec_query_optimizer_info;
GO
-- same reason as above; observe the "2" replaced "1"
-- therefore, we will have a different plan
GO
INSERT INTO tempdb..OptStats
SELECT 2 AS Run, *
FROM sys.dm_exec_query_optimizer_info;
GO哪位能针对这段代码,谈谈红色注释部分究竟是什么含义,特别是the following GO is intentional to ensure
the query plan reuse will happen for the following INSERT for its next invocation in this script
一句。 the following GO 究竟指哪个GO,好像有些语句后都跟了两个GO,为何要这样做?
the query plan reuse will happen for the following INSERT for its next invocation in this script
(中文意思应该是:后面的go用来保证再次执行此INSERT语句时,可以重用执行计划) "后面的go" 到底指哪个,是注释后面的go,还是insert语句后的go?