D
D
DTX2016-04-22 21:35:10
PHP
DTX, 2016-04-22 21:35:10

How to store comments ratings by users?

The sum of pluses and minuses, I think, is logical to store in the comment line. The question is how to store the pluses and minuses so that the addition / removal occurs optimally. What type of table is better to use, what indexes should be done?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
khipster, 2016-04-22
@khipster

Different entities do not need to be crammed into one cell. Just an int column. Yes, it will not affect performance in any way.

A
Artyom Karetnikov, 2016-04-23
@art_karetnikov

I would split it into two different fields if you really want maximum performance. Then it will be possible to understand how much is for, how much is against - it will be possible with a simple amount, yes. But if, with all the frankness, it is possible to store both types in one field of type int, the difference will be negligibly small. You do not need to store the amount, it is cheaper to calculate it. For: 1, against -1, normal.
But then - well, at least an IP address is useful in order to prevent one from voting several times, right? One more field.
If there is a need to store the data of their social networks, and now it is fashionable to store everything about the user in general, then there is also a field for the link to the social network and the second - to the type of this network. Total:
rid (Pkey), u_vote, u_ip, u_soc_net, u_soc_net_type.
Index only on the u_vote field within this task. If you need a selection by social networks, then the index for the type of social network.

M
Maxim Timofeev, 2016-04-22
@webinar

If you store pluses and minuses, why store the sum? And vice versa.
How is it to "store in the comment line"?
It depends on what to store, in what form, what structure and how it will be used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question