Fix the resolving tve index for subquery. Fix the UNION problem. Clean up some code