```
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;
```
{
public:
    bool is_rewrite = false;
    using TypeToVisit = ASTSelectWithUnionQuery;
    void visit(ASTSelectWithUnionQuery & union_select_query, ASTPtr &);
    static bool needChild(const ASTPtr & node, const ASTPtr &)
    {
        if (node && node->as<TypeToVisit>())
            return false;
        return true;
    }
    PredicateRewriteVisitorData(const Context & context_, const ASTs & predicates_, Names && column_names_, bool optimize_final_);
private:
    const Context & context;
    const ASTs & predicates;
    const Names column_names;
    bool optimize_final;
    void visitFirstInternalSelect(ASTSelectQuery & select_query, ASTPtr &);
    void visitOtherInternalSelect(ASTSelectQuery & select_query, ASTPtr &);
    bool rewriteSubquery(ASTSelectQuery & subquery, const Names & outer_columns, const Names & inner_columns);
};
using PredicateRewriteMatcher = OneTypeMatcher<PredicateRewriteVisitorData, PredicateRewriteVisitorData::needChild>;
using PredicateRewriteVisitor = InDepthNodeVisitor<PredicateRewriteMatcher, true>;
}