I have a table setup like below.
Table comment_flags
user_id
comment_id
I allow users to flag a comment and then give them the option to unflag it, because they may have made a mistake.
The problem is that when they unflag a comment, after I delete the record , the comment_flags
table get roughly 30-40bytes of overhead, even after only unflagging 5 comments.
Heres basically whats going on:-
A user flags a comment, so I insert user_id
and comment_id
into comment_flags
table, then the user unflags the comment and I delete from the comment_flags
table by the user_id
and comment_id
.
I am not sure that it's my SQL thats causing the problem though, I think it's just the DELETE
statement in general.
I could optimise the table after every DELETE
statement to clean up the table.
Is this seen as a good idea? How does everyone else deal with this?
My sql is very basic.
INSERT INTO comment_flags VALUE('$user_id', '$comment_id')
DELETE FROM comment_flags WHERE user_id = '$user_id' AND comment_id = '$comment_id'