You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Peter Schröder <Pe...@freenet-ag.de> on 2007/06/01 16:06:15 UTC
performing count
hi,
i am wondering about the perfomance-impact of using cayenne to performing an result-count.
currently i am doing something like this, wich is very straight-forward.
SelectQuery query = new SelectQuery(Tcomrecherche.class, qualifier);
List list = context.performQuery(query);
return list.size();
i could also use an SQLTemplate or a named query to perform a COUNT(*) which would be much uglier. i would prefer the first solution, but i think that this operation will take much more work for mysql-db than the direct query.
are there some hints on how to handle this?
kind regards,
peter
Re: performing count
Posted by Michael Gentry <bl...@gmail.com>.
The way you show is definitely the wrong approach, as it'll read the entire
table. Try:
http://cwiki.apache.org/confluence/display/CAYDOC/Customizing+Queries
Look at the "Indirect Queries" section at the bottom. That approach would
be much faster.
/dev/mrg
On 6/1/07, Peter Schröder <Pe...@freenet-ag.de> wrote:
>
> hi,
>
> i am wondering about the perfomance-impact of using cayenne to performing
> an result-count.
>
> currently i am doing something like this, wich is very straight-forward.
>
> SelectQuery query = new SelectQuery(Tcomrecherche.class,
> qualifier);
> List list = context.performQuery(query);
> return list.size();
>
> i could also use an SQLTemplate or a named query to perform a COUNT(*)
> which would be much uglier. i would prefer the first solution, but i think
> that this operation will take much more work for mysql-db than the direct
> query.
>
> are there some hints on how to handle this?
>
> kind regards,
> peter
>
Re: performing count
Posted by Mike Kienenberger <mk...@gmail.com>.
It will always be faster for the database to return count(*) than to
fetch all records and count them yourself.
However, if you're going to load those objects into memory anyway, it
may be faster for your application in the long run to fetch them all
up front.
On 6/1/07, Peter Schröder <Pe...@freenet-ag.de> wrote:
> hi,
>
> i am wondering about the perfomance-impact of using cayenne to performing an result-count.
>
> currently i am doing something like this, wich is very straight-forward.
>
> SelectQuery query = new SelectQuery(Tcomrecherche.class, qualifier);
> List list = context.performQuery(query);
> return list.size();
>
> i could also use an SQLTemplate or a named query to perform a COUNT(*) which would be much uglier. i would prefer the first solution, but i think that this operation will take much more work for mysql-db than the direct query.
>
> are there some hints on how to handle this?
>
> kind regards,
> peter
>