Repository: ClickHouse/ClickHouse
File: src/Interpreters/Context.h (C/C++)

Code before:
    /// Id of initiating query for distributed queries; or current query id if it's not a distributed query.
    String getInitialQueryId() const;

    void setCurrentDatabase(const String & name);
    /// Set current_database for global context. We don't validate that database
    /// exists because it should be set before databases loading.
    void setCurrentDatabaseNameInGlobalContext(const String & name);
    void setCurrentQueryId(const String & query_id);

    void killCurrentQuery() const;
    bool isCurrentQueryKilled() const;

    bool hasInsertionTable() const { return !insertion_table_info.table.empty(); }
    bool hasInsertionTableColumnNames() const { return insertion_table_info.column_names.has_value(); }
    bool hasInsertionTableColumnsDescription() const { return insertion_table_info.columns_description.has_value(); }
    void setInsertionTable(StorageID db_and_table, std::optional<Names> column_names = std::nullopt, std::optional<ColumnsDescription> column_description = std::nullopt);
    const StorageID & getInsertionTable() const { return insertion_table_info.table; }
    const std::optional<Names> & getInsertionTableColumnNames() const{ return insertion_table_info.column_names; }
    const std::optional<ColumnsDescription> & getInsertionTableColumnsDescription() const { return insertion_table_info.columns_description; }

    void setDistributed(bool is_distributed_) { is_distributed = is_distributed_; }
    bool isDistributed() const { return is_distributed; }

    bool isUnderRestore() const { return is_under_restore; }
    void setUnderRestore(bool under_restore) { is_under_restore = under_restore; }

    String getDefaultFormat() const;    /// If default_format is not specified, some global default format is returned.
    void setDefaultFormat(const String & name);

    String getInsertFormat() const;
    void setInsertFormat(const String & name);

    MultiVersion<Macros>::Version getMacros() const;
    void setMacros(std::unique_ptr<Macros> && macros);

    bool displaySecretsInShowAndSelect() const;
    Settings getSettingsCopy() const;
    const Settings & getSettingsRef() const { return *settings; }
    void setSettings(const Settings & settings_);

    /// Set settings by name.
    void setSetting(std::string_view name, const String & value);
    void setSetting(std::string_view name, const Field & value);
    void setServerSetting(std::string_view name, const Field & value);
    void applySettingChange(const SettingChange & change);
    void applySettingsChanges(const SettingsChanges & changes);

    /// Checks the constraints.
    void checkSettingsConstraints(const AlterSettingsProfileElements & profile_elements, SettingSource source);
    void checkSettingsConstraints(const SettingChange & change, SettingSource source);
    void checkSettingsConstraints(const SettingsChanges & changes, SettingSource source);

Review comment (suggestion):
`ColumnsDescription` here looks like query metadata and is typically expected to be immutable once captured. Exposing it as `std::shared_ptr<ColumnsDescription>` allows mutation through shared ownership and makes it harder to reason about safety. Consider switching to `std::shared_ptr<const ColumnsDescription>` (and updating setter/getter accordingly) to enforce immutability and prevent accidental modification.

Code after:

    void addViewSource(const StoragePtr & storage);
    StoragePtr getViewSource() const;

    String getCurrentDatabase() const;
    String getCurrentQueryId() const { return client_info.current_query_id; }

    /// Id of initiating query for distributed queries; or current query id if it's not a distributed query.
    String getInitialQueryId() const;

    void setCurrentDatabase(const String & name);
    /// Set current_database for global context. We don't validate that database
    /// exists because it should be set before databases loading.
    void setCurrentDatabaseNameInGlobalContext(const String & name);
    void setCurrentQueryId(const String & query_id);

    void killCurrentQuery() const;
    bool isCurrentQueryKilled() const;

    bool hasInsertionTable() const { return !insertion_table_info.table.empty(); }
    bool hasInsertionTableColumnNames() const { return insertion_table_info.column_names.has_value(); }
    bool hasInsertionTableColumnsDescription() const { return insertion_table_info.columns_description != nullptr; }
    void setInsertionTable(StorageID db_and_table, std::optional<Names> column_names = std::nullopt, std::shared_ptr<ColumnsDescription> column_description = nullptr);
    const StorageID & getInsertionTable() const { return insertion_table_info.table; }
    const std::optional<Names> & getInsertionTableColumnNames() const{ return insertion_table_info.column_names; }
    const std::shared_ptr<ColumnsDescription> & getInsertionTableColumnsDescription() const { return insertion_table_info.columns_description; }

    void setDistributed(bool is_distributed_) { is_distributed = is_distributed_; }
    bool isDistributed() const { return is_distributed; }

    bool isUnderRestore() const { return is_under_restore; }
    void setUnderRestore(bool under_restore) { is_under_restore = under_restore; }

    String getDefaultFormat() const;    /// If default_format is not specified, some global default format is returned.
    void setDefaultFormat(const String & name);

    String getInsertFormat() const;
    void setInsertFormat(const String & name);

    MultiVersion<Macros>::Version getMacros() const;
    void setMacros(std::unique_ptr<Macros> && macros);

    bool displaySecretsInShowAndSelect() const;
    Settings getSettingsCopy() const;
    const Settings & getSettingsRef() const { return *settings; }
    void setSettings(const Settings & settings_);

    /// Set settings by name.
    void setSetting(std::string_view name, const String & value);
    void setSetting(std::string_view name, const Field & value);
    void setServerSetting(std::string_view name, const Field & value);