Get rid of the extra flag, use the subquery flag instead; Add test cases for temp table count query optimization;