Split key column from sort column

E.g. a view has documents of different types.
We want to sort on `(doctype, date)` but key on `ref`.