为什么不能使用sys.
表创建索引视图?
我不想每次查询该视图时都写order by
,所以我想在要排序的字段上创建聚簇索引。
这是视图:
ALTER VIEW [dbo].[sysVW_Row_Groups]
--WITH SCHEMABINDING
AS
SELECT
OBJECT_NAME(rg.OBJECT_ID) as table_name
,i.name as index_name
--,i.type_desc as index_type_desc
,rg.partition_number
,p.rows as rows_per_partition_number
--,p.data_compression_desc as data_compresion_partition
,row_group_id
,state_description
,total_rows as total_rows_row_group
,convert(decimal(10,2),(total_rows*1.0/POWER(2,20))*100) as full_row_groups
--,size_in_bytes
,convert(decimal(10,2),(size_in_bytes*1.0)/POWER(2,20)) as size_in_Mbytes
,convert(decimal(10,2),(total_rows*1.0/p.rows)*100) as partition_percentage_rows
,deleted_rows
,i.compression_delay
,ps.name as partition_scheme_name
--,ps.type_desc as partition_scheme_type_desc
,pf.name as partition_function_name
--,pf.type_desc as partition_function_type_desc
,pf.boundary_value_on_right
,pf.fanout as number_of_resulting_partitions
FROM SYS.COLUMN_STORE_ROW_GROUPS rg
inner join sys.partitions p ON rg.partition_number = p.partition_number and object_name(rg.object_id) = object_name(p.object_id)
and data_compression_desc = 'COLUMNSTORE' --Focused on in columnstore indexes
inner join sys.indexes i ON OBJECT_NAME(rg.OBJECT_ID) = OBJECT_NAME(i.OBJECT_ID)
inner join sys.partition_schemes ps ON i.data_space_id = ps.data_space_id
inner join sys.partition_functions pf ON ps.function_id = pf.function_id
我知道这对我对列存储索引的帮助不大,但是无论如何...
我收到以下错误消息:
Msg 2720, Level 16, State 1, Procedure sysVW_Row_Groups, Line 10 [Batch Start Line 6]
Cannot schema bind view 'dbo.sysVW_Row_Groups' because it references system object 'SYS.COLUMN_STORE_ROW_GROUPS'.
答案 0 :(得分:2)
Select * from indexed_view
不保证有关查询返回的订单的任何信息。 (如评论所示)。因此,请不要以为您的应用程序会崩溃。
关于“为什么不能在系统表上创建索引视图?”造成这种情况的原因有两个。