Re: schema design question

Поиск
Список
Период
Сортировка
От David Fetter
Тема Re: schema design question
Дата
Msg-id 20070819181216.GK28490@fetter.org
обсуждение исходный текст
Ответ на schema design question  ("mark overmeer" <markovermeer@gmail.com>)
Ответы Re: schema design question
Список 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@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

В списке pgsql-performance по дате отправления:

Предыдущее
От: "mark overmeer"
Дата:
Сообщение: Re: schema design question
Следующее
От: "Steinar H. Gunderson"
Дата:
Сообщение: Re: schema design question