Solved

How does SQL Server 2005 know which partition to use?

Posted on 2007-03-27
8
191 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
 

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now