fdo#78079: Write test for this.

Change-Id: I3d3fc54cb433ec60d51341c3b4a077414a99a14c
fdo#78079: Re-work sort by column to get it to do the right thing.

Also fixed reference update problem.

Change-Id: I06e6115ef969a011fdd5c92d5eb1927fb7ae789b