I
I
invite2010-11-15 01:28:34
Database
invite, 2010-11-15 01:28:34

Comment database architecture

Good afternoon.

There was a strange dilemma in the implementation of comments on the site.

It is assumed that there will be a large number of articles (actually not articles, but that’s not the point), and only a small part of them are relevant (frequently requested), with a short period of time these relevant ones go to the archive (without the possibility of adding new comments) and appear new. What is the best way to organize storage in a relational database for all comments, given that the main indicator is the speed of processing / issuing?

Actually, while thoughts are around two options:
- General table of comments (confuses the possible decrease in the speed of issuance in the process of table growth)
- A separate table for each article

I admit the possibility that I look at this matter from the wrong angle.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey, 2010-11-15
@invite

One table is enough. Why bother with something? Sampling by key (article ID) is very fast (for example, in my table there are about 4 million records, fetching a dozen records by key takes about 0.03 seconds).
But a bunch of tables (especially if there are a lot of articles) will quickly clog the database server table cache.
The most brakes will be when adding comments to the table, I would recommend (in the case of a muscle) to include delay_key_write in the table.

B
bishai, 2010-11-15
@bishai

Definitely one table.

W
Wott, 2010-11-15
@Wott

Don't be embarrassed and try it.
One table is quite normal. Millions of records are not a problem for a simple sample. The main thing is not to kill with stupid requests, since the comment will most likely be text, and they are not created when fetching in MEMORY. Therefore it is impossible that in request temporary on the table with them was created.

D
Dmitry Dedukhin, 2010-11-15
@Demetros

One InnoDB table can easily cope with several tens and even hundreds of millions of records - you just need enough RAM on the server.
The main thing is not to make extra keys in it, so that when adding a record there is no large-scale rebuilding of indexes.
If there is a task of searching in the text of comments, then either look towards full-text MyISAM indexes (which works much worse when writing and reading at the same time), or use specialized solutions like Sphinx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question