Question

So I have a table:

CREATE TABLE `slots` (
 `customerid` int(11) NOT NULL,
 `orderid` int(11) NOT NULL,
 `queueid` int(11) NOT NULL AUTO_INCREMENT,
 `item_id` int(3) NOT NULL,
 `variable1` int(3) NOT NULL,
 `variable2` int(3) NOT NULL,
 `variable3` int(3) NOT NULL,
 `variable4` int(3) NOT NULL,
 `variable5` int(3) NOT NULL,
 `variable6` int(3) NOT NULL,
 `variable7` tinyint(1) NOT NULL,
 `variable8` tinyint(1) NOT NULL,
 `variable9` tinyint(1) NOT NULL,
 PRIMARY `queueid` (`queueid`),
 UNIQUE KEY (`customerid`,`orderid`),
 KEY `orderid` (`orderid`)
) ENGINE=InnoDB AUTO_INCREMENT=25883472 DEFAULT CHARSET=latin1

That I want to partition horizontally by customerid. The problem is that customerid and orderid must form a unique combination -> I've created an unique key for that and use INSERT IGNORE to ignore inserts that would result in a duplicate row.

Would that still work with partitioned table? Or it wouldn't help with my insert speed (I am partitioning the table to achieve higher INSERT speed but I still need to watch out to not insert one row multiple times ).

Was it helpful?

Solution 2

The partitioning docs have this to say;

All columns used in the partitioning expression for a partitioned table must be part of every unique key that the table may have.

In other words, it will work as long as you're partitioning on customerid, orderid or both, otherwise your unique key is invalid.

OTHER TIPS

In this case if you want to partition based on customerId & also want to keep UNIQUE KEY on customerId & orderId

Add customerId to your PK

MySQL doc says

every unique key on the table must use every column in the table's partitioning expression. (This also includes the table's primary key, since it is by definition a unique key.

So customerId should be part of both UNIQUE KEY as well PRIMARY KEY.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top