Is it more efficient to use a taglist field, with all the tags separated by a space, or use 2 more tables (tag: tagid tagtext, tagitem: tagid, itemid)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The efficiency largely depends on what you are doing. If you want to query based on the tag name, it is probably faster if you have a tag table with the ID keyed on both the tag and items table (i.e. option #2). However, unless you have thousands of rows of either, it probably won’t make a difference. If you don’t have that many tags at all, the difference will be even less.
If you want to get tags by item IDs, though, the first method is ever so slightly faster. Again, I doubt you will notice.
There are other considerations to make: data integrity and normalization. If you use two tables and foreign keys, it is much easier for you to have your set of tags be consistent with the items. If a tag is removed and you are only using one table, old items will still have the old tags. Additionally, it’s much easier to get a list of unique tags and keep it consistent. If you have tags in another table, this opens up a whole new world of organization: you can make timestamps for tag creation and modification, mark tags as active or inactive (and possibly other statuses), etc.