Re: [question] How to query a subset of a resultset efficiently

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Mar 02 2005 - 15:30:21 EST

  • Next message: sabiha: "Re: question-DataView(DOTableModel)"

    Laszlo,

    I don't see why the cases would be any different in Cayenne behavior, but
    as you have related objects involved, this might have its side effects. So
    can you post SQL log demonstrating what you are saying here?

    Andrus

    > Hi everybody,
    >
    > I have noticed that when I use a 'paged query' and I try to query the
    > results of the current resultset, Cayenne fires queries for all results
    > found. I expected that Cayenne would only fire a query for the current
    > page. By example:
    >
    > pPageSize = new Integer(15);
    >
    > [...]
    >
    > SelectQuery qry = new SelectQuery(MyClass.class);
    > qry.setPageSize(pPageSize.intValue());
    >
    > // There are approximately 3000 records in total. However I set a page
    >
    > size of 15.
    > List lst = mContext.performQuery(qry);
    >
    > List tmpList = new ArrayList();
    > if (lst.size() > 0)
    > {
    > FotoHandler ftoh = new FotoHandlerImpl(mContext);
    > int start = pCurrentRow.intValue();
    > int end = pCurrentRow.intValue() + pPageSize.intValue();
    >
    > for (int i=start; i < end; i ++)
    > {
    > // only check for foto's that are actually shown.
    > MyClass cls = (MyClass)lst.get(i);
    > Foto fto = ftoh.getFirstForWoning(cls, fte);
    > tmpList.add(i, new VrijstaandeWoning(cls, fto));
    > } //if
    > } //if
    > [...]
    >
    > The code above will result in the correct results but also in firing
    > 3000+ queries. The code that follows now, will result in 'just' 15
    > queries, but this is expected. However, now I am looping trough 3000+
    > results for nothing.
    >
    > [...]
    > SelectQuery qry = new SelectQuery(MyClass.class);
    > qry.setPageSize(pPageSize.intValue());
    >
    > List lst = mContext.performQuery(qry);
    >
    > List tmpList = new ArrayList(lst.size());
    > if (lst.size() > 0)
    > {
    > FotoHandler ftoh = new FotoHandlerImpl(mContext);
    > int start = pCurrentRow.intValue();
    > int end = pCurrentRow.intValue() + pPageSize.intValue();
    >
    > for (int i=0; i < lst.size(); i ++)
    > {
    > // only check for foto's that are actually shown.
    > if (i >= start && i < end)
    > {
    > MyClass cls = (MyClass)lst.get(i);
    > Foto fto = ftoh.getFirstForWoning(cls, fte);
    > tmpList.add(i, new VrijstaandeWoning(cls, fto));
    > } //if
    > else
    > {
    > tmpList.add(i, null);
    > } //if
    > } //if
    > } //if
    > [...]
    >
    > My question is if this is expected behaviour?
    >
    > Thanks in advance, Laszlo



    This archive was generated by hypermail 2.0.0 : Wed Mar 02 2005 - 15:30:24 EST