4 ms·
What you are missing here is "denormalization" -- e.g. many-to-many relationships. You can either use a JOIN with a table on a "normalized" database, or keep ma
by dagss 10y ago
What you are missing here is "denormalization" -- e.g. many-to-many relationships. You can either use a JOIN with a table on a "normalized" database, or keep managing the result of the join in application code. Loading the entire tables into application code very seldom has anything to do with it...
A more realistic example is, do you get Alice's pets by doing a JOIN on tables Person, Pet, PetOwnedByPerson ("SQL") -- or by having an array column "pets" in Person? ("NoSQL")
- erikb 10y agoYes "denormalization" was the word for that. Is that still a thing?
- lostcolony 10y agoIt's a term used frequently in NoSQL land, to explain a key difference to people coming from SQL. In SQL land, normalizing your data is still the canonical thing to do, and I don't recall anyone in academia officially talking about denormalizing ever having its place...but in industry, the realities of use cases and performance have meant its usage. But I don't know that it's a standard tool given out to graduating software devs and DBAs.
- baakss 10y agoThe link I posted above is a common SQL land usage. Dimensional modeling in a star schema is very widely used in BI projects. There's actually two competing philosophies on data warehousing (Inmon and Kimball), but I've only ever used Kimball's method, which favors denormalization. http://www.computerweekly.com/tip/Inmon-vs-Kimball-Which-approach-is-suitable-for-your-data-warehouse http://www.computerweekly.com/tip/Inmon-vs-Kimball-Which-app...
- gaius 10y agoOf course they do, that's why there are the Normal Forms. Since like the 1970s people have been talking about this stuff. It's actual maths.
- baakss 10y agoYes, especially in business intelligence / data warehousing. Here is an excellent resource if you're interested in this sort of thing: https://www.amazon.com/Data-Warehouse-Toolkit-Complete-Dimensional/dp/0471200247 https://www.amazon.com/Data-Warehouse-Toolkit-Complete-Dimen...
- spudlyo 10y agoCan verify, still a thing. There is even a fun saying that goes with it. "Normalize until it hurts, denormalize until it works."
- MustardTiger 10y agoYes, and almost always used as pre-emptive optimization that didn't need to be done. Often times even making things slower because the person doing it didn't understand what they were doing, they just heard "denormalizing makes it fast".
- zspitzer 10y agoor you can use a materialized view https://www.postgresql.org/docs/current/static/rules-materializedviews.html https://www.postgresql.org/docs/current/static/rules-materia...
- jrochkind1 10y agoI don't think materialized views are an answer to this problem, precisely because postgres materialized views do not automatically update when the underlying data has changed.
- dragonwriter 10y agoSure, you have to write the code to do updates; but "materialized views" are a technique long used even in SQL databases that had no automated support for them; denormalized derived tables that are used for regular, recurring queries while the DB retains normalized base tables are a common thing (heck, in Enterprise environments, I've more than once run into a setup where custom maintenance of jury-rigged materialized views are used in a database system with strong materialized view support simply because the system has been around and maintained longer than the server software has had that support.)