/* * Copyright (C) 2015-present ScyllaDB * * Modified by ScyllaDB */ /* * SPDX-License-Identifier: (LicenseRef-ScyllaDB-Source-Available-1.0 and Apache-2.0) */ #pragma once #include "schema_altering_statement.hh" #include "index_target.hh" #include "schema/schema_fwd.hh" #include #include namespace cql3 { class query_processor; class index_name; namespace statements { class index_prop_defs; /** A CREATE INDEX statement parsed from a CQL query. */ class create_index_statement : public schema_altering_statement { const sstring _index_name; const std::vector<::shared_ptr> _raw_targets; const ::shared_ptr _properties; const bool _if_not_exists; cql_stats* _cql_stats = nullptr; public: create_index_statement(cf_name name, ::shared_ptr index_name, std::vector<::shared_ptr> raw_targets, ::shared_ptr properties, bool if_not_exists); future<> check_access(query_processor& qp, const service::client_state& state) const override; void validate(query_processor&, const service::client_state& state) const override; future, utils::chunked_vector, cql3::cql_warnings_vec>> prepare_schema_mutations(query_processor& qp, const query_options& options, api::timestamp_type) const override; virtual std::unique_ptr prepare(data_dictionary::database db, cql_stats& stats) override; struct base_schema_with_new_index { schema_ptr schema; index_metadata index; }; std::optional build_index_schema(data_dictionary::database db) const; view_ptr create_view_for_index(const schema_ptr, const index_metadata& im, const data_dictionary::database&) const; private: void validate_for_local_index(const schema& schema) const; void validate_for_frozen_collection(const index_target& target) const; void validate_not_full_index(const index_target& target) const; void validate_for_collection(const index_target& target, const column_definition&) const; void rewrite_target_for_collection(index_target& target, const column_definition&) const; void validate_is_values_index_if_target_column_not_collection(const column_definition* cd, const index_target& target) const; void validate_target_column_is_map_if_index_involves_keys(bool is_map, const index_target& target) const; void validate_targets_for_multi_column_index(std::vector<::shared_ptr> targets) const; static index_metadata make_index_metadata(const std::vector<::shared_ptr>& targets, const sstring& name, index_metadata_kind kind, const index_options_map& options); std::vector<::shared_ptr> validate_while_executing(data_dictionary::database db) const; }; } }