简体   繁体   English

SQL Server中联合的替代方法

[英]Alternatives to Unions in SQL Server

I have a number of schema bound views that I'd like to add indexes to for performance purposes. 我有许多架构绑定视图,为了性能目的,我想添加索引。

The problem is that they have multiple union all s in them. 问题在于它们中有多个union all

I'm looking for some general refactoring suggestions/approaches to replace the union all s with something that would allow index creation on the view. 我正在寻找一些一般的重构建议/方法,以允许在视图上创建索引的方式替换union all

Basically, there are two logical scenarios for the unions that are being used in the views currently: 基本上,当前在视图中使用的联合有两种逻辑方案:

  1. We have an EntityA which is expressed by the view. 我们有一个由视图表示的EntityA。 The sources for this entity come from many different tables. 该实体的来源来自许多不同的表格。 That is, some EntityAs are recorded in TableA, some are recorded in TableB. 也就是说,某些EntityA记录在表A中,有些记录在表B中。

  2. We have EntityA which is expressed by the view. 我们有由视图表示的EntityA。 TableA sources EntityA. TableA来源EntityA。 Each row in TableA needs to produce multiple EntityAs in the view. TableA中的每一行都需要在视图中产生多个EntityAs。

Thank you. 谢谢。

我不确定这是否会更快,但是您可以创建一个临时表,以所需的方式建立索引,然后从union每个部分插入所需的值,而不是执行union allunion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM