I have two innoDB tables and I'm updating a table with a batch of 10 threads (one batch per thread), but some time I get dead-lock.

```
java.sql.BatchUpdateException: Deadlock encountered while trying to get a lock; Try restarting the transaction
at com.mysql.jdbc.StatementImpl.executeBatch (StatementImpl.java:1046)
at com.jolbox.bonecp.StatementHandle.executeBatch (StatementHandle.java:469)
```

Table 1 Scheme –

```
CREATE TABLE `FantasyMatchUserPlayersV2` (
`id` bigint (20) NOT NULL AUTO_INCREMENT,
`contestType` int (11) DEFAULT NULL,
`lastUpdatedTime` bigint (20) NOT NULL,
`matchId` int (11) NOT NULL,
`matchIdPlayerIdContestType` varchar (255) DEFAULT NULL,
`matchIdPlayerIdContestTypeUserBucket` varchar (255) DEFAULT NULL,
`playerId` int (11) DEFAULT NULL,
`score` int (11) NOT NULL,
`userBucket` int (11) NOT NULL,
`userId` bigint (20) DEFAULT NULL,
PRIMARY KEY ("id"),
KEY `matchId_playerId_contestType_userBucket` (` matchIdPlayerIdContestTypeUserBucket`),
KEY `matchId_playerId_contestType` (` matchIdPlayerIdContestType`),
KEY `userId` (` userId`),
KEY `matchId` (` matchId`),
KEY `playerId` (` playerId`)
) ENGINE = InnoDB
```

Table 2 Scheme –

```
CREATE TABLE `FantasyMatchContestsV2` (
`id` bigint (20) NOT NULL AUTO_INCREMENT,
`captainId` int (11) DEFAULT NULL,
`complete` tinyint (1) DEFAULT NULL,
`contestType` int (11) DEFAULT NULL,
`createdTime` datetime DEFAULT NULL,
`lastUpdatedTime` bigint (20) NOT NULL,
`matchId` int (11) NOT NULL,
`matchIdContestTypeUserBucket` varchar (255) DEFAULT NULL,
`points` int (11) NOT NULL,
`userBucket` int (11) NOT NULL,
`userId` bigint (20) DEFAULT NULL,
`viceCaptainId` int (11) DEFAULT NULL,
PRIMARY KEY ("id"),
UNIQUE KEY `userId` (` userId`, `matchIdContestTypeUserBucket`),
KEY `matchIdContestTypeUserBucket` (` matchIdContestTypeUserBucket`),
KEY `captainId` (` captainId`),
KEY `viceCaptainId` (` viceCaptainId`),
KEY `contestType` (` contestType`),
KEY `matchId` (` matchId`)
) ENGINE = InnoDB
```

Batch statements executed by 10 threads, each thread executes a different type of contest (from 1 to 10)

```
update FantasyMatchContestsV2 c inner Join FantasyMatchUserPlayersV2 p to c.matchId = p.matchId AND c.userId = p.userId AND c.contestType = p.contestType AND c.userBucket = p.userBucket set c.points + (c.points + 124 )), c.lastUpdatedTime = 1555161797491 where p.playerId = 127 AND p.matchId = 40288 AND p.contestType = 0 and p.userBucket = 0,
Update FantasyMatchContestsV2 c-setpoints = (points + 248), lastUpdatedTime = 1555161797491 where c.captainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 0.
Update FantasyMatchContestsV2 c-setpoints = (points + 124), lastUpdatedTime = 1555161797491 where c.viceCaptainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 0.
update FantasyMatchContestsV2 c inner Join FantasyMatchUserPlayersV2 p to c.matchId = p.matchId AND c.userId = p.userId AND c.contestType = p.contestType AND c.userBucket = p.userBucket set c.points + (c.points + 124 )), c.lastUpdatedTime = 1555161797491 where p.playerId = 127 AND p.matchId = 40288 AND p.contestType = 0 and p.userBucket = 1,
Updating FantasyMatchContestsV2 c-setpoints = (points + 248), lastUpdatedTime = 1555161797491 where c.captainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 1.
Updating FantasyMatchContestsV2 c-setpoints = (points + 124), lastUpdatedTime = 1555161797491 where c.viceCaptainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 1.
update FantasyMatchContestsV2 c inner Join FantasyMatchUserPlayersV2 p to c.matchId = p.matchId AND c.userId = p.userId AND c.contestType = p.contestType AND c.userBucket = p.userBucket set c.points + (c.points + 124 )), c.lastUpdatedTime = 1555161797491 where p.playerId = 127 AND p.matchId = 40288 AND p.contestType = 0 and p.userBucket = 2,
Update FantasyMatchContestsV2 c-setpoints = (points + 248), lastUpdatedTime = 1555161797491 where c.captainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 2.
Update FantasyMatchContestsV2 c-setpoints = (points + 124), lastUpdatedTime = 1555161797491 where c.viceCaptainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 2.
update FantasyMatchContestsV2 c inner Join FantasyMatchUserPlayersV2 p to c.matchId = p.matchId AND c.userId = p.userId AND c.contestType = p.contestType AND c.userBucket = p.userBucket set c.points + (c.points + 124 )), c.lastUpdatedTime = 1555161797491 where p.playerId = 127 AND p.matchId = 40288 AND p.contestType = 0 and p.userBucket = 3,
Update FantasyMatchContestsV2 c-setpoints = (points + 248), lastUpdatedTime = 1555161797491 where c.captainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 3.
Update FantasyMatchContestsV2 c-setpoints = (points + 124), lastUpdatedTime = 1555161797491 where c.viceCaptainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 3.
update FantasyMatchContestsV2 c inner Join FantasyMatchUserPlayersV2 p to c.matchId = p.matchId AND c.userId = p.userId AND c.contestType = p.contestType AND c.userBucket = p.userBucket set c.points + (c.points + 124 )), c.lastUpdatedTime = 1555161797491 where p.playerId = 127 AND p.matchId = 40288 AND p.contestType = 0 and p.userBucket = 4,
Update FantasyMatchContestsV2 c-setpoints = (points + 248), lastUpdatedTime = 1555161797491 where c.captainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 4,
Update FantasyMatchContestsV2 c-setpoints = (points + 124), lastUpdatedTime = 1555161797491 where c.viceCaptainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 4.
update FantasyMatchContestsV2 c inner Join FantasyMatchUserPlayersV2 p to c.matchId = p.matchId AND c.userId = p.userId AND c.contestType = p.contestType AND c.userBucket = p.userBucket set c.points + (c.points + 124 )), c.lastUpdatedTime = 1555161797491 where p.playerId = 127 AND p.matchId = 40288 AND p.contestType = 0 and p.userBucket = 5,
Update FantasyMatchContestsV2 c-setpoints = (points + 248), lastUpdatedTime = 1555161797491 where c.captainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 5,
Update FantasyMatchContestsV2 c-setpoints = (points + 124), lastUpdatedTime = 1555161797491 where c.viceCaptainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 5.
update FantasyMatchContestsV2 c inner Join FantasyMatchUserPlayersV2 p to c.matchId = p.matchId AND c.userId = p.userId AND c.contestType = p.contestType AND c.userBucket = p.userBucket set c.points + (c.points + 124 )), c.lastUpdatedTime = 1555161797491 where p.playerId = 127 AND p.matchId = 40288 AND p.contestType = 0 and p.userBucket = 6,
Update FantasyMatchContestsV2 c-setpoints = (points + 248), lastUpdatedTime = 1555161797491 where c.captainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 6,
Update FantasyMatchContestsV2 c-setpoints = (points + 124), lastUpdatedTime = 1555161797491 where c.viceCaptainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 6,
update FantasyMatchContestsV2 c inner Join FantasyMatchUserPlayersV2 p to c.matchId = p.matchId AND c.userId = p.userId AND c.contestType = p.contestType AND c.userBucket = p.userBucket set c.points + (c.points + 124 )), c.lastUpdatedTime = 1555161797491 where p.playerId = 127 AND p.matchId = 40288 AND p.contestType = 0 and p.userBucket = 7,
Updating FantasyMatchContestsV2 c-setpoints = (points + 248), lastUpdatedTime = 1555161797491 where c.captainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 7,
Update FantasyMatchContestsV2 c-setpoints = (points + 124), lastUpdatedTime = 1555161797491 where c.viceCaptainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 7,
update FantasyMatchContestsV2 c inner Join FantasyMatchUserPlayersV2 p to c.matchId = p.matchId AND c.userId = p.userId AND c.contestType = p.contestType AND c.userBucket = p.userBucket set c.points + (c.points + 124 )), c.lastUpdatedTime = 1555161797491 where p.playerId = 127 AND p.matchId = 40288 AND p.contestType = 0 and p.userBucket = 8,
Update FantasyMatchContestsV2 c-setpoints = (points + 248), lastUpdatedTime = 1555161797491 where c.captainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 8,
Update the c-points of FantasyMatchContestsV2 = (points + 124), lastUpdatedTime = 1555161797491, where c.viceCaptainId = 127 and c.matchId = 40288 and c.contestType = 0 and c.userBucket = 8
```