Merge MessageDatabase, improve message selection performance