Query optimization general algorithm and syntax tree