I have a table that has to store millions of posts (in the near future) in mysql. Here is the simplified structure (I didn't indicate my primary keys because my question is based on that):
CREATE TABLE `posts` (
`post_id` INT NOT NULL AUTO_INCREMENT,
`user_id` BIGINT(20) NOT NULL,
`title` VARCHAR(100),
`content` TEXT
) ENGINE = MyISAM;
My question is: What is the best way to define my keys?
Is it best to use my
AUTO_INCREMENT
ing 'post_id
' only as a primary and a unique key considering the amount of records that needs to be stored?Must I use both '
post_id
' and 'user_id
' as a composite key to use as a primary and unique key? If this is best, how do I use it in other tables as a foreign key? Do I simply add them as columns in those tables?
Could you please also indicate the advantages and disadvantages (if any) of each and perhaps some advice on which ENGINE to use. I think Innodb will be best if I use the second option. I don't know.