Solomonoff's Secret":3gxqbk3a said:
LordHunter317":3gxqbk3a said:
It's silly to have such a limitation when resolving it takes only a few more CREATE TABLE statements up front.
Sure, I'm not arguing against doing that on principle - only that I'd look for the simplest solution initially if there were no reason to believe I'd need the more complex setup.
First, I'm not sure why you think continued ALTER TABLE operations is less complex than creating a few extra tables upfront (and maybe a trigger) and then doing INSERT/DELETES on them. It's rather apparent you don't understand the cost of managing these operations, nor their cost in terms of database execution time. Modifying a table definition is generally a v. expensive operation and generally should be avoided whenever possible[2].
More importantly though, your solution is only simpler if we can assume the number of configuration values is bounded, and they have meaningful types in the database. Assuming the former isn't a good idea, as these number of required values tends to grow over time as the code gets more complex[1]. The values in the OP all appear to be CSS properties, so it's pretty easy to see how that could grow rapidly. It's especially true if the application supports plugins or other extensible functionality where the number simply cannot be known. As an example, my completely fresh installation of Firefox 12 had over 1500 configuration values.
Plus, I'm not sure what data typing in the database really adds here. MySQL doesn't come with native support for validating CSS colors, font names, or font sizes. It would obviously be possible to add such support (at least for the colors and sizes) but an awful lot of work. All of the configuration data I've ever stored has a similar nature: umasks, user names, hostnames, URLs, base64-encoded API keys, SSL cipher selections, IP addresses, paths, random enumerated strings (e.g., 'a' or 'b'). For a lot of those things, only the application can do the validation, so data store type-safety doesn't add a whole lot. And the application's validation may be as simple as, "Take the value as-is and try to use it, throwing an error when it fails". For many of the things I mentioned, that's all you can do!
It also requires a full copy of the table and locks it from all other concurrent writes. For global settings, not such a big deal. For per-user settings, that can be a big deal.
With PostgreSQL, alters are relatively painless.
Add a column is painless in PostgreSQL if it can default to NULL. Otherwise, you still have to lock the table from all other concurrent writes. That includes altering/adding a NOT NULL constraint to a column. Rebuilding a table is a slow operation, so it's not something you want to do on a busy and/or big table unless you must. It is not a great idea to pick a design where this is your planned upgrade path.
[1] Unless you're a GNOME developer and you're going to delete them all eventually, I suppose.
[2] Even when it is necessary, it is frequently faster, safer, and less painful to create a new table and rename, even though that has ugly costs like requiring all stored procedures and views that reference the table to be recreated. This is true even on "real" databases like Oracle and PostgreSQL.