You are currently browsing the archives for the Peeves category.
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jun | ||||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 | |
Archive for the Peeves Category
The Rule Challenge
2010-06-21 by Andrew.
I’ve made this challenge on IRC several times, and I think on the mailing lists too, but I’m putting it up here for reference.
I’m not a fan of rules. I’ve used them in production code in the past, though I’d avoid doing so again, and (unlike most people who end up using them) have spent a fair bit of time analyzing their behaviour and effects. I’ve come to the following conclusion:
All non-trivial rules are incorrect.
I define “non-trivial” as follows:
- Any rule with multiple action statements is non-trivial.
- Any rule using DO ALSO is non-trivial.
- Any rule with a WHERE clause is non-trivial.
This pretty much only leaves rules which rewrite into at most one simple statement, which I’ll concede can sometimes be written correctly (but often are not).
I define “incorrect” as “produces surprising or destructive behaviour in response to ordinary SQL statements”. In general this requires SQL statements not forseen by the rule writer; it’s easy to write rules that work only for certain statements, but doing this in real code amounts to laying a minefield for your future developers.
My challenge is simple: show me a counterexample to the above claims. Any takers?
[EDIT: to clarify, by “rule with a WHERE clause” I mean a conditional rule with WHERE used in the rule definition, not merely a rule whose action statement has a WHERE clause in it.]
Posted in PlanetPG, Postgres, Peeves | 5 Comments »
On Normalization
2008-12-08 by Andrew.
People have funny ideas about database normalization.
What normalization is not:
- creating an (id,value) table for every single piece of data is not normalization
- using surrogate keys for everything is not normalization
- a way to improve performance (though it sometimes does)
Equally, failing to do the above does not mean your data is “denormalized”.
What normalization is:
- keeping your data consistent by ensuring that the relationships between values exist only in one place
- applying the rules: 1NF, 2NF, 3NF, BCNF, 4NF, 5NF … usually between 3NF and 4NF is enough
Obviously, though, there are times when one denormalizes for performance reasons, with appropriate care to ensure consistency isn’t lost in the process.
Posted in PlanetPG, SQL, Peeves | 1 Comment »