Re: schema design question

From: David Fetter <david(at)fetter(dot)org>
To: mark overmeer <markovermeer(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: schema design question
Date: 2007-08-19 18:12:16
Message-ID: 20070819181216.GK28490@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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(at)fetter(dot)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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Steinar H. Gunderson 2007-08-19 18:26:58 Re: schema design question
Previous Message mark overmeer 2007-08-19 15:23:14 Re: schema design question