ENG-5616 fix indexing of self-joins and grouping based on index ordering