Reuven M Lerner’s article titled “Use Your Database” in the August 2015 Linux Journal re-iterates the point I make in my post about moving logic to the database to improve performance.
Don’t forget how fast your DBMS is nor how much processing power you almost certainly have sitting idle on your DB server(s). Use it!