News for hackers. Stuff that matters.
Re:You Can Do It in SQL, Stop Writing Extra Code for That by thecopy on Friday December 14, 2018 @11:48AM (#18682188)
There is a significant difference between being a DBA and knowing SQL

Regarding your question:

> Is there a quantifiable performance gain with moving more operations to SQL rather than implementing it in my language of choice?

It depends, of course, but in my experience the answer is yes for 90% of the cases.

Re:You Can Do It in SQL, Stop Writing Extra Code for That by notahappycamper on Friday December 14, 2018 @12:02PM (#18682354)
Is this due to query optimization, or something else?
Re:You Can Do It in SQL, Stop Writing Extra Code for That by vonseel on Friday December 14, 2018 @12:38PM (#18682696)
I’d love to see an answer from someone more experienced on this as well.

In my experience, the database is just faster than application code at most stuff and queries can be written in a way that similar logic can’t be optimized at the application level. Additionally, database code is usually (always?) going to be faster than something like Python/Ruby.

Code review is more difficult at the database level, however, and SQL talent is more rare. It may be more challenging to scale and maintain a team of engineers working on a codebase with a lot of application logic implemented in stored procs/SQL versus ORM code (such as active record or Django). Just my opinion, have worked on teams with ORM usage as well as separate DBA teams and all logic in SQL. SQL by hand is more powerful and flexible, surely, but for most use cases I would prefer to keep code in one place (application) and only reach for the tool (raw SQL) when needed for optimizations.

Re:You Can Do It in SQL, Stop Writing Extra Code for That by PeterisP on Friday December 14, 2018 @01:37PM (#18683291)
There's a meaningful difference to where a particular calculation happens. Even if the exact same steps are done, it's more efficient to look at 10 items in the database, pick 1 item, and transfer it out to the application rather than transfer 10 items to the application and then pick one item there; doing the calculation close to the source data enables ways to do it efficiently.
Re:You Can Do It in SQL, Stop Writing Extra Code for That by eveningcoffee on Friday December 14, 2018 @07:30PM (#18686192)
Optimizer (with the statistical knowledge about the data) and being closer to the data (important data may be always in memory) and most importantly supportive data structures like indexes and materialized views.
Re:You Can Do It in SQL, Stop Writing Extra Code for That by perfmode on Friday December 14, 2018 @01:26PM (#18683155)
RMBDS systems are very good at pruning results. They can perform complex multi step operations without round trips. Etc