SQL Puzzle Optimization: The UDTF Approach For A Decay Function
How do you implement a decay function in SQL? You can use window functions, which scale better than joins, or better yet, you can try what Felipe Hoffa did: use tabular UDFs. In this video, Felipe shows you how you can use a tabular UDF to write custom code that can analyze a table row by row while preserving state. Felipe wrote a table UDF in JavaScript that uses a low amount of memory to keep track of the decaying values. He was able to run it in 36 seconds, instead of the 46 seconds that the SQL with windows solution took; and then he optimized the JavaScript even further and ran it in just 9 seconds. Read more detail on how Felipe did this in his blog: https://bit.ly/38kJ442
❄Join our YouTube community❄ https://bit.ly/3lzfeeB
Connect with Felipe Hoffa:
Twitter: @felipehoffa
LinkedIn: https://www.linkedin.com/in/hoffa