```
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;
```
{
    is_rewrite |= rewriteSubquery(select_query, column_names, column_names);
}
void PredicateRewriteVisitorData::visitOtherInternalSelect(ASTSelectQuery & select_query, ASTPtr &)
{
    
    ASTPtr temp_internal_select = select_query.clone();
    ASTSelectQuery * temp_select_query = temp_internal_select->as<ASTSelectQuery>();
    size_t alias_index = 0;
    for (auto & ref_select : temp_select_query->refSelect()->children)
    {
        if (!ref_select->as<ASTAsterisk>() && !ref_select->as<ASTQualifiedAsterisk>() && !ref_select->as<ASTColumnsMatcher>() &&
            !ref_select->as<ASTIdentifier>())
        {
            if (const auto & alias = ref_select->tryGetAlias(); alias.empty())
                ref_select->setAlias("--predicate_optimizer_" + toString(alias_index++));
        }
    }
    const Names & internal_columns = InterpreterSelectQuery(
        temp_internal_select, context, SelectQueryOptions().analyze()).getSampleBlock().getNames();
    if (rewriteSubquery(*temp_select_query, column_names, internal_columns))
    {
        is_rewrite |= true;
        select_query.setExpression(ASTSelectQuery::Expression::SELECT, std::move(temp_select_query->refSelect()));
        select_query.setExpression(ASTSelectQuery::Expression::HAVING, std::move(temp_select_query->refHaving()));
    }
}
static void cleanAliasAndCollectIdentifiers(ASTPtr & predicate, std::vector<ASTIdentifier *> & identifiers)