第一次光标操作是如此之慢,当查询大量数据。如何解决? [英] First time Cursor Operation is so slow, when query bulk data. How to solve?

查看:417
本文介绍了第一次光标操作是如此之慢,当查询大量数据。如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须查询三表,并且该数据显示给我customerView。

I have to query three table, and display the data to my customerView.

我的code是这样的:

My code is like this:

Log.v(TAG, System.CurrentTimeMillis())
int len = cursor.getCount();
Log.v(TAG, System.CurrentTimeMillis())

Product[] products = new Product[len];
int i = 0;
while(cursor.moveToNext()){
    products[i] = new Product(cursor.getstring(0),.....);
}
Log.v(TAG, System.CurrentTimeMillis())

SQLite的查询:

Sqlite query:

 String sql = "SELECT T1.PRODUCT_ID, CODE, SHORT_DESCRIPTION, CATEGORY_CODE,
     BRAND_CODE, FORM_CODE, DENOMINATOR, T1.PIECE_PRICE, T1.lowest_piece_price, 
     T2.sku_type, T1.master_sku " + 
 "FROM CUSTOMER_PROD_LIST_ITEMS T1 INNER JOIN PRODUCT T2 ON 

T1.PRODUCT_ID = T2.ID INNER JOIN PRODUCT_UOMS ON T2.ID = 
                                          PRODUCT_UOMS.PRODUCT_ID"+ 
"WHERE T1.VALID = 1 AND PRODUCT_UOMS.VALID = 1 AND 
   CUSTOMER_PRODUCT_LIST_ID = " + customer_pdtlist_ID + " 
ORDER BY T1.PRODUCT_ID ASC";

我的测试之后,如果我们在游标1500rows,我们要花费超过30秒才能完成这条线(cursor.getcount())。如果我删除这条线,并使用ArrayList发生。我能找到,我们应该花超过30s为Cursor.moveToNext()。

After my testing, if we have 1500rows in the cursor, we have to spend more than 30s to finish this line(cursor.getcount()) . If I delete this line, and use ArrayList to take place. i can find that we should spend more than 30s for Cursor.moveToNext().

所以我的问题是,为什么第一次游标操作应该采取这样长的时间?和我们怎么解决?

So my question is why the first time cursor operation should take such long time? and how do we solve?

和这个人有相同的问题,<一个href=\"http://stackoverflow.com/questions/4391388/poor-sqlite-implementation-first-time-data-access-way-too-slow\">Poor SQLite的执行?第一次数据访问太慢。但答案是不为我工作。
顺便说一句,我发现在iPhone显示屏同样1500rows,只需要3秒amost

And this man have the same question Poor SQLite implementation? First time data access way too slow. but the answer is not working for me. by the way, I find display same 1500rows in Iphone, just need amost 3s.

在此先感谢!

推荐答案

好吧,伙计们,我没有这里acouple days.And被我找到了解决方案,你必须为你的表的索引,这将提高查询速度。感谢所有相同

ok, guys, i have not been here for acouple days.And i found the solution that is you have to create index for your table which will improve the query speed. thanks all the same

这篇关于第一次光标操作是如此之慢,当查询大量数据。如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆