I think there is still some misunderstanding. The problem is NOT the getCount() method, that just happens to be where the query is performed. If you move your code around, you are just going to move around whatever the first call you make that actually performs the query.
If the majority of your time is spent in the first call to the cursor (that requires having the query executed), then you need to optimize the time of the query itself, no amount of rearranging your iterating code is going to help. Also if I am reading your numbers right and you are actually performing over 500 queries for 1120 total rows... there's a big optimization target. :) Your first goal should probably be to rework your query and table structure so you can do that in just a couple (ideally one) query. On Wed, May 20, 2009 at 2:50 PM, Sublimity Mobile Software < [email protected]> wrote: > > My current database layer is used to convert query results into bean > objects. I did a test and the results where: > > Total time loading queries = 15273ms > Queries executed = 561 > Executing All Queries = 3781 ( ~25% of the total time ) > GetCount() method uses = 7291ms ( ~48% of the total time ) > Loaded Objects = 1120 > > It uses 7291ms of the total 15273ms loading the data into the cursor > through using the getCount() method. I can not remove any columns from > the query as you suggested because i need those values in my bean > objects. > > Any suggestions? > > > On 20 mei, 17:06, Marco Nelissen <[email protected]> wrote: > > If you're sure there is nothing to be gained from optimizing the > > database itself, then it seems your only option is to not use a > > database at all. > > Are you *sure* the database/query can't be further optimized? How much > > time does your query take anyway? > > > > On Wed, May 20, 2009 at 2:17 AM, Sublimity Mobile Software > > > > <[email protected]> wrote: > > > > > Thank you for your reply. > > > > > You where right. The getCount() method takes indeed a lot of time. So > > > i filled another window by using fillWindow() like this: > > > > > Cursor c = db.query(var1, var2, var3 .....); > > > SQLiteCursor liteCursor = (SQLiteCursor) c; > > > CursorWindow cw = new CursorWindow(true); > > > liteCursor.fillWindow(0, cw); > > > > > And then looping the CursorWindow to get all rows and columns. > > > > > I presumed that this would make a performance boost because i thought > > > that by doing this i will cut back on overhead. But this actually > > > takes about 40% more time then simply calling getCount() that > > > eventually loads the data into the cursor > > > > > I already optimized the database and the queries so there is nothing > > > to gain here. > > > > > But would you there be another way the get values from a database in a > > > faster way? > > > > > On 19 mei, 02:52, Marco Nelissen <[email protected]> wrote: > > >> On Mon, May 18, 2009 at 7:47 AM, Sublimity Mobile Software > > > > >> <[email protected]> wrote: > > > > >> > Hi, > > > > >> > Currently i'm working on a database system for some applications. I > > >> > need to do a lot of queries to load data from the database into the > > >> > application. After being amazed how much time it took to do these > > >> > queries on the database i found out that much time was consumed by > > >> > cursor.MoveToFirst(). This functions costs currently ~25% of all my > > >> > database action. > > > > >> If you rearrange your code to call getCount() first, you'll find that > > >> getCount() took most of the time. > > >> Basically, it's actually fetching the data that's taking most of the > > >> time, and that data fetch is not done inside query(), but afterwards, > > >> usually as a result of calling getCount(), which calls fillWindow(), > > >> which then fetches the data. moveToFirst() calls getCount() > > >> internally. > > >> If calling getCount() takes too long, then your query is taking too > > >> long. Try optimizing it by using an index, returning less columns, > > >> etc. > > > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

