Re: Referential Integrity Checks with Statement-level Triggers - Mailing list pgsql-hackers

From Corey Huinker
Subject Re: Referential Integrity Checks with Statement-level Triggers
Date
Msg-id CADkLM=diwD7cQW-kvuEEVLKW-P7EN0gqDYBdUm2vGR3zd+zz-A@mail.gmail.com
Whole thread Raw
In response to Re: Referential Integrity Checks with Statement-level Triggers  (Emre Hasegeli <emre@hasegeli.com>)
Responses Re: Referential Integrity Checks with Statement-level Triggers
List pgsql-hackers
Attached is a patch that refactors DELETE triggers to fire at the statement level.

I chose delete triggers partly out of simplicity, and partly because there some before/after row linkage in the ON UPDATE CASCADE cases where statement level triggers might not be feasible as we have currently implemented them.

After having done the work, I think INSERT triggers would be similarly straightforward, but wanted to limit scope.

Also, after having stripped the delete cases out of the update-or-delete functions, it became obvious that the on-update-set-null and on-update-set-default cases differed by only 3-4 lines, so those functions were combined.

On a vagrant VM running on my desktop machine, I'm seeing a speed-up of about 25% in the benchmark provided. I think that figure is cloudy and below my expectations. Perhaps we'd get a much better picture of whether or not this is worth it on a bare metal machine, or at least a VM better suited to benchmarking.

Currently 4 make-check tests are failing. Two of which appear to false positives (the test makes assumptions about triggers that are no longer true), and the other two are outside the scope of this benchmark so I'll revisit them if we go forward.

ri-set-logic.sql is an edited benchmark script adapted from Kevin Grittner's benchmark that he ran against hand-rolled triggers and posted on 2016-11-02 
ri_test.out is a copy paste of two runs of the benchmark script.

Many thanks to everyone who helped, often despite their own objections to the overall reasoning behind the endeavor. I'm aware that a large contingent of highly experienced people would very much like to replace our entire trigger architecture, or at least divorce RI checks from triggers. Maybe this patch spurs on that change. Even if nothing comes of it, it's been a great learning experience.

On Sat, Dec 22, 2018 at 11:28 AM Emre Hasegeli <emre@hasegeli.com> wrote:
> It is far from a premature optimization IMO, it is super useful and something I was hoping would happen ever since I heard about transition tables being worked on.

Me too.  Never-ending DELETEs are a common pain point especially for
people migrated from MySQL which creates indexes for foreign keys
automatically.
Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: ArchiveEntry optional arguments refactoring
Next
From: Chapman Flack
Date:
Subject: Re: ArchiveEntry optional arguments refactoring