开发者

Slow update with OrmLite

开发者 https://www.devze.com 2023-03-19 20:27 出处:网络
I have a simple structure and i noticed that updating records in my database takes too long to execute.

I have a simple structure and i noticed that updating records in my database takes too long to execute.

This is how my data class is defined:

public static final String TILE_MAP_UNIQUE_ID_FIELD_NAME = "tileMap_unique_id"; 
@DatabaseField (uniqueIndexName = "unique_tileMapCache", canBeNull = false)
int tileMap_unique_id;
public static final String TILE_MAP_LEVEL_ID_FIELD_NAME = "tileMap_level_id"; 
@DatabaseField (uniqueIndexName = "unique_tileMapCache", canBeNull = false)
String tileMap_level_id;
public static final String COLUMN_FIELD_NAME = "column"; 
@DatabaseField (uniqueIndexName = "unique_tileMapCache", canBeNull = false)
long column;
public static final String ROW_FIELD_NAME = "row";
@DatabaseField (uniqueIndexName = "unique_tileMapCache", canBeNull = false)
long row;
public static final String IMAGE_DATA_FIELD_NAME = "image_data";
@DatabaseField (dataType = DataType.BYTE_ARRAY, index = true, canBeNull = false)
byte[] image_data;
public static final String IMAGE_DATA_LENGHT_FIELD_NAME = "image_data_lenght";
@DatabaseField (index = true, canBeNull = false)
int image_data_lenght;
public static final String DATE_CREATED_FIELD_NAME = "date_created";
@DatabaseField(index = true, canBeNull = false)
Date date_created;
public static final String DATE_LAST_ACCESSED_FIELD_NAME = "date_last_accessed";
@DatabaseField(index = true, canBeNull = false)
Date date_last_accessed;
public static final String ACCESSED_COUNTER = "accessed_counter";
@DatabaseField(index = true, canBeNull = false)
int accessed_counter;

And this is the update statement somewhere in my application:

Dao<TileMapCacheData, Integer> updateTileMapCacheDataDao = dbHelper.getTileMapCacheDataDao();
UpdateBuilder<TileMapCacheData, Integer> upd开发者_StackOverflow社区ateBuilder = updateTileMapCacheDataDao.updateBuilder();
updateBuilder.updateColumnValue(TileMapCacheData.DATE_LAST_ACCESSED_FIELD_NAME, new Date());
updateBuilder.updateColumnValue(TileMapCacheData.ACCESSED_COUNTER, record.accessed_counter + 1);
updateBuilder.where()
.eq(TileMapCacheData.TILE_MAP_UNIQUE_ID_FIELD_NAME, tileMap.getUniqueId())
.and()
.eq(TileMapCacheData.TILE_MAP_LEVEL_ID_FIELD_NAME, tileMap.getLevelId(tileImage.tile.level))
.and()
.eq(TileMapCacheData.COLUMN_FIELD_NAME, tileImage.tile.column)
.and()
.eq(TileMapCacheData.ROW_FIELD_NAME, tileImage.tile.row);
updateTileMapCacheDataDao.update(updateBuilder.prepare());

The SQL looks like this:

UPDATE `tilemapcachedata` SET `date_last_accessed` = ? ,`accessed_counter` = 11 WHERE (((`tileMap_unique_id` = -1902272760 AND `tileMap_level_id` = '5' ) AND `column` = 24 ) AND `row` = -6 )

Does any one see where the problem is? The .update() takes several seconds and it should be executed instantly.

Any idea would be great.


The only thing that I see is the byte[] image_data; field may hold some huge value that is slowing things down. But the update you show is not even touching the image_data field so I have no idea why it is taking so long.

I would recommend enabling some of the logging in ORMLite to see if you can figure out where the time is going. See http://ormlite.com/docs/logging

Also, you have a lot of indexes in this table including and index on the byte[] image_data. You might consider removing some of these indexes unless they are truly necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消