Plansplaining part 27 – LAG and LEAD

This is part twenty-seven of the plansplaining series, and episode five in the mini-series on window functions. The previous parts covered the basics, fast-track optimization, window frames ending at UNBOUNDED FOLLOWING, and window frames specified with RANGE instead of ROWS. In this post, we will shift our attention to the LAG and LEAD functions. Two functions that do not even accept a window frame specification. So why are they in this series? Read on to find out! LAG LAG and LEAD were introduced in SQL Server 2012. They require an OVER clause, but it can only specify PARTITION BY and…
Read More

Plansplaining part 26 – Windows with a ranged frame

1 Comment
This is part twenty-six of the plansplaining series. And already the fourth episode about window functions. The first of those posts covered basic window functions; the second post focused on fast-track optimization for running aggregates, and the third post explained how the optimizer works around the lack of execution plan support for UNBOUNDED FOLLOWING. But all of those were about OVER specifications that use the ROWS keyword. Let’s now look at the alternative, the RANGE keyword. RANGE instead of ROWS When a RANGE specification is used, then number PRECEDING and number FOLLOWING are not allowed. So this leaves us with…
Read More

T-SQL Tuesday 169 – Thank you, community!

No Comments
It is December. And it is Tuesday. So I guess it’s time for T-SQL Tuesday again. Our host this month is Kay Sauter, and his seasonally inspired topic is to call out the gratitude that we often feel towards other, but fail to express. This is a very easy task for me. If you’re a regular reader of this blog, then you will know that, during the last year, my focus was more on being ill and getting better than on dissecting execution plans (although I never really fully stopped doing the latter 😉). During all that time, the support…
Read More

Plansplaining part 25 – Windows without upper bound

No Comments
This is part twenty-five of the plansplaining series, and the third part that covers window functions. I have already explained how basic window functions work, with or without a window frame. When a window frame is present, a Window Spool operator will, for each row, return first that row, and then all rows that are visible in its frame. A Stream Aggregate then computes the requested aggregations on those rows. In the previous part, I then explained how “fast-track optimization” severely reduces the amount of work in cases where the window frame starts at UNBOUNDED PRECEDING. I also showed that…
Read More

Execution Plan Video Training – pre-orders open

No Comments
I have been working hard, the past months, to complete the next series of videos for the Execution Plan Video Training. The advanced level of block 3, Combining Data, is now ready. And from now until the end of the year, you can benefit from a nice pre-order discount. Advanced joins The basics of each of the four join operators are covered in the basic level of block 3. But there is a lot more to be told about these operators, and that is what the advanced level covers. There are four videos (“chapters”) in this level. Only one of…
Read More

Plansplaining part 24 – Windows on the fast track

No Comments
This is part twenty-four of the plansplaining series. In the previous part, I explained the execution plans for basic window functions, with and without a window frame. Especially the latter group performed quite poorly in the examples. So let’s now look at an optimization that SQL Server can apply to most cases, that prevents this rather bad scaling. Running totals The examples in the previous post all used a window frame that started at (some number) PRECEDING. And as long as (some number) is quite low (and the end of the frame is not defined as (huge number) FOLLOWING), the…
Read More

Plansplaining part 23 / T-SQL Tuesday 168 – Window functions

8 Comments
I skipped the last two T-SQL Tuesdays. But this month, I will participate again. The monthly blog party is once more hosted by Steve Jones. His chosen topic is: Window Functions. In his invitation, Steve specifically asks for examples where Window functions provided a neat solution to a real world problem. Well, sorry Steve, but I am not going to do that. But your invitation did inspire to me write about the execution plans for these window functions. And there is, in fact, so much to write about it, that this is just the first part. So that makes this…
Read More

Black Friday returns!

No Comments
November approaches again. For Europeans, that is a month like any other, for Americans, November means: Black Friday, with huge discounts! Two years ago, I decided to try an experiment. All of November 2021, I offered a 50% discount on all prices for the SQLServerFast Execution Plan Video Training – both individual videos, as well as the already cheaper full-block purchase. The results were better than expected, and certainly reason to repeat this. Last year, I tried something else: a Black Friday Charity, where the 50% discount was not offered to you, as the customer, but donated to charity. Though…
Read More

An update on MERGE

7 Comments
The MERGE statement compares source and target data, and then inserts into, updates, and deletes from the target table, all in a single statement. This statement was introduced in SQL Server 2008. I liked it, because it allows you to replace a set of multiple queries with just one single query. And while a statement with that many options necessarily has a more complex syntax, I still believe that, in most cases, a single MERGE statement is easier to read, write, and maintain, than a combination of at least an INSERT and an UPDATE, often a DELETE, and sometimes first…
Read More

T-SQL Tuesday 165 – Job titles vs actual work

It’s the second Tuesday of the month again, so that means that it’s time for another T-SQL Tuesday. Our host is Josephine Bush, and she wants us to talk about the often confusing job titles in the data world. And while I will (of course) share my thoughts on that topic, I have decided to also include a short rant about a very much related topic: tracks on conferences. Those who have submitted conference talks before will probably immediately understand why I call that a very much related topic. The rest will have to read on! Job titles I advertise…
Read More

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close