sqlschool.gr logo

articles

Articles of SQLschool.gr Team

Fast copy data from table to table

Antonios Chatzipavlis
Sunday 20 August 2017

Δεν είναι σπάνιες οι φορές που χρειάζεται να μεταφερθούν δεδομένα από ένα πίνακα σε ένα άλλο οι λόγοι αρκετοί όπως table archiving, table partitioning κ.α.

Όταν οι εγγραφές είναι λίγες (<10000) ένα απλό INSERT SELECT statement είναι η εύκολη λύση με αρκετά καλό χρόνο απόκρισης και κάνεις μας δεν σκέφτεται κάτι άλλο εκτός από το να έχει όσο το δυνατό μικρότερο locking impact.

Τι γίνεται όμως όταν έχεις να μεταφέρεις δεδομένα που είναι πολλά;

Πρόσφατα χρειάστηκε να κάνω ένα table partitioning σε ένα πίνακα που είχε περίπου 1B rows σε ένα αρκετά καλό infrastructure.

Εξαρχής ήμουν πεπεισμένος για το ποια είναι η βέλτιστη διαδικασία και με αυτή ξεκίνησα αλλά ήθελα να δω και τις συμπεριφορές των άλλων περιπτώσεων.

Θα πρέπει να επισημάνω επίσης ότι σε τέτοιες διαδικασίες πέρα από τον βασικό σκοπό που είναι η μεταφορά των δεδομένων και του χρόνου που θα χρειαστεί είναι και το πόσο χώρο θα χρειαστεί το transaction log και το όσο το μικρότερο δυνατό locking impact.

Για τις μετρήσεις μου πήρα τα δεδομένα ενός μήνα που ήταν περίπου στα 20Μ rows και εκτέλεσα τρία σενάρια.

Το ένα ήταν με απλό INSERT SELECT το άλλο με ένα SSIS package και το άλλο κάνοντας χρήση του BCP και τα αποτελέσματα φαίνονται παρακάτω.


chart 1

chart 2

Θα πρέπει να επισημάνω ότι δεν υπήρχαν απαιτήσεις transformation καθώς το BCP σε αυτή την περίπτωση έχει περιορισμένες δυνατότητες σε σχέση με τις άλλες λύσεις.

Τέλος να πως ότι για να έχω τον καλύτερο έλεγχο της διαδικασίας με το BCP έκανα export/import τα δεδομένα ανά μήνα και όλη διαδικασία δεν πήρε πάνω από 15 ώρες καθώς ήταν 60 μήνες.


//antonch


Antonios Chatzipavlis

Antonios Chatzipavlis

Antonios is a Data Solutions Consultant and Trainer. He has been working in IT since 1988. In his career, he has worked as senior developer, IT Manager, Solutions Architect and IT Consultant. Since 1995 he has been devoted on new technologies and software development tools, mainly by Microsoft, either by training company staff and colleagues or assisting them in design, development and implementation as a consultant or chief developer. He has focused in Databases and Data Science since 1995. He specialized in Microsoft SQL Server since version 6.0 in areas like SQL Server Internals, Database Design and Development, Business Intelligence and in 2010 he has started working with Azure Data Platform, NoSQL databases, Big Data Technologies and Machine Learning. He is an active member of many IT communities in Greece, answering colleagues' questions and writing articles in his web site. He is the owner of SQLschool.gr which is a community portal with a lot of information about Microsoft SQL Server. He has been a Microsoft Certified Trainer (MCT) since 2000. Microsoft honored him as MVP on Data Platform due to his activities in SQL Server since 2010. He holds a large number of Microsoft Certifications and Microsoft SQL Server Certifications since version 6.5.

Episode

Task Flows in Microsoft Fabric

image

More Episodes...

Tip

What's New in SQL Server 2022 - Episodes

More Tips...

Become a member

If you want to receive updates from us become a member to our community.

Connect

Explore

Learn


sqlschool.gr © 2010-2025 All rights reserved

This site uses cookies for operational and analytics purposes only. By continuing to browse this site, you agree to their use.