简体   繁体   English

如何从SQL Server 2012中的表的一个分区获取COUNT(*)?

[英]How to get COUNT(*) from one partition of a table in SQL Server 2012?

My table have 7 million records and I do split table in 14 part according to ID, each partition include 5 million record and size of partition is 40G. 我的表有700万条记录,我根据ID分成14个部分,每个分区包含500万条记录,分区大小为40G。 I want to run a query to get count in one partition but it scan all partitions and time of Query become very large. 我想运行一个查询来获取一个分区的计数,但它扫描所有分区,查询的时间变得非常大。

SELECT COUNT(*) 
FROM Item 
WHERE IsComplated = 0 
  AND ID Between 1 AND 5000000

How can I run my query on one partition only without scan other partition? 如何在不扫描其他分区的情况下在一个分区上运行查询?

Refer http://msdn.microsoft.com/en-us/library/ms188071.aspx 请参阅http://msdn.microsoft.com/en-us/library/ms188071.aspx

B. Getting the number of rows in each nonempty partition of a partitioned table or index The following example returns the number of rows in each partition of table TransactionHistory that contains data. B.获取分区表或索引的每个非空分区中的行数以下示例返回包含数据的表TransactionHistory的每个分区中的行数。 The TransactionHistory table uses partition function TransactionRangePF1 and is partitioned on the TransactionDate column. TransactionHistory表使用分区函数TransactionRangePF1,并在TransactionDate列上进行分区。 To execute this example, you must first run the PartitionAW.sql script against the AdventureWorks2012 sample database. 要执行此示例,必须首先针对AdventureWorks2012示例数据库运行PartitionAW.sql脚本。 For more information, see PartitioningScript. 有关更多信息,请参阅PartitioningScript。

USE AdventureWorks2012;
GO
SELECT $PARTITION.TransactionRangePF1(TransactionDate) AS Partition, 
COUNT(*) AS [COUNT] FROM Production.TransactionHistory 
GROUP BY $PARTITION.TransactionRangePF1(TransactionDate)
ORDER BY Partition ;
GO

C. Returning all rows from one partition of a partitioned table or index The following example returns all rows that are in partition 5 of the table TransactionHistory. C.从分区表或索引的一个分区返回所有行以下示例返回表TransactionHistory的分区5中的所有行。 Note Note To execute this example, you must first run the PartitionAW.sql script against the AdventureWorks2012 sample database. 注意注意要执行此示例,必须首先针对AdventureWorks2012示例数据库运行PartitionAW.sql脚本。 For more information, see PartitioningScript. 有关更多信息,请参阅PartitioningScript。

SELECT * FROM Production.TransactionHistory
WHERE $PARTITION.TransactionRangePF1(TransactionDate) = 5 ;

暂无
暂无

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

相关问题 SQL Server 2012:如何从多个表联接中获取计数组 - SQL Server 2012 : how to get count group by from multiple table joins 有没有办法从分区表中删除范围值(sql server 2012) - Is there a way to drop a range value from a partition table (sql server 2012) oracle服务器如何从分区表中获取分区列名 - How to get partition column name from partition table in oracle server 如何在SQL Server 2012中将数据从另一个表的多个表行插入一个表行? - How to insert data into one table row from multiple table rows in another table in SQL Server 2012? 获取每个父级的子级数.SQL Server 2012 - Get count of children from each parent.SQL Server 2012 在SQL Server 2012中创建具有日期作为范围分区的表 - Creating a table with date as range partition in SQL Server 2012 如何在SQL Server 2012数据库的一个表中分配许多列 - How distribute many columns in one table in SQL Server 2012 database 如何在SQL Server 2012中为第一张表的每个ID获取电子邮件ID(一个值),然后将第二张表的电子邮件名称显示为逗号? - How to get Email ID(one value) for each ID for 1st table and then display Email Name from 2nd table as comma Separated in SQL Server 2012? 如何获取SQL Server中的联接表的计数? - How to get the count of a join table in sql server? 如何计算一个表中的值并更新 SQL Server 中同一台服务器上的另一个表? - How to count values from one table and update another table on same server in SQL Server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM