MySQL multiple insert without auto incrementing id on duplicate key update (InnoDB)
===

My application stores messages for a chat channel that users will be uploading automatically. There will be at most 5 people uploading messages to the database. More than one is required because I cannot be sure the people using the upload tool are actually connected to the chat channel and getting the latest messages. The upload tool checks for new messages every second and if it finds any it posts those messages to the application which stores the messages in an InnoDB table using PHP.

It's important to note the idea of this is such that there will be hundreds if not thousands of channels all doing the same thing.

This means there are many instances where the messages may be duplicated and a high chance of different timestamps on those messages (the messages hit the uploader's computers with different timestamps.) To counter this I have created the following table.

    CREATE TABLE `RCIntel_raw_commands` (
      `command_id` bigint(20) NOT NULL AUTO_INCREMENT,
      `channel_id` mediumint(9) NOT NULL,
      `command_date_time` datetime NOT NULL,
      `command_sender` tinytext NOT NULL,
      `command_message` text NOT NULL,
      `command_hash_1` varchar(32) NOT NULL DEFAULT '',
      `command_hash_2` varchar(32) NOT NULL DEFAULT '',
      `command_hash_3` varchar(32) NOT NULL DEFAULT '',
      PRIMARY KEY (`command_id`),
      UNIQUE KEY `command_hash_1` (`command_hash_1`),
      UNIQUE KEY `command_hash_2` (`command_hash_2`),
      UNIQUE KEY `command_hash_3` (`command_hash_3`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

To counteract the duplicate messages that may have different timestamps I have taken the datetime of the message, removed the seconds count and hashed that along with the sender and message. Hashes are also done for +-1 minute so that any identical messages from the same sender within a couple of minutes are counted as duplicates.

The hashes are set as unique keys as you can see. I'm inserting using...

    INSERT INTO RCIntel_raw_commands(
    	channel_id,
    	command_date_time,
    	command_sender,
    	command_message,
    	command_hash_1,
    	command_hash_2,
    	command_hash_3)
    VALUES
    	(
    		[channel_id_1],
    		[command_date_time_1],
    		[command_sender_1],
    		[command_message_1],
    		[command_hash_1_1],
    		[command_hash_2_1],
    		[command_hash_3_1]
    	),
    	(
    		[channel_id_2],
    		[command_date_time_2],
    		[command_sender_2],
    		[command_message_2],
    		[command_hash_1_2],
    		[command_hash_2_2],
    		[command_hash_3_2]
    	)
    ON DUPLICATE KEY UPDATE
    	command_hash_1 = VALUES(command_hash_1),
    	command_hash_2 = VALUES(command_hash_2),
    	command_hash_3 = VALUES(command_hash_3)

The problem is command_id is being incremented anyway (as explained in the manual.) I thought about removing the auto incrementing ID but I'm using it to limit a select query when fetching new messages on the front end via ajax.

I did read this... http://stackoverflow.com/questions/5924762/prevent-autoincrement-on-mysql-duplicate-insert however I'm worried that every insert requiring a select as well is going to cause major strain on the server.

I've tried to be as succinct as possible with the issue as I know an answer may be to rewrite something not directly pertaining to the issue, but which will cascade through the application solving the problem. 

Would anyone please help me find a more elegant solution to this problem? Thanks very much.