Can AUTO_INCREMENT be safely used in a BEFORE TRIGGER in MySQL
Instagram's Postgres method of implementing custom Ids for Sharding is great, but I need the implementation in MySQL. So, I converted the method found at the bottom of this blog, here: http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram MySQL Version: CREATE TRIGGER shard_insert BEFORE INSERT ON tablename FOR EACH ROW BEGIN DECLARE seq_id BIGINT; DECLARE now_millis BIGINT; DECLARE our_epoch BIGINT DEFAULT 1314220021721; DECLARE shard_id INT DEFAULT 1; SET now_millis = (SELECT UNIX_TIMESTAMP(NOW(3)) * 1000); SET seq_id = (SELECT AUTO_INCREMENT FROM information