Program Options Management

Status
Not open for further replies.

Calvin

Ars Tribunus Angusticlavius
9,331
Subscriptor++
Here's our setup:

- We have a win32 C++ application that we run about 40 instances of. These instances are spread among dozens of servers. the instances are in "groups" of 2-20 that have certain major settings in common.
- some portion of application setup is done through a local ini file. The ini file tells it which instance of the app it is, what data servers to connect to, and what database to connect to, and some other, smaller settings
- the database tells it a bunch more settings, usually settings that are relevant at the "group" level.

We're looking at making some changes that could lead to the number of instances ballooning to several hundred, and adding a bunch of additional configuration settings at the "group" level. Up until now, "group" settings in the database have been kept in a bunch of smaller tables, each table is purpose-built to map a "group" to one or more values for a particular setting, so the column names tend to be the setting names.

As the number of settings has increased, it's become increasingly difficult to figure out exactly how any given instance or group is configured, and I'm looking for a better solution. I've suggested the idea of a "settings map" table, where one column specifies a group, the second column specifies the setting name, and the third column specifies the column itself. Another developer sees the organizational advantage, but is wary of losing our current ability to use various DB constraints to ensure that we have the basic settings established for each and every group.

Is there a happy middle ground? Is there a better way to unify all the information contained in the various (and increasing number of) tables? Perhaps through a view that shows you how a given instance/group is setup?

thanks in advance.
 

Alamout

Ars Legatus Legionis
27,285
It seems like we're talking about a pretty small amount of information, here--even if you had a few thousand groups and needed to keep track of hundreds of settings, I'd think you're still talking about megabytes of data (unless 'settings' means something more involved in this case...I'm assuming that's pretty benign configuration stuff and thus is mostly short strings or the like).

If that's true, and it just isn't a lot of data, then why not just have a table like this:
Code:
          Setting1    Setting2    ...    SettingN
Group1  group1Val1  group1val2    ...  group1valN
Group2  group2Val1  group2val2    ...  group2valN
...
Where you simply specify every setting that is ever relevant to a group--the other groups will still have that setting set in some way, I would think. If not, you can use 'N/A' or what have you.

It isn't the most efficient way of storing this data, but it's dead easy to add a group (and not that hard to add a setting if you just remake the database), and it's dead easy to figure out what settings a given group has (if you know what group it's in, which could be another table). It should also be easy to have constraints on adding a group--require certain columns to have certain values. If this wouldn't take up much space, why not err on the side of simplicity?
 

fitten

Ars Legatus Legionis
55,635
Subscriptor++
The above way also insures that every group easily has every setting defined (may be a default entered when adding a new column onto the table but at least you don't have to add a row for every group with the new setting... missing a group turns up a NULL, so what does your program do then?).

I'd agree, though... keep it simple until it can't be simple any more.
 

HL7

Ars Praefectus
3,523
Subscriptor++
I like your original idea from a data design standpoint. Alamout's idea is simple, but personally I've never been a fan of changing table structure to accommodate a program setting.

It would be very easy, in your design, to determine if a group is missing settings but you need more than one table. First you'd want to create a Settings table with the names of all of the possible settings. Then you'd create your GroupSettings table, with each row containing a group, a setting, and its value. It would be very easy through a left join to determine if a group is missing a setting.

You could also implement default settings if that's something you need. You might, for example, allow a NULL for the group in the GroupSettings table to indicate that the value is a default. It would be possible through joins to use the group's setting value if it exists, or sub in the value from the NULL group if not.

I suppose which one you pick depends on which one you add more often -- settings or groups. If your number of settings is more or less fixed at this point and the number of groups changes a lot, use Alamout's design. If the number of settings is always increasing, I think your original design is better because it doesn't require a change to DB structure to add a new setting.

It would be helpful to know exactly what a 'setting' is though. I'm assuming it's a simple value, but if that's the case then it's unclear to me why your settings have required multiple small tables up to now.
 
D

Deleted member 43669

Guest
Why having a lot of columns is bad?

I would vote on having as many settings as possible in the same place. If you want to use a database for configuration, store as much as you can there.

If you use a database, enforce consistency. Invalid configuration (i.e. missing configuration) should be impossible. You should achieve this using the simplest constraints possible.
 

Alamout

Ars Legatus Legionis
27,285
HL7":3t7s8w5a said:
koala":3t7s8w5a said:
Why having a lot of columns is bad?
It's not. I think that changing a database structure to accommodate what is essentially data (client application settings) is bad as a general practice.
Yeah, it's hard to know what to do without a better idea of what he's talking about. I was working with the idea that the settings are fairly well-defined--they only change when the version of the software changes, maybe. If that's not the case (or if there are too many settings to define them all) then a different structure makes sense.

It's true that Calvin's design is amenable to some database queries that will answer the relevant questions--but applying the KISS principle makes that part trivial.

It really comes down to "make the common case fast" (and the fast case common, although that doesn't apply as much), where "fast" means easy and reliable. We don't know what the common case is...adding a group? Adding a setting? Something else?
 
Status
Not open for further replies.