Solved

How does SQL Server 2005 know which partition to use?

Posted on 2007-03-27
8
216 Views
Last Modified: 2010-03-19
Most examples for SQL Server 2005 involve a sales table that you split based on date, i.e. sales records prior to 2000 go to this partition, and the ones after that go to another one. Nice and simple.

Say I have a sales table:

id    Amount    Date
1    10            1/1/1999
2    9.99         1/1/2007

Now then, I put all the records prior to 2000 in it's own partition.

So when I do something like this: SELECT * FROM Sales WHERE DATE = 1/1/1999
the SQL server will know which partition to look at. Very nice.

Now then, if I do this: SELECT * FROM Sales WHERE id = 1
How will the SQL server know which partition to look at?


Thank You!
0
Comment
Question by:krupini
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18800619
it knows because the "date"  column has been defined as the partitioning key  with a set of "constraint" ranges
so tableA is the only 1 which could contain pre 2000 data...

if you don't specify the partition key in your query each partition/table/view will be searched for rows matching your criteria... it only if a specific partition key criteria is available that only the matching object will be searched...

hth
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18800627
remeber your partitioning key doesn't have to be unique within the table... and you'll still need a primary key
which is unique for performance / validity reasons.  
0
 
LVL 8

Accepted Solution

by:
drydenhogg earned 500 total points
ID: 18800652
Low fat is correct, it will index seek / scan (index dependant) each of the partitions within a partitioned table. It should run each partition seek / scan in parrallel (assuming your not limiting the DOP).

0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:krupini
ID: 18800761
So from what I understand, if the date is not specified, which is a partition key, the SQL server will look in all partitions, one by one.

Is there any specific order which the SQL server will use to look at partitions? For example, will it look at the most recent partition first (the one for 2000 - Now) records, and if it's not there it will look at (<2000) partition?

Thanks.
0
 
LVL 8

Expert Comment

by:drydenhogg
ID: 18800798
It will look in all partitions in parallel, 1 thread per partition. (Unless DOP prevents the parallelism)
0
 
LVL 5

Expert Comment

by:Atropa
ID: 18801551
Oh no fair, the cookie should so go to lowfat - concidering it is a diet cookie that is
0
 

Author Comment

by:krupini
ID: 18803332
drydenhogg explanation was more clear and to the point. I should have split the points, I wish I could edit the decision ....
0
 
LVL 5

Expert Comment

by:Atropa
ID: 18803354
Eh, he would have needed a low fat one anyway and where is the joy in sugar-free cookies!
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 68
Isolation level in SQL server 3 55
Need help with a query 6 81
Need to find substring in SQL 5 44
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question