I
I
ink2011-04-12 15:10:30
MySQL
ink, 2011-04-12 15:10:30

What is the best way to implement content tagging on the site?

There are 2 options.
1. Make it a classic schema of 3 database tables; content_table, tags_table, content_to_tags_table.
Where the first table is the content table, the second table is the tags, and the last is the links between content and tags.
2. Make 2 tables content_table, tags_table. The first table is identical to the one in the first case. The structure of the 2nd table is as follows:
CREATE TABLE `dr_test`.`tags_table` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`content_id` INT NOT NULL,
`term` VARCHAR( 255 ) NOT NULL,
INDEX ( `term` )
) ENGINE=MYISAM;
That is, the value of the `term` field will be an index and will be repeated the number of times that the content was tagged with it.
example:
id | content_id | term
1 | 1 | some_tag
2 | 2 | some_tag
the question is, is it worth using the 2nd option in terms of database performance?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
Borro, 2011-04-12
@Borro

From the point of view of database performance, you can use the first method, but cache the tags_table table in memory and match in php, here the database will have to work with smaller amounts of data, and it will also give you less volume, which will affect the speed of work.

L
lalaki, 2011-04-12
@lalaki

if you do it on some framework, for example, Symfony, or at least use an ORM like Doctrine, the solution is obvious: first use the default ORM mechanisms - they will give a trivial solution, i.e. most likely option 1. And you do optimization as needed, looking at the profiler

M
Masterkey, 2011-04-12
@Masterkey

I wanted to write a panel, and then I thought that you did not write the key points for solving the problem.
expected frequency in each of the tables
SELECT~UPDATE~DELETE~INSERT
what are they?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question