r/SQL • u/yughiro_destroyer • Jul 06 '26
Discussion Why do we need abstractions over SQL?
When I mean abstractions, I mainly mean OOP and ORMs.
SQL is so simple and beautiful. Tables with rows and columns are easy to understand. And once you pick up the SQL syntax, you can pretty much achieve anything with queries. Not to mention that SQL is universal and works everywhere and anytime.
Then you have the software development world... where you're asked to constantly use ORMs or map records as OOP objects. Why? ORMs are limited and do not have the flexibility of simple queries. Also mapping records as objects increases bloat, reduces performance that can hurt if the application grows and is overall not as straightforward to work with.
The only good things that ORMs are doing by default are to provide data safety and prevent SQL injection. But with some minimum and basic knowledge and discipline, you can write pure queries without having those problems. Any ideas?
View all comments
Show parent comment
1
u/NoYouAreTheFBI Jul 07 '26
Yes but materialisation is not native to sub querying. Any standard subquery in line will also not materialise.
We can absolutely materialise any step in a CTE by just defining it as a temp table.
So a prime example is stack tracablility, where you need to get a large BOM trace through manufacturing. And the # is importnat because its a functional command to define a TT.
So in effect you can create query checkpoints for things you need to recall multiple times.
Most IL querying trends to recall a core componant multiple times... so you can opt to just materialise that componant.
So in short no Query Materialises natively, in SQL server you have to use the optimiser to do that yourself.
Finally there is a cost to write, if you are looking at a small throughput the recompute is arguably irrelevant however if you have a large subset that is being hit multiple times then a single write to recall is arguably a performance boost.
And you can do this a few times depending on how many steps are pushed but again there is a cost to write.