2

我想执行一个简单的查询,但需要很多时间。在我的表中,有 3 个列:

id(int)针(字符串)字(字符串)

needle 可以是任何类型的字符,并且不是英文的。

word 也是任何类型的字符,并且不是英语。

有 3000 行。

我可以通过简单的查询将针替换为单词。但是速度很慢,100字大约需要2s。我可以通过什么方式提高速度?谢谢

4

1 回答 1

4

I can replace needle to word by simple query. but it is very slow, takes about 2s for 100 words. In what way can i improve the speed? thanks

I suggest you to wrap your update statements into one TRANSACTION that rapidly increase your performance(tested by myself).

At first it rapidly increase your performace and second also your dealing with database becomes much more safer.

Here is basic snippet of pseudo-code:

try {
   db.beginTransaction(); // starting transaction
   // perform updates
   db.setTransactionSuccessful(); // marks transaction successful i.e. commit()
}
finally {
   if (db != null) {
      if (db.inTransaction()) {
         db.endTransaction();
      }
      db.close();
   }
}
于 2013-04-15T16:39:14.417 回答