Here is an idea. Make in the db where you want to keep the map tiles two tables. one coordinates and CRC of the image tile and in the second table the CRC of the image and the image. This way you can exclude duplicates, we'll have only one tile that is blue... or white... or whatever. you make the CRC as a unique key in the images table. when you insert, you insert in both tables, in the image table the insert will fail (if the CRC is already there). this way you won't have to check if the image is already in the table before inserting. What do you think?