Tens implementation of SQL Server database table partitioning

Source: Internet
Author: User
Tags filegroup

Tens implementation of SQL Server database table partitioning 2010-09-10 13:37 anonymous databasefont Size:T | T

In general, under the Tens data pressure, partitioning is a better way to improve performance. This article describes the implementation of a SQL Server database table partition.

Ad:51cto Net + 12th salon: The beauty of big data-how to drive user experience with data

Recently using a cache of SQL Server, the volume of data 100w a day growth, while accepting customer inquiries, speed due to the increasing volume of data more and more slowly, here thanks to Killkill and invitations, recently read a set of books good, interested students can read << life > >

Review the frequently Used indexes

I. Clustered index

The page level of the clustered index contains the index key and also the data page, so the answer to what is stored in the leaf level of the clustered index in addition to the key value is everything, that is, all the fields in each row are at the leaf level.
The other is that the data itself is part of the clustered index, and the clustered index keeps the data in the table in order based on the key value.

In SQL Server, all clustered indexes are unique, and if you do not specify a unique keyword when you create a clustered index, SQL Server guarantees the uniqueness of the index internally by adding a unique identifier (uniqueifier) to the record when needed. The unique identifier is a 4-byte value that is added to the data as a field attached to the clustered index key, and only those rows that are declared as index key fields and have duplicate values are added.

Two. Nonclustered indexes

For nonclustered indexes, the leaf level does not contain all the data. In addition to the key values, the index row in each leaf level (the lowest layer of the tree) contains a bookmark (bookmark) that tells SQL Server where to find the data row corresponding to the index key. A bookmark lesson can be in two formats. If a clustered index exists on the table, the bookmark is the clustered index key for the corresponding data row. If the table is a heap structure, or if there is no clustered index, the bookmark is a row identifier, row Identifier,rid, which locates the actual row in the format of the file number's slot number.

The presence or absence of nonclustered indexes does not affect the organization of data pagination, so each table is not limited to owning a nonclustered index as clustered indexes, and SQL Server 2005 can contain 249 nonclustered indexes per table SQL Server 2008 Each table can contain 999 nonclustered indexes. But it actually used to be a lot less than this number.

Three. Include index

The number of index key fields is limited to 16, a total of 900 bytes, and the included columns appear only at the leaf level and do not control the sorting of indexed rows in any way. Their purpose is to enable the leaf level to contain more information to make the index tuning capability of the overlay index (covering indexes) more effective. An overlay index is a nonclustered index that finds all the information that satisfies a query at its leaf level, so that the SQL There is no need for server to access data paging at all, and in some cases SQL Serer will silently add an inclusion column to the index. This can happen if the index is based on the partition table, which is where I am today the blogger O (∩_∩) O (partitioned table) without specifying on filegroup or no partition_scheme.

One. SQL SERVER Table partitioning describes:

The table partitioning technology introduced by SQL Server allows users to distribute data across different physical disks, improving the parallel processing performance of these disks to optimize query performance ...

Two. A SQL SERVER database table partition is done in three steps:

1. Create a partition function

2. Create a partition Schema

3. Partitioning the table

Based on the cache update mechanism, I use time to partition, where everyone uses the appropriate fields as a partition according to business requirements.

Create the number of database partition files, where the data stored for one year is divided into 12 partitions, and the folder containing the Primary folder and the FG1 FG2 FG3 FG4 is now set up in D disk. ............

  1. IF EXISTS (SELECT name from sys.databases WHERE name = N' airavcache ')
  2. DROP DATABASE [Airavcache]
  3. GO
  4. CREATE DATABASE [Airavcache]
  5. On PRIMARY
  6. (name=' Data Partition DB Primary FG ',
  7. Filename=
  8. ' D:\Data\Primary\AirAvCache Primary fg.mdf ',
  9. Size=5,
  10. MAXSIZE=500,
  11. Filegrowth=1),
  12. FILEGROUP [Airavcache FG1]
  13. (NAME = ' Airavcache FG1 ',
  14. FILENAME =
  15. ' D:\Data\FG1\AirAvCache fg1.ndf ',
  16. SIZE = 5MB,
  17. MAXSIZE=500,
  18. Filegrowth=1),
  19. FILEGROUP [Airavcache FG2]
  20. (NAME = ' Airavcache FG2 ',
  21. FILENAME =
  22. ' D:\Data\FG2\AirAvCache fg2.ndf ',
  23. SIZE = 5MB,
  24. MAXSIZE=500,
  25. Filegrowth=1),
  26. FILEGROUP [Airavcache FG3]
  27. (NAME = ' Airavcache FG3 ',
  28. FILENAME =
  29. ' D:\Data\FG3\AirAvCache fg3.ndf ',
  30. SIZE = 5MB,
  31. MAXSIZE=500,
  32. Filegrowth=1),
  33. FILEGROUP [Airavcache FG4]
  34. (NAME = ' Airavcache FG4 ',
  35. FILENAME =
  36. ' D:\Data\FG4\AirAvCache fg4.ndf ',
  37. SIZE = 5MB,
  38. MAXSIZE=500,
  39. Filegrowth=1),
  40. FILEGROUP [Airavcache FG5]
  41. (NAME = ' Airavcache FG5 ',
  42. FILENAME =
  43. ' D:\Data\FG5\AirAvCache fg5.ndf ',
  44. SIZE = 5MB,
  45. MAXSIZE=500,
  46. Filegrowth=1),
  47. FILEGROUP [Airavcache FG6]
  48. (NAME = ' Airavcache FG6 ',
  49. FILENAME =
  50. ' D:\Data\FG6\AirAvCache fg6.ndf ',
  51. SIZE = 5MB,
  52. MAXSIZE=500,
  53. Filegrowth=1),
  54. FILEGROUP [Airavcache FG7]
  55. (NAME = ' Airavcache FG7 ',
  56. FILENAME =
  57. ' D:\Data\FG7\AirAvCache fg7.ndf ',
  58. SIZE = 5MB,
  59. MAXSIZE=500,
  60. Filegrowth=1),
  61. FILEGROUP [Airavcache FG8]
  62. (NAME = ' Airavcache FG8 ',
  63. FILENAME =
  64. ' D:\Data\FG8\AirAvCache fg8.ndf ',
  65. SIZE = 5MB,
  66. MAXSIZE=500,
  67. Filegrowth=1),
  68. FILEGROUP [Airavcache FG9]
  69. (NAME = ' Airavcache FG9 ',
  70. FILENAME =
  71. ' D:\Data\FG9\AirAvCache fg9.ndf ',
  72. SIZE = 5MB,
  73. MAXSIZE=500,
  74. Filegrowth=1),
  75. FILEGROUP [Airavcache FG10]
  76. (NAME = ' Airavcache FG10 ',
  77. FILENAME =
  78. ' D:\Data\FG10\AirAvCache fg10.ndf ',
  79. SIZE = 5MB,
  80. MAXSIZE=500,
  81. Filegrowth=1),
  82. FILEGROUP [Airavcache FG11]
  83. (NAME = ' Airavcache FG11 ',
  84. FILENAME =
  85. ' D:\Data\FG11\AirAvCache fg11.ndf ',
  86. SIZE = 5MB,
  87. MAXSIZE=500,
  88. Filegrowth=1),
  89. FILEGROUP [Airavcache FG12]
  90. (NAME = ' Airavcache FG12 ',
  91. FILENAME =
  92. ' D:\Data\FG12\AirAvCache fg12.ndf ',
  93. SIZE = 5MB,
  94. MAXSIZE=500,
  95. filegrowth=1)

After you've created it.

Open FG1 folder See more Airavcachefg1.ndf file

Create a partition function

  1. Use Airavcache
  2. GO
  3. --Create a function
  4. CREATE PARTITION FUNCTION [Airavcache PARTITION Range] (DATETIME)
  5. As RANGE left for VALUES (' 2010-09-01 ',' 2010-10-01 ',' 2010-11-01 ',
  6. ' 2010-12-01 ',' 2011-01-01 ',' 2011-02-01 ',' 2011-03-01 ',' 2011-04-01 ',
  7. ' 2011-05-01 ',' 2011-06-01 ',' 2010-07-01 ');

Creating a Partition Schema

    1. CREATE PARTITION Scheme [airavcache PARTITION scheme]
    2. As PARTITION [Airavcache PARTITION Range]
    3. to ([Airavcache FG1], [Airavcache FG2], [Airavcache fg3],[airavcache fg4],[airavcache Fg5],[airavcache FG6],[AirAvCache Fg7],[airavcache FG8],
    4. [Airavcache fg9],[airavcache Fg10],[airavcache Fg11],[airavcache FG12]);

Create a table using the Airavcache partitiion scheme schema

  1. CREATE TABLE [dbo].[ Avcache] (
  2. [Citypair] [varchar] (6) not NULL,
  3. [Flightno] [varchar] (+) NULL,
  4. [Flightdate] [DateTime] not NULL,
  5. [CacheTime] [DateTime] not NULL DEFAULT (getdate ()),
  6. [Avnote] [varchar] (+) NULL
  7. ) on [Airavcache Partition Scheme] (flightdate);
  8. --note that the [Airavcache Partition scheme] architecture is used, depending on the flightdate partition

Query partition status

    1. --View Usage
    2. SELECT *, $PARTITION. [Airavcache Partition Range] (flightdate)
    3. FROM dbo. Avcache

You can see that September and October have been separated.

Tens implementation of SQL Server database table partitioning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.