Solved

How does SQL Server 2005 know which partition to use?

Posted on 2007-03-27
8
203 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
  • 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sql Permission 6 59
Divide by zero error encountered. 2 39
passing parameter in sql procedure 9 61
INSERT DATE FROM STRING COLUMN 18 56
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…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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