Wednesday, November 08, 2017

How to Avoid Excessive Sorts in Window Functions

DZone Database Zone
How to Avoid Excessive Sorts in Window Functions
How to Avoid Excessive Sorts in Window Functions

Usually, this blog is 100% pro-window-functions and advocates using them for any occasion. But like any tool, window functions come at a price and we must carefully evaluate if that's a price we're willing to pay. That price can be a sort operation. And as we all know, sort operations are expensive. They follow O(n log n) complexity, which must be avoided at all costs for large datasets.

In a previous post, I've described how to calculate a running total with window functions (among other ways). In this post, we're going to calculate the cumulative revenue at each payment in our Sakila database.

No comments:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...