Download presentation
Presentation is loading. Please wait.
1
T-SQL Window function deep dive part 2
Kathi Kellenberger @auntkathi
2
What are window functions?
Nothing to do with Windows OS Standard functionality added to T-SQL Functions that operate on a set or window of rows Always with an OVER clause (but sometimes you will see an OVER clause without a window function) Always found in the SELECT and ORDER BY Makes queries easier to write Often better performance What are window functions?
3
What are window functions?
2005 ROW_NUMBER(), RANK(), DENSE_RANK() and NTILE() Window aggregates 2012 Framing Enhanced window aggregates with ORDER BY Analytic functions Offset functions What are window functions?
4
Execution Plan Operators
5
Execution Plan Operators
6
Execution Plan Operators
7
POC Index (from Itzik Ben-Gan)
Filtered column(s) + Partition column(s) + Order by column(s) + Covering columns(s) Indexes
8
Window Aggregates Use caution with window aggregates
Pre-aggregate if possible Older techniques might perform better Window Aggregates
9
Default frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
Better performance with ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW IMPORTANT: If ORDER BY column values are not unique, will get different results using RANGE Framing
10
Performance
11
Performance
12
Summary POC index can help all window functions Use ROWS for framing
Use window aggregates (without ORDER BY) with caution Summary
13
Resources Adam Machanic’s Big Adventure Script
king-big-adventure.aspx My book: Expert T-SQL Window Functions Itzik Ben-Gan’s book: Microsoft SQL Server 2012 High-Performance T-SQL Using Window Functions Beginning T-SQL 3rd Edition by Kathi Kellenberger and Scott Shaw Resources
14
Just like Jimi Hendrix …
We love to get feedback Please complete the session feedback forms
15
SQLBits - It's all about the community...
Please visit Community Corner, we are trying this year to get more people to learn about the SQL Community, equally if you would be happy to visit the community corner we’d really appreciate it.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.