views:

181

answers:

2

I have a table that has millions of records and we are looking at implementing table partitioning. Looking at it we have a foreign key "GroupID" that we would like to partition on. Is this possible?

The Group will have more entries added to it, so as new GroupID's are added can the partition's be made dynamically?

+1  A: 

Yes you can use partitioning, yes new partitions can be made dynamically. It's easiest to use a partitioning scheme that does not need to be updated though.

SQL Enterprise 2005 & up:

SQL 2005 and up has built in transparent support for partitioning if you are using SQL development edition or enterprise edition. Dynamically adding more partitions means that you'd have to create a new partitioning function, new partition schemes and probably new file groups.

You can alter a partition function by using SPLIT:

ALTER PARTITION FUNCTION MyPartitionFunction ()
SPLIT RANGE (2);

SQL 2000 or SQL 2005 & up non-enterprise:

Otherwise you can still use partitioning but you need to do it the old MS SQL 2000 way. In the old way you have to physically create many tables, and then a view that is a UNION ALL of each of the tables. So you need knowledge of the schema before hand.

The good news about the old partitioning way is it's even easier to create new partitions dynamically. You just need to create a new table with a new constraint and update your view.

There are some limitations though, your partitioning column must be part of your primary key. And to do inserts directly into your View you'll need to NOT have an Identity column (one that is auto incremented by MS SQL)

Brian R. Bondy
2005 Standard does not have that built in?
Dustin Laine
@durilai: That's correct, you'll have to use the old partitioning way. Enterprise is expensive (for some people's budgets) and unfortunately they don't include partitioning in standard.
Brian R. Bondy
@durilai: I added some more common pitfalls about the old partitioning way for you too.
Brian R. Bondy
I'm not sure I would say 'extremely expensive' - it's relative and in comparison to similarly capable platforms it prices well. When storing in the billions of rows (which suits many partition systems), the storage costs can dwarf any SQL costs :)
Andrew
@Andrew: I agree and I edited my comment.
Brian R. Bondy
Does SQL 2008 Standard support it?
Dustin Laine
@durilai: no it doesn't
Brian R. Bondy
+1  A: 

Group ID may not be the best item to partition on, partitioning suits a rolling window effect and is designed more for removing of outdated data and the rolling in of new data.

By Grouping on ID you only allow yourself to add / remove groups, e.g. no element of time / longevity of data. There is also a hard limit of 1000 partitions per parrtitioned table, limiting you to 1000 groups. Since you intend on add group ID's and it is not indicated as a static number you will potentially hit this hard limit.

The only option to extend that limit of 1000 is to place a partitioned view across multiple partitioned tables.

The question I would ask is what causes new data to be added / older data to be removed and on what basis is that made. Just because the table is millions of rows does not make it an immediate candidate for partitioning, which is why I would ask the question.

In terms of dynamically adding them - that feature does not exist you would have to write the stored procedures and logic to handle the allocation of new filegroups / set next used and splitting of the partition function. It can be done, but SQL is not going to do it for you.

Andrew
How to partition on groups, do you still use RANGE?
Dustin Laine
You can partition on a int, so partitioning on GroupID is fine, what you need to check is whether you will have over 1000 groups, at which point you start doing ranges so that is is 10 per partition and then you should stop and ask - what benefit am I getting from doing this, partition elimination only - and you have no instrumented test to show it will help - it will hinder some queries.
Andrew
@Andrew, I agree. We have more than 1000. We would want to partition out the top 3 groups.
Dustin Laine