r/FullStack • u/tillas_ • 16d ago
Question Why implement procedural programming inside an RDBMS (MariaDB) instead of handling all business logic in backend application code?
So I have just seen the procedural programming language in the MariaDB RDBMS. So my question is, why in a relational database management system would you need SQL to also have the power of a programming language? Why in the layer of the database server would you need that? Can that be achieved with your backend server logic programming language, whether it be JavaScript, PHP, Python, Rust, Go, etc.? Why is there a programming language, why SQL is a programming language more so than just for querying and interacting with a database or databases? How does that fit into the full picture of full stack web development?
Edit: Thank you everyone for the thoughtful responses, technical insights, and feedback. All of this input is extremely helpful much appreciated!
View all comments
Show parent comment
1
u/jshine13371 15d ago edited 15d ago
A set-based operation is one designed to process a collection of data as opposed to a procedural operation that typically operates on a single instance of data (e.g. a scalar value or instance of a data object like a record).
Algorithmically speaking, it's based on set theory which is mathematically optimal for working with data and the logical data structures used to store that data. Physically speaking, it's implemented as an abstraction between the developer and the physical layer via the logical layer as way to remove imperfect human decision on how to physically process the data and instead let the database engine make that decision based on the aforementioned set theory algorithms.
In short, the biggest distinction between database layer code and application layer code is with databases you tell them what you want and the database engine figures out the most reasonably optimal way to physically serve you the results. In the application layer, the code says exactly how you want the physical processing to occur, which is often imperfect and doesn't consider the array of factors that affect the performance of physically processing data, mainly the statistics of that data. E.g. an inner loop between two collections isn't always the most performant way to compare those two collections, and other times a hash match isn't either. But the multitude of factors that determine which would be better for a given set of data are mostly accounted for in a database engine and are dynamically applied, for the same set of code, based on the specific data being operated on.