Integration Services (SSIS) internals and performance tuning

Back in 2014, I created a 214-page deck for a pre-con at SQLSaturday Johannesburg and Cape Town. Since then I’ve presented it at a good number of large and small conferences.
I don’t often work with SSIS anymore, so I thought I’d publish the entire deck here.
The material is quite text-heavy, so it should be readable. I compiled the deck from several sources (see the last four slides). Also, please note it doesn’t cover SSIS 2016 and the buffer optimizations that came in that version.

Integration Services (SSIS) internals and performance tuning

SQL Server Performance Troubleshooting Free Scripts and Tools List

Back in the days, I used to collect a lot of different scripts, tools, and other goodies for troubleshooting SQL Server performance issues. These days, however, I use what is available for free and keep a list of those in my head. 
I’ve meant to write that list down for a while, and today Chrissy asked: 

So here it is… 
Disclaimer: While I do work as a Premier Field Engineer for Microsoft, this is my list – this is not an official list from my employer. 

Free scripts and tools from Microsoft

These are scripts and tools provided for free by Microsoft that I use. Some of them come “as-is” with no official support.

  • BPCheck – This is by far my favorite script and one I use all the time. I like to joke that there are one good thing and one bad thing about this script. The good thing is that it gives me a lot of information. The bad thing is that it gives me a lot of information. It can overwhelm the first time you run it, but once you have used it a few times, it is handy.
  • Pssdiag/Sqldiag Manager – This tool creates a customized pssdiag utility that uses sqldiag to collect diagnostics data, such as profiler trace, extended events, perfmon and DMV information. I use this all the time for data collection used to troubleshoot performance problems. There is also version for Linux available (see this blog post, for how to use the Linux version).
  • SQL Nexus – Loads and analyzes performance data collected by Pssdiag. It loads the data into a database and does reporting.
  • PAL – The Performance Analysis of Logs (PAL) tool reads a perfmon counter log and analyzes it using different thresholds. It generates an HTML based report (or XML, if you prefer), which shows which counters are interesting. It has templates for SQL Server workloads but works with a lot of other workloads too.
  • RML – The Replay Markup Language (RML) utilities can analyze profiler traces or replay the trace file against another instance of SQL Server. For how to use it, read this blog post.
  • WinDbg – Windows Debugger. Useful for debugging a memory dump.
  • Tigertoolbox – This is the repository for the SQL Server Tiger Team and contains a lot of good stuff. Maybe you need some SQL Performance Baseline reports, fix your VLFs, or view the waits and latches. It is also the home of BPCheck.
  • diskspd – Storage load generator / performance test tool. It replaces SQLIO. I use this if I want to benchmark the IO subsystem of a new machine / VM. There are two good blog posts about how to use diskspd here and here.
  • SQL Server Management Studio – SSMS is now a standalone application (it used to ship with the SQL Server installation) and got quite a few improvements in the newer versions.
  • sysinternals – Tools for advanced troubleshooting on Windows, which I use from time to time.
  • SQL Server Data Tools – Not a tool I use for performance troubleshooting, but it is in my toolbox for when I have to look at an SSIS package.
  • Visual Studio Code – My go-to editor for… everything.

Free scripts, tools, and resources from the community

The awesome SQL Server community has made a lot of things available.

  • SQL Server Diagnostic Information Queries – Before I discovered Glenn Berry‘s DMV queries, I used to collect scripts myself. Not anymore. Glenn updates his queries every month. While I prefer to use BPCheck to get information from the DMVs, I find that Glenn’s scripts are better structured and easier to use.
  • sp_whoisactive – Think sp_who2… but much better. This script by Adam Machanic shows which statements are being executed and can include the estimated execution plan, acquired locks, tempdb resource allocation, and more.
  • sp_helpindex rewrite – sp_helpindex that ships with SQL Server do not show newer functionality (such as included columns and filters), so Kimberly Tripp rewrote it to include this information. Also, be sure to read her blog post on indexing strategies.
  • Ola Hallengren’s SQL Server Maintenance Solution – Ola’s scripts are great, easy to use, and make life easier for a lot of DBAs around the world. The index and statistics maintenance part of the script is an easy way to reduce index fragmentation and make sure your statistics are up to date.
  • Plan Explorer – While SSMS can show the execution plan just fine, Plan Explorer makes it a little easier to read.
  • Statistics Parser – Parses the output of SET STATISTICS IO and SET STATISTICS TIME and makes it a lot easier to read and analyze.
  • Poor SQL – Ever got a SQL query that is just poor formatted or just one line? This site can format it to something readable.
  • dbatools – I don’t use these PowerShell modules for performance troubleshooting, but they are useful for checking best practices and other DBA tasks.
  • SQL Server Version List – I use this up-to-date list of SQL Server versions to check if any service packs or commutative updates are missing.
  • SQL Server Wait Types Library and Latches Classes Library – While I remember the most common wait types and latches classes I see all the time, I sometimes run into one I haven’t seen before or can’t remember what is. Paul Randal‘s libraries are handy resources to look up those.

That’s it! If you have a free tool or script you use (or wrote yourself), leave a comment – would love to check it out!

SQL Server Performance Troubleshooting Free Scripts and Tools List

First time speaking at a large tech conference: How I prepared

This is the story of how I prepared for the talk at my first large tech conference and ended up getting a great speaker evaluation.
PASS Summit 2014 was the first time I was speaking at a large tech conference. While I have talked at over 30 conferences over the past two years, some of them with several hundreds of participants, this one was different; PASS Summit had 5,900 registrations. With 233 attendees the room felt packed. A few people were standing in the back and sitting on the floor. 
PASS Summit 2014 talk 
The title of the talk was Integration Services (SSIS) for the DBA. I had already delivered it at SQLBits XII earlier the year. While my speaker evaluation from SQLBits was excellent, I was not happy with the talk I already had. Therefore, I restructured it. 
And it paid off. 
My speaker evaluation score was well above average, and one of the best I have ever got. Some comments in the evaluation were:

AWESOME presentation 
The session was very well balanced. A great amount of slides and demos. 
Fantastic, well-prepared session, with great demos incl. Game of Thrones demo!! 
Explanation of version differences, in particular, was enlightening. Thanks. 
Some very useful management techniques learned David was extremely engaging and made the topic fun for everyone in the session.

Structuring the presentation

A good structure is everything. When I wrote my dissertation at the University of Bradford, my supervisor introduced me to the following structure:

  1. What?
  2. How?
  3. So what?

Another structure is the three-act structure, which creative writing, screenwriting, and storytelling use.
I used the structure I had learned during my studies and ended up with this:

  1. What is SQL Server Integration Services (SSIS)?
  2. How do I deploy, configure, and execute SSIS packages?
  3. How do I monitor and troubleshoot SSIS packages?

The last question is not a “so what?”. But I thought it would still fit into that category. At least close enough. 
I also planned a five minutes introduction, where I introduced myself, the topic, who the talk was for (I wanted to make sure that people knew it was a level 200 DBA focused session, and not a deep dive into the topic from a developer point of view), and what they would learn. 
Before I began the work on slides or demos, I wrote a detailed plan in Evernote. I find that I am much faster creating slides and demos this way. Writing things down in plain text makes it easier for me to think about the content and structure than if I was doing it in PowerPoint.


I am not a big fan of slides with a lot of text. I know people can pull it off, like Kimberly Tripp and Paul Randal, but most people can’t; myself included. I create tech-rich slides for my workshop material, because it is a whole day training, and it is nice for the audience to go back and go through the notes. However, not for short talks. 
Instead, I prefer a big font with just a few words. I am a big fan of Zack Holman’s slide decks and would like to be better at creating beautiful slide decks. 
The slides would follow the structure I had written in Evernote. 
PowerPoint is the de facto slide deck tool in the Windows world where I live. I have created slide decks on my Mac in Keynote and Deckset, which both are great options. When using PowerPoint, I change the default settings:

  • Disable the presenter view. When using presenter view the laptop goes from mirroring the screen to extending it. When I jump out of the presentation to do a demo, the computer goes back to mirroring the screen and the projector will need to readjust. Best case, this gives a few seconds of a black screen and a flickering display for another second or two. Worst case, it messes up the resolution. Don’t use it. Use speaker notes on a separate device (iPad, Surface, a piece of paper) instead.
  • Disable the Slide Show Popup Toolbar. I know others who like to draw on their slides and should keep this. I don’t and don’t want it to show up if I move my mouse.
  • Disable the mouse cursor during the presentation. I don’t need it, and it is an annoyance if I hit my mouse or track pad.


My demos took place in SQL Server Management Studio and SQL Server Data Tools. I tried to use geekiness and humor in the demos rather than just using a standard demo database. For example, I got hold of a Game of Thrones data set and had Dr. Who quotes in my data flow. It spiced things up and worked well. 
The demos should be sophisticated enough to prove your point, but simple enough for the audience to follow. I prefer to create more straightforward demos. Fewer things can go wrong. 
In my first demo, I began the design of a package from scratch. While Buck Woody (blog) says “never type in demos,” I like the life it brings to it. So, I drag-and-dropped my first demo; but only halfway. Then I brought in a finished package, so the audience did not have to watch me drag-and-drop for 15 minutes. It worked very well and much better than if I had only used the finished package to show how SSIS works. 
The rest of my demos were pre-scripted in T-SQL. 
Other things I did was:

  • Have a reset strategy. I could reset my demo in about 30 seconds in case something went wrong.
  • I had configured SQL Server Management Studio to use a larger font size, displaying the results in a separate tab, include the query in the result set, and added line numbers. Size 16 is what I normally use, but the resolution was higher than they had told me, and it was hard to read from the back of the room. So I bumped it up to 18 when I did my tech check. Other settings I changed: Enable lined numbers and show query results in a new tab.
  • ZoomIt is the preferred tool by many presenters, but it had things that bothered me. It did not feel smooth. Instead, I switched to using Windows 8.1’s built-in magnifier, which can do multi-level zoom while still demoing. 
  • I considered using bigger fonts in Visual Studio as well but settled for using the magnifier. I think it worked better.

Be Utterly Prepared (No excuses)

As Scott Hanselman writes in a blog post about being prepared for absolute chaos at technical presentations: “Be Utterly Prepared (No excuses)“. 
For every talk I give, I prepare. This time I took it to another level. I put in at least 80 hours into this one hour and 15 minutes talk. 
And again, it paid off. Everything ran smooth. Here are comments from the speaker evaluation:

Presenter was very knowledgeable on the subject. He kept the steady pace throughout the session and kept it interesting. The session was awesome. Very interactive. He kept the audience awake and engaged in the presentation. He was relaxed but at the same time very focused. He presented an enormous amount of information but in a very easy to follow and understand way. 
The audience was kept well engaged- excellent use of humor and great slides. Excellent! You really made a connection with your DBA audience! 
Great personality. 
He enjoys his work & it shows in his lectures. He had a really good connection with the crowd 
Speaker had great energy and was very passionate and knowledgeable about the material. Would have bought whatever had he been a sales guy. Great job. 
Very well done presentation; good match of material to the time allotted. The pace was right on. Nice job! 
Awesome sample data. We love the disarming, personal touch. The speaker was very knowledgeable of the content and did an excellent job repeating questions and answering them. 
David was extremely engaging and made the topic fun for everyone in the session. Loved it!

Here are a few things I did to be utterly prepared:

  • I wrote detailed speaker notes in Evernote. Not every sentence I wanted to say, but keywords and phrases in a bullet point format. And then I had the speaker notes on my iPad on stage. Nobody seemed to notice it, as I glanced on it from time to time, and it helped me not forget anything. 
  • Backup speaker notes. Yes, even with my speaker notes on my iPad, I had a few details I kept forgetting when doing my dry runs. I wrote them down on a few pieces of paper, in large writing, and placed them on the table on stage.
  • I practiced. And then I practiced more. Until I knew my talk inside out. Before the presentation, I always do a few dry runs. But this time I did it significant more times than usual. I am not great at winging it, because I believe structure is so fundamental to a great talk. I would feel like Speaker 47 if I did.
  • My demos worked. But oh my, did I have a lot of demo fails during my trial runs. Minor stuff, but still something that annoyed me. Trying them out repeatedly helped me get rid of those glitches and made everything run very smooth.
  • I ran my demos inside VMware Workstation. One benefit of using a VM is that it is easier to move the demos to a backup computer. 
  • I brought not one, but two backup laptops. Both laptops had an identical setup (slides and VM for demos) as the primary laptop. And am I happy I did! Because both failed. But my primary laptop worked fine.
  • Time management is very important. To ensure I would not run out of time, I created few additional demos. The extra demos were essential to the talk, in case I didn’t have time for them. Having a watch that shows the remaining time is important to control the pace the talk. One of the best things I’ve bought was a Logitech Professional Presenter R800, which has a build in LCD display that shows the remaining time.
  • At the end of my talk I didn’t take any questions. It is better to end the talk on a high. This was a tip I learned from Scott Hanselman. Instead, I took questions throughout the session. I was happy with this decision. When other presenters taking questions at the end of their session, the audience walked out during the Q and A. Not a few people, but the majority. Instead, my talk ended with a link to the slides and demos, a “thank you so much for attending and have a great conference,” and an applaud from the audience.

On the day

One of the most important things I do when I arrive at a conference is a tech check. While PASS Summit had a projector in the speaker ready room, I went during the lunch break to the room I had to present in and did a tech check. There was trouble with the projector. The result was skewed screen resolution or the screen cut off, which showed in many other presentations. I got a technician to look at it and got it fixed within 5 minutes. 
Don’t do the tech check right before the talk. Never. Things go wrong all the time. I have learned this the hard way. To avoid technical failure, I have over time collected a big bag with different cables, converters, USB sticks, batteries, an extra mouse and extra presenter. 
During my tech check, I went to the back of the room several times and made sure everything looked great.

  • Is the resolution correct? Is the image not stretched? I had trouble here and needed to get a technician. The problem was that my laptop couldn’t figure out the correct resolution.
  • Is part of the image cut off on the projector? This happens more often than not and also happened here. After changing the resolution and pressing the auto adjust button on the projector, everything worked.
  • Big enough font on the slides? Looked good.
  • Did the colors look good? Are they readable? Are the photos and other graphical elements sharp and easy to see? Check, check, check.
  • Big enough font in the demos? No, so I bumped it up.
  • Did the magnifier work? Yes.
  • Was the Logitech presenter and mouse working and charged? Yes.
  • Was the laptop charged and plugged in. Always check if it is charging – I have tried to run out of battery mid-talk.

During the talk

I always try to start right on time. I am Danish that way. And end on time. Sometimes I small talk with the audience before the talk, sometimes I don’t. If I do, I am being a little silly or telling a funny story. 
I followed the prepared script close, but still allowed time for questions throughout the talk and going off-script here and there. 
I had a lot of fun. The first few minutes are always the hardest. Will they like it? Is everything working fine, or will the laptop blow up (or just run out of battery)? After that, I am having a blast. One of the best comments I got was that I take my personality with me onto the stage. I try to do that as I want to show people I am having fun doing this. 
To sum up, I try to not waste everybody’s time for an hour and 15 minutes by being prepared.

Further reading:

A few blog posts and online courses I recommend anyone serious about public speaking at tech conferences. They helped me a lot.

First time speaking at a large tech conference: How I prepared

Regional and language settings for Oracle client used with SQL Server linked server

Today, I ran into a problem while migrating a Data Warehouse solution to another server. 
The solution have linked servers for extracting data from an Oracle source system. 
The query would go something like this: 

INSERT INTO dbo.MyTable 
 TO_CHAR(COL1_DT, ''YYYY'') AS Col1Year
 , COL2
 , COL3
 , SUM(AMOUNT) AS Amount
 , COL2
 , COL3

I had migrated everything, but while running the extract job, which ran queries like the above, we would get errors like these: 
Conversion failed when converting the nvarchar value '123456,78' to data type int. 
Error converting data type nvarchar to numeric. 
The problem was that instead of using a dot (.) as the decimal symbol, a comma (,) was being returned. This would make the data convert to nvarchar, and an implicit conversion to a NUMERIC or INT would fail. 
Everything was running fine on the old server. The collation of the server and databases were identical (Latin1_General_CI_AS), but the regional and language settings were different. On the old server they were set to English (United States) and on the new server to Danish. Changing the settings on the new server to English (United States) did not help. 
After troubleshooting a bit on #sqlhelp with Amit Banerjee (twitter | blog) and William Durkin (twitter | blog), as well as via Skype with Jørgen Guldmann (twitter | blog), Jørgen ended up pointing me in the right direction. 
The problem as that the NLS_LANG parameter was set to Danish (where we use a comma (,) as the decimal symbol). It is stored in the registry under the following sub-key: 
Where ID is the unique number identifying the Oracle home. 
The trick was to change this sub-key from: 
And then everything worked fine, and the decimal symbol was now a dot (.) instead of a comma (,).

Regional and language settings for Oracle client used with SQL Server linked server

MSBuild error (and fix) with Visual Studio 2013 SQL Server tooling and SQL Server 2014

To show the possibilities with continuous integration with SQL Server development, I decided to spin up a virtual machine with Visual Studio 2013, Team Foundation Server 2013, and SQL Server 2014. While setting it up, I ran into an error that I thought I’d share here. 
If you want to know more about how to set up continuous integration for SQL Server development, Jamie Thomson (blog | twitter) wrote a very good blog post about continuous deployment of SSDT database projects to Windows Azure using Team Foundation Service. This approach can also be used for on premise build servers using Team Foundation Server, which is what I was looking for. 
With Visual Studio 2013 you can no longer download SQL Server Data Tool separately as SQL Server tooling is included. You will need to use either one paid versions of Visual Studio or one of the free express editions
If you wish to deploy to SQL Server 2014, you also need to update the SQL Server tooling from within Visual Studio
While I was trying to set up a build server, I ran into this error: 
C:Builds3MyProjectAdventureWorks Test Server BuildSourcesMainAdventureWorksAdventureWorksAdventureWorks.sqlproj (63): The imported project "C:Program Files (x86)MSBuildMicrosoftVisualStudiov11.0SSDT Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. 
In my .sqlproj file, the Import declaration showed: 
The C:Program Files (x86)MSBuildMicrosoftVisualStudiov11.0SSDT path did not exist, but the C:Program Files (x86)MSBuildMicrosoftVisualStudiov12.0SSDT did. 
It looked like an old MSBuild version was being used, so the solution I found was to override the variable in the build definition to use the newest version. This is what I did:
1. Find build definition under Builds in the Team Explorer
2. Click Edit build definition
3. Click Process
4. Click Advanced
5. Add /p:VisualStudioVersion=12.0 under MSBuild arguments
My build arguments ended up looking like this, when adding the build, publish and SqlPublishProfilePath arguments
/t:Build /t:Publish /p:SqlPublishProfilePath=AdventureWorks.Test.publish.xml /p:VisualStudioVersion=12.0 
After that, the build worked just fine.

MSBuild error (and fix) with Visual Studio 2013 SQL Server tooling and SQL Server 2014

Create Data Warehouse extract tables from SQL Server source system

I have often found that I needed a quick script for giving me CREATE TABLE statements for each table in a source system database, so I could create these tables in my extract schema in my Data Warehouse. This can be done using SQL Server Management Studio, but I found that I would then have to edit each statement to remove keys, indexes, identity columns, and everything else that I rarely want in my extract tables.
Having not being able to find one, I wrote my own, and though I’d share it here. The following script writes a CREATE TABLE statement for each table in a SQL Server source database, so I can use them for creating extract tables in a data warehouse.

DECLARE @ExtractSchema NVARCHAR(100) = 'Extract'
SELECT 'CREATE TABLE [' + @ExtractSchema + '].['
      + SCHEMA_NAME (t.schema_id)
      + '_' + + '] (' + LEFT(cols .column_list, LEN(cols .column_list) - 1) + ')'
FROM sys.tables t
CROSS APPLY (SELECT '[' + c .name + '] ' + UPPER(ty .name)
                    + CASE WHEN IN ('decimal', 'numeric') THEN
                              '(' + CONVERT(NVARCHAR(10), c.precision)
                              + ', '
                              + CONVERT (NVARCHAR(10), c.scale)
                              + ')'
                      WHEN = 'float' THEN
                         '(' + CONVERT(NVARCHAR(10), c.precision ) + ')'
                      WHEN IN ('datetime2', 'datetimeoffset', 'time') THEN
                         '(' + CONVERT(NVARCHAR(10), c.scale) + ')'
                      WHEN IN ('char', 'nchar', 'varchar', 'nvarchar') THEN
                         '(' + CASE WHEN c.max_length = - 1
                                   THEN 'MAX'
                                   ELSE CAST (c.max_length AS NVARCHAR(10))
                              END + ')'
                      ELSE ''
                    + CASE WHEN c.is_nullable = 0 THEN ' NOT'
                      ELSE ''
                    + ' NULL, '
               FROM sys.columns c
               INNER JOIN sys.types ty
               ON c.user_type_id = ty.user_type_id
               WHERE t.object_id = c.object_id
               ORDER BY c.column_id
               FOR XML PATH('')
      ) cols (column_list)
Create Data Warehouse extract tables from SQL Server source system

When does SQL Server partition split move data?

One of the many benefits when using table partitioning in SQL Server is the metadata only operations, such as switch, split, and merge. However, if we are not careful, splitting partition can potential take a long time if data end up being moved between two partitions.
In this blog post we will take a look at when SQL Server partition split will be a metadata only operation, and when data will be moved between partitions.
According to Books Online, we should avoid splitting or merging populated partitions:

Always keep empty partitions at both ends of the partition range to guarantee that the partition split (before loading new data) and partition merge (after unloading old data) do not incur any data movement. Avoid splitting or merging populated partitions. This can be extremely inefficient, as this may cause as much as four times more log generation, and may also cause severe locking.

But let’s take a look at what is actually happening when we split a partition. By using fn_dblog to read from the transaction log, we can see whether we have data movement or not when we split a partition.
To demonstrate this, I have created a partitioned table with two partitions; one empty and one with 20000 rows. The 20000 rows are split between 10000 rows with the date 20120301 and 10000 rows with the date 20120501. I am using right range partitioning. Using the DMVs (see my previous blog post for a query that gives you information about the partitions), let’s take a look at the two partitions:

Test #1: Split a partition with data on both sides of the new boundary point

In this test we split with a new boundary point 20120401, which means that we will have data on both sides of the new boundary point.

-- This is the actual split
SPLIT RANGE (20120401)
-- End of split
-- Get the xact ID from our current explicit transaction
SELECT @xact_id = transaction_id
FROM sys.dm_tran_current_transaction
-- Get the entries in the transaction log related to the
-- above transaction doing a split
SELECT [Current LSN], [Operation], [AllocUnitName], [Context]
     , [Transaction ID] , [Transaction Name], [Xact ID]
FROM ::fn_dblog(NULL,NULL)
WHERE [Transaction ID] = (
     SELECT TOP 1 [Transaction ID]
     FROM ::fn_dblog(NULL,NULL)
     WHERE [Xact ID] = @xact_id)

This results in the following output where we can see that there are 20,258 entries in the transaction log.
If we take a further look, we can see that most of the entries are LOB_INSERT_ROWS and LOB_DELETE_ROWS, which tells us that 10,000 rows are inserted into the new partition and deleted the old partition.
After this split, the partitions now look like this:

Test #2: Split a partition with data on the left side of the new boundary point

In this test we split with a new boundary point 20120601, which means that we will have data on the left side of the new boundary point, and the right side will be empty.

SPLIT RANGE (20120601)
SELECT @xact_id = transaction_id
FROM sys.dm_tran_current_transaction
SELECT [Current LSN], [Operation], [AllocUnitName], [Context]
     , [Transaction ID] , [Transaction Name], [Xact ID]
FROM ::fn_dblog(NULL,NULL)
WHERE [Transaction ID] = (
     SELECT TOP 1 [Transaction ID]
     FROM ::fn_dblog(NULL,NULL)
     WHERE [Xact ID] = @xact_id)

This results in the following output where we can see that there are only 19 entries in the transaction log.
Despite we have data in the partition that we split, it is a metadata only operation. Quite a different case than our previous test. In this case, we are using right range partitioning, and if the data is only on the left side of the new boundary point, there is no data movement. This makes sense as the new partition being created is empty.

Test #3: Split an empty partition

In this test we split with a new boundary point 20120801, which means that we split the last partition which is empty.

SPLIT RANGE (20120801)
SELECT @xact_id = transaction_id
FROM sys.dm_tran_current_transaction
SELECT [Current LSN], [Operation], [AllocUnitName], [Context]
     , [Transaction ID] , [Transaction Name], [Xact ID]
FROM ::fn_dblog(NULL,NULL)
WHERE [Transaction ID] = (
     SELECT TOP 1 [Transaction ID]
     FROM ::fn_dblog(NULL,NULL)
     WHERE [Xact ID] = @xact_id)

This results in the following output where we can see that there are only 19 entries in the transaction log.
This result is expected as it is an empty partition we are splitting. Let’s take a look at our partitions.

Test #4: Split a partition with data on the left side of the new boundary point

In this test we split with a new boundary point 20120201, which means that we will have data on the right side of the new boundary point, and the left side will be empty.

SPLIT RANGE (20120201)
SELECT @xact_id = transaction_id
FROM sys.dm_tran_current_transaction
SELECT [Current LSN], [Operation], [AllocUnitName], [Context]
     , [Transaction ID] , [Transaction Name], [Xact ID]
FROM ::fn_dblog(NULL,NULL)
WHERE [Transaction ID] = (
     SELECT TOP 1 [Transaction ID]
     FROM ::fn_dblog(NULL,NULL)
     WHERE [Xact ID] = @xact_id)

This results in the following output where we can see that there are 20,307 entries in the transaction log.
If we again take a further look, we can see that most of the entries are LOB_INSERT_ROWS and LOB_DELETE_ROWS, which suggests that it inserts all rows into the new partition and deleted the old partition.
If we look at our partitions, we can see that the old partition 2 is now empty (although 1 page is still allocated for it) and the new partition 3 contains all the rows. So when the data is on the right side of the new boundary point, and the left side is empty, it moves all rows.

Left range partitioning

If we had used left range partitioning instead of right range, the results would have been opposite the ones shown above. Here, there would be data movement if there would be data only on the left side of the new boundary point, and it would be a metadata operation only if there would be data only on the right side of the new boundary point.


While the recommendation in books online is to only split empty partitions, it is possible to split a partition with data and still get a metadata operation only. However, this is undocumented, and could change. I have seen designs where the last (or first) partition was not kept empty, and as of SQL Server 2012 that seems safe. As long as we know that there only will be data on the left side (of the last partition, in right range partitioning) or the right side (of the first partition, in left range partitioning) of the new boundary point for the split.

When does SQL Server partition split move data?

Partitioning on Microsoft SQL Server

Here is a few links to articles, white papers, and best practices on partitioning on Microsoft SQL Server. I have these at the end of my slide deck on layered partitioning, which uses a combination of partitioned tables and a partitioned view, and thought that I would put them up here as well.
Partitioning on Microsoft SQL Server

View partitions in SQL Server

This query is quite useful when looking at which partitions are in the database. It is originally taken from the book Microsoft SQL Server 2008 Internals (p. 438), and then I have tweaked it a bit and added some more information.
I used this query in my demo today at SQLSaturday #152 in Bulgaria, where I talked about layered partitioning.

DECLARE @TableName NVARCHAR(200) = N'Facts.Credit'
SELECT SCHEMA_NAME(o.schema_id) + '.' + OBJECT_NAME(i.object_id) AS [object]
     , p.partition_number AS [p#]
     , AS [filegroup]
     , p.rows
     , au.total_pages AS pages
     , CASE boundary_value_on_right
       WHEN 1 THEN 'less than'
       ELSE 'less than or equal to' END as comparison
     , rv.value
     , CONVERT (VARCHAR(6), CONVERT (INT, SUBSTRING (au.first_page, 6, 1) +
       SUBSTRING (au.first_page, 5, 1))) + ':' + CONVERT (VARCHAR(20),
       CONVERT (INT, SUBSTRING (au.first_page, 4, 1) +
       SUBSTRING (au.first_page, 3, 1) + SUBSTRING (au.first_page, 2, 1) +
       SUBSTRING (au.first_page, 1, 1))) AS first_page
FROM sys.partitions p
INNER JOIN sys.indexes i
     ON p.object_id = i.object_id
AND p.index_id = i.index_id
INNER JOIN sys.objects o
     ON p.object_id = o.object_id
INNER JOIN sys.system_internals_allocation_units au
     ON p.partition_id = au.container_id
INNER JOIN sys.partition_schemes ps
     ON ps.data_space_id = i.data_space_id
INNER JOIN sys.partition_functions f
     ON f.function_id = ps.function_id
INNER JOIN sys.destination_data_spaces dds
     ON dds.partition_scheme_id = ps.data_space_id
     AND dds.destination_id = p.partition_number
INNER JOIN sys.filegroups fg
     ON dds.data_space_id = fg.data_space_id
LEFT OUTER JOIN sys.partition_range_values rv
     ON f.function_id = rv.function_id
     AND p.partition_number = rv.boundary_id
WHERE i.index_id < 2
     AND o.object_id = OBJECT_ID(@TableName);

The result is something like the following.
View partitions in SQL Server
The query shows:

  • object – The table name.
  • p# – The partition number.
  • filegroup – The filegroup the partition is located on. Note that in this result, I am using the same filegroup for all partitions, but usually you would probably not do this.
  • rows – Number of rows in the partition.
  • comparison – shows “less than” if you are using right range partitioning or “less than or equal to” if you are using left range partitioning.
  • value – The boundary point between the two partitions. This value is either in the right or left partition of the boundary point, depending on whether or not you are using right range or left range partitioning.
  • first_page – The first file:page allocated for the partition.
View partitions in SQL Server