Database is the last thing that scales usually so if you put a bunch of computational load on it besides queries, you've set yourself up for scaling/sharding sooner than later.
OTOH, if you can pre-process the data (or shards) in the server (or servers), you won't need to move it across the network for processing.
Hard problems are hard and one of the reasons databases outlive their systems and developers is because moving that data is a Royal Pain.
Plotting a Mandelbrot on the Mac would take a lot longer, even in C, than just making the printer do it.
Usually overnight, because the program took a couple hours to run most of the time.