Add batching to MySQL upsert query

This patch generates multi-row upsert statements for MySQL.