Answer the question
In order to leave comments, you need to log in
postgresql keys and triggers. What is better to use for what?
I ask as a noob in posgresql, who came from mysql forests.
There
are 2 tables:
[conversation conversations]
id
last_message_id
message_counter
[
message messages]
id
conversation_id adding/deleting a message, the last_message_id should change - probably a trigger? Or is it possible to do some auto-updating through the views (view)?
When adding, increase (increase, not recalculate - does not change when removed) message_counter - probably a trigger?
Answer the question
In order to leave comments, you need to log in
In my opinion, triggers are evil! If perishing and triggers, then only for data validation. Otherwise, under heavy loads, you can get unpredictable system behavior, deadlocks, and performance degradation.
In your case, the last_message_id and message_counter fields can be calculated by additional queries and they have nothing to do in the table at all, just make an index.
Ready for discussion!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question