SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Keeping at table lean and highly available


Keeping at table lean and highly available

Author
Message
Y.B.
Y.B.
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5574 Visits: 2369
Even better...that's fantastic Gila.

Thank You


SELECT quote FROM brain WHERE original = 1
0 rows returned
Y.B.
Y.B.
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5574 Visits: 2369
Sorry one more question if I may.

What would be the best stategy for creating a new partition on the main table in such a way that I would not have to recreate the partition function and scheme every time I run the stored procedure?


SELECT quote FROM brain WHERE original = 1
0 rows returned
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)

Group: General Forum Members
Points: 224046 Visits: 40419
Been a while since I even created a partitioned table, but bassed on the information provided so far, I have absolutely no idea, not even a shot in the dark.

It would help if you would provide the current DDL (CREATE TABLE statement) for the table, including indexes.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Evil Kraig F
Evil Kraig F
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52477 Visits: 7660
yb751 (6/21/2012)
Sorry one more question if I may.

What would be the best stategy for creating a new partition on the main table in such a way that I would not have to recreate the partition function and scheme every time I run the stored procedure?


You can't, not easily. You could 'rotate' the partitions by using a contrived control value for them, but I don't recommend it as it defeats some of the optimization techniques used under the hood to help partitioning be seamless to the end user's speed.

You nearly always end up programatically rebuilding the partition function and scheme.


- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)

Group: General Forum Members
Points: 224046 Visits: 40419
Evil Kraig F (6/21/2012)
yb751 (6/21/2012)
Sorry one more question if I may.

What would be the best stategy for creating a new partition on the main table in such a way that I would not have to recreate the partition function and scheme every time I run the stored procedure?


You can't, not easily. You could 'rotate' the partitions by using a contrived control value for them, but I don't recommend it as it defeats some of the optimization techniques used under the hood to help partitioning be seamless to the end user's speed.

You nearly always end up programatically rebuilding the partition function and scheme.


But we can give you a better answer, if you provide us with more details.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Y.B.
Y.B.
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5574 Visits: 2369
Well I think I might have it conceptually. Just starting to code it right now...I'll post the final result if everything checks out.

Just create a partition function on two values 1 & 2 let's say but that really doesn't matter.
Before I load the staging table I'll just check what the current value is in the main table and populate the staging table with the opposite number using a case statement. Then when I partition the main table the one partition will remain empty ready to be switched with the valid numbered range from the staging table.


SELECT quote FROM brain WHERE original = 1
0 rows returned
Michael Valentine Jones
Michael Valentine Jones
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35898 Visits: 11933
Lynn Pettis (6/21/2012)
Assuming that you are doing this update in a stored procedure, I would do something more along the lines of this psudo code:

... prep work

set transaction isolation level serializable;
begin transaction
begin try
truncate destination_table;
insert into destination_table;

commit transaction
end try
begin catch
rollback transaction
... other error code as needed
end catch

end -- end of update procedure.


In conjunction with this, they could have the web application query the table using the snapshot isolation level (or set the database to read committed snapshot) so that the web app will still be able to see the data that was committed before the update transaction started.

That would eliminate even momentary blocking, and be much simple to implement than a partitioned table.

Note: You can enable the database for SNAPSHOT isolation while the database is online, but cannot be enabled for READ COMMITTED SNAPSHOT while there are users connected.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (549K reputation)SSC Guru (549K reputation)SSC Guru (549K reputation)SSC Guru (549K reputation)SSC Guru (549K reputation)SSC Guru (549K reputation)SSC Guru (549K reputation)SSC Guru (549K reputation)

Group: General Forum Members
Points: 549867 Visits: 47744
Err....
You don't recreate the partition scheme or function...

The two things you'd do to add a new partition are to mark the next filegroup then add a new partition value to the function.

Roughly (and copied from BoL)
ALTER PARTITION SCHEME partition_scheme_name 
NEXT USED <file group name>


then
ALTER PARTITION FUNCTION partition_function_name  ()
SPLIT RANGE (<new boundary point>Wink



Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Y.B.
Y.B.
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5574 Visits: 2369
Michael Valentine Jones (6/21/2012)


In conjunction with this, they could have the web application query the table using the snapshot isolation level (or set the database to read committed snapshot) so that the web app will still be able to see the data that was committed before the update transaction started.

That would eliminate even momentary blocking, and be much simple to implement than a partitioned table.

Note: You can enable the database for SNAPSHOT isolation while the database is online, but cannot be enabled for READ COMMITTED SNAPSHOT while there are users connected.




Another good option. I'm interesting in persuing the partition method simply to give me an excuse to learn more about it. However if it blows up in my face, I'm sure I'll run back to this. :-D


SELECT quote FROM brain WHERE original = 1
0 rows returned
Michael Valentine Jones
Michael Valentine Jones
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35898 Visits: 11933
yb751 (6/21/2012)
Michael Valentine Jones (6/21/2012)


In conjunction with this, they could have the web application query the table using the snapshot isolation level (or set the database to read committed snapshot) so that the web app will still be able to see the data that was committed before the update transaction started.

That would eliminate even momentary blocking, and be much simple to implement than a partitioned table.

Note: You can enable the database for SNAPSHOT isolation while the database is online, but cannot be enabled for READ COMMITTED SNAPSHOT while there are users connected.




Another good option. I'm interesting in persuing the partition method simply to give me an excuse to learn more about it. However if it blows up in my face, I'm sure I'll run back to this. :-D


Since one of your main concerns was "highly available", I think you might want to reconsider.

With the partition switching, there will still be unavoidable blocking, since you are making a schema change.

Withe snapshot isolation, the data will continue to be available without blocking.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search