```
select version();
┌─version()───┐
│ 22.5.1.2079 │
└─────────────┘

CREATE TABLE order
(
    `ID` String,
    `Type` Enum8('TYPE_0' = 0, 'TYPE_1' = 1, 'TYPE_2' = 2),
    `Num` UInt64,
    `Data` String,
    `RowCreatedAt` DateTime DEFAULT now()
)
ENGINE = ReplacingMergeTree()
PARTITION BY toYYYYMMDD(RowCreatedAt)
PRIMARY KEY ID
ORDER BY (ID, Type, Num)
TTL RowCreatedAt + toIntervalWeek(6)
SETTINGS index_granularity = 8192;

insert into order (ID, Type, Num, Data, RowCreatedAt) select toString(cityHash64(ID)%2000), case cityHash64(ID)%3 when 0 then 'TYPE_0' when 1 then 'TYPE_1' when 2 then 'TYPE_2' ELSE 'TYPE_0' END, cityHash64(ID), ID, toDateTime(toUInt32(now()) - round(rand32() / 4294967295 * 4100000, 0))  from generateRandom('ID String ', 1, 1000) limit 100000;
insert into order (ID, Type, Num, Data, RowCreatedAt) select toString(cityHash64(ID)%2000), case cityHash64(ID)%3 when 0 then 'TYPE_0' when 1 then 'TYPE_1' when 2 then 'TYPE_2' ELSE 'TYPE_0' END, cityHash64(ID), ID, toDateTime(toUInt32(now()) - round(rand32() / 4294967295 * 4100000, 0))  from generateRandom('ID String ', 1, 1000) limit 100000;
insert into order (ID, Type, Num, Data, RowCreatedAt) select toString(cityHash64(ID)%2000), case cityHash64(ID)%3 when 0 then 'TYPE_0' when 1 then 'TYPE_1' when 2 then 'TYPE_2' ELSE 'TYPE_0' END, cityHash64(ID), ID, toDateTime(toUInt32(now()) - round(rand32() / 4294967295 * 4100000, 0))  from generateRandom('ID String ', 1, 1000) limit 100000;
insert into order (ID, Type, Num, Data, RowCreatedAt) select toString(cityHash64(ID)%2000), case cityHash64(ID)%3 when 0 then 'TYPE_0' when 1 then 'TYPE_1' when 2 then 'TYPE_2' ELSE 'TYPE_0' END, cityHash64(ID), ID, toDateTime(toUInt32(now()) - round(rand32() / 4294967295 * 4100000, 0))  from generateRandom('ID String ', 1, 1000) limit 100000;
insert into order (ID, Type, Num, Data, RowCreatedAt) select toString(cityHash64(ID)%2000), case cityHash64(ID)%3 when 0 then 'TYPE_0' when 1 then 'TYPE_1' when 2 then 'TYPE_2' ELSE 'TYPE_0' END, cityHash64(ID), ID, toDateTime(toUInt32(now()) - round(rand32() / 4294967295 * 4100000, 0))  from generateRandom('ID String ', 1, 1000) limit 100000;
insert into order (ID, Type, Num, Data, RowCreatedAt) select toString(cityHash64(ID)%2000), case cityHash64(ID)%3 when 0 then 'TYPE_0' when 1 then 'TYPE_1' when 2 then 'TYPE_2' ELSE 'TYPE_0' END, cityHash64(ID), ID, toDateTime(toUInt32(now()) - round(rand32() / 4294967295 * 4100000, 0))  from generateRandom('ID String ', 1, 1000) limit 100000;
insert into order (ID, Type, Num, Data, RowCreatedAt) select toString(cityHash64(ID)%2000), case cityHash64(ID)%3 when 0 then 'TYPE_0' when 1 then 'TYPE_1' when 2 then 'TYPE_2' ELSE 'TYPE_0' END, cityHash64(ID), ID, toDateTime(toUInt32(now()) - round(rand32() / 4294967295 * 4100000, 0))  from generateRandom('ID String ', 1, 1000) limit 100000;
insert into order (ID, Type, Num, Data, RowCreatedAt) select toString(cityHash64(ID)%2000), case cityHash64(ID)%3 when 0 then 'TYPE_0' when 1 then 'TYPE_1' when 2 then 'TYPE_2' ELSE 'TYPE_0' END, cityHash64(ID), ID, toDateTime(toUInt32(now()) - round(rand32() / 4294967295 * 4100000, 0))  from generateRandom('ID String ', 1, 1000) limit 100000;
insert into order (ID, Type, Num, Data, RowCreatedAt) select toString(cityHash64(ID)%2000), case cityHash64(ID)%3 when 0 then 'TYPE_0' when 1 then 'TYPE_1' when 2 then 'TYPE_2' ELSE 'TYPE_0' END, cityHash64(ID), ID, toDateTime(toUInt32(now()) - round(rand32() / 4294967295 * 4100000, 0))  from generateRandom('ID String ', 1, 1000) limit 100000;

select count(*) from order;
┌─count()─┐
│  892441 │
└─────────┘

set optimize_move_to_prewhere = 0;
SELECT Data
FROM order
WHERE (ID = '1') AND (Type = 'TYPE_1')
ORDER BY Num ASC
FORMAT `Null`

Ok.

set optimize_move_to_prewhere = 1;
SELECT Data
FROM order
WHERE (ID = '1') AND (Type = 'TYPE_1')
ORDER BY Num ASC
FORMAT `Null`

Received exception from server (version 22.5.1):
Code: 10. DB::Exception: Received from localhost:9000. DB::Exception: Not found column Type in block. There are only columns: ID, Num, equals(Type, 'TYPE_1'), Data. (NOT_FOUND_COLUMN_IN_BLOCK)

```
{
    ExpressionActionsChain::Step & step = chain.lastStep(columns_after_array_join);
    getRootActions(analyzedJoin().leftKeysList(), only_types, step.actions());
    return true;
}
JoinPtr SelectQueryExpressionAnalyzer::appendJoin(
    ExpressionActionsChain & chain,
    ActionsDAGPtr & converting_join_columns)
{
    const ColumnsWithTypeAndName & left_sample_columns = chain.getLastStep().getResultColumns();
    JoinPtr join = makeJoin(*syntax->ast_join, left_sample_columns, converting_join_columns);
    if (converting_join_columns)
    {
        chain.steps.push_back(std::make_unique<ExpressionActionsChain::ExpressionActionsStep>(converting_join_columns));
        chain.addStep();
    }
    ExpressionActionsChain::Step & step = chain.lastStep(columns_after_array_join);
    chain.steps.push_back(std::make_unique<ExpressionActionsChain::JoinStep>(
        syntax->analyzed_join, join, step.getResultColumns()));
    chain.addStep();
    return join;
}
static ActionsDAGPtr createJoinedBlockActions(ContextPtr context, const TableJoin & analyzed_join)
{
    ASTPtr expression_list = analyzed_join.rightKeysList();
    auto syntax_result = TreeRewriter(context).analyze(expression_list, analyzed_join.columnsFromJoinedTable());
    return ExpressionAnalyzer(expression_list, syntax_result, context).getActionsDAG(true, false);
}
static std::shared_ptr<IJoin> chooseJoinAlgorithm(std::shared_ptr<TableJoin> analyzed_join, const Block & right_sample_block, ContextPtr context)