Denormalization for Performance: Don't Blame the Relational Model
dbdebunk.com
dbdebunk.com
The overview is like this:
1) You need some operation to have low turnaround time / latency
2) So you maintain and update a cache, typically while writing to the data store.
3) Like all caches, you can either invalidate it before changing the data, slightly harming availability, or you can have it lag behind (eventual consistency).
So the article is actually wrong, you don't need to trade consistency for performance. You can increase read performance (lower latency) without losing consistency, by having a cache (denormalization) and invalidating the relevant caches BEFORE writing data (which lowers write latency, but not necessarily write throughput... typically, we don't care about write latency as much as read latency.)
Nice one. The only hard thing missing now is:
No one seems to talk about this but the "Moore's law has ended" meme does not apply to most database scenarios. Database servers are normally not CPU bound: they are bound by available memory and disk bandwidth and these are both still increasing.
Relational databases are relatively easy for anyone to start working with, but optimizing and tuning queries requires fair amount of domain knowledge. You'd be surprised to learn how little denormalization big financial company databasees have. They have people who are experts that do only databases.
For I/O intensive work you may need transaction rows where data written together is stored together, but it's not denormalization, it's optimizing for I/O bottleneck.
Query planners can do most of the work, if the person crafting queries has understanding of how they work. Carefully grafted queries and tuning memory layout for tables correctly is usually the right way to fix performance problems.
Because, unlike most products which only require training to work with, true RDBMSs require knowledge of data and relational fundamentals and such is scarce today, because education has been replaced by sheer training.
How many database "experts" do you know today who have any background in logic and math, particularly those designing DBMSs?
I've watched them for almost 50 years and they've become worse and worse, not better.
>kpmah: I think most are pragmatic and admit you _may_ have to do denormalise for performance
>calpaterson: So _rare_ to actually have to denormalise for performance today though.
The article's author didn't describe it as "may"/"rare" which leaves some wiggle room for the cases of denormalization required in real-world implementations. Instead he used absolute qualifiers such as "never", "no reason", "any":
- the "additional development costs" that Bolenok refers to -- but they would _never_ be justified:
- "consistency-performance tradeoff [...], there is _no_ reason to expect _any_."
The author does write his advice in abstract terms instead of discussing concrete "case studies" so we are left to speculate what mental model of the database world he holds in his mind when he's rigid with strict rules of normalization and relational purity. Based on the topics in his papers[1], I'm guessing his world consists of a single OLTP database. E.g, you develop a non-cloud restaurant reservation & POS system with a single-instance database. Yes, you don't need any denormalization hacks in that scenario.
But for other problems such as distributed databases, you can't do joins across 2 geographically separated data centers. (Well, you theoretically could do it but the slow nested-loop performance across the WAN would make it unusable for a real-world application.) Some duplication via data denormalization is required and no "sufficiently smart db engine"[2] can automatically optimize for it. An application architect has to manually make that design decision and live with the deliberate tradeoffs. (E.g., batch jobs now have to be run to periodically keep databases at different datacenters in sync.) There are many real-world scenarios that require denormalization which have nothing to do with a junior programmer's lack of SQL knowledge to join 20 tables to populate an "edit customer" data entry screen.
[1]http://www.dbdebunk.com/p/papers_3.html
[2]riff on the theoretical "Sufficiently Smart Compiler" to solve all performance optimizations so there's never a need to write performance-specific language syntax or switch to a "faster" language... because as we all know... "languages" are not fast or slow -- it's the "implementations" that are fast or slow. That Ruby is not as fast as C/C++ is an implementation detail (SSC) and not the issue of the language syntax.
But for other problems such as distributed databases, you can't do joins across 2 geographically separated data centers
That's where replication comes in as your (arguably) most powerful weapon.I work with databases for, literally, decades and have never seen a successful implementation of two-phase-commits or joins on geographically distinct entities.
I don't blame poor performance on the mathematical purity of logical relations between entities.
>the article does imply that on rare occasion you may be forced to denormalize
You didn't read the article carefully enough. You overlooked how the author seemed to allow for denormalization but he immediately negated the followup dev work as "never justified":
" -- and performance is still unsatisfactory. You denormalize and, as Bolenok recognizes, introduce redundancy. [..] - but they would never be justified:"
If users are so accepting of denormalization as a solution to performance and are unaware of all its costs, why should vendors bother to come up with true RDBMSs that obviate the need to denormalize?
As long as users do not understand the RDM and its benefits true RDBMSs will remain a fantasy. Ignorance has never been conducive to progress.
As I understand the article, it seems to say...just because all the existing databases you have seen suck at performance when normalized doesn't mean normalization can't be fast.
You mean DBMSs, not databases. Yes, that's the argument, but it's precisely this kind of lack of understanding that prevents better RDBMSs.
Just because most SQL DBMSes happen to implement relations, foreign keys, aggregates, etc. in a specific way, it doesn't automatically mean that the specifics of these implementations must be elevated to the status of laws of nature.
Problem is practitioners confuse RDBMSs with SQL DBMSs and are incapable of seeing what they're missing in terms of practical benefits of the latter.
* use as many constraints as possible (this helps the query optimizer)
* use indexes which bring better performance in your use case (e.g. bitmap join index or even index-organized tables)
* apply table/index partitioning
* use materialized views as a query result cache
I have never seen a properly denormalized table. In practice you will get a "historically grown" system way to often and doing anything like that will break things.
The whole article seems to be quite academic from my personal experience a textbook normalized database is slow beyond belief (i did exactly that once and we had to revert it back).
>I have never seen a properly denormalized table
Do you mean normalized? There's no such thing as "properly" denormalized, anything that is not normal is denormalized.
>The whole article seems to be quite academic from my personal experience a textbook normalized database is slow beyond belief (i did exactly that once and we had to revert it back).
I've seen lots of people say that, but then consistently found those same people don't actually know what the normalization rules are, and all they did was create a different denormalized database that happened to have poor performance for the queries they were using.
So, while it might be perfectly true it somehow misses some big point.
I dare you to demonstrate that the "big data solutions" guarantee logical and semantic correctness the way true RDBMSs do. Without that, garbage in garbage out. But because those "solutions" are so complex that nobody understand them, including those who designed them, their results are BELIEVED to be correct, which is not the same thing as being correct.
Any query that needs to calculate some result and has many rows benefit from storing pre-calculated values. With a trade-off in precision, correctness, and so on.
Might apply to your business or not.
Theoretically it's possible to imagine a normalised relation with 50 columns. In practice a table like that is unusual and suspect (frankly, even in a denormalised design).
That is impressively pointless pedantry even for HN, well done.
>Theoretically it's possible to imagine a normalised relation with 50 columns
Yes, that would be what I said. "You're wrong because exactly what you said is correct!"
Any linking of number of columns to normalization is pure nonsense. The only accurate thing that can be said is that if you split a relation into multiple projections, by definition each will have less attributes than the original relation. But this is a triviality and it says nothing about the number of columns in the projected relations.
Pedantry is though. And that's what that entirely pointless post was.
>Any linking of number of columns to normalization is pure nonsense.
That's what I said, that's the point. Don't jump in to a thread you can't be bothered to read.
A R-table is a visual shorthand for a relation -- a way to visualize it on some physical medium (paper, screen) and the two should not be confused.
Full normalization does not decompose into relations with same key, because that means splitting one type of entities in two, that makes no logical sense. Rather, it splits non-5NF relations that represent facts of multiple types into 5NF relations that represent facts of a single type and they have different keys.
sounds suspiciously like denormalization
Second, if they share the same key, then it's not normalization, as the the split relations have distinct keys.
Normalization is the process of organizing the attributes and relations to, among other things, eliminate redundancy. 2 relations that store and share the same primary key is by definition redundant.
Splitting relations for the sake of skinnier tables is creating redundancy(the primary key is stored twice) and insert/update anomalies and can be reasonably thought of as a denormalizing behavior.