索引视图可以提高性能

时间:2021-10-30 19:39:56
SET STATISTICS TIME ON

SELECT
  MemberProvince ,
       
MemberCity ,
       
COUNT ( 1 ) AS 数量
FROM
    member . memberbaseinfo
GROUP
BY MemberProvince ,
       
MemberCity
SET
STATISTICS TIME OFF
--DROP VIEW vv

CREATE
VIEW vv
WITH
SCHEMABINDING
AS

   
SELECT   MemberProvince ,
           
MemberCity
,
           
COUNT_BIG (*) AS 数量
   
FROM     member . memberbaseinfo
   
GROUP BY MemberProvince ,
           
MemberCity


CREATE
UNIQUE CLUSTERED INDEX IDX_V1
ON
vv ( MemberProvince , MemberCity ) ;
   

SET
STATISTICS TIME ON

SELECT
  MemberProvince ,
       
MemberCity ,
       
COUNT
( 1 ) AS 数量
FROM
    member . memberbaseinfo
GROUP
BY MemberProvince ,
       
MemberCity
性能有大幅提升