i've a large table with about 2Mln records, and i want to partition it.
I've the id column as PRIMARY AUTO_INCREMENT int (and it must to be always UNIQUE). I've a column "theyear" int(4) and i want to partition BY RANGE from 2016 to 2050, because most of Query use a WHERE statement getting 1 year at time.
Making the partitioning i get an error saying that the "theyear" key must be with PRIMARY KEY, so i've edited the primary key doing a multicolumn key PRIMARY (id, theyear).
It's all OK, but my "id" columns isn't UNIQUE anymore, because it checks "theyear" columns too... So if I insert:
INSERT INTO table (id, theyear) VALUES (1, 2016);
INSERT INTO table (id, theyear) VALUES (1, 2017);
it says NO ERROR, because the UNIQUE check both id and theyear.
How can implement partitioning without lose UNIQUE on "id" column?
Thanks.
unique
constraint against year? - cwallenpooleSHOW CREATE TABLE
. I will probably argue that a suitable index will as fast or faster then partitioning. Perhaps the index would start with YEAR. Hint: mysql.rjweb.org/doc.php/partitionmaint - Rick James