Use KeyComparable for checking self-reference

Includes #1226 as both need NULL handling in MKeyComparable.

Last commit is the new change, entirely in ConstraintHandler.