On 11/02/16 15:05, 'Hugo Osvaldo Barrera' via Django developers
(Contributions to Django itself) wrote:
> > There was some research by Sebastian Vetter on "single-child
> > auto-resolve" solutions for MTI and how they scaled (from memory,
> > model-utils' InheritanceManager, polymorphic, and generic-m2m)
> >
https://github.com/elbaschid/mti-lightbulb
> Django already uses MTI. The only difference I'm proposing is,
> basically, making life simpler for those wanting to get all objects as
> their native class, rather than parent class (while not affecting those
> that don't use them).
I know Django uses MTI. This thread is, after all, talking about a tool
for a _specific_ use case of MTI.
This investigation was specifically comparing the _scalability_ of 3
solutions to the same problem.
The implementations differ as:
polymorphic:
- has a "hidden" content_type field to indicate which child model to
link for this "parent" record
- uses prefetch_related to resolve
- results in 1+N queries
InheritanceManager (admin-tools):-
- uses select_related to grab _all_ the child models
- selects the first one that exists
- always results in 1 query
- can blow your DB server's brains out with the number of joins (if you
have a couple of hundred child models).
- can select the "wrong" child if you somehow made two for the same parent
Generic M2M:
- quite a different solution, but could be used in the same way for
Seb's purposes.
- don't recall specifics
- scaled dramatically better than the other two
--
C