不确定我是否理解 SqlServer 中索引视图在幕后的作用
我正在使用 sql server 2008,并开始发现使用索引视图可以帮助我加快一些查询的速度……因为我的架构不是基本的。
因此,如果我有一个如下所示的表...
**ParentTable
ParentId INT PK IDENTITY
Name VARCHAR(MAX)
**ChildTable
ChildId INT PK IDENTITY
ParentId INT (FK to the table above)
Name VARCHAR(MAX)
Boundary GEOGRAPHY
CentrePoint GEOGRAPHY
CentrePointFlattened GEOMETRY
因此,对于父表中的每一行,它可以有零到多个子项。
首先,如果我创建子级的索引视图,如果 ParentId 字段可以为空,则该视图将不起作用。所以我需要将其设为必需。
现在问题来了。
我有一个子表内部连接到父表的索引视图(注意我只是索引任一表中的某些字段)...
(pseduo sql code)
ParentId INT
Name VARCHAR(MAX) AS ParentName
ChildId INT
Name VARCHAR(MAX) as ChildName
Boundary GEOGRAPHY
现在,这 5 个字段的数据是否已序列化/复制到另一个位置再次?或者索引视图是否只创建一些作为表数据的索引 id?
I'm using sql server 2008 and have started to find using Indexed Views are helping me speed up some of my queries ... as my schema isn't basic.
So, if i have a table that is the following...
**ParentTable
ParentId INT PK IDENTITY
Name VARCHAR(MAX)
**ChildTable
ChildId INT PK IDENTITY
ParentId INT (FK to the table above)
Name VARCHAR(MAX)
Boundary GEOGRAPHY
CentrePoint GEOGRAPHY
CentrePointFlattened GEOMETRY
So for each row in the parent table, it can have zero to many children.
Firstly, if I make an index'd view of the children, it won't work if the ParentId filed can be nullable. So i need to make it required.
Now the question.
I have an index view of the children table inner join'd to the parent table (note i'm only indexing some of the fields from either table)...
(pseduo sql code)
ParentId INT
Name VARCHAR(MAX) AS ParentName
ChildId INT
Name VARCHAR(MAX) as ChildName
Boundary GEOGRAPHY
Now, are the data for these 5 fields serialized/copied to ANOTHER location again ? or does the index view only create some index id's that is the data for the table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。索引视图基本上是另一个不可见表,它会随着基础表的更改而自动更新。
Yes. Indexed view is basically another invisible table that gets updated automatically as underlying tables change.