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@xxxxxxxxxx> 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 ---------------------------(end of broadcast)--------------------------- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate