semsol / arc2

ARC RDF Classes for PHP
Other
332 stars 89 forks source link

Make id column in table id2val a PRIMARY KEY and set AUTO_INCREMENT #71

Closed k00ni closed 9 years ago

k00ni commented 9 years ago

The reason for that change is to improve the handling of that table, if you need to manage it manually.

Without that change, if you want to add a new entry to that table, you have to first count of all entries of the table, increment that number and use it as the new value of the id-column. But using that method can let you run into race conditions, highly problematic in situation with a high number of write and read operations.

With my change, you let MySQL increase the value of the id-column. Which means, you only pass the values for the other columns and MySQL auto increment the value. Using Primary Key for id-column let it become a real "id".

Of course, existing tables have to be upgraded. You can do that by executing the following SQL-queries in the according MySQL-table (replace XXX with your chosen prefix):

ALTER TABLE `XXX_id2val` ADD PRIMARY KEY(`id`)
ALTER TABLE  `XXX_id2val` CHANGE  `id`  `id` MEDIUMINT( 8 ) UNSIGNED NOT NULL AUTO_INCREMENT