Retrieving records using slug instead of ID

I'm currently trying to find a better way (in terms of usability and performance) when dealing with a situation, such as retrieving records tagged with a specific tag or category, or something like that.

A good way (the way I wanted to do this) is to retrieve the entries with the tag tag / category, so the URL will look like this:

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

fetching slug entries that looks better:

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

fetching by ID and adding a bullet behind to make it more search engine friendly. This is better in performance because fetching data using an integer id will be faster than a string. (Cmiiw)

Now, with a db schema like:

posts    post_to_tags    tags
-----    ------------    ----
id       id              id
title    post_id         name
content  tag_id          slug
...                      ...

? , , ? (, 10 000 , n - )

.

+5
2

URL db :

select ...
from   posts p
join   posts_to_tags pt on pt.post_id = p.post_id
join   tags t on t.id = pt.tag_id
where  t.slug = [url slug value];

tag.slug, ,

select ...
from   posts p
join   posts_to_tags pt on pt.post_id = p.post_id
where  pt.tag_id = [url tag ID];
+4

, ? (, " " " " ).

0

All Articles