Sorry, I have left out the PK requirement.
What Nicolas wrote is right, I also use an O/R mapper and inheritance is
solved with vertical partitioning. The tables are connected to each other
with the PK. And the mapper defines views for each class with left joins.
The mapper generates queries based on these views. A high fraction of
the joins would be eliminated almost in every query.

My simple example:

Class hierarchy and fields:
Shape (ID, X, Y)
+-Circle (ID, Radius)
+-Rectangle (ID, Width, Height)

The mapper creates 3 tables with the columns next to the class name.
And it creates 3 views. One of them:

RectangleView:  SELECT r."ID" as "ID", s."X" as "X", s."Y" as "Y", r."Width"
as "Width", r."Height" as "Height" FROM "Rectangle" r LEFT JOIN "Shape" s ON
( r.ID=s.ID)

Now if I query Rectangle object IDs, whose Width is greater than 5, it will
generate this:

SELECT "ID" FROM RectangleView WHERE "Width">5

In this case I don't need to left join the Shape table, because X and Y
columns are not used.

The other typical situation is when I execute more complex,
not-O/Rmapper-generated SQL commands based on these views for reporting. For
example the average width of rectangles whose height is greater than 10.

This optimization should be also applied to subqueries.

Is this optimization relatively easy to introduce?

I would gladly work on this, but unfortunately I don't know the codebase at
I would really appreciate if someone competent implemented this feature in

Thank you in advance,

Reply via email to