[EXTERNAL] Re: [odb-users] Problem with pointer in base class

Ball, John R jrball at sandia.gov
Wed Jul 3 14:30:52 EDT 2013


The problem is over constrained because of the number of objects I'm dealing with. 

>> I tried this with polymorphic inheritance and ended up with large Foo 
>> and Bar base tables which might be a problem - I don' t know yet.
>
>With polymorphic inheritance, tables corresponding to Foo and Bar base classes will only contain data members in these >classes while derived tables will contain additional data members added in derived classes.
>
>With the reuse inheritance each table always contains all the data members from base to the derived class.
>

The Foo hierarchy is 4-6 levels deep resulting in about 150 leaf node class types. Significant data such as creation time, unique identifier, and source are stored in the Foo base. Additional information is stored at each level of the hierarchy - none are abstract. I expect to have to deal with on the order of a million Foo based objects so using polymorphic inheritance results in a million or so entries in the Foo table, 500,000 in the first level derived object table, etc. When you get down to the leaf node tables, you are in the 1000's of objects which is reasonable to work with. I wanted to stick with reuse inheritance so all the data would be in the leaf node tables to avoid the performance hit on queries and also to make the table sizes manageable.

The delema is: polymorphic inheritance allows me to use the base class pointer but results in multiple tables each with entries for each object and the associated performance hit related to depth while reuse inheritance gives me table granularity but prevents me from using the base class Foo pointer. 

>So I don't see how the tables could be bigger with the polymorphism inheritance. You may end up with fewer tables (if >some of the bases are abstract) in resue inheritance, but not with smaller ones.
>
>

With reuse inheritance I have the given number of objects in the database but they are distributed across individual tables so no one table is outlandishly large. Unless I'm mistaken, all million objects would have entries in the Foo base, each level of derivation, and at the leaf class level meaning 4-6 million objects in the DB instead of just 1 million if stored using reuse inheritance.

>> In the meantime, if I go this way, can I still do queries against Foo 
> >derived or do I have to query against Foo base?
>
>You can query for either. In fact, in polymorphic inheritance, the object type (base or derived) that you query for >becomes part of the query condition. For example:
>
>db.query<fruit> (query::color == red); // Any red fruit.
>db.query<apple> (query::color == red); // Only red apples.
>
>Boris

Does the apple query go against just the apple table, which is relatively small, or does it hit the fruit table first? This is a performance question rather than a structural one but it is germane to my problem.


==========
John R. Ball - CISSP
Sandia National Laboratories, Albuquerque NM
Organization 5541 - Data Systems IA Lead Engineer
Phone: (505) 844-1356
Pager: (505) 951-6328
Bldg 752/122 MS 0975
E-Mail: jrball at sandia.gov <mailto:jrball at sandia.gov>
========== 


-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Wednesday, July 03, 2013 9:41 AM
To: Ball, John R
Cc: odb-users at codesynthesis.com
Subject: [EXTERNAL] Re: [odb-users] Problem with pointer in base class

Hi John,

Ball, John R <jrball at sandia.gov> writes:

> I tried this with polymorphic inheritance and ended up with large Foo 
> and Bar base tables which might be a problem - I don' t know yet.

With polymorphic inheritance, tables corresponding to Foo and Bar base classes will only contain data members in these classes while derived tables will contain additional data members added in derived classes.

With the reuse inheritance each table always contains all the data members from base to the derived class.

So I don't see how the tables could be bigger with the polymorphism inheritance. You may end up with fewer tables (if some of the bases are abstract) in resue inheritance, but not with smaller ones.


> In the meantime, if I go this way, can I still do queries against Foo 
> derived or do I have to query against Foo base?

You can query for either. In fact, in polymorphic inheritance, the object type (base or derived) that you query for becomes part of the query condition. For example:

db.query<fruit> (query::color == red); // Any red fruit.
db.query<apple> (query::color == red); // Only red apples.

Boris




More information about the odb-users mailing list