by feoren · 2y ago · 0 comments
This applies directly to database designs and why almost every database is awful unmaintainable garbage. If you have a table per category of thing, your database is terrible; but know you're in good company, as 99.9% of database developers make this simple and completely avoidable mistake.
Unfortunately our laws also like to categorize things, which does sometimes make it unavoidable in software dealing with those laws.
> Fish generally live in the water, breathe through gills, have tails and fins, possess a certain hydrodynamic shape, lay eggs, and are in a certain part of the phylogenetic tree.
This is not true (somewhat saved by "generally"). Either you're describing physical characteristics, or you're describing phylogeny; not both. Phylogenetically, whales are fish, and so are you. (This rests on the idea that only monophyletic groups are at all meaningful in genetics; nothing ever stops being in the "fish" tree, if such a tree even exists. Cats are felines and mammals and lizards and fish. Unless you believe there is no such thing as a fish at all, which is also a solution.)
> A fish is a creature phylogenetically related to various other fish, and with certain defining anatomical features.
Take a shark, pretty universally recognized as a kind of fish. If the argument is "whales are closer, phylogenetically, to humans and cats than to sharks, therefore they are mammals", then you should know: so are salmon. Salmon are closer, phylogenetically, to humans and cats than to sharks.
The point not being that you should call whales fish, but rather being: fuck categories.
> When terms are not defined directly by God, we need our own methods of dividing them into categories.
No, we really, genuinely, honestly, do not need any methods of dividing things into categories. We really don't.
I realize that the author does kinda get to a weaker version of this with talk about fuzzy borders and the goals of the category. The transgender discussion is pretty good, with his criticism of the fallacious argument:
> If a man thinks he’s a woman, then we might (empathetically) wish he were a woman, other people might demand we call him a woman, and we might be much more popular if we say he’s a woman. But if we’re going to be rationalists who focus on believing what’s actually true, then we’ve got to call him a man and take the consequences.
I go much harder anti-category and say: this argument is fallacious on its face because it asserts that belonging to the category "man" is even theoretically a factual thing. It's not, just as belonging to any category is not. Any argument that it is either True or False that object X belongs to category Y is immediately fallacious and should be completely discarded.
Are you arguing for mereological nihilism?
Wait, did you just come up with a category for my anti-category rhetoric!? Now you listen here ...
Everyone seems to think that one record is one noun. No! One record is one statement. One table is not a list of instances of one distinct noun; it's a list of instances of one kind of statement you want to make. This is much closer to a "pure" relational model (e.g. as espoused by Codd, as hinted at in Out of the Tar Pit) than constantly making the exact categories-are-hard-boundaries mistake discussed in TFA. Most people have started recognizing the problems with "class Cat : class Animal", but then they do this exact thing in their databases, reintroducing all the same problems.
Or put more specifically, one could argue that a SalesOrder and a PurchaseOrder are the same thing, because fundamentally they are with a different perspective. But one cannot argue that a Teacher and a Student are the same thing. As a result having a table for Teachers and a separate table for Students is a good thing. And that would be categorization.
Are you arguing that Students and Teachers should be stored in the same table when modeling a DB? If so, then you are arguing for categorization. But even then, that's not the heat of the issue.
More detailed there are 3 arguments that in my opinion you are muddling together:
1. Some things are the same thing but viewed from the perspective of two different users, these should be modeled as the same thing (PurchaseOrder vs SalesOrder). [I agree with this specific case, but there aren't a ton of these]
2. You should model events in a system and not nouns/entities [The Out of the Tarpit argument, which I also agree with and is the direction of ideal coding if performance were no object, and you can easily do queries / derived models on top of it.]
3. You shouldn't categorize things. [This argument I don't understand as I see generalization and categorization as the essence of software modeling, but am open to an explanation. A StudentEnrolled event table should be categorized separately from a ClassLectureGiven event table, and those are categories.]
I am not arguing that.
> As a result having a table for Teachers and a separate table for Students is a good thing. And that would be categorization.
I disagree that that's a good thing.
> Are you arguing that Students and Teachers should be stored in the same table when modeling a DB? If so, then you are arguing for categorization.
No. I am arguing that you do not know beforehand how many tables Students and Teachers (nor Purchase/Sales Orders) are going to take up, because you are going to come up with more things to say about them. The more design attention you give it, the more tables they're likely to take up. And those tables are very likely to be shared with other entities. Because once you start making statements like "This record was modified by User X" you are no longer even speaking the language of Students and Teachers.
> 1. Some things are the same thing but viewed from the perspective of two different users, these should be modeled as the same thing
No, I am not claiming that. I never said "same thing".
> 2. You should model events in a system and not nouns/entities
No, I didn't say "events", I said "statements". An event is "X happened at Y time" -- which also happens to be a statement. But another statement is "Carbon is a chemical element with symbol C, atomic number 6, and standard atomic weight of 12.011". You could argue that's actually 3 statements, and that decision is a complex engineering decision you make based on the tradeoffs in front of you. I'd actually probably break it down into "Carbon is a chemical element with symbol C and atomic number 6", since those are relatively unique to Chemical Elements, and take its atomic weight and some other properties to a different table since those properties are shared more widely.
Modeling events accidentally tends to get databases closer to the design I advocate for, which is "one table per set of data fields you need to make a clear statement". But that's just a happy coincidence. I claim the success of event-based architectures is mostly coincidental to their "eventness" and actually more to do with the fact that they're closer to a "statement-driven" rather than "noun-driven" architecture. You can have a statement-driven architecture without events at all.
In fact it would be silly to try to model the statement that Carbon's Atomic Number is 6 as an event. Plenty of things are just "facts" (for purposes of your system) that you want to state without having to say when this fact became true.
> 3. You shouldn't categorize things.
Correct.
In your defense, I am trying to jam a big argument with a decade of theory behind it into an HN comment, so I don't really fault you for not getting my point. But I'm saying a good database design is about 90 degrees rotated to the standard "one table per noun" design. You don't put your Students and Teachers in the same table, nor in different tables: you don't put them in any table. You only put statements in tables. Some of those statements are about Students. Some of them are about Teachers. Some of your Students are also Teachers! (Ever seen a class TA'd by a Ph.D. student?) Some of your statements about Students will still be true when they stop being Students, and some won't! You make a new table when you need to make a new kind of statement about anything, regardless of what noun or category they're about. You basically never need to worry about what an entity "is" or "is not". You literally never need to categorize anything.
So, I build a table (call it "transactions"?) that contains all of these, without repeating any of the similar fields. (I'll note that that's still categorizing data; I'm not sure what that implies about your original point.) There will, of necessity, be fields that are different across the two transaction, um, types. How do you handle those?
What happens when your unified table gets so big that it affects performance? It seems to me that separating the two types of transaction into separate tables at least postpones that day.
What about presenting different types of data to end-users? Business logic dictates that accountants and analysts will want to treat these types of transaction differently.
How easy is this design to work with and reason about? I'd fear it comes at the cost of monster queries which align poorly with business logic. I'd be worried that makes said analysts dependent on the db architect to construct their queries for them, which isn't a situation I'd prefer. Is that, in practice, not a concern?
Which of those real-world concerns am I over-valuing?
> So, I build a table (call it "transactions"?) that contains all of these, without repeating any of the similar fields.
That's still kinda just re-categorizing things. It's more like: identify the groups of fields that PurchaseOrders and SalesOrders have in common, and make that group a table (or possibly more than one).
> How easy is this design to work with and reason about? I'd be worried that makes said analysts dependent on the db architect to construct their queries for them, which isn't a situation I'd prefer. Is that, in practice, not a concern?
It's much easier to work with and reason about long-term for software developers, in my opinion. It's much harder to work directly in the database, which is a deal-breaker for some. Analysts are not constructing their own queries without help from a lot of views; but you have more opportunity to custom-tailor those views to their specific needs. Frankly, I don't think business analysts should be directly hitting the database -- it is a persistence layer, not an application layer. It'd be like demanding that analysts can specific memory addresses -- it's just the wrong layer of abstraction for them. "Canonical" functionality is added piecemeal in layers by various domain "library"-like layers. Analysis can pick the libraries that they need (more likely, devs set this up for them).
> I'd fear it comes at the cost of monster queries which align poorly with business logic.
Yes, queries are bigger and include more JOINs, but they are more aligned with the business logic, not less. I've done it with table sizes on the order of 100 million records (SQL Server), and it's just fine, but I haven't gotten into the real "big data" sizes. Databases are very good at joins with proper indexes nowadays. If you're in "big data" size, I don't see a reason why table-per-noun is any better of a starting point for Apache Spark or whatever you're doing.
> Which of those real-world concerns am I over-valuing?
In my opinion, you are over-valuing direct access to the database tables with no business logic applied on top at the application layer. That's what the application layer is for.
Closed sales orders increase cost of goods sold and accounts receivable. Closed purchase orders increase assets and accounts payable.
You could create one uber-record that could represent all of these different assets, but it wouldn't necessarily be a good idea, because my clients and their accountants conceive of them as separate entities, and I need to make them legible to my clients as separate entities.
I create schemas that store/make legible data beyond a double-entry general ledger.
“Reality is complicated and it's hard to even speak English without relying on categories at all.”
So are you modifying your position or am I missing something?
Person A: "I am highly critical of society for the following nine reasons..."
Person B: "Curious! You are critical of society, and yet you live in it! Hypocrite much?"
Person A: "Yes I do also need to buy groceries to live."
Person B feels like they gotcha'd Person A, but really, they haven't. Our conversation went like this:
Me: "Categories are stupid and you basically never need them. Stop trying to categorize things."
You: "Curious! You hate categories and yet you used them implicitly in your statement about how bad they are! Hypocrite much?"
Me: "Yes, I do need to speak English for anyone to understand me, and I suppose one could argue that English words are themselves categories."
Almost every exercise in categorizing things or arguing about what category things belong to is pointless. Saying "aha, but you yourself are categorizing arguments as being about or not about categories!" feels like a weak nitpicky gotcha to me.
In fact I think the pointlessness of this very exchange is evidence in my favor.