←back to thread

570 points davidgu | 3 comments | | HN request time: 0s | source
Show context
polote ◴[] No.44525307[source]
Rls and triggers dont scale either
replies(2): >>44525677 #>>44525805 #
shivasaxena ◴[] No.44525677[source]
Yeah, I'm going to remove triggers in next deploy of a POS system since they are adding 10-50ms to each insert.

Becomes a problem if you are inserting 40 items to order_items table.

replies(5): >>44525741 #>>44526565 #>>44526644 #>>44526757 #>>44526964 #
candiddevmike ◴[] No.44526644[source]
How do you handle trigger logic that compares old/new without having a round trip back to the application?
replies(1): >>44527025 #
SoftTalker ◴[] No.44527025[source]
Do it in a stored procedure not a trigger. Triggers have their place but a stored procedure is almost always better. Triggers can surprise you.
replies(1): >>44527147 #
1. candiddevmike ◴[] No.44527147[source]
I don't follow how you would do that in a stored procedure outside of a trigger.
replies(1): >>44527554 #
2. const_cast ◴[] No.44527554[source]
I think instead of performing an INSERT you call a stored proc that does the insert and some extra stuff.
replies(1): >>44535087 #
3. shivasaxena ◴[] No.44535087[source]
Yes, we already have all of our business logic in postgres functions(create_order, create_partial_payment etc).

Doing the extra work in stored procedures is noticeably faster than relying on triggers.