简体   繁体   English

在SQL中对视图进行分区

[英]Partitioning Views in sql

How do I partition an Indexed View in MS-SQL ? 如何在MS-SQL中对索引视图进行分区? I have a index view created which stores range of values. 我创建了一个索引视图,用于存储值的范围。 The view definition is as follows 视图定义如下

CREATE VIEW dbo.target_individual_product WITH SCHEMABINDIN       
    AS SELECT day_dim.date_time AS Date,  
    SUM(ISNULL(order_dim.quantity,0)) AS Target_Acheived,  
    branch_dim.branch_name AS Branch_Name ,   
    product_dim.product_name AS Product_Name  
FROM dbo.day_dim INNER JOIN  
     dbo.order_fact ON day_dim.day_id = order_fact.day_id  
INNER JOIN dbo.product_dim ON order_fact.product_id = product_dim.product_id   
INNER JOIN dbo.branch_dim ON order_fact.branch_id = branch_dim.branch_id   
INNER JOIN dbo.order_dim ON order_fact.order_id = order_dim.order_id  
GROUP BY order_dim.quantity, day_dim.date_time,branch_dim.branch_name, product_dim.product_name  
GO
CREATE UNIQUE CLUSTERED INDEX target_individual_product_I on target_individual_product (Date)

Now i want to partition this table using date column. 现在,我想使用日期列对该表进行分区。 How do I do that ? 我怎么做 ?

I have little experience with partitioning, but I think you are confusing things. 我对分区的经验很少,但我认为您感到困惑。 (Gurus, please correct me if I'm wrong). (专家,如果我错了,请纠正我)。

As far as I know there are three types of partitioning in SQL Server : 据我所知,SQL Server中三种分区类型

A partitioned table can be partitioned on a column such as date. 分区表可以按日期等列进行分区。

A partitioned view is a view specifying a UNION between similar queries from different tables. 分区视图是在不同表的相似查询之间指定UNION的视图。

A partioned-aligned indexed view is an indexed view that is partitioned along the same column(s) as the partitioned table to which it is linked. 分区对齐的索引视图是一个索引视图,该视图沿着与其链接到的分区表相同的列进行分区。

I don't think it is possible to partition an indexed view without partitioning the underlying table. 我认为不对基础表进行分区就不可能对索引视图进行分区。 Therefore, I would suggest that you partition your day_dim on the date_time column, and then create a partition-aligned indexed view to match this column. 因此,我建议您在date_time列上对day_dim进行分区,然后创建一个与分区对齐的索引视图以匹配此列。 See this link and scroll down to Query 11 for an example how to do this. 请参阅此链接,并向下滚动到查询11 ,以获取有关如何执行此操作的示例。

You appear to be looking for a "partition-aligned" index; 您似乎正在寻找“分区对齐”索引; partitioning is supported in SQL 2008 Enterprise Edition (you didn't mention your version or edition). SQL 2008 Enterprise Edition支持分区(您没有提到您的版本)。 Partitioned indexes are discussed in Books Online, but there is no discussion of partitioning view indexes that I can find, although it is possible and it's described in a white paper here (see query 11 at the end of the paper): 在联机丛书中讨论了分区索引,但是我没有找到关于分区视图索引的讨论,尽管有可能,并且在此处的白皮书中对此进行了描述(请参阅本文末尾的查询11):

http://msdn.microsoft.com/en-us/library/dd171921.aspx http://msdn.microsoft.com/en-us/library/dd171921.aspx

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

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