fdo#81309: Adjust references during sort.

(cherry picked from commit 5c6ee09126631342939ae8766fe36083d8c011e3)

Conflicts:
	sc/inc/sortparam.hxx
	sc/source/ui/docshell/dbdocfun.cxx
	sc/source/ui/undo/undodat.cxx

Change-Id: I2b98610f6b774400ecfaffe2905201c27fcab33f
Reviewed-on: https://gerrit.libreoffice.org/10305
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>