Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Keeping at table lean and highly available Expand / Collapse
Author
Message
Posted Thursday, June 21, 2012 11:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 1:09 PM
Points: 20, Visits: 111
Even better...that's fantastic Gila.

Thank You
Post #1319512
Posted Thursday, June 21, 2012 12:43 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 1:09 PM
Points: 20, Visits: 111
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?
Post #1319556
Posted Thursday, June 21, 2012 1:18 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 12:03 AM
Points: 20,703, Visits: 32,344
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.



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)
Post #1319592
Posted Thursday, June 21, 2012 1:22 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:04 AM
Points: 5,383, Visits: 7,457
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
Post #1319596
Posted Thursday, June 21, 2012 1:31 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 12:03 AM
Points: 20,703, Visits: 32,344
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.



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)
Post #1319604
Posted Thursday, June 21, 2012 1:34 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 1:09 PM
Points: 20, Visits: 111
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.
Post #1319606
Posted Thursday, June 21, 2012 1:37 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 11:09 PM
Points: 3,108, Visits: 11,502
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.


Post #1319607
Posted Thursday, June 21, 2012 1:44 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 6:13 AM
Points: 39,976, Visits: 36,336
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>)




Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1319612
Posted Thursday, June 21, 2012 1:45 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 1:09 PM
Points: 20, Visits: 111
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.
Post #1319613
Posted Thursday, June 21, 2012 1:52 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 11:09 PM
Points: 3,108, Visits: 11,502
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.


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.





Post #1319619
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse