Indentation
Perform ExecLockIndexTuples as late as possible

Lock index tuples immediately prior to heap insertion.

The exclusive write lock acquired on a buffer by the btree code has the
potential to wreck havoc with triggers, which could easily self-deadlock when
interacting in any way with a locked index.

Note the semantics of ON DUPLICATE KEY DO NOTHING, and how it interacts with
before and after triggers.