Code review comment: We can set it, but we don't need to use it.

Code under review:
public List<OptExpression> transform(OptExpression input, OptimizerContext context) {
        LogicalScanOperator scanOperator = (LogicalScanOperator) input.getOp();
        ColumnRefSet requiredOutputColumns = context.getTaskContext().getRequiredColumns();

        
        
        Set<ColumnRefOperator> outputColumns =
                scanOperator.getColRefToColumnMetaMap().keySet().stream().filter(requiredOutputColumns::contains)
                        .collect(Collectors.toSet());
        outputColumns.addAll(Utils.extractColumnRef(scanOperator.getPredicate()));
        boolean canUseAnyColumn = false;
        if (outputColumns.size() == 0) {
            outputColumns.add(Utils.findSmallestColumnRef(
                    new ArrayList<>(scanOperator.getColRefToColumnMetaMap().keySet())));
            canUseAnyColumn = true;
        }

        if (!context.getSessionVariable().isEnableCountStarOptimization()) {
            canUseAnyColumn = false;
        }

        if (scanOperator.getColRefToColumnMetaMap().keySet().equals(outputColumns)) {
            scanOperator.setCanUseAnyColumn(canUseAnyColumn);
            return Collections.emptyList();
        } else {
            Map<ColumnRefOperator, Column> newColumnRefMap = outputColumns.stream()
                    .collect(Collectors.toMap(identity(), scanOperator.getColRefToColumnMetaMap()::get));
            if (scanOperator instanceof LogicalOlapScanOperator) {
                LogicalOlapScanOperator olapScanOperator = (LogicalOlapScanOperator) scanOperator;

                LogicalOlapScanOperator.Builder builder = new LogicalOlapScanOperator.Builder();
                LogicalOlapScanOperator newScanOperator = builder.withOperator(olapScanOperator)
                        .setColRefToColumnMetaMap(newColumnRefMap).build();
                newScanOperator.setCanUseAnyColumn(canUseAnyColumn);
                return Lists.newArrayList(new OptExpression(newScanOperator));
            } else {
                LogicalScanOperator.Builder builder = OperatorBuilderFactory.build(scanOperator);
                scanOperator.setCanUseAnyColumn(canUseAnyColumn);
                Operator newScanOperator =
                        builder.withOperator(scanOperator).setColRefToColumnMetaMap(newColumnRefMap).build();
                return Lists.newArrayList(new OptExpression(newScanOperator));
            }
        }
    }

Line commented on: boolean canUseAnyColumn = false;

Revised code:
public List<OptExpression> transform(OptExpression input, OptimizerContext context) {
        LogicalScanOperator scanOperator = (LogicalScanOperator) input.getOp();
        ColumnRefSet requiredOutputColumns = context.getTaskContext().getRequiredColumns();

        
        
        Set<ColumnRefOperator> outputColumns =
                scanOperator.getColRefToColumnMetaMap().keySet().stream().filter(requiredOutputColumns::contains)
                        .collect(Collectors.toSet());
        outputColumns.addAll(Utils.extractColumnRef(scanOperator.getPredicate()));
        boolean canUseAnyColumn = false;
        if (outputColumns.size() == 0) {
            outputColumns.add(Utils.findSmallestColumnRef(
                    new ArrayList<>(scanOperator.getColRefToColumnMetaMap().keySet())));
            canUseAnyColumn = true;
        }

        if (!context.getSessionVariable().isEnableCountStarOptimization()) {
            canUseAnyColumn = false;
        }

        if (scanOperator.getColRefToColumnMetaMap().keySet().equals(outputColumns)) {
            scanOperator.setCanUseAnyColumn(canUseAnyColumn);
            return Collections.emptyList();
        } else {
            Map<ColumnRefOperator, Column> newColumnRefMap = outputColumns.stream()
                    .collect(Collectors.toMap(identity(), scanOperator.getColRefToColumnMetaMap()::get));
            if (scanOperator instanceof LogicalOlapScanOperator) {
                LogicalOlapScanOperator olapScanOperator = (LogicalOlapScanOperator) scanOperator;

                LogicalOlapScanOperator.Builder builder = new LogicalOlapScanOperator.Builder();
                LogicalOlapScanOperator newScanOperator = builder.withOperator(olapScanOperator)
                        .setColRefToColumnMetaMap(newColumnRefMap).build();
                newScanOperator.setCanUseAnyColumn(canUseAnyColumn);
                return Lists.newArrayList(new OptExpression(newScanOperator));
            } else {
                LogicalScanOperator.Builder builder = OperatorBuilderFactory.build(scanOperator);
                scanOperator.setCanUseAnyColumn(canUseAnyColumn);
                Operator newScanOperator =
                        builder.withOperator(scanOperator).setColRefToColumnMetaMap(newColumnRefMap).build();
                return Lists.newArrayList(new OptExpression(newScanOperator));
            }
        }
    }