Optimize updating a row that's locked by same xid
Optimize updating a row that's locked by same xid

Updating or locking a row that was already locked by the same
transaction under the same Xid caused a MultiXact to be created; but
this is unnecessary, because there's no usefulness in being able to
differentiate two locks by the same transaction.  In particular, if a
transaction executed SELECT FOR UPDATE followed by an UPDATE that didn't
modify columns of the key, we would dutifully represent the resulting
combination as a multixact -- even though a single key-update is
sufficient.

Optimize the case so that only the strongest of both locks/updates is
represented in Xmax.  This can save some Xmax's from becoming
MultiXacts, which can be a significant optimization.

This missed optimization opportunity was spotted by Andres Freund while
investigating a bug reported by Oliver Seemann in message
CANCipfpfzoYnOz5jj=UZ70_R=CwDHv36dqWSpwsi27vpm1z5sA@mail.gmail.com
and also directly as a performance regression reported by Dong Ye in
message
d54b8387.000012d8.00000010@YED-DEVD1.vmware.com
Reportedly, this patch fixes the performance regression.

Since the missing optimization was reported as a significant performance
regression from 9.2, backpatch to 9.3.

Andres Freund, tweaked by Álvaro Herrera

techdragon/Postgres-XL,jmcatamney/gpdb,ovr/postgres-xl,greenplum-db/gpdb,xinzweb/gpdb,yazun/postgres-xl,yazun/postgres-xl,Postgres-XL/Postgres-XL,50wu/gpdb,lisakowen/gpdb,lisakowen/gpdb,lisakowen/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,yazun/postgres-xl,pavanvd/postgres-xl,oberstet/postgres-xl,pavanvd/postgres-xl,oberstet/postgres-xl,xinzweb/gpdb,ashwinstar/gpdb,Postgres-XL/Postgres-XL,adam8157/gpdb,greenplum-db/gpdb,oberstet/postgres-xl,oberstet/postgres-xl,50wu/gpdb,50wu/gpdb,techdragon/Postgres-XL,adam8157/gpdb,adam8157/gpdb,jmcatamney/gpdb,lisakowen/gpdb,50wu/gpdb,lisakowen/gpdb,ashwinstar/gpdb,adam8157/gpdb,lisakowen/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,zeroae/postgres-xl,50wu/gpdb,ovr/postgres-xl,50wu/gpdb,adam8157/gpdb,xinzweb/gpdb,ashwinstar/gpdb,zeroae/postgres-xl,50wu/gpdb,yazun/postgres-xl,techdragon/Postgres-XL,lisakowen/gpdb,xinzweb/gpdb,ashwinstar/gpdb,ovr/postgres-xl,zeroae/postgres-xl,ashwinstar/gpdb,zeroae/postgres-xl,greenplum-db/gpdb,pavanvd/postgres-xl,Postgres-XL/Postgres-XL,50wu/gpdb,jmcatamney/gpdb,ovr/postgres-xl,xinzweb/gpdb,Postgres-XL/Postgres-XL,ovr/postgres-xl,adam8157/gpdb,techdragon/Postgres-XL,ashwinstar/gpdb,yazun/postgres-xl,techdragon/Postgres-XL,jmcatamney/gpdb,xinzweb/gpdb,adam8157/gpdb,pavanvd/postgres-xl,pavanvd/postgres-xl,oberstet/postgres-xl,adam8157/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,greenplum-db/gpdb,Postgres-XL/Postgres-XL,zeroae/postgres-xl,greenplum-db/gpdb,xinzweb/gpdb,xinzweb/gpdb,lisakowen/gpdb