cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrei Veprev (Commented) (JIRA)" <>
Subject [jira] [Commented] (CAY-1681) Third prefetch kind - DISJOINT_BY_ID
Date Fri, 23 Mar 2012 13:03:29 GMT


Andrei Veprev commented on CAY-1681:

Attaching a patch with DISJOIN_BY_ID prefetch implementation.
After some discussion with Andrus, the decision was to do all prefetch queries for that type
of prefetch on the object conversion stage of query execution (conversion from data rows to
objects). So here it is, most of the staff done inside HierarchicalObjectResolver.

Flatten relationships are not implemented yet, as well as support for phantoms in a middle
of prefetch tree hierarchy (marked as TODO in the patch).
> Third prefetch kind - DISJOINT_BY_ID
> ------------------------------------
>                 Key: CAY-1681
>                 URL:
>             Project: Cayenne
>          Issue Type: Task
>          Components: Core Library
>            Reporter: Andrus Adamchik
>            Assignee: Andrus Adamchik
>         Attachments: CAY-1681.patch
> (here is a mailing list thread discussing the issue:
> I keep encountering a common scenario where neither JOINT or DISJOINT prefetch strategies
are adequate - queries with fetch limit. It is very common in the application to display X
most recent entries from a table with millions of rows, and then drill down to the object
details. E.g. assume 2 entities - "Order" and "LineItem", with orders having multiple line
items. We want 10 most recent orders, with line items prefetched, so you'd so something like
>  SelectQuery q = new SelectQuery(Order.class);
>  q.addPrefetch("lineItems");
>  q.setFetchLimit(10);
> "Disjoint" prefetch in this situation would fetch 10 orders and ALL LineItems in DB.

> "Joint" prefetch will fetch anywhere between 1 and 10 orders, depending on how many line
items the first 10 orders have, i.e. fetch limit is applied to to-many join, not to the query
root. And this is certainly not what we want. 
> Now Cayenne already has something that can solve the problem:
> q.setPageSize(10); // same as fetch limit
> Paginated query is the most optimal way to prefetch here. Whenever a result list is accessed,
Cayenne would execute 2 IN () queries - one for the Orders, another one - for the LineItems.
Both queries are matching on a set of Order PKs and are pretty efficient, and only return
the objects that we care about.
> The problem with this solution is that it is counterintuitive to the user (why should
I set "pageSize" to make my prefetches work) and adds one extra query (the IN query resolving
the root object list). Would be cool to turn it into a separate type of prefetch.  Something
like "disjoint by id"?

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message