Re: PreFetch Hints without Qualifiers

"B. W. Fitzpatrick" <[email protected]>
Newsgroups gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
"Eric Bergerson" <[email protected]> writes:
> I have a simple schema:
>   Candidates toMany Matches toOne Masters
> 
> My application displays Candidates and the Match and Master information
> related to each Candidate.  Since both Match and Master instances related to
> each displayed Candidates are accessed each time, I use prefetch hints to
> bring in the related Match and Master for each candidate.
> 
> Normally this works fine.  As long as I have some form of qualification on
> my fetchSpecification, I get the query generation I expect:
> 
> 1.) fetch of the qualified candidates;
> 2.) fetch of the qualified matches that can be joined to the qualified
> candidates.
> 3.) fetch of the masters that can be joined to the qualified matches that
> can be joined to the qualified candidates.
> 
> When I send the same exact fetch specification, either with a null qualifier
> or an empty EOAndQualifier, I don't get the same fetches.  Rather it
> generates a fetch of all the objects in each of the three entities.
> 
> Of course, this is total overkill.  It should fetch all of the candidates,
> but it should only fetch the matches and masters that can be joined back to
> the candidates.  In my case, for instance, less than a third of the masters
> have a join back to the candidates, so I don't need to bring the other two
> thirds of the objects into memory.
> 
> Does anyone know why this is happening and how to prevent it?

Yes--I know exactly what's happening. It's part of the way that EOF
works. When you set prefetching keypaths, EOF performs your primary
fetch, with the qualifier that you set on the fetchSpec, then fetches
each of the keypaths using the same qualifier. So if you set no
qualifier at all, it has no way of pulling in, to use your example
above, masters and matches that have non-null relationships to
candidate. Think about what EOF is doing behind the scenes, and it
should make sense as to why it has to be this way.

As for workarounds, I'd suggest 2 things: Either do the 3 fetches
separately, using EONotQualifiers on the secondary entities (eg get me
all masters whose candidate attribute is not null). or you can try
fiddling about with batch fetching across the relationships from
candidate to match as well as candidate to master.

Good luck,

-Fitz
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.