query reordering magic