安卓的SQLite和巨大的数据集 [英] Android SQLite and huge data sets

查看:94
本文介绍了安卓的SQLite和巨大的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在创建的是有几百HTML的SQLite数据库百兆客户端的应用程序。我们已经实现了一个方法来查询这些数据,并通过这一切滚动以相当快的方式。问题是一些数据库有很大疑问(20000行),我们看到的错误,当我们正在成长中的查询为用户滚动。所以我想,问题是,什么选择我们在查询和显示数以万计的数据行的Andr​​oid的?

下面是我们所看到的堆栈跟踪:

  09-10 19:19:12.575:WARN / IInputConnectionWrapper(640):showStatusIcon上的非活动InputConnection
09-10 19:19:18.226:DEBUG / dalvikvm(640):GC释放446对象/在330ms 16784字节
09-10 19:19:32.886:ERROR / CursorWindow(19416):需要成长:MSIZE = 1048576,大小= 36,可用空间()= 30,= numRows行17717
09-10 19:19:32.896:ERROR / CursorWindow(19416):没有增长,因为已经有17717行(S),最大大小1048576
09-10 19:19:32.916:ERROR / CursorWindow(19416):该行失败,所以背出新行从allocRowSlot 17716会计
09-10 19:19:33.005:ERROR /光标(19416):无法分配fieldDir在startPos 0行17716
09-10 19:19:35.596:DEBUG /光标(19416):finish_program_and_get_row_count行24315
09-10 19:19:41.545:DEBUG / dalvikvm(698):GC释放2288对象/在260ms 126080字节
09-10 19:19:43.705:WARN / KeyCharacterMap(19416):没有键盘ID 0
09-10 19:19:43.717:WARN / KeyCharacterMap(19416):使用默认的键盘对应:/system/usr/keychars/qwerty.kcm.bin
09-10 19:20:04.705:ERROR / CursorWindow(19416):需要成长:MSIZE = 1048576,大小= 17,可用空间()= 3,= numRows行17094
09-10 19:20:04.716:ERROR / CursorWindow(19416):没有增长,因为已经有17094行(S),最大大小1048576
09-10 19:20:04.726:ERROR /光标(19416):无法分配17个字节的文本/一滴在17093,2
09-10 19:20:05.656:DEBUG /光标(19416):finish_program_and_get_row_count行5257
09-10 19:24:54.685:DEBUG / dalvikvm(637):GC释放9297对象/在247ms 524176字节
09-10 19:32:07.656:DEBUG / dalvikvm(19416):GC释放9035对象/在199ms 495840字节
 

下面是我们的CursorAdapter code:

 私有类MyAdapter扩展ResourceCursorAdapter {

    公共MyAdapter(上下文的背景下,光标光标){
        超(背景下,R.layout.my_row,光标);
    }

    公共无效bindView(查看视图,上下文的背景下,光标光标){
        RowData数据=新RowData();
        data.setName(cursor.getInt(cursor.getColumnIndex(名字)));

        TextView的tvItemText =(TextView中)view.findViewById(R.id.tvItemText);
        tvItemText.setText(data.getName());

        view.setTag(数据);
    }

    @覆盖
    公共光标runQueryOnBackgroundThread(CharSequence的约束){
        / *显示进度指示器* /
        updateHandler.post(onFilterStart);

        / *运行实际查询* /
        如果(约束== NULL){
            返回myDbObject.getData(空);
        }

        返回myDbObject.getData(constraint.toString());
    }
}
 

解决方案
  

做的选择,我们在查询   和显示数万   数据行的Andr​​oid?

另外告诉你一个3.5LCD读20000行是蝙蝠粪疯了你的意思; - ?)

看起来 CursorWindow ,用于地方在幕后,是有问题管理> 17000行。这可能是两件事之一:

  1. 您的堆空间不足。随着16MB非压缩堆,而事实上,一个光标持有的全部结果在堆集,是不是出了问题。
  2. CursorWindow 仅支持1MB的数据,这是错误信息更直接地表明了什么。

如果有是把查询到​​的离散块一个合乎逻辑的方式,你可以做增量查询和使用 CursorJoiner 将它们拼接在一起,看看有没有什么帮助。

不过,在所有的严重性,20000行3.5屏幕,在设备上最近似于一个12岁的PC马力,真的是问了很多。

We are creating an app for a client that has hundreds of megabytes of HTML in SQLite databases. We have implemented a way to query this data and scroll through it all in a reasonably fast manner. The issue is that some of the databases have very large queries (20,000+ rows) and we are seeing errors when we are growing the queries as the user is scrolling. So I guess the question is, what options do we have in querying and displaying tens of thousands of rows of data in Android?

Here is the stacktrace we're seeing:

09-10 19:19:12.575: WARN/IInputConnectionWrapper(640): showStatusIcon on inactive InputConnection
09-10 19:19:18.226: DEBUG/dalvikvm(640): GC freed 446 objects / 16784 bytes in 330ms
09-10 19:19:32.886: ERROR/CursorWindow(19416): need to grow: mSize = 1048576, size = 36, freeSpace() = 30, numRows = 17717
09-10 19:19:32.896: ERROR/CursorWindow(19416): not growing since there are already 17717 row(s), max size 1048576
09-10 19:19:32.916: ERROR/CursorWindow(19416): The row failed, so back out the new row accounting from allocRowSlot 17716
09-10 19:19:33.005: ERROR/Cursor(19416): Failed allocating fieldDir at startPos 0 row 17716
09-10 19:19:35.596: DEBUG/Cursor(19416): finish_program_and_get_row_count row 24315
09-10 19:19:41.545: DEBUG/dalvikvm(698): GC freed 2288 objects / 126080 bytes in 260ms
09-10 19:19:43.705: WARN/KeyCharacterMap(19416): No keyboard for id 0
09-10 19:19:43.717: WARN/KeyCharacterMap(19416): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-10 19:20:04.705: ERROR/CursorWindow(19416): need to grow: mSize = 1048576, size = 17, freeSpace() = 3, numRows = 17094
09-10 19:20:04.716: ERROR/CursorWindow(19416): not growing since there are already 17094 row(s), max size 1048576
09-10 19:20:04.726: ERROR/Cursor(19416): Failed allocating 17 bytes for text/blob at 17093,2
09-10 19:20:05.656: DEBUG/Cursor(19416): finish_program_and_get_row_count row 5257
09-10 19:24:54.685: DEBUG/dalvikvm(637): GC freed 9297 objects / 524176 bytes in 247ms
09-10 19:32:07.656: DEBUG/dalvikvm(19416): GC freed 9035 objects / 495840 bytes in 199ms

Here is our CursorAdapter code:

    private class MyAdapter extends ResourceCursorAdapter {

    public MyAdapter(Context context, Cursor cursor) {
        super(context, R.layout.my_row, cursor);        
    }

    public void bindView(View view, Context context, Cursor cursor) {                
        RowData data = new RowData();
        data.setName(cursor.getInt(cursor.getColumnIndex("name")));

        TextView tvItemText = (TextView)view.findViewById(R.id.tvItemText);
        tvItemText.setText(data.getName());

        view.setTag(data);
    }

    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        /* Display the progress indicator */
        updateHandler.post(onFilterStart);

        /* Run the actual query */               
        if (constraint == null) {
            return myDbObject.getData(null);                     
        }

        return myDbObject.getData(constraint.toString());                
    }            
}

解决方案

what options do we have in querying and displaying tens of thousands of rows of data in Android?

You mean besides telling you that reading 20,000+ rows on a 3.5" LCD is bat-guano crazy? ;-)

It looks like CursorWindow, which is used somewhere under the covers, is having issues managing >17,000 rows. That could be one of two things:

  1. You are out of heap space. With a 16MB non-compacting heap, and the fact that a Cursor holds the entire result set in the heap, that is not out of the question.
  2. CursorWindow only supports 1MB of data, which is what the error message suggests more directly.

If there is a logical way to divide your queries into discrete chunks, you could do incremental queries and use CursorJoiner to stitch them together, and see if that helps.

But, in all seriousness, 20,000+ rows in a 3.5" screen, on a device that most closely resembles a 12-year-old PC in horsepower, is really asking a lot.

这篇关于安卓的SQLite和巨大的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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