IMO normalizing up front is rarely ever a mistake. The primary advantage of normalization is it makes your schema amenable to changes in requirements. What if category ends up needing a description, and an id for a permalink-able page with links to each post in a category, etc.? Normalize up front and then denormalize where you need to when the requirements crystalize and your focus becomes responsiveness.
I think his example was rather poor as I can think of at least 3 use cases off of the top of my head where having separate categories would be a good idea, and having varchar arrays would be a giant PITA. That said I'm not sure he was trying to make the point that upfront normalisation is bad in itself, just that doing too much "what if maybe someday we might want to separate this" kind of normalisation is a waste of…
Mistakes Beginners Make When Working with Databases
61–70 of 209 posts
Re: Mistakes Beginners Make When Working with Databases
#62 innodb_file_per_table
or generally learning db configuration to be on the list. It's a huge pain when your little web server runs out of disk space because innodb is eating it all.Re: Mistakes Beginners Make When Working with Databases
#63Related to that: inconsistent values for NULL/False, e.g. "No", "", "False", "false", etc...(or rather, not using a boolean type to enforce this).
And related to that: general unawareness of what NULL means. It's not the same as "" or "False" or 0, both in a technical sense and in a real-world sense.
Re: Mistakes Beginners Make When Working with Databases
#64Point 1 is silly - this depends greatly on what your application needs to do. If you need to store the image together with the metadata or other information related to the image that is transactional data - then storing the image in the database is the way to go. This also helps a lot with database backups, migrations etc..
Not every PostgreSQL-backed application is a public-facing web app. A fat-client that connects directly to the PostgreSQL database to do "stuff" with transactional data will have a much easier time if any related images are stored alongside the transactional data.
Re: Mistakes Beginners Make When Working with Databases
#65IMO normalizing up front is rarely ever a mistake. The primary advantage of normalization is it makes your schema amenable to changes in requirements. What if category ends up needing a description, and an id for a permalink-able page with links to each post in a category, etc.? Normalize up front and then denormalize where you need to when the requirements crystalize and your focus becomes responsiveness.
Only as a general rule: I have found that write once read mostly tables (history tables) are great candidates for denormalizing. State tables (read & write) usually benefit from 3rd form normalization.
Re: Mistakes Beginners Make When Working with Databases
#66Pretty weak, partly terrible advice. - Storing images and blobs: granted, usually not a good idea - Limit/offset will take you a veeeery long way until you have to think about stuff like deep paging. And however you try to tackle that, if the stuff you paginate needs ordering, it's simply a hard problem and not a mistake. - UUID primary keys? Horrible advice that's only applicable at Google/Facebook scale (and even t…
UUID primary keys aren't needed for big keyspaces, they are needed when you need multiple processes (especially a flexible number of multiple processes) to generate unique IDs independently of each other and the central database, which will eventually get stored in the central database. This can be important at much smaller than Google/Facebook scale, depending on the use case.
Re: Mistakes Beginners Make When Working with Databases
#67Earlier quoted context omitted.
Its sad that UUIDs are not handled well yet, even in 2016. Its a final id solution that clearly avoids all id collision issues.
UUIDs don't avoid all id collision issues, and it's far from final. They'll prevent you from using BRIN indexes effectively, for example. Timestamp plus unique server id is an arguably much better approach; on top of everything else, timestamps are actually useful, and they fit in 8 bytes.
If you do use this scheme, be careful that your timestamp is sufficiently granular that it's not possible to generate two identical IDs in quick succession....
Re: Mistakes Beginners Make When Working with Databases
#68I'm suprised by this point: "the database tends to be an after-thought in application design". Maybe it's a generational thing (I'm 40+), but I tend to always start with thinking about the data structures and design in conjunction with the UI design. Getting a solid database design in place early in the development cycle is critical to building a solid, stable system- you can of course alter the database as you start…
Treating data as an afterthought is a great way to have to be re-defining your application logic every time you re-define your data because you forgot something.
Re: Mistakes Beginners Make When Working with Databases
#69 - failure to lock rows with pessimistic locking
- failure to consider optimistic locking when viable
- data sets within a table (undernormalization)
- too much duplicate app code that should be stored procedure
- overuse of stored procedures that should be in app code
- appending with insert
- appending to datasets with variable length
- "smart" keys that can never be changed without rewriting
- underuse of indexing to slow read performance
- overuse of indexing to slow update performance
- records too big for good hashing (undernormalization)
- columns with different typed data (when DBMS allows)
- columns with different logical data (app driven)
- enhancing by inserting columns instead of appending
- poor or missing audits
- poor or missing security
- poor or missing archivingRe: Mistakes Beginners Make When Working with Databases
#70Pretty weak, partly terrible advice. - Storing images and blobs: granted, usually not a good idea - Limit/offset will take you a veeeery long way until you have to think about stuff like deep paging. And however you try to tackle that, if the stuff you paginate needs ordering, it's simply a hard problem and not a mistake. - UUID primary keys? Horrible advice that's only applicable at Google/Facebook scale (and even t…