我的数据库中有一个表,它有 14 列和 125 行。当我启动我的应用程序来创建数据库时,肯定会花费太多时间(在我看来):我做了 16 次尝试,这些就是结果。
===========================
Average time: 12.715 s
Minimum time: 8.486 s
Maximum time: 21.159 s
===========================
这就是我创建表的方式:
private static final String DATABASE_RECIPES_CREATE = "CREATE TABLE IF NOT EXISTS "
+ MetaData.TABLE_RECIPES + " ("
+ MetaData.KEY_ID + " integer primary key autoincrement, "
+ MetaData.KEY_NEW + " integer not null, "
+ MetaData.KEY_TITLE + " text not null, "
+ MetaData.KEY_INGREDIENTS + " text not null, "
+ MetaData.KEY_TIME + " text not null, "
+ MetaData.KEY_PEOPLE + " text not null, "
+ MetaData.KEY_WINE + " text, "
+ MetaData.KEY_SUGGESTIONS + " text, "
+ MetaData.KEY_DIRECTIONS + " text not null, "
+ MetaData.KEY_AUTHOR + " text, "
+ MetaData.KEY_DIFFICULTY + " text not null, "
+ MetaData.KEY_CATEGORY + " text not null, "
+ MetaData.KEY_VEGETARIAN + " integer, "
+ MetaData.KEY_IMAGE + " text)";
这就是我将所有行值添加到表中的方式:
public long addRecipe(int _id, int _new, String _title, String _ingredients, String _time, String _people, String _wine, String _suggestions,
String _directions, String _author, String _difficulty, String _category, int _vegetarian, String _image)
{
ContentValues initialValues = new ContentValues();
initialValues.put(MetaData.KEY_ID, _id);
initialValues.put(MetaData.KEY_NEW, _new);
initialValues.put(MetaData.KEY_TITLE, _title);
initialValues.put(MetaData.KEY_INGREDIENTS, _ingredients);
initialValues.put(MetaData.KEY_TIME, _time);
initialValues.put(MetaData.KEY_PEOPLE, _people);
initialValues.put(MetaData.KEY_WINE, _wine);
initialValues.put(MetaData.KEY_SUGGESTIONS, _suggestions);
initialValues.put(MetaData.KEY_DIRECTIONS, _directions);
initialValues.put(MetaData.KEY_AUTHOR, _author);
initialValues.put(MetaData.KEY_DIFFICULTY, _difficulty);
initialValues.put(MetaData.KEY_CATEGORY, _category);
initialValues.put(MetaData.KEY_VEGETARIAN, _vegetarian);
initialValues.put(MetaData.KEY_IMAGE, _image);
return mDb.insert(MetaData.TABLE_RECIPES, null, initialValues);
}
问题:
由于我的最终表将包含至少 400 行,有什么方法可以加快它的创建速度?
编辑 1: 我再添加一个问题:对于某些列,根本不需要“text”或“int”类型。将它们更改为“tinytext”、“smallint”和“tinyint”(在可能的情况下)会产生任何性能差异吗?