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


Synonyms versus Partitioning for daily load?


Synonyms versus Partitioning for daily load?

Author
Message
@SixStringSQL
@SixStringSQL
SSC-Enthusiastic
SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)

Group: General Forum Members
Points: 132 Visits: 382
Our BI team needs to perform a daily load of a customer-facing fact table from our warehouse.

We've pretty much decided to go with a swapping technique, where yesterday's data remains available until today's populate is complete.

The table will be 100% loaded every day, and 95% of the data will be unchanged from the day before (lack of PKs on the source system, etc, necessitates this).

So, competing strategies to weigh:

1) Have two tables, myTable_A, and myTable_B, and use two synonyms to refer to them. myTable_Load, and myTable_Read. They would swap every successful run, so that the SSIS package always writes to the _Load table, and the customers always use the _Read.

2) Put a new column on the table, and partition on it. The load won't effect the partition that's already active, and then swap them out.

Synonyms seems like a more natural approach, but as am over-building DBA, I am leaning toward partitioning!

What are your experiences? And am I missing something obvious?

Thanks in advance!
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27587 Visits: 13268
Method 1 seems more easy to set-up than method 2.
Is it a big data load?


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18684 Visits: 20451
There is another possibility.

Have two tables, t1 and t2, with identical structures.

t1 is your 'main' table. Assume that it is up to date with data.

On the next day, load table t2. Then use sp_rename to swap t1 and t2. And repeat ...


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Jack Corbett
  Jack Corbett
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18696 Visits: 14899
I agree with Koen and Phil, if this is a complete "wipe and load" then I wouldn't bother with partitioning since it just adds complexity. The Load and rename would be the fastest way I think.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
@SixStringSQL
@SixStringSQL
SSC-Enthusiastic
SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)

Group: General Forum Members
Points: 132 Visits: 382
Thanks for the replies, all...

Question: Is there no benefit of using synonyms over renaming the base tables themselves?
Steve Jones
Steve Jones
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: Administrators
Points: 63338 Visits: 19115
Personally, I like the synonym approach since it's a layer of abstraction. If I needed to move to 3 tables, or implement partitioning, or anything else, I like having a place to point people and potentially still keeping the tables separate. However, I'm not sure it's much more than personal preference.

I also think partitioning is overkill.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87092 Visits: 41113
@SixStringSQL (8/14/2014)
Thanks for the replies, all...

Question: Is there no benefit of using synonyms over renaming the base tables themselves?


I like Synonyms for this type of thing for several reasons.

Let's consider this...

The table will be 100% loaded every day, and 95% of the data will be unchanged from the day before (lack of PKs on the source system, etc, necessitates this).



If the data is completely rebuilt, what's happening to the log file? Chances are that your DW (or whatever) database is in the FULL recovery mode and you have Point-in-Time backups being done. That could be a shedload of data that you're backing up every day... data that can easily be reconstructed and doesn't actually need for log file backups on the construction of said tables. With that in mind, putting the data on a different database that uses simple recovery would be the way to go. You wouldn't even have to backup that new database.

Then, there's the subject of Disaster Recovery. Making a gross understatement, the less data you have in a database, the faster you can recover it using a restore. For such a "swapping" system, one would be tempted to drop the "old" table when the "new" table is ready to help in this area but then you lose the ability to compare the "old" with the "new" for reporting as some would have you do.

To solve all of those problems, I actually have 3 tables... "old", "new", and "empty". "Old" and "new" are in a separate database with the SIMPLE recovery model. None of that data needs to actually live in the main database so I save on backup time and restore time. The "empty" table lives in the main database and would be used during a disaster recovery if all hell broke loose. I could be recovering the main database and rebuilding the data in the other database at the same time. The main database would restore much more quickly than if all of this data were in just the main database. If the main database comes online before I manage to rebuild the data in the "new" table, then I just point the Synonym to the "empty" table in the main database and I'm back online for any functionality that doesn't use the "new" table. As soon as the rebuild process is done on the other database, it'll flop the Synonym and Bob's your uncle. You can't do that with renaming a table.

Then there's the idea of expansion vs cost. SAN disks are relatively expensive creatures and having two copies of the same large tables (which can easily be rebuilt, require no backups, etc, etc) is a waste of valuable and sometimes expensive hardware. We made that realization and moved a lot of such data to a much less iSCSI system. People thought I was a little crazy when I insisted the reference to the "old" and "new" tables also be done using synonyms but they didn't think so when we did the move. There was zero downtime and zero code changes because I simply repointed those synonyms to the newly named tables (while the old tables were still in service and working) on the new drives, did the data rebuild like we normally would, and we were done!

You just can't do that with simple table renames... not without changing some code. How often do things like that happen? Maybe never. But, if it ever does happen, it's bloody simple and it didn't take any extra time to write the initial code for.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
@SixStringSQL
@SixStringSQL
SSC-Enthusiastic
SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)

Group: General Forum Members
Points: 132 Visits: 382
I'm honored by everyone's responses...Thanks, superstars!

Jeff, some very good points...

I will weigh everyone's suggestions.

Thanks for your help, everyone!
@SixStringSQL
@SixStringSQL
SSC-Enthusiastic
SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)

Group: General Forum Members
Points: 132 Visits: 382
One update: Consider that MSSQL won't allow a "truncate table <synonym>"...You'll need a work-around stored proc.
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