As discussed with @kitaisreal 
{
    if (hasPrimaryKey())
        return primary_key.expression->getRequiredColumns();
    return {};
}
Names StorageInMemoryMetadata::getPrimaryKeyColumns() const
{
    if (!primary_key.column_names.empty())
        return primary_key.column_names;
    return {};
}
ASTPtr StorageInMemoryMetadata::getSettingsChanges() const
{
    if (settings_changes)
        return settings_changes->clone();
    return nullptr;
}
const SelectQueryDescription & StorageInMemoryMetadata::getSelectQuery() const
{
    return select;
}
bool StorageInMemoryMetadata::hasSelectQuery() const
{
    return select.select_query != nullptr;
}
namespace
{
    using NamesAndTypesMap = DenseHashMap<StringRef, const IDataType *, StringRefHash>;
    using UniqueStrings = DenseHashSet<StringRef, StringRefHash>;
    String listOfColumns(const NamesAndTypesList & available_columns)