Added missing logic to handle the case when subquery tables are optimized away early during optimization.