From: David Fetter <david@fetter.org>
To: mark overmeer <markovermeer@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: schema design question
Date: Sun, 19 Aug 2007 11:12:16 -0700
Message-ID: <20070819181216.GK28490@fetter.org> (raw)
In-Reply-To: <ea41f7570708190619u6daf7cep96430d20566d6159@mail.gmail.com>
References: <ea41f7570708190619u6daf7cep96430d20566d6159@mail.gmail.com>
On Sun, Aug 19, 2007 at 03:19:52PM +0200, mark overmeer wrote:
> Hi,
>
> Maybe not completely the wright place to ask but... I have this
> schema design question (db is postgres of course). I have a couple
> of classes with attributes.
Danger, Will Robinson! Danger!
The DBMS way of looking at things is fundamentally different from OO
coding, and if you try to make them fit together naïvely as you do
below, you only get grief.
> The only goal is to search the object
> that I want to find (which is stored on the harddrive).
>
> I have hundreds of classes that are similar but not the same. They all have
> attributes/properties (type is probably String), e.g. (in pseudo code):
>
> class A_version_1 {
> attribute1, attribute2, attribute3, ..., attributeN
> }
>
> class A_version_2 {
> attribute1, attribute3, ..., attributeN, attributeN+1, attributeN+2
> }
>
> class B_version_1 {
> attribute3, attribute4, attribute7, attributeN+3, ..., attributeN+M
> }
>
>
> Class A will have attributes from class B, class B will have
> attributes from class C and so on. My initial thought was to use the
> (sometimes dreaded) EAV model: class_id, object_id, attribute_id and
> attribute_value. In this way I can make queries like:
>
> SELECT CLASS_ID,
> OBJECT_ID
> FROM EAV_TABLE EAV
There's your mistake. EAV is not performant, and won't become so.
Decide what your database will and won't do, and design your schema
around that. I know it takes a little extra helping of courage, but
it's worth it in the long run.
Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter
Remember to vote!
Consider donating to PostgreSQL: http://www.postgresql.org/about/donate
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: david@fetter.org, markovermeer@gmail.com
Subject: Re: schema design question
In-Reply-To: <20070819181216.GK28490@fetter.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox