Re: Searing array fields - or should I redesign?

From: Jim Nasby <jim(at)nasby(dot)net>
To: Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr>
Cc: Jan Kesten <jan(at)dafuer(dot)de>, Bryan Montgomery <monty(at)english(dot)net>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Searing array fields - or should I redesign?
Date: 2010-12-17 15:51:52
Message-ID: 29A1D8F2-E9E5-407D-8FD5-3C64646A9F89@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Dec 16, 2010, at 11:26 AM, Vincent Veyron wrote:
>> table logdetail
>> logid int
>> attribute varchar/int
>> value decimal
>> textvalue varchar
>>
>> You can retrieve logentries for specific vehicles, timeframes and attributes - and you can extend more log attributes without changing the database structure. I would suggest another table for the attributes where you can lookup if it is a text or numeric entry.
> ..
>
> The problem with this approach is that you need to loop through your
> recordset in your code to collect all the values.
> If you only have one value per key to store per vehicule, it's much
> easier to have one big table with all the right columns, thus having
> just one line to process with all the information . So, from your
> example :
>
> create table logtable(
> id_vehicle text,
> date_purchased date,
> voltage integer,
> rpm integer);
>
> the corresponding record being
> vehicle123, now(), 13, 600
>
> this will simplify your queries/code _a lot_. You can keep subclasses
> for details that have more than one value. Adding a column if you have
> to store new attributes is not a big problem.

Plus, that logdetail table will have a per-row overhead of 24+4 (or 8)+4 (or 8)+1 bytes, assuming attribute is stored as an int (which you'd want). That's a minimum of 33 bytes per attribute, and you don't even have payload yet.

Entity-attribute-value (what logdetail is) is extremely expensive. You want to avoid it at all costs unless you have a really trivial amount of data.
--
Jim C. Nasby, Database Architect jim(at)nasby(dot)net
512.569.9461 (cell) http://jim.nasby.net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2010-12-17 16:05:21 Re: Table both does not and does exist! wth?
Previous Message Melvin Davidson 2010-12-17 15:47:44 Table both does not and does exist! wth?