```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".

if (no_data || (!has_lower_limit && !has_upper_limit))
            {
                sampling.use_sampling = false;
            }
            else
            {
                
                std::shared_ptr<ASTFunction> lower_function;
                std::shared_ptr<ASTFunction> upper_function;
                
                
                
                ASTPtr sampling_key_ast = metadata_snapshot->getSamplingKeyAST();
                if (select.final())
                {
                    sampling_key_ast = std::make_shared<ASTIdentifier>(sampling_key.column_names[0]);
                    
                    available_real_columns.emplace_back(sampling_key.column_names[0], std::move(sampling_column_type));
                }
                if (has_lower_limit)
                {
                    if (!key_condition->addCondition(sampling_key.column_names[0], Range::createLeftBounded(lower, true))) 
                        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>(lower));
                    lower_function = std::make_shared<ASTFunction>();
                    lower_function->name = "greaterOrEquals";
                    lower_function->arguments = args;
                    lower_function->children.push_back(lower_function->arguments);