```sql
DROP TABLE IF EXISTS tp;

create table tp (d1 Int32, d2 Int32, eventcnt Int64,
projection p (select sum(eventcnt), d1 group by d1)) 
engine = SummingMergeTree order by (d1, d2);

set allow_experimental_projection_optimization = 1, force_optimize_projection = 1;

select sum(eventcnt) eventcnt, d1
from tp
group by d1;

DB::Exception: No projection is used when allow_experimental_projection_optimization = 1.

```

The exception message is also incorrect, should be "when force_optimize_projection = 1".

sampling.filter_function = lower_function;
                }
                if (has_upper_limit)
                {
                    if (!key_condition->addCondition(sampling_key.column_names[0], Range::createRightBounded(upper, false))) 
                        throw Exception("Sampling column not in primary key", ErrorCodes::ILLEGAL_COLUMN);
                    ASTPtr args = std::make_shared<ASTExpressionList>();
                    args->children.push_back(sampling_key_ast);
                    args->children.push_back(std::make_shared<ASTLiteral>(upper));
                    upper_function = std::make_shared<ASTFunction>();
                    upper_function->name = "less";
                    upper_function->arguments = args;
                    upper_function->children.push_back(upper_function->arguments);
                    sampling.filter_function = upper_function;
                }
                if (has_lower_limit && has_upper_limit)
                {
                    ASTPtr args = std::make_shared<ASTExpressionList>();
                    args->children.push_back(lower_function);
                    args->children.push_back(upper_function);
                    sampling.filter_function = std::make_shared<ASTFunction>();
                    sampling.filter_function->name = "and";
                    sampling.filter_function->arguments = args;
                    sampling.filter_function->children.push_back(sampling.filter_function->arguments);
                }
                ASTPtr query = sampling.filter_function;
                auto syntax_result = TreeRewriter(context).analyze(query, available_real_columns);
                sampling.filter_expression = ExpressionAnalyzer(sampling.filter_function, syntax_result, context).getActionsDAG(false);
            }
        }