I'm just working on putting together the table for blog posts on my site.
I know how to use SQL, and I know a bit about the different types and lengths, but I'm at a loss as to the best lengths and types for my table.
The way I currently have it setup is:
Tags is a string array of tags for the post, the same with categories. Projects will be an array of ints, that are the ids for the "projects" that are associated with the post. (projects each have their own page about them, and when you go to the page you can get a list of all the posts about it).
My question is, what is the most optimized way I can setup this table?
UPDATE:
Currently I'm interesting in the best ways to store this and optimize disk usage. Right now I have a free x10hosting server I'm going to be using, which has a 512mb limit. If necessary I can pay for a larger server later on, but I want to stick with the free one till I max out my limits.
For a serious space conservation requirement:
FIND_IN_SET()
to check if a tags
contains a particular tag
. This will be slow, and cannot use any indexes.In PHP you can use a function called "serialize" which I use in SQL storage all the time.
$foo = serialize($bar);
Now just store $foo. $bar can even be complete objects. After the fact you can just grab the value and
$bar = unserialize($foo);
$bar now contains whatever you wanted before. Array, object, et al. This makes the layout of your sql table lazy but since the beginning and end results are just variables in a php script, the table doesn't really matter. Just make the fields text (not varchar(max)) and you are gravy!