I have two tables, like these:
Table People:
VARCHAR Name
INTEGER Age
Table Message
VARCHAR Message
VARCHAR Name
There are hundreds of insert and delete going on with the Message table with queries like this:
insert into Message VALUES ('Hello there', 'John');
delete from Message where name = 'John';
My question is, is it worth while to add an ID field in People and reference the User as an id in Message? Will the following queries be much faster?
FIRST - select id from User where name = 'John'
THEN - delete from Message where id = $id
I thought at first inserts and deletes by searching for an id will be faster than by searching by characters. But how much faster? Will the speed incresase offset the performance hit from needing an extra query to the User table to find the id?
As you said, the extra query will make it SLIGHTLY slower (of course there are dependences on the name’s length, database type, etc.)
But what happens when the user changes his name, when you want to delete an user, etc?. That sort of design will give you lots of pain. It’s better to normalize, regardless of this tiny performance issue,