You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Joe Baldwin <jf...@earthlink.net> on 2009/06/16 19:31:24 UTC

Faulting Behavior with setPageSize() and Sort Ordering

This is a question concerning making performance enhancements with  
Cayenne directives.

Lets say you use the following SelectQuery method

	query.setPageSize(RowsPerPage);

But then you decide to sort order the result list using

	Ordering order = new Ordering(<entity>.<attribute>_PROPERTY, true);
	order.orderList(resultList);

If I understand the docs, then the purpose of setting the PageSize  
parameter is to reduce the work load (and increase performance) by  
limiting fetching to the first "RowsPerPage" amount of data-objects.

I am wondering whether performing a sort ordering on the resultList  
triggers *all* the page and object faults.  If I am correct then sort  
ordering would render setPageSize moot in this scenario.

Is my analysis correct or has Cayenne somehow avoided this?  (Or is  
there another way to do sort ordering?)

Joe



Re: Faulting Behavior with setPageSize() and Sort Ordering

Posted by Andrey Razumovsky <ra...@gmail.com>.
2009/6/16 Joe Baldwin <jf...@earthlink.net>

> That sounds logical.  So if I limit my sort ordering to the initial query
> then the objects in pages 2-n will remain hollow?
>

Yes. Adding an ordering leads to ORDER BY statements in generated SQL, so
all the processing remains the same.

Re: Faulting Behavior with setPageSize() and Sort Ordering

Posted by Mike Kienenberger <mk...@gmail.com>.
On Tue, Jun 16, 2009 at 1:58 PM, Joe Baldwin<jf...@earthlink.net> wrote:
> That sounds logical.  So if I limit my sort ordering to the initial query
> then the objects in pages 2-n will remain hollow?
>
> (I have a few instances in which there is sort ordering by the client (which
> is post query - resultset ordering).  I will have to take a look at this
> design to implement this rule better.)

In those cases, it's generally better to resubmit the query with the
new ordering.

Re: Faulting Behavior with setPageSize() and Sort Ordering

Posted by Joe Baldwin <jf...@earthlink.net>.
That sounds logical.  So if I limit my sort ordering to the initial  
query then the objects in pages 2-n will remain hollow?

(I have a few instances in which there is sort ordering by the client  
(which is post query - resultset ordering).  I will have to take a  
look at this design to implement this rule better.)

Thanks,
Joe



On Jun 16, 2009, at 1:45 PM, Andrey Razumovsky wrote:

> The trick of paginated query is that all objects returned are  
> HOLLOW, thus
> having only identifier. Ordering.orderList will surely resolve *all*
> records, how else would it know parameters of each object. To order  
> a long
> list properly you need to set ordering to a query:
>
> query.setPageSize(RowsPerPage);
> query.addOrdering(order);
> List orderedResults = context.performQuery(query);
>
> 2009/6/16 Joe Baldwin <jf...@earthlink.net>
>
>> This is a question concerning making performance enhancements with  
>> Cayenne
>> directives.
>>
>> Lets say you use the following SelectQuery method
>>
>>       query.setPageSize(RowsPerPage);
>>
>> But then you decide to sort order the result list using
>>
>>       Ordering order = new Ordering(<entity>.<attribute>_PROPERTY,  
>> true);
>>       order.orderList(resultList);
>>
>> If I understand the docs, then the purpose of setting the PageSize
>> parameter is to reduce the work load (and increase performance) by  
>> limiting
>> fetching to the first "RowsPerPage" amount of data-objects.
>>
>> I am wondering whether performing a sort ordering on the resultList
>> triggers *all* the page and object faults.  If I am correct then sort
>> ordering would render setPageSize moot in this scenario.
>>
>> Is my analysis correct or has Cayenne somehow avoided this?  (Or is  
>> there
>> another way to do sort ordering?)
>>
>> Joe
>>
>>
>>


Re: Faulting Behavior with setPageSize() and Sort Ordering

Posted by Andrey Razumovsky <ra...@gmail.com>.
The trick of paginated query is that all objects returned are HOLLOW, thus
having only identifier. Ordering.orderList will surely resolve *all*
records, how else would it know parameters of each object. To order a long
list properly you need to set ordering to a query:

query.setPageSize(RowsPerPage);
query.addOrdering(order);
List orderedResults = context.performQuery(query);

2009/6/16 Joe Baldwin <jf...@earthlink.net>

> This is a question concerning making performance enhancements with Cayenne
> directives.
>
> Lets say you use the following SelectQuery method
>
>        query.setPageSize(RowsPerPage);
>
> But then you decide to sort order the result list using
>
>        Ordering order = new Ordering(<entity>.<attribute>_PROPERTY, true);
>        order.orderList(resultList);
>
> If I understand the docs, then the purpose of setting the PageSize
> parameter is to reduce the work load (and increase performance) by limiting
> fetching to the first "RowsPerPage" amount of data-objects.
>
> I am wondering whether performing a sort ordering on the resultList
> triggers *all* the page and object faults.  If I am correct then sort
> ordering would render setPageSize moot in this scenario.
>
> Is my analysis correct or has Cayenne somehow avoided this?  (Or is there
> another way to do sort ordering?)
>
> Joe
>
>
>