Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android cursor movetofirst performance issue

i am trying to optimize my application. I noticed that cursor.movetofirst() method somehow slowing the performance of my code.

Cursor cursor = myDbHelper.getDayInfo(new SimpleDateFormat("yyyy-MM-dd").format(myCalendar.getTime());

above line executes in 10 ms in 2.1 emulator, and

if(cursor != null && cursor.moveToFirst()) 

this line took about 1.6 seconds. I made little search about this. Somepeople say make it in another thread or in asynctask, but this will make the code more complicated. I 'm just trying to figure out what is actually happening to this cursor. Can anyone simplify or give a hint about database performance increase related to my question?

like image 860
Fredrick Gauss Avatar asked Aug 05 '26 03:08

Fredrick Gauss


1 Answers

It's been a while since this was marked answered but you never really got a great answer here. Even on a very large table a single row query should usually take much less than 1.6 seconds. The reason it's slow is that you don't have an index for the column(s) that you are querying on so it has to scan the entire table to find those values. If you create an index you can cut the time down to a fraction of a second.

like image 93
goto10 Avatar answered Aug 06 '26 16:08

goto10