可怜的SQLite的执行?第一次数据访问太慢 [英] Poor SQLite implementation? First time data access way too slow

查看:1552
本文介绍了可怜的SQLite的执行?第一次数据访问太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid编程,但我早已习惯正在与SQLite数据库。

  • 我的应用程序打开SD卡上的SQLite3的数据库,并运行一个比较复杂的查询(5联接,1子查询,2 where子句)使用 SQLiteDatabase.rawQuery

     公开光标queryDataBase(SQL字符串,字符串[] selectionArgs两个){
        光标C = myDB.rawQuery(SQL,selectionArgs两个);
        返回℃;
    }
     

  • SQL语句被硬codeD给字符串

  • 查询返回585行,24列。
  • 在我所要做的存储空间和索引之间进行权衡,但是在所有更大的表(约〜40 000项,目前)使用索引,SQLite的显示了查询:步骤: 155,排序:0,AutoIdx:1077
  • 我不使用主键,因此我也没有什么重命名为_id。

  • rawQuery的执行是比较快的,运行时间约 2毫秒

  • 访问这些数据需要太多时间,如通过c.moveToFirst(),执行时间大约是 1700毫秒!(相同Cursor.getRowCount(),或表面上的所有第一次进入实际结果集)。
  • 在做同样的在PC上(2 GHz的,1 GB内存,SATA2 HDD)与如SQLiteSpy需要的 15毫秒以显示结果集。
  • 在该电脑采用了C ++实现它也是在做这件事的 15毫秒至30毫秒

那么,我在这里丢失?它实际上是可能的,我的手机用800兆赫,2 GB RAM,的MicroSD大约是120倍慢?

解决方案
  

rawQuery的执行是比较快的,执行时间大约为2毫秒。

     

访问这些数据需要太多时间,如通过c.moveToFirst(),执行时间为1700毫秒! (相同Cursor.getRowCount(),或表面上的所有第一次进入实际结果集)。

这是关键:rawQuery实际上并不执行查询,但被延迟,直到第一次查询结果必须是使用

来源: <一href="http://groups.google.com/group/android-developers/browse_thread/thread/c9277225f8dbc4d1/65de841f284f09e6?lnk=gst" rel="nofollow">http://groups.google.com/group/android-developers/browse_thread/thread/c9277225f8dbc4d1/65de841f284f09e6?lnk=gst

I am new to Android programming, however I am quite used working with SQLite databases.

  • My application opens a SQLite3 database on the SD card and runs a relatively complex query (5 joins, 1 subquery, 2 where clauses) using SQLiteDatabase.rawQuery

    public Cursor queryDataBase(String sql, String[] selectionArgs){
        Cursor c = myDB.rawQuery(sql, selectionArgs);
        return c;
    }
    

  • The SQL statement is given by a hardcoded String.

  • The query returns 585 rows with 24 columns.
  • I had to do a trade-off between storage space and indexing, but on all bigger tables (about ~ 40 000 entries, for now) indexes are used, SQLite shows for the query: Steps: 155 , Sorts: 0, AutoIdx: 1077
  • I am not using primary keys, thus I also didn't rename anything to "_id".

  • The execution of rawQuery is relatively fast, execution time is about 2 ms.

  • Accessing this data takes way too much time, e.g. by c.moveToFirst(), execution time is about 1700 ms! (same for Cursor.getRowCount(), or apparently all first time access to the actual result set).
  • Doing the same on a PC (2 GHz, 1 GB RAM, SATA2 HDD) with e.g. SQLiteSpy it takes 15 ms to display the result set.
  • Doing it on the PC with a C++ Implementation it's also 15 ms up to 30 ms.

So what am I missing here? Is it actually possible that my handset with 800 MHz, 2 GB RAM, MicroSD is about 120 times slower?

解决方案

The execution of rawQuery is relatively fast, execution time is about 2 ms.

Accessing this data takes way too much time, e.g. by c.moveToFirst(), execution time is about 1700 ms! (same for Cursor.getRowCount(), or apparently all first time access to the actual result set).

That's the key: rawQuery does not actually perform the query, but that is delayed until the first time the query results needs to be use.

Source: http://groups.google.com/group/android-developers/browse_thread/thread/c9277225f8dbc4d1/65de841f284f09e6?lnk=gst

这篇关于可怜的SQLite的执行?第一次数据访问太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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