Re: [Modeling-users] Questions and suggestions
Status: Abandoned
Brought to you by:
sbigaret
|
From: Sebastien B. <sbi...@us...> - 2003-06-12 00:16:06
|
Ernesto Revilla <er...@si...> wrote:
> Inheritance:
>=20
> I'm absolutely astonished. In your example:
>=20
> >>> q =3D qWQF('toAddresses.zipCode like "4%"')
> >>> fs =3D FS('Employee', qualifier=3Dq)
> >>> fs_deep =3D FS('Employee', qualifier=3Dq, deepFlag=3D1) # Note the de=
epFlag
> >>> ec.objectsWithFetchSpecification(fs)
>=20
> how this is done at SQL level? Do you execute 3 (one for each subclass of
> the specified class) SQL queries appending it's result objects to a list?
That's exactly the way this is done: any deep fetch is made against the
whole inheritance hierarchy below the specified entity (here, Employee)
--this is DatabaseContext's responsability, you can have a look at
objectsWithFetchSpecification().
This is the reason why the PK automatic generation support only uses one
source per inheritance tree, either a sequence (postgresql) or a
dedicated table (mysql, sqlite): this is required if we want that a
relationship points to different rows in different tables.
> Can you tell us a little bit about your experience, e.g. performance
> penalties, complications when using inheritance in real world application=
s?
Performance penalty:
mostly what you would expect, i.e. as many fetchs as there are classes
in the inheritance tree below a given entity. Not that big since in
any case you'll have to do this by hand if it was not automatically
handled.
However the framework does not stop after finding the first
row/object. The reason for this is that if it can find more than an
object for a given GlobalID that's a serious error, at least at the
framework's eyes, and this error should not be hidden. So all fetchs
are executed --whatever their result. But unless your inheritance tree
is really big, some additional fetchs returning no row have no
significant impact.
Complications in real world applications:
I can't think of any complications :) If you think reliability:
inheritance support is used in two important projects I know, it has
been extensively used and tested for months.
Okay, sometimes it happens that you just want A in relation with B,
not with any of B's subentities: in such a case, you'll have to deal
with the extra fetchs the framework makes (there's no way to express
this in a model, but this can be enforced by custom business-logic
validation), but again that's no big deal unless you have a big
inheritance hierarchy.
BTW: you can see the exact SQL statements that the framework executes by
setting the environment varibale MDL_ENABLE_DATABASE_LOGGING to any
value (except non-empty string).
> The example you specified (address<<---->employee) is good, could also be:
> travelling guide, novel, historic novel, etc. to match you book-author
> example. It would be nice if you could copy and paste it into the
> inheritance section (quick and dirty), perhaps it could be expanded in the
> next version.
You're right here, I realize this section definitely needs to be
written, and a raw copy/paste or a summary of this thread should be
sufficient for a first draft; I'll do this for the next release.
Deriving the book/author model with travelling guides, novels etc. is
also a good idea --I might reuse it in the coming tutorial (I was
looking for a better model than store/employee to demonstrate
inheritance, and this one looks actually better ;)
-- S=E9bastien.
|