database - Fetching records with slug instead of ID -


I am currently trying to find the best method (in the case of applicability and execution) a specific tag, or category Tagged with, or something like that

A good way (the way I wanted to) would be to get the record with the tag / category slug, so that the URL will look like:

  http: / /stackoverflow.com/questions/tagged/language-agnostic  

Getting records by a slug, which looks better than:

  http: // stackoverflow .com / questions / tag / 789 / language-agnostic  

To render by ID and backwards so that it is more suited to search engine optimization. This is a better performance-driven, because getting data from an integer ID will get faster than the string. (CMII)

Now, like a DB schema like:

  Post Post_tags Tag ----- ------------ - - ID ID ID title post_id Name Content tag_ id slug ... ...  

Am I doing this right? Do I need to know to avoid performance or problems? (Eg tags should not exceed 10000 records, or tags should not be more than sl al n characters, or something else)

Thanks in advance.

With the first URL style and your current DB design, you can:

Select
  ... Join posts in posts by post_to_tags pt at pt.post_id = p.post_id tag in t.id = pt.tag_id, where t.slug = [url slug value] ;  

Until tags.slug is indexed, it should be very efficient, select rarely

  Pttag_id = [url tag id] from posts that join post_to_tags pt on Pt.post_id = p.post_id;  

Comments