**Describe the bug**

The query:
```
SELECT
    (current_database = currentDatabase()) AND (type = 0),
    ((current_database = currentDatabase()) AND (type = NULL)) AND (type = NULL) AND ((current_database = currentDatabase()) AND (type = 1048575)) AND (type = NULL) AND (event_date >= yesterday())
FROM system.query_log
ARRAY JOIN ProfileEvents
WHERE ProfileEvents AND (current_database = currentDatabase())
ORDER BY event_time DESC NULLS FIRST
LIMIT 0
```
crashes the server.

Most likely introduced here: #16618
}
                    }
                    NameAndTypePair key{column_name, node->result_type};
                    
                    if (!unique_keys.count(key.name))
                    {
                        unique_keys.insert(key.name);
                        aggregation_keys.push_back(key);
                        
                        aggregated_columns.push_back(std::move(key));
                    }
                }
                if (group_asts.empty())
                {
                    select_query->setExpression(ASTSelectQuery::Expression::GROUP_BY, {});
                    has_aggregation = select_query->having() || !aggregate_descriptions.empty();
                }
            }
        }
        else
            aggregated_columns = temp_actions->getNamesAndTypesList();
        for (const auto & desc : aggregate_descriptions)
            aggregated_columns.emplace_back(desc.column_name, desc.function->getReturnType());
    }
    else
    {
        aggregated_columns = temp_actions->getNamesAndTypesList();
    }
}
void ExpressionAnalyzer::initGlobalSubqueriesAndExternalTables(bool do_global)