On Tue, 2010-09-14 at 19:08 +0200, Miha Vrhovnik wrote:
When removing/receiving new message and same in case of doveadm recalc. SELECT with key.. if not found INSERT else UPDATE
I don't think this kind of code exists anywhere? It's possible that doveadm does a SELECT, but it's not to find out if the row exists or not, it just wants to know what the current quota value is (although for quota recalc that's probably pointless and could be optimized away).
The actual row updating code works with INSERT INTO .. ON DUPLICATE KEY UPDATE .. with MySQL, and with INSERT+trigger with PostgreSQL.
unless I'm missing something upper one could be optimized to UPDATE if changed rows < 1 then INSERT
which wouldn't require the SELECT and would also spare the trigger when using postresql.
The trigger is there to avoid race conditions:
- two processes try to add the row at the same time
- one process tries to update the row when another had just deleted it