2 ms·
Sorry, I expressed that poorly. I was trying to refer to something more general than a primary key, but primary keys are probably the best example. But the sam
by antonvs 3y ago
Sorry, I expressed that poorly.
I was trying to refer to something more general than a primary key, but primary keys are probably the best example. But the same kind of optimization can be used on any value which is essentially immutable.
Consider the following schema:
company: (company_id, company_name)
user: (user_id, user_name)
company_users: (company_id, user_id)
transactions: (transaction_id, user_id, company_id, amount, date)
The presence of company_id in the transactions table is a denormalization, since the source of truth in that case is actually the `company_users` table. But assuming the ids in the system are immutable, this optimization doesn't suffer from any of the issues raised in the OP article. It makes for simpler code that executes faster. It doesn't "deprive us of the correct answer to the problem."