```
drop table IF EXISTS numbers_indexed;
drop table IF EXISTS squares;

create table numbers_indexed Engine=MergeTree ORDER BY number PARTITION BY bitShiftRight(number,8) SETTINGS index_granularity=8 AS SELECT * FROM numbers(16384); 

CREATE VIEW squares AS WITH number*2 AS square_number SELECT number, square_number FROM numbers_indexed;

SET max_rows_to_read=8, read_overflow_mode='throw';

-- ok
WITH number*2 AS square_number SELECT number, square_number FROM numbers_indexed WHERE number = 999;

-- fail
SELECT * FROM squares WHERE number = 999;
```
{
    if ((!optimize_final && subquery.final())
        || subquery.with() || subquery.withFill()
        || subquery.limitBy() || subquery.limitLength()
        || hasStatefulFunction(subquery.select(), context))
        return false;
    for (const auto & predicate : predicates)
    {
        std::vector<ASTIdentifier *> identifiers;
        ASTPtr optimize_predicate = predicate->clone();
        cleanAliasAndCollectIdentifiers(optimize_predicate, identifiers);
        for (const auto & identifier : identifiers)
        {
            const auto & column_name = identifier->shortName();
            const auto & outer_column_iterator = std::find(outer_columns.begin(), outer_columns.end(), column_name);
            
            
            if (outer_column_iterator != outer_columns.end())
                identifier->setShortName(inner_columns[outer_column_iterator - outer_columns.begin()]);
        }
        
        
        subquery.setExpression(ASTSelectQuery::Expression::HAVING,
            subquery.having() ? makeASTFunction("and", optimize_predicate, subquery.having()) : optimize_predicate);
    }
    return true;
}
}