News for hackers. Stuff that matters.
Re:Squeeze the hell out of the system you have by taylodl on Friday August 11, 2023 @04:41PM (#37093731)
My hot take: always use a materialized view or a stored procedure. Hide the actual, physical tables from the Application's account!

The application doesn't need to know how the data is physically stored in the database. They specify the logical view they need of the data. The DBAs create the materialized view/stored procedure that's needed to implement that logical view.

Since the application is never directly accessing the underlying physical data, it can be changed to make the retrieval more efficient without affecting any of the database's users. You're also getting the experts to create the required data access for you in the fastest, most efficient way possible.

We've been doing this for years now and it works great. It's alleviated so many headaches we used to have.

Re:Squeeze the hell out of the system you have by alfor on Friday August 11, 2023 @05:08PM (#37094054)
But for the saves the structure is visible?
Re:Squeeze the hell out of the system you have by taylodl on Friday August 11, 2023 @05:10PM (#37094077)
You can update underlying data via a materialized view.
Re:Squeeze the hell out of the system you have by NortySpock on Friday August 11, 2023 @10:39PM (#37096455)
Heck, at least with SQL Server 2017, I've been able to write updates to a thin view, and so long as the columns referenced were not ambiguous, the database would handle the underlying tables and locks required.
Re:Squeeze the hell out of the system you have by walterbell on Friday August 11, 2023 @05:18PM (#37094165)
Interface contracts and indirection FTW.

2011, "Materialized Views" by Rada Chirkova and Jun Yang, https://dsf.berkeley.edu/cs286/papers/mv-fntdb2012.pdf

> We cover three fundamental problems: (1) maintaining materialized views efficiently when the base tables change, (2) using materialized views effectively to improve performance and availability, and (3) selecting which views to materialize. We also point out their connections to a few other areas in database research, illustrate the benefit of cross-pollination of ideas with these areas, and identify several directions for research on materialized views.

Re:Squeeze the hell out of the system you have by downWidOutaFite on Friday August 11, 2023 @06:18PM (#37094746)
This doesn't work because DBAs are rarely on the dev team's sprint schedule. If the DBAs are blocking them devs can and will figure out how to route around the gatekeepers. In general, keep the logic in the app not the db.
Re:Squeeze the hell out of the system you have by taylodl on Friday August 11, 2023 @07:17PM (#37095196)
We have sprints. We also have super responsive DBAs. Keeping the logic in the app is the path to unresponsive database calls. Been there, done that. Not going back to that crap.

In all seriousness, I won't work for an organization that works the way you describe. It's a red flag and a sign of organizational issues, personality issues, and ineffective management. Don't need to waste my time at a place like that.

Re:Squeeze the hell out of the system you have by icedchai on Friday August 11, 2023 @08:12PM (#37095567)
Also, many companies don't even have DBAs these days. DBA is, at best, a part time job for a senior+ engineer.
Re:Squeeze the hell out of the system you have by lanstin on Friday August 11, 2023 @08:00PM (#37095497)
That's how it was at AOL. But also, in general, people who wrote C code never designed SQL stuff. We'd come up with some requirements, meet with a DBA (who at the time got paid a lot more money, I always assumed because their work was inherently dull), they'd put together stored procedures for use to call, and then do whatever on the physical table side. They did sometimes change the physical table stuff without us having to change anything (not sharding tho, that was edit a TCL file and restart when they said to restart).
Re:Squeeze the hell out of the system you have by wvenable on Friday August 11, 2023 @11:49PM (#37096848)
"Show me your flowchart and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowchart; it'll be obvious." -- Fred Brooks, The Mythical Man Month (1975)

> The application doesn't need to know how the data is physically stored in the database.

In all the applications that I've designed, the application and the database design are in sync. That's not say that you wouldn't use materialized views to deal with certain broad queries but I just don't see how this level of abstraction would make a big difference.

Re:Squeeze the hell out of the system you have by taylodl on Monday August 14, 2023 @09:25AM (#37120783)
There's the physical data model, and there's the logical data model. The application(s) only deal with the logical data model. They don't need to worry about how the data is physically stored.

This allows for the forward-compatible evolution of the logical data model which may necessitate extreme changes to the physical data model to keep everything performant. The client application(s) aren't affected by all the changes.

Re:Squeeze the hell out of the system you have by wvenable on Monday August 14, 2023 @01:19PM (#37123713)
The application usually has a logical data model in the form of objects representing the data, which, in turn stores that data to the physical model. This could be a separate middle tier layer or not. You're proposing another logical model in the database and I don't see the advantage.

These models shouldn't be significantly different from each other. How you store the data physically should be is very much how it's represented logically. And then how the UI represents the data model to the user.

If you have 2 tables -- a summary and a detail for example -- that's going to be similarly represented to the user in the UI. If you break that summary down into another table (because you need to allow, say, more addresses) you're going to bubble that right up the UI for saving and loading. For querying, you might have a materialized view that summarizes the detail data when viewing a bunch of summaries together but that's in addition to rest of the model.

I'm going to need some kind of example to understand the advantage of this.

Re:Squeeze the hell out of the system you have by porridgeandrice on Saturday August 12, 2023 @12:23AM (#37097032)
Yeah, I like doing this too. Not _always_, but for a few things. I use it to emulate partial functions.

In a show hosting/ticket booking app for example, I never want in any case user facing search/by-id endpoints to serve a show from 2 months ago. So I create a view `select * from shows where time > now`. I can now use this as a 'table' and apply more filters and joins to this if I wish.