In a project in which I need to implement like/unlike functionality, I want to know which approach would better than other from performance point of view. If I have to go with insert delete, then what would happen if someone like/unlike it so many times (Then probably most of primary key numbers will be occupied based on like/unlike)?
Does anyone know how social networking sites do it?
EDIT:
My table is as below:
CREATE TABLE `junc_user_share_like` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`jusid` int(10) unsigned NOT NULL,
`liker` mediumint(8) unsigned NOT NULL,
`when` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `jusid` (`jusid`,`liker`),
KEY `liker` (`liker`),
CONSTRAINT `junc_user_share_like_ibfk_1` FOREIGN KEY (`liker`) REFERENCES `user` (`uid`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `junc_user_share_like_ibfk_2` FOREIGN KEY (`jusid`) REFERENCES `junc_user_share` (`jusid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB
EDIT 2:
As you said with last updates this is what I've inferred:
INSERT INTO likes SET jusid=$jusid, liker=$liker
UPDATE junc_user_share SET likes=likes+1 WHERE id=$id
This works great for likes, but what if someone wants to undo his like? Should I delete record from likes? My problem is exactly here? What to do here?