Remove unnecessary checks when flattening ors and ands
Move expression reordering in Ors from query graph builder to ast rewriting