cql3: const cleanups and API de-pointerization

* Pass raw::select_statement::parameters as lw_shared_ptr
 * Some more const cleanups here and there
 * lists,maps,sets::equals now accept const-ref to *_type_impl
   instead of shared_ptr
 * Remove unused `get_column_for_condition` from modification_statement.hh
 * More methods now accept const-refs instead of shared_ptr

Every call site where a shared_ptr was required as an argument
has been inspected to be sure that no dangling references are
possible.

Tests: unit(dev, debug)

Signed-off-by: Pavel Solodovnikov <pa.solodovnikov@scylladb.com>
Message-Id: <20200220153204.279940-1-pa.solodovnikov@scylladb.com>
This commit is contained in:
Pavel Solodovnikov
2020-02-20 18:32:04 +03:00
committed by Avi Kivity
parent df2f67626b
commit 8efb02146f
44 changed files with 224 additions and 231 deletions

View File

@@ -408,7 +408,7 @@ selectStatement returns [shared_ptr<raw::select_statement> expr]
( K_ALLOW K_FILTERING { allow_filtering = true; } )?
( K_BYPASS K_CACHE { bypass_cache = true; })?
{
auto params = ::make_shared<raw::select_statement::parameters>(std::move(orderings), is_distinct, allow_filtering, is_json, bypass_cache);
auto params = make_lw_shared<raw::select_statement::parameters>(std::move(orderings), is_distinct, allow_filtering, is_json, bypass_cache);
$expr = ::make_shared<raw::select_statement>(std::move(cf), std::move(params),
std::move(sclause), std::move(wclause), std::move(limit), std::move(per_partition_limit),
std::move(gbcolumns));

View File

@@ -80,12 +80,12 @@ column_identifier::raw::raw(sstring raw_text, bool keep_case)
}
}
::shared_ptr<selection::selectable> column_identifier::raw::prepare(const schema& s) {
::shared_ptr<selection::selectable> column_identifier::raw::prepare(const schema& s) const {
return prepare_column_identifier(s);
}
::shared_ptr<column_identifier>
column_identifier::raw::prepare_column_identifier(const schema& schema) {
column_identifier::raw::prepare_column_identifier(const schema& schema) const {
if (schema.regular_column_name_type() == utf8_type) {
return ::make_shared<column_identifier>(_text, true);
}

View File

@@ -112,9 +112,9 @@ private:
public:
raw(sstring raw_text, bool keep_case);
virtual ::shared_ptr<selectable> prepare(const schema& s) override;
virtual ::shared_ptr<selectable> prepare(const schema& s) const override;
::shared_ptr<column_identifier> prepare_column_identifier(const schema& s);
::shared_ptr<column_identifier> prepare_column_identifier(const schema& s) const;
virtual bool processes_selection() const override;

View File

@@ -165,13 +165,13 @@ lists::value::get_with_protocol_version(cql_serialization_format sf) {
}
bool
lists::value::equals(shared_ptr<list_type_impl> lt, const value& v) {
lists::value::equals(const list_type_impl& lt, const value& v) {
if (_elements.size() != v._elements.size()) {
return false;
}
return std::equal(_elements.begin(), _elements.end(),
v._elements.begin(),
[t = lt->get_elements_type()] (const bytes_opt& e1, const bytes_opt& e2) { return t->equal(*e1, *e2); });
[t = lt.get_elements_type()] (const bytes_opt& e1, const bytes_opt& e2) { return t->equal(*e1, *e2); });
}
const std::vector<bytes_opt>&

View File

@@ -83,7 +83,7 @@ public:
static value from_serialized(const fragmented_temporary_buffer::view& v, const list_type_impl& type, cql_serialization_format sf);
virtual cql3::raw_value get(const query_options& options) override;
virtual bytes get_with_protocol_version(cql_serialization_format sf) override;
bool equals(shared_ptr<list_type_impl> lt, const value& v);
bool equals(const list_type_impl& lt, const value& v);
virtual const std::vector<bytes_opt>& get_elements() const override;
virtual sstring to_string() const;
friend class lists;

View File

@@ -196,12 +196,12 @@ maps::value::get_with_protocol_version(cql_serialization_format sf) {
}
bool
maps::value::equals(map_type mt, const value& v) {
maps::value::equals(const map_type_impl& mt, const value& v) {
return std::equal(map.begin(), map.end(),
v.map.begin(), v.map.end(),
[mt] (auto&& e1, auto&& e2) {
return mt->get_keys_type()->compare(e1.first, e2.first) == 0
&& mt->get_values_type()->compare(e1.second, e2.second) == 0;
[&mt] (auto&& e1, auto&& e2) {
return mt.get_keys_type()->compare(e1.first, e2.first) == 0
&& mt.get_values_type()->compare(e1.second, e2.second) == 0;
});
}

View File

@@ -84,7 +84,7 @@ public:
static value from_serialized(const fragmented_temporary_buffer::view& value, const map_type_impl& type, cql_serialization_format sf);
virtual cql3::raw_value get(const query_options& options) override;
virtual bytes get_with_protocol_version(cql_serialization_format sf);
bool equals(map_type mt, const value& v);
bool equals(const map_type_impl& mt, const value& v);
virtual sstring to_string() const;
};

View File

@@ -144,7 +144,7 @@ protected:
std::transform(rs.begin(), rs.end(), col_specs.begin(), [] (auto cs) {
return cs->column_specification;
});
auto t = to_term(col_specs, get_value(), db, schema->ks_name(), bound_names);
auto t = to_term(col_specs, *get_value(), db, schema->ks_name(), bound_names);
return ::make_shared<restrictions::multi_column_restriction::EQ>(schema, rs, t);
}
@@ -156,7 +156,7 @@ protected:
return cs->column_specification;
});
if (_in_marker) {
auto t = to_term(col_specs, get_value(), db, schema->ks_name(), bound_names);
auto t = to_term(col_specs, *get_value(), db, schema->ks_name(), bound_names);
auto as_abstract_marker = static_pointer_cast<abstract_marker>(t);
return ::make_shared<restrictions::multi_column_restriction::IN_with_marker>(schema, rs, as_abstract_marker);
} else {
@@ -179,7 +179,7 @@ protected:
std::transform(rs.begin(), rs.end(), col_specs.begin(), [] (auto cs) {
return cs->column_specification;
});
auto t = to_term(col_specs, get_value(), db, schema->ks_name(), bound_names);
auto t = to_term(col_specs, *get_value(), db, schema->ks_name(), bound_names);
return ::make_shared<restrictions::multi_column_restriction::slice>(schema, rs, bound, inclusive, t);
}
@@ -201,10 +201,10 @@ protected:
}
virtual shared_ptr<term> to_term(const std::vector<shared_ptr<column_specification>>& receivers,
::shared_ptr<term::raw> raw, database& db, const sstring& keyspace,
const term::raw& raw, database& db, const sstring& keyspace,
variable_specifications& bound_names) const override {
auto as_multi_column_raw = dynamic_pointer_cast<term::multi_column_raw>(raw);
auto t = as_multi_column_raw->prepare(db, keyspace, receivers);
const auto& as_multi_column_raw = dynamic_cast<const term::multi_column_raw&>(raw);
auto t = as_multi_column_raw.prepare(db, keyspace, receivers);
t->collect_marker_specification(bound_names);
return t;
}
@@ -215,7 +215,7 @@ protected:
int previous_position = -1;
std::vector<const column_definition*> names;
for (auto&& raw : get_entities()) {
const auto& def = to_column_definition(schema, raw);
const auto& def = to_column_definition(schema, *raw);
check_true(def.is_clustering_key(), "Multi-column relations can only be applied to clustering columns but was applied to: %s", def.name_as_text());
check_false(std::count(names.begin(), names.end(), &def), "Column \"%s\" appeared twice in a relation: %s", def.name_as_text(), to_string());

View File

@@ -58,7 +58,7 @@ operation::set_element::to_string(const column_definition& receiver) const {
}
shared_ptr<operation>
operation::set_element::prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
operation::set_element::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
using exceptions::invalid_request_exception;
auto rtype = dynamic_pointer_cast<const collection_type_impl>(receiver.type);
if (!rtype) {
@@ -99,7 +99,7 @@ operation::set_field::to_string(const column_definition& receiver) const {
}
shared_ptr<operation>
operation::set_field::prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
operation::set_field::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
if (!receiver.type->is_user_type()) {
throw exceptions::invalid_request_exception(
format("Invalid operation ({}) for non-UDT column {}", to_string(receiver), receiver.name_as_text()));
@@ -129,13 +129,13 @@ operation::set_field::is_compatible_with(shared_ptr<raw_update> other) const {
return !dynamic_pointer_cast<set_value>(std::move(other));
}
shared_ptr<column_identifier::raw>
operation::field_deletion::affected_column() {
return _id;
const column_identifier::raw&
operation::field_deletion::affected_column() const {
return *_id;
}
shared_ptr<operation>
operation::field_deletion::prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
operation::field_deletion::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
if (!receiver.type->is_user_type()) {
throw exceptions::invalid_request_exception(
format("Invalid deletion operation for non-UDT column {}", receiver.name_as_text()));
@@ -160,7 +160,7 @@ operation::addition::to_string(const column_definition& receiver) const {
}
shared_ptr<operation>
operation::addition::prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
operation::addition::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
auto v = _value->prepare(db, keyspace, receiver.column_specification);
auto ctype = dynamic_pointer_cast<const collection_type_impl>(receiver.type);
@@ -195,7 +195,7 @@ operation::subtraction::to_string(const column_definition& receiver) const {
}
shared_ptr<operation>
operation::subtraction::prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
operation::subtraction::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
auto ctype = dynamic_pointer_cast<const collection_type_impl>(receiver.type);
if (!ctype) {
if (!receiver.is_counter()) {
@@ -237,7 +237,7 @@ operation::prepend::to_string(const column_definition& receiver) const {
}
shared_ptr<operation>
operation::prepend::prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
operation::prepend::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
auto v = _value->prepare(db, keyspace, receiver.column_specification);
if (!dynamic_cast<const list_type_impl*>(receiver.type.get())) {
@@ -256,7 +256,7 @@ operation::prepend::is_compatible_with(shared_ptr<raw_update> other) const {
::shared_ptr <operation>
operation::set_value::prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
operation::set_value::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
auto v = _value->prepare(db, keyspace, receiver.column_specification);
if (receiver.type->is_counter()) {
@@ -284,7 +284,7 @@ operation::set_value::prepare(database& db, const sstring& keyspace, const colum
}
::shared_ptr <operation>
operation::set_counter_value_from_tuple_list::prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
operation::set_counter_value_from_tuple_list::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
static thread_local const data_type counter_tuple_type = tuple_type_impl::get_instance({int32_type, uuid_type, long_type, long_type});
static thread_local const data_type counter_tuple_list_type = list_type_impl::get_instance(counter_tuple_type, true);
@@ -362,13 +362,13 @@ operation::set_value::is_compatible_with(::shared_ptr <raw_update> other) const
return false;
}
shared_ptr<column_identifier::raw>
operation::element_deletion::affected_column() {
return _id;
const column_identifier::raw&
operation::element_deletion::affected_column() const {
return *_id;
}
shared_ptr<operation>
operation::element_deletion::prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
operation::element_deletion::prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
if (!receiver.type->is_collection()) {
throw exceptions::invalid_request_exception(format("Invalid deletion operation for non collection column {}", receiver.name()));
} else if (!receiver.type->is_multi_cell()) {

View File

@@ -162,7 +162,7 @@ public:
* be a true column.
* @return the prepared update operation.
*/
virtual ::shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) = 0;
virtual ::shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const = 0;
/**
* @return whether this operation can be applied alongside the {@code
@@ -186,7 +186,7 @@ public:
/**
* The name of the column affected by this delete operation.
*/
virtual ::shared_ptr<column_identifier::raw> affected_column() = 0;
virtual const column_identifier::raw& affected_column() const = 0;
/**
* This method validates the operation (i.e. validate it is well typed)
@@ -199,7 +199,7 @@ public:
* @param receiver the "column" this operation applies to.
* @return the prepared delete operation.
*/
virtual ::shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) = 0;
virtual ::shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const = 0;
};
class set_value;
@@ -216,7 +216,7 @@ public:
: _selector(std::move(selector)), _value(std::move(value)), _by_uuid(by_uuid) {
}
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) override;
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override;
virtual bool is_compatible_with(shared_ptr<raw_update> other) const override;
};
@@ -232,7 +232,7 @@ public:
: _field(std::move(field)), _value(std::move(value)) {
}
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) override;
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override;
virtual bool is_compatible_with(shared_ptr<raw_update> other) const override;
};
@@ -247,9 +247,9 @@ public:
: _id(std::move(id)), _field(std::move(field)) {
}
virtual shared_ptr<column_identifier::raw> affected_column() override;
virtual const column_identifier::raw& affected_column() const override;
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) override;
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override;
};
class addition : public raw_update {
@@ -261,7 +261,7 @@ public:
: _value(value) {
}
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) override;
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override;
virtual bool is_compatible_with(shared_ptr<raw_update> other) const override;
};
@@ -275,7 +275,7 @@ public:
: _value(value) {
}
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) override;
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override;
virtual bool is_compatible_with(shared_ptr<raw_update> other) const override;
};
@@ -289,7 +289,7 @@ public:
: _value(std::move(value)) {
}
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) override;
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override;
virtual bool is_compatible_with(shared_ptr<raw_update> other) const override;
};
@@ -303,8 +303,8 @@ public:
element_deletion(shared_ptr<column_identifier::raw> id, shared_ptr<term::raw> element)
: _id(std::move(id)), _element(std::move(element)) {
}
virtual shared_ptr<column_identifier::raw> affected_column() override;
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) override;
virtual const column_identifier::raw& affected_column() const override;
virtual shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override;
};
};

View File

@@ -56,7 +56,7 @@ protected:
public:
set_value(::shared_ptr<term::raw> value) : _value(std::move(value)) {}
virtual ::shared_ptr <operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) override;
virtual ::shared_ptr <operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override;
#if 0
protected String toString(ColumnSpecification column)
@@ -71,7 +71,7 @@ public:
class operation::set_counter_value_from_tuple_list : public set_value {
public:
using set_value::set_value;
::shared_ptr <operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) override;
::shared_ptr <operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const override;
};
class operation::column_deletion : public raw_deletion {
@@ -82,11 +82,11 @@ public:
: _id(std::move(id))
{ }
virtual ::shared_ptr<column_identifier::raw> affected_column() override {
return _id;
virtual const column_identifier::raw& affected_column() const override {
return *_id;
}
::shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) {
::shared_ptr<operation> prepare(database& db, const sstring& keyspace, const column_definition& receiver) const {
// No validation, deleting a column is always "well typed"
return ::make_shared<constants::deleter>(receiver);
}

View File

@@ -45,8 +45,8 @@
namespace cql3 {
const column_definition&
relation::to_column_definition(const schema& schema, ::shared_ptr<column_identifier::raw> entity) {
auto id = entity->prepare_column_identifier(schema);
relation::to_column_definition(const schema& schema, const column_identifier::raw& entity) {
auto id = entity.prepare_column_identifier(schema);
auto def = get_column_definition(schema, *id);
if (!def || def->is_hidden_from_cql()) {
throw exceptions::unrecognized_entity_exception(id, shared_from_this());

View File

@@ -250,7 +250,7 @@ protected:
* @throws InvalidRequestException if the <code>Raw</code> term is not valid
*/
virtual ::shared_ptr<term> to_term(const std::vector<::shared_ptr<column_specification>>& receivers,
::shared_ptr<term::raw> raw,
const term::raw& raw,
database& db,
const sstring& keyspace,
variable_specifications& boundNames) const = 0;
@@ -271,8 +271,8 @@ protected:
const sstring& keyspace,
variable_specifications& boundNames) const {
std::vector<::shared_ptr<term>> terms;
for (auto&& r : raws) {
terms.emplace_back(to_term(receivers, r, db, keyspace, boundNames));
for (const auto& r : raws) {
terms.emplace_back(to_term(receivers, *r, db, keyspace, boundNames));
}
return terms;
}
@@ -285,7 +285,7 @@ protected:
* @return the column definition corresponding to the specified entity
* @throws InvalidRequestException if the entity cannot be recognized
*/
virtual const column_definition& to_column_definition(const schema& schema, ::shared_ptr<column_identifier::raw> entity) final;
virtual const column_definition& to_column_definition(const schema& schema, const column_identifier::raw& entity) final;
};
using relation_ptr = ::shared_ptr<relation>;

View File

@@ -61,7 +61,7 @@ selectable::writetime_or_ttl::to_string() const {
}
shared_ptr<selectable>
selectable::writetime_or_ttl::raw::prepare(const schema& s) {
selectable::writetime_or_ttl::raw::prepare(const schema& s) const {
return make_shared<writetime_or_ttl>(_id->prepare_column_identifier(s), _is_writetime);
}
@@ -92,7 +92,7 @@ selectable::with_function::to_string() const {
}
shared_ptr<selectable>
selectable::with_function::raw::prepare(const schema& s) {
selectable::with_function::raw::prepare(const schema& s) const {
std::vector<shared_ptr<selectable>> prepared_args;
prepared_args.reserve(_args.size());
for (auto&& arg : _args) {
@@ -125,7 +125,7 @@ selectable::with_anonymous_function::to_string() const {
}
shared_ptr<selectable>
selectable::with_anonymous_function::raw::prepare(const schema& s) {
selectable::with_anonymous_function::raw::prepare(const schema& s) const {
std::vector<shared_ptr<selectable>> prepared_args;
prepared_args.reserve(_args.size());
for (auto&& arg : _args) {
@@ -164,7 +164,7 @@ selectable::with_field_selection::to_string() const {
}
shared_ptr<selectable>
selectable::with_field_selection::raw::prepare(const schema& s) {
selectable::with_field_selection::raw::prepare(const schema& s) const {
// static_pointer_cast<> needed due to lack of covariant return type
// support with smart pointers
return make_shared<with_field_selection>(_selected->prepare(s),
@@ -191,7 +191,7 @@ selectable::with_cast::to_string() const {
}
shared_ptr<selectable>
selectable::with_cast::raw::prepare(const schema& s) {
selectable::with_cast::raw::prepare(const schema& s) const {
return ::make_shared<selectable::with_cast>(_arg->prepare(s), _type);
}

View File

@@ -72,7 +72,7 @@ public:
public:
virtual ~raw() {}
virtual ::shared_ptr<selectable> prepare(const schema& s) = 0;
virtual ::shared_ptr<selectable> prepare(const schema& s) const = 0;
/**
* Returns true if any processing is performed on the selected column.
@@ -110,7 +110,7 @@ public:
raw(functions::function_name function_name, std::vector<shared_ptr<selectable::raw>> args)
: _function_name(std::move(function_name)), _args(std::move(args)) {
}
virtual shared_ptr<selectable> prepare(const schema& s) override;
virtual shared_ptr<selectable> prepare(const schema& s) const override;
virtual bool processes_selection() const override;
static ::shared_ptr<selectable::with_function::raw> make_count_rows_function();
};
@@ -134,7 +134,7 @@ public:
raw(shared_ptr<functions::function> f, std::vector<shared_ptr<selectable::raw>> args)
: _function(f), _args(std::move(args)) {
}
virtual shared_ptr<selectable> prepare(const schema& s) override;
virtual shared_ptr<selectable> prepare(const schema& s) const override;
virtual bool processes_selection() const override;
};
};
@@ -157,7 +157,7 @@ public:
raw(shared_ptr<selectable::raw> arg, cql3_type type)
: _arg(std::move(arg)), _type(std::move(type)) {
}
virtual shared_ptr<selectable> prepare(const schema& s) override;
virtual shared_ptr<selectable> prepare(const schema& s) const override;
virtual bool processes_selection() const override;
};
};

View File

@@ -70,7 +70,7 @@ public:
raw(shared_ptr<selectable::raw> selected, shared_ptr<column_identifier::raw> field)
: _selected(std::move(selected)), _field(std::move(field)) {
}
virtual shared_ptr<selectable> prepare(const schema& s) override;
virtual shared_ptr<selectable> prepare(const schema& s) const override;
virtual bool processes_selection() const override;
};
};

View File

@@ -256,7 +256,7 @@ uint32_t selection::add_column_for_post_processing(const column_definition& c) {
selector_factories::create_factories_and_collect_column_definitions(
raw_selector::to_selectables(raw_selectors, *schema), db, schema, defs);
auto metadata = collect_metadata(schema, raw_selectors, *factories);
auto metadata = collect_metadata(*schema, raw_selectors, *factories);
if (processes_selection(raw_selectors) || raw_selectors.size() != defs.size()) {
return ::make_shared<selection_with_processing>(schema, std::move(defs), std::move(metadata), std::move(factories));
} else {
@@ -265,13 +265,13 @@ uint32_t selection::add_column_for_post_processing(const column_definition& c) {
}
std::vector<::shared_ptr<column_specification>>
selection::collect_metadata(schema_ptr schema, const std::vector<::shared_ptr<raw_selector>>& raw_selectors,
selection::collect_metadata(const schema& schema, const std::vector<::shared_ptr<raw_selector>>& raw_selectors,
const selector_factories& factories) {
std::vector<::shared_ptr<column_specification>> r;
r.reserve(raw_selectors.size());
auto i = raw_selectors.begin();
for (auto&& factory : factories) {
::shared_ptr<column_specification> col_spec = factory->get_column_specification(*schema);
::shared_ptr<column_specification> col_spec = factory->get_column_specification(schema);
::shared_ptr<column_identifier> alias = (*i++)->alias;
r.push_back(alias ? col_spec->with_alias(alias) : col_spec);
}

View File

@@ -197,7 +197,7 @@ private:
[] (auto&& s) { return s->processes_selection(); });
}
static std::vector<::shared_ptr<column_specification>> collect_metadata(schema_ptr schema,
static std::vector<::shared_ptr<column_specification>> collect_metadata(const schema& schema,
const std::vector<::shared_ptr<raw_selector>>& raw_selectors, const selector_factories& factories);
public:
static ::shared_ptr<selection> from_selectors(database& db, schema_ptr schema, const std::vector<::shared_ptr<raw_selector>>& raw_selectors);

View File

@@ -69,7 +69,7 @@ public:
raw(shared_ptr<column_identifier::raw> id, bool is_writetime)
: _id(std::move(id)), _is_writetime(is_writetime) {
}
virtual shared_ptr<selectable> prepare(const schema& s) override;
virtual shared_ptr<selectable> prepare(const schema& s) const override;
virtual bool processes_selection() const override;
};
};

View File

@@ -162,11 +162,11 @@ sets::value::get_with_protocol_version(cql_serialization_format sf) {
}
bool
sets::value::equals(set_type st, const value& v) {
sets::value::equals(const set_type_impl& st, const value& v) {
if (_elements.size() != v._elements.size()) {
return false;
}
auto&& elements_type = st->get_elements_type();
auto&& elements_type = st.get_elements_type();
return std::equal(_elements.begin(), _elements.end(),
v._elements.begin(),
[elements_type] (bytes_view v1, bytes_view v2) {

View File

@@ -81,7 +81,7 @@ public:
static value from_serialized(const fragmented_temporary_buffer::view& v, const set_type_impl& type, cql_serialization_format sf);
virtual cql3::raw_value get(const query_options& options) override;
virtual bytes get_with_protocol_version(cql_serialization_format sf) override;
bool equals(set_type st, const value& v);
bool equals(const set_type_impl& st, const value& v);
virtual sstring to_string() const override;
};

View File

@@ -54,37 +54,37 @@ namespace cql3 {
::shared_ptr<term>
single_column_relation::to_term(const std::vector<::shared_ptr<column_specification>>& receivers,
::shared_ptr<term::raw> raw,
const term::raw& raw,
database& db,
const sstring& keyspace,
variable_specifications& bound_names) const {
// TODO: optimize vector away, accept single column_specification
assert(receivers.size() == 1);
auto term = raw->prepare(db, keyspace, receivers[0]);
auto term = raw.prepare(db, keyspace, receivers[0]);
term->collect_marker_specification(bound_names);
return term;
}
::shared_ptr<restrictions::restriction>
single_column_relation::new_EQ_restriction(database& db, schema_ptr schema, variable_specifications& bound_names) {
const column_definition& column_def = to_column_definition(*schema, _entity);
const column_definition& column_def = to_column_definition(*schema, *_entity);
if (!_map_key) {
auto term = to_term(to_receivers(*schema, column_def), _value, db, schema->ks_name(), bound_names);
auto term = to_term(to_receivers(*schema, column_def), *_value, db, schema->ks_name(), bound_names);
return ::make_shared<single_column_restriction::EQ>(column_def, std::move(term));
}
auto&& receivers = to_receivers(*schema, column_def);
auto&& entry_key = to_term({receivers[0]}, _map_key, db, schema->ks_name(), bound_names);
auto&& entry_value = to_term({receivers[1]}, _value, db, schema->ks_name(), bound_names);
auto&& entry_key = to_term({receivers[0]}, *_map_key, db, schema->ks_name(), bound_names);
auto&& entry_value = to_term({receivers[1]}, *_value, db, schema->ks_name(), bound_names);
return make_shared<single_column_restriction::contains>(column_def, std::move(entry_key), std::move(entry_value));
}
::shared_ptr<restrictions::restriction>
single_column_relation::new_IN_restriction(database& db, schema_ptr schema, variable_specifications& bound_names) {
const column_definition& column_def = to_column_definition(*schema, _entity);
const column_definition& column_def = to_column_definition(*schema, *_entity);
auto receivers = to_receivers(*schema, column_def);
assert(_in_values.empty() || !_value);
if (_value) {
auto term = to_term(receivers, _value, db, schema->ks_name(), bound_names);
auto term = to_term(receivers, *_value, db, schema->ks_name(), bound_names);
return make_shared<single_column_restriction::IN_with_marker>(column_def, dynamic_pointer_cast<lists::marker>(term));
}
auto terms = to_terms(receivers, _in_values, db, schema->ks_name(), bound_names);
@@ -98,12 +98,12 @@ single_column_relation::new_IN_restriction(database& db, schema_ptr schema, vari
::shared_ptr<restrictions::restriction>
single_column_relation::new_LIKE_restriction(
database& db, schema_ptr schema, variable_specifications& bound_names) {
const column_definition& column_def = to_column_definition(*schema, _entity);
const column_definition& column_def = to_column_definition(*schema, *_entity);
if (!column_def.type->is_string()) {
throw exceptions::invalid_request_exception(
format("LIKE is allowed only on string types, which {} is not", column_def.name_as_text()));
}
auto term = to_term(to_receivers(*schema, column_def), _value, db, schema->ks_name(), bound_names);
auto term = to_term(to_receivers(*schema, column_def), *_value, db, schema->ks_name(), bound_names);
return ::make_shared<single_column_restriction::LIKE>(column_def, std::move(term));
}

View File

@@ -118,7 +118,7 @@ public:
protected:
virtual ::shared_ptr<term> to_term(const std::vector<::shared_ptr<column_specification>>& receivers,
::shared_ptr<term::raw> raw, database& db, const sstring& keyspace,
const term::raw& raw, database& db, const sstring& keyspace,
variable_specifications& bound_names) const override;
#if 0
@@ -157,7 +157,7 @@ protected:
variable_specifications& bound_names,
statements::bound bound,
bool inclusive) override {
auto&& column_def = to_column_definition(*schema, _entity);
auto&& column_def = to_column_definition(*schema, *_entity);
if (column_def.type->references_duration()) {
using statements::request_validations::check_false;
@@ -171,15 +171,15 @@ protected:
throw exceptions::invalid_request_exception("Slice restrictions are not supported on duration columns");
}
auto term = to_term(to_receivers(*schema, column_def), _value, db, schema->ks_name(), bound_names);
auto term = to_term(to_receivers(*schema, column_def), *_value, db, schema->ks_name(), bound_names);
return ::make_shared<restrictions::single_column_restriction::slice>(column_def, bound, inclusive, std::move(term));
}
virtual shared_ptr<restrictions::restriction> new_contains_restriction(database& db, schema_ptr schema,
variable_specifications& bound_names,
bool is_key) override {
auto&& column_def = to_column_definition(*schema, _entity);
auto term = to_term(to_receivers(*schema, column_def), _value, db, schema->ks_name(), bound_names);
auto&& column_def = to_column_definition(*schema, *_entity);
auto term = to_term(to_receivers(*schema, column_def), *_value, db, schema->ks_name(), bound_names);
return ::make_shared<restrictions::single_column_restriction::contains>(column_def, std::move(term), is_key);
}

View File

@@ -95,7 +95,7 @@ create_index_statement::validate(service::storage_proxy& proxy, const service::c
"Secondary indexes are not supported on COMPACT STORAGE tables that have clustering columns");
}
validate_for_local_index(schema);
validate_for_local_index(*schema);
std::vector<::shared_ptr<index_target>> targets;
for (auto& raw_target : _raw_targets) {
@@ -157,11 +157,11 @@ create_index_statement::validate(service::storage_proxy& proxy, const service::c
throw exceptions::invalid_request_exception(
format("Cannot create secondary index on non-frozen collection or UDT column {}", cd->name_as_text()));
} else if (cd->type->is_collection()) {
validate_for_frozen_collection(target);
validate_for_frozen_collection(*target);
} else {
validate_not_full_index(target);
validate_is_values_index_if_target_column_not_collection(cd, target);
validate_target_column_is_map_if_index_involves_keys(cd->type->is_map(), target);
validate_not_full_index(*target);
validate_is_values_index_if_target_column_not_collection(cd, *target);
validate_target_column_is_map_if_index_involves_keys(cd->type->is_map(), *target);
}
}
@@ -176,17 +176,17 @@ create_index_statement::validate(service::storage_proxy& proxy, const service::c
_properties->validate();
}
void create_index_statement::validate_for_local_index(schema_ptr schema) const {
void create_index_statement::validate_for_local_index(const schema& schema) const {
if (!_raw_targets.empty()) {
if (const auto* index_pk = std::get_if<std::vector<::shared_ptr<column_identifier::raw>>>(&_raw_targets.front()->value)) {
auto base_pk_identifiers = *index_pk | boost::adaptors::transformed([&schema] (const ::shared_ptr<column_identifier::raw>& raw_ident) {
return raw_ident->prepare_column_identifier(*schema);
return raw_ident->prepare_column_identifier(schema);
});
auto remaining_base_pk_columns = schema->partition_key_columns();
auto remaining_base_pk_columns = schema.partition_key_columns();
auto next_expected_base_column = remaining_base_pk_columns.begin();
for (const auto& ident : base_pk_identifiers) {
auto it = schema->columns_by_name().find(ident->name());
if (it == schema->columns_by_name().end() || !it->second->is_partition_key()) {
auto it = schema.columns_by_name().find(ident->name());
if (it == schema.columns_by_name().end() || !it->second->is_partition_key()) {
throw exceptions::invalid_request_exception(format("Local index definition must contain full partition key only. Redundant column: {}", ident->to_string()));
}
if (next_expected_base_column == remaining_base_pk_columns.end()) {
@@ -212,44 +212,44 @@ void create_index_statement::validate_for_local_index(schema_ptr schema) const {
}
}
void create_index_statement::validate_for_frozen_collection(::shared_ptr<index_target> target) const
void create_index_statement::validate_for_frozen_collection(const index_target& target) const
{
if (target->type != index_target::target_type::full) {
if (target.type != index_target::target_type::full) {
throw exceptions::invalid_request_exception(
format("Cannot create index on {} of frozen<map> column {}",
index_target::index_option(target->type),
target->as_string()));
index_target::index_option(target.type),
target.as_string()));
}
}
void create_index_statement::validate_not_full_index(::shared_ptr<index_target> target) const
void create_index_statement::validate_not_full_index(const index_target& target) const
{
if (target->type == index_target::target_type::full) {
if (target.type == index_target::target_type::full) {
throw exceptions::invalid_request_exception("full() indexes can only be created on frozen collections");
}
}
void create_index_statement::validate_is_values_index_if_target_column_not_collection(
const column_definition* cd, ::shared_ptr<index_target> target) const
const column_definition* cd, const index_target& target) const
{
if (!cd->type->is_collection()
&& target->type != index_target::target_type::values) {
&& target.type != index_target::target_type::values) {
throw exceptions::invalid_request_exception(
format("Cannot create index on {} of column {}; only non-frozen collections support {} indexes",
index_target::index_option(target->type),
target->as_string(),
index_target::index_option(target->type)));
index_target::index_option(target.type),
target.as_string(),
index_target::index_option(target.type)));
}
}
void create_index_statement::validate_target_column_is_map_if_index_involves_keys(bool is_map, ::shared_ptr<index_target> target) const
void create_index_statement::validate_target_column_is_map_if_index_involves_keys(bool is_map, const index_target& target) const
{
if (target->type == index_target::target_type::keys
|| target->type == index_target::target_type::keys_and_values) {
if (target.type == index_target::target_type::keys
|| target.type == index_target::target_type::keys_and_values) {
if (!is_map) {
throw exceptions::invalid_request_exception(
format("Cannot create index on {} of column {} with non-map type",
index_target::index_option(target->type), target->as_string()));
index_target::index_option(target.type), target.as_string()));
}
}
}
@@ -299,7 +299,7 @@ create_index_statement::announce_migration(service::storage_proxy& proxy, bool i
} else {
kind = schema->is_compound() ? index_metadata_kind::composites : index_metadata_kind::keys;
}
auto index = make_index_metadata(schema, targets, accepted_name, kind, index_options);
auto index = make_index_metadata(targets, accepted_name, kind, index_options);
auto existing_index = schema->find_index_noname(index);
if (existing_index) {
if (_if_not_exists) {
@@ -329,8 +329,7 @@ create_index_statement::prepare(database& db, cql_stats& stats) {
return std::make_unique<prepared_statement>(make_shared<create_index_statement>(*this));
}
index_metadata create_index_statement::make_index_metadata(schema_ptr schema,
const std::vector<::shared_ptr<index_target>>& targets,
index_metadata create_index_statement::make_index_metadata(const std::vector<::shared_ptr<index_target>>& targets,
const sstring& name,
index_metadata_kind kind,
const index_options_map& options)

View File

@@ -83,15 +83,14 @@ public:
virtual std::unique_ptr<prepared_statement> prepare(database& db, cql_stats& stats) override;
private:
void validate_for_local_index(schema_ptr schema) const;
void validate_for_frozen_collection(::shared_ptr<index_target> target) const;
void validate_not_full_index(::shared_ptr<index_target> target) const;
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_is_values_index_if_target_column_not_collection(const column_definition* cd,
::shared_ptr<index_target> target) const;
void validate_target_column_is_map_if_index_involves_keys(bool is_map, ::shared_ptr<index_target> target) const;
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<index_target>> targets) const;
static index_metadata make_index_metadata(schema_ptr schema,
const std::vector<::shared_ptr<index_target>>& targets,
static index_metadata make_index_metadata(const std::vector<::shared_ptr<index_target>>& targets,
const sstring& name,
index_metadata_kind kind,
const index_options_map& options);

View File

@@ -225,7 +225,7 @@ future<shared_ptr<cql_transport::event::schema_change>> create_view_statement::a
throw exceptions::invalid_request_exception(format("Cannot use query parameters in CREATE MATERIALIZED VIEW statements"));
}
auto parameters = ::make_shared<raw::select_statement::parameters>(raw::select_statement::parameters::orderings_type(), false, true);
auto parameters = make_lw_shared<raw::select_statement::parameters>(raw::select_statement::parameters::orderings_type(), false, true);
raw::select_statement raw_select(_base_name, std::move(parameters), _select_clause, _where_clause, nullptr, nullptr, {});
raw_select.prepare_keyspace(keyspace());
raw_select.set_bound_variables({});

View File

@@ -81,11 +81,11 @@ namespace raw {
::shared_ptr<cql3::statements::modification_statement>
delete_statement::prepare_internal(database& db, schema_ptr schema, variable_specifications& bound_names,
std::unique_ptr<attributes> attrs, cql_stats& stats) {
std::unique_ptr<attributes> attrs, cql_stats& stats) const {
auto stmt = ::make_shared<cql3::statements::delete_statement>(statement_type::DELETE, bound_names.size(), schema, std::move(attrs), stats);
for (auto&& deletion : _deletions) {
auto&& id = deletion->affected_column()->prepare_column_identifier(*schema);
auto&& id = deletion->affected_column().prepare_column_identifier(*schema);
auto def = get_column_definition(*schema, *id);
if (!def) {
throw exceptions::invalid_request_exception(format("Unknown identifier {}", *id));
@@ -101,7 +101,7 @@ delete_statement::prepare_internal(database& db, schema_ptr schema, variable_spe
op->collect_marker_specification(bound_names);
stmt->add_operation(op);
}
prepare_conditions(db, schema, bound_names, *stmt);
prepare_conditions(db, *schema, bound_names, *stmt);
stmt->process_where_clause(db, _where_clause, bound_names);
if (!db.supports_infinite_bound_range_deletions()) {
if (!stmt->restrictions().get_clustering_columns_restrictions()->has_bound(bound::START)

View File

@@ -119,7 +119,7 @@ index_target::raw::columns(std::vector<::shared_ptr<column_identifier::raw>> c)
}
::shared_ptr<index_target>
index_target::raw::prepare(const schema& s) {
index_target::raw::prepare(const schema& s) const {
struct prepare_visitor {
const schema& _schema;
target_type _type;

View File

@@ -90,7 +90,7 @@ struct index_target {
static ::shared_ptr<raw> keys_and_values_of(::shared_ptr<column_identifier::raw> c);
static ::shared_ptr<raw> full_collection(::shared_ptr<column_identifier::raw> c);
static ::shared_ptr<raw> columns(std::vector<::shared_ptr<column_identifier::raw>> c);
::shared_ptr<index_target> prepare(const schema&);
::shared_ptr<index_target> prepare(const schema&) const;
};
};

View File

@@ -529,7 +529,7 @@ modification_statement::prepare(database& db, cql_stats& stats) {
}
::shared_ptr<cql3::statements::modification_statement>
modification_statement::prepare(database& db, variable_specifications& bound_names, cql_stats& stats) {
modification_statement::prepare(database& db, variable_specifications& bound_names, cql_stats& stats) const {
schema_ptr schema = validation::validate_column_family(db, keyspace(), column_family());
auto prepared_attributes = _attrs->prepare(db, keyspace(), column_family());
@@ -539,7 +539,7 @@ modification_statement::prepare(database& db, variable_specifications& bound_nam
}
void
modification_statement::prepare_conditions(database& db, schema_ptr schema, variable_specifications& bound_names,
modification_statement::prepare_conditions(database& db, const schema& schema, variable_specifications& bound_names,
cql3::statements::modification_statement& stmt) const
{
if (_if_not_exists || _if_exists || !_conditions.empty()) {
@@ -562,8 +562,8 @@ modification_statement::prepare_conditions(database& db, schema_ptr schema, vari
stmt.set_if_exist_condition();
} else {
for (auto&& entry : _conditions) {
auto id = entry.first->prepare_column_identifier(*schema);
const column_definition* def = get_column_definition(*schema, *id);
auto id = entry.first->prepare_column_identifier(schema);
const column_definition* def = get_column_definition(schema, *id);
if (!def) {
throw exceptions::invalid_request_exception(format("Unknown identifier {}", *id));
}

View File

@@ -132,11 +132,6 @@ private:
std::optional<bool> _is_raw_counter_shard_write;
const std::function<const column_definition&(::shared_ptr<column_condition>)> get_column_for_condition =
[](::shared_ptr<column_condition> cond) -> const column_definition& {
return cond->column;
};
protected:
std::optional<restrictions::statement_restrictions> _restrictions;
public:

View File

@@ -66,7 +66,7 @@ public:
bool if_exists);
protected:
virtual ::shared_ptr<cql3::statements::modification_statement> prepare_internal(database& db, schema_ptr schema,
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats);
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) const override;
};
}

View File

@@ -77,7 +77,7 @@ public:
bool if_not_exists);
virtual ::shared_ptr<cql3::statements::modification_statement> prepare_internal(database& db, schema_ptr schema,
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) override;
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) const override;
};
@@ -99,7 +99,7 @@ public:
insert_json_statement(::shared_ptr<cf_name> name, ::shared_ptr<attributes::raw> attrs, ::shared_ptr<term::raw> json_value, bool if_not_exists, bool default_unset);
virtual ::shared_ptr<cql3::statements::modification_statement> prepare_internal(database& db, schema_ptr schema,
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) override;
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) const override;
};

View File

@@ -82,15 +82,15 @@ protected:
public:
virtual std::unique_ptr<prepared_statement> prepare(database& db, cql_stats& stats) override;
::shared_ptr<cql3::statements::modification_statement> prepare(database& db, variable_specifications& bound_names, cql_stats& stats);
::shared_ptr<cql3::statements::modification_statement> prepare(database& db, variable_specifications& bound_names, cql_stats& stats) const;
protected:
virtual ::shared_ptr<cql3::statements::modification_statement> prepare_internal(database& db, schema_ptr schema,
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) = 0;
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) const = 0;
// Helper function used by child classes to prepare conditions for a prepared statement.
// Must be called before processing WHERE clause, because to perform sanity checks there
// we need to know what kinds of conditions (static, regular) the statement has.
void prepare_conditions(database& db, schema_ptr schema, variable_specifications& bound_names,
void prepare_conditions(database& db, const schema& schema, variable_specifications& bound_names,
cql3::statements::modification_statement& stmt) const;
};

View File

@@ -99,7 +99,7 @@ public:
using result_row_type = std::vector<bytes_opt>;
using ordering_comparator_type = compare_fn<result_row_type>;
private:
::shared_ptr<parameters> _parameters;
lw_shared_ptr<const parameters> _parameters;
std::vector<::shared_ptr<selection::raw_selector>> _select_clause;
std::vector<::shared_ptr<relation>> _where_clause;
::shared_ptr<term::raw> _limit;
@@ -107,7 +107,7 @@ private:
std::vector<::shared_ptr<cql3::column_identifier::raw>> _group_by_columns;
public:
select_statement(::shared_ptr<cf_name> cf_name,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
std::vector<::shared_ptr<selection::raw_selector>> select_clause,
std::vector<::shared_ptr<relation>> where_clause,
::shared_ptr<term::raw> limit,
@@ -131,31 +131,31 @@ private:
/** Returns a ::shared_ptr<term> for the limit or null if no limit is set */
::shared_ptr<term> prepare_limit(database& db, variable_specifications& bound_names, ::shared_ptr<term::raw> limit);
static void verify_ordering_is_allowed(::shared_ptr<restrictions::statement_restrictions> restrictions);
static void verify_ordering_is_allowed(const restrictions::statement_restrictions& restrictions);
static void validate_distinct_selection(schema_ptr schema,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions);
static void validate_distinct_selection(const schema& schema,
const selection::selection& selection,
const restrictions::statement_restrictions& restrictions);
void handle_unrecognized_ordering_column(const column_identifier& column);
void handle_unrecognized_ordering_column(const column_identifier& column) const;
select_statement::ordering_comparator_type get_ordering_comparator(schema_ptr schema,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions);
select_statement::ordering_comparator_type get_ordering_comparator(const schema& schema,
selection::selection& selection,
const restrictions::statement_restrictions& restrictions);
bool is_reversed(schema_ptr schema);
bool is_reversed(const schema& schema) const;
/** If ALLOW FILTERING was not specified, this verifies that it is not needed */
void check_needs_filtering(::shared_ptr<restrictions::statement_restrictions> restrictions);
void check_needs_filtering(const restrictions::statement_restrictions& restrictions);
void ensure_filtering_columns_retrieval(database& db,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions);
selection::selection& selection,
const restrictions::statement_restrictions& restrictions);
/// Returns indices of GROUP BY cells in fetched rows.
std::vector<size_t> prepare_group_by(const schema& schema, selection::selection& selection) const;
bool contains_alias(const column_identifier& name);
bool contains_alias(const column_identifier& name) const;
::shared_ptr<column_specification> limit_receiver(bool per_partition = false);

View File

@@ -81,7 +81,7 @@ public:
conditions_vector conditions, bool if_exists);
protected:
virtual ::shared_ptr<cql3::statements::modification_statement> prepare_internal(database& db, schema_ptr schema,
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats);
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) const override;
};
}

View File

@@ -67,7 +67,7 @@ namespace cql3 {
namespace statements {
thread_local const shared_ptr<select_statement::parameters> select_statement::_default_parameters = ::make_shared<select_statement::parameters>();
thread_local const lw_shared_ptr<const select_statement::parameters> select_statement::_default_parameters = make_lw_shared<select_statement::parameters>();
select_statement::parameters::parameters()
: _is_distinct{false}
@@ -127,7 +127,7 @@ select_timeout(const restrictions::statement_restrictions& restrictions) {
select_statement::select_statement(schema_ptr schema,
uint32_t bound_terms,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions,
::shared_ptr<std::vector<size_t>> group_by_cell_indices,
@@ -725,7 +725,7 @@ select_statement::process_results(foreign_ptr<lw_shared_ptr<query::result>> resu
}
primary_key_select_statement::primary_key_select_statement(schema_ptr schema, uint32_t bound_terms,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions,
::shared_ptr<std::vector<size_t>> group_by_cell_indices,
@@ -752,7 +752,7 @@ primary_key_select_statement::primary_key_select_statement(schema_ptr schema, ui
indexed_table_select_statement::prepare(database& db,
schema_ptr schema,
uint32_t bound_terms,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions,
::shared_ptr<std::vector<size_t>> group_by_cell_indices,
@@ -791,7 +791,7 @@ indexed_table_select_statement::prepare(database& db,
}
indexed_table_select_statement::indexed_table_select_statement(schema_ptr schema, uint32_t bound_terms,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions,
::shared_ptr<std::vector<size_t>> group_by_cell_indices,
@@ -1228,7 +1228,7 @@ indexed_table_select_statement::find_index_clustering_rows(service::storage_prox
namespace raw {
select_statement::select_statement(::shared_ptr<cf_name> cf_name,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
std::vector<::shared_ptr<selection::raw_selector>> select_clause,
std::vector<::shared_ptr<relation>> where_clause,
::shared_ptr<term::raw> limit,
@@ -1294,7 +1294,7 @@ std::unique_ptr<prepared_statement> select_statement::prepare(database& db, cql_
auto restrictions = prepare_restrictions(db, schema, bound_names, selection, for_view, _parameters->allow_filtering());
if (_parameters->is_distinct()) {
validate_distinct_selection(schema, selection, restrictions);
validate_distinct_selection(*schema, *selection, *restrictions);
}
select_statement::ordering_comparator_type ordering_comparator;
@@ -1302,13 +1302,13 @@ std::unique_ptr<prepared_statement> select_statement::prepare(database& db, cql_
if (!_parameters->orderings().empty()) {
assert(!for_view);
verify_ordering_is_allowed(restrictions);
ordering_comparator = get_ordering_comparator(schema, selection, restrictions);
is_reversed_ = is_reversed(schema);
verify_ordering_is_allowed(*restrictions);
ordering_comparator = get_ordering_comparator(*schema, *selection, *restrictions);
is_reversed_ = is_reversed(*schema);
}
check_needs_filtering(restrictions);
ensure_filtering_columns_retrieval(db, selection, restrictions);
check_needs_filtering(*restrictions);
ensure_filtering_columns_retrieval(db, *selection, *restrictions);
auto group_by_cell_indices = ::make_shared<std::vector<size_t>>(prepare_group_by(*schema, *selection));
::shared_ptr<cql3::statements::select_statement> stmt;
@@ -1378,25 +1378,25 @@ select_statement::prepare_limit(database& db, variable_specifications& bound_nam
return prep_limit;
}
void select_statement::verify_ordering_is_allowed(::shared_ptr<restrictions::statement_restrictions> restrictions)
void select_statement::verify_ordering_is_allowed(const restrictions::statement_restrictions& restrictions)
{
if (restrictions->uses_secondary_indexing()) {
if (restrictions.uses_secondary_indexing()) {
throw exceptions::invalid_request_exception("ORDER BY with 2ndary indexes is not supported.");
}
if (restrictions->is_key_range()) {
if (restrictions.is_key_range()) {
throw exceptions::invalid_request_exception("ORDER BY is only supported when the partition key is restricted by an EQ or an IN.");
}
}
void select_statement::validate_distinct_selection(schema_ptr schema,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions)
void select_statement::validate_distinct_selection(const schema& schema,
const selection::selection& selection,
const restrictions::statement_restrictions& restrictions)
{
if (restrictions->has_non_primary_key_restriction() || restrictions->has_clustering_columns_restriction()) {
if (restrictions.has_non_primary_key_restriction() || restrictions.has_clustering_columns_restriction()) {
throw exceptions::invalid_request_exception(
"SELECT DISTINCT with WHERE clause only supports restriction by partition key.");
}
for (auto&& def : selection->get_columns()) {
for (auto&& def : selection.get_columns()) {
if (!def->is_partition_key() && !def->is_static()) {
throw exceptions::invalid_request_exception(format("SELECT DISTINCT queries must only request partition key columns and/or static columns (not {})",
def->name_as_text()));
@@ -1405,18 +1405,18 @@ void select_statement::validate_distinct_selection(schema_ptr schema,
// If it's a key range, we require that all partition key columns are selected so we don't have to bother
// with post-query grouping.
if (!restrictions->is_key_range()) {
if (!restrictions.is_key_range()) {
return;
}
for (auto&& def : schema->partition_key_columns()) {
if (!selection->has_column(def)) {
for (auto&& def : schema.partition_key_columns()) {
if (!selection.has_column(def)) {
throw exceptions::invalid_request_exception(format("SELECT DISTINCT queries must request all the partition key columns (missing {})", def.name_as_text()));
}
}
}
void select_statement::handle_unrecognized_ordering_column(const column_identifier& column)
void select_statement::handle_unrecognized_ordering_column(const column_identifier& column) const
{
if (contains_alias(column)) {
throw exceptions::invalid_request_exception(format("Aliases are not allowed in order by clause ('{}')", column));
@@ -1425,11 +1425,11 @@ void select_statement::handle_unrecognized_ordering_column(const column_identifi
}
select_statement::ordering_comparator_type
select_statement::get_ordering_comparator(schema_ptr schema,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions)
select_statement::get_ordering_comparator(const schema& schema,
selection::selection& selection,
const restrictions::statement_restrictions& restrictions)
{
if (!restrictions->key_is_in_relation()) {
if (!restrictions.key_is_in_relation()) {
return {};
}
@@ -1441,14 +1441,14 @@ select_statement::get_ordering_comparator(schema_ptr schema,
// ultimately ship them to the client (CASSANDRA-4911).
for (auto&& e : _parameters->orderings()) {
auto&& raw = e.first;
::shared_ptr<column_identifier> column = raw->prepare_column_identifier(*schema);
const column_definition* def = schema->get_column_definition(column->name());
::shared_ptr<column_identifier> column = raw->prepare_column_identifier(schema);
const column_definition* def = schema.get_column_definition(column->name());
if (!def) {
handle_unrecognized_ordering_column(*column);
}
auto index = selection->index_of(*def);
auto index = selection.index_of(*def);
if (index < 0) {
index = selection->add_column_for_post_processing(*def);
index = selection.add_column_for_post_processing(*def);
}
sorters.emplace_back(index, def->type);
@@ -1474,17 +1474,17 @@ select_statement::get_ordering_comparator(schema_ptr schema,
};
}
bool select_statement::is_reversed(schema_ptr schema) {
bool select_statement::is_reversed(const schema& schema) const {
assert(_parameters->orderings().size() > 0);
parameters::orderings_type::size_type i = 0;
bool is_reversed_ = false;
bool relation_order_unsupported = false;
for (auto&& e : _parameters->orderings()) {
::shared_ptr<column_identifier> column = e.first->prepare_column_identifier(*schema);
::shared_ptr<column_identifier> column = e.first->prepare_column_identifier(schema);
bool reversed = e.second;
auto def = schema->get_column_definition(column->name());
auto def = schema.get_column_definition(column->name());
if (!def) {
handle_unrecognized_ordering_column(*column);
}
@@ -1518,14 +1518,14 @@ bool select_statement::is_reversed(schema_ptr schema) {
}
/** If ALLOW FILTERING was not specified, this verifies that it is not needed */
void select_statement::check_needs_filtering(::shared_ptr<restrictions::statement_restrictions> restrictions)
void select_statement::check_needs_filtering(const restrictions::statement_restrictions& restrictions)
{
// non-key-range non-indexed queries cannot involve filtering underneath
if (!_parameters->allow_filtering() && (restrictions->is_key_range() || restrictions->uses_secondary_indexing())) {
if (!_parameters->allow_filtering() && (restrictions.is_key_range() || restrictions.uses_secondary_indexing())) {
// We will potentially filter data if either:
// - Have more than one IndexExpression
// - Have no index expression and the column filter is not the identity
if (restrictions->need_filtering()) {
if (restrictions.need_filtering()) {
throw exceptions::invalid_request_exception(
"Cannot execute this query as it might involve data filtering and "
"thus may have unpredictable performance. If you want to execute "
@@ -1542,16 +1542,16 @@ void select_statement::check_needs_filtering(::shared_ptr<restrictions::statemen
* to the user.
*/
void select_statement::ensure_filtering_columns_retrieval(database& db,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions) {
for (auto&& cdef : restrictions->get_column_defs_for_filtering(db)) {
if (!selection->has_column(*cdef)) {
selection->add_column_for_post_processing(*cdef);
selection::selection& selection,
const restrictions::statement_restrictions& restrictions) {
for (auto&& cdef : restrictions.get_column_defs_for_filtering(db)) {
if (!selection.has_column(*cdef)) {
selection.add_column_for_post_processing(*cdef);
}
}
}
bool select_statement::contains_alias(const column_identifier& name) {
bool select_statement::contains_alias(const column_identifier& name) const {
return std::any_of(_select_clause.begin(), _select_clause.end(), [&name] (auto raw) {
return raw->alias && name == *raw->alias;
});

View File

@@ -70,10 +70,10 @@ public:
using ordering_comparator_type = raw::select_statement::ordering_comparator_type;
static constexpr int DEFAULT_COUNT_PAGE_SIZE = 10000;
protected:
static thread_local const ::shared_ptr<parameters> _default_parameters;
static thread_local const lw_shared_ptr<const parameters> _default_parameters;
schema_ptr _schema;
uint32_t _bound_terms;
::shared_ptr<parameters> _parameters;
lw_shared_ptr<const parameters> _parameters;
::shared_ptr<selection::selection> _selection;
::shared_ptr<restrictions::statement_restrictions> _restrictions;
::shared_ptr<std::vector<size_t>> _group_by_cell_indices; ///< Indices in result row of cells holding GROUP BY values.
@@ -103,7 +103,7 @@ protected :
public:
select_statement(schema_ptr schema,
uint32_t bound_terms,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions,
::shared_ptr<std::vector<size_t>> group_by_cell_indices,
@@ -165,7 +165,7 @@ class primary_key_select_statement : public select_statement {
public:
primary_key_select_statement(schema_ptr schema,
uint32_t bound_terms,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions,
::shared_ptr<std::vector<size_t>> group_by_cell_indices,
@@ -186,7 +186,7 @@ public:
static ::shared_ptr<cql3::statements::select_statement> prepare(database& db,
schema_ptr schema,
uint32_t bound_terms,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions,
::shared_ptr<std::vector<size_t>> group_by_cell_indices,
@@ -198,7 +198,7 @@ public:
indexed_table_select_statement(schema_ptr schema,
uint32_t bound_terms,
::shared_ptr<parameters> parameters,
lw_shared_ptr<const parameters> parameters,
::shared_ptr<selection::selection> selection,
::shared_ptr<restrictions::statement_restrictions> restrictions,
::shared_ptr<std::vector<size_t>> group_by_cell_indices,

View File

@@ -307,7 +307,7 @@ insert_statement::insert_statement( ::shared_ptr<cf_name> name,
::shared_ptr<cql3::statements::modification_statement>
insert_statement::prepare_internal(database& db, schema_ptr schema,
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats)
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) const
{
auto stmt = ::make_shared<cql3::statements::update_statement>(statement_type::INSERT, bound_names.size(), schema, std::move(attrs), stats);
@@ -348,7 +348,7 @@ insert_statement::prepare_internal(database& db, schema_ptr schema,
stmt->add_operation(std::move(operation));
};
}
prepare_conditions(db, schema, bound_names, *stmt);
prepare_conditions(db, *schema, bound_names, *stmt);
stmt->process_where_clause(db, relations, bound_names);
return stmt;
}
@@ -367,14 +367,14 @@ insert_json_statement::insert_json_statement( ::shared_ptr<cf_name> name,
::shared_ptr<cql3::statements::modification_statement>
insert_json_statement::prepare_internal(database& db, schema_ptr schema,
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats)
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) const
{
assert(dynamic_pointer_cast<constants::literal>(_json_value) || dynamic_pointer_cast<abstract_marker::raw>(_json_value));
auto json_column_placeholder = ::make_shared<column_identifier>("", true);
auto prepared_json_value = _json_value->prepare(db, "", ::make_shared<column_specification>("", "", json_column_placeholder, utf8_type));
prepared_json_value->collect_marker_specification(bound_names);
auto stmt = ::make_shared<cql3::statements::insert_prepared_json_statement>(bound_names.size(), schema, std::move(attrs), stats, std::move(prepared_json_value), _default_unset);
prepare_conditions(db, schema, bound_names, *stmt);
prepare_conditions(db, *schema, bound_names, *stmt);
return stmt;
}
@@ -390,7 +390,7 @@ update_statement::update_statement( ::shared_ptr<cf_name> name,
::shared_ptr<cql3::statements::modification_statement>
update_statement::prepare_internal(database& db, schema_ptr schema,
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats)
variable_specifications& bound_names, std::unique_ptr<attributes> attrs, cql_stats& stats) const
{
auto stmt = ::make_shared<cql3::statements::update_statement>(statement_type::UPDATE, bound_names.size(), schema, std::move(attrs), stats);
@@ -409,7 +409,7 @@ update_statement::prepare_internal(database& db, schema_ptr schema,
}
stmt->add_operation(std::move(operation));
}
prepare_conditions(db, schema, bound_names, *stmt);
prepare_conditions(db, *schema, bound_names, *stmt);
stmt->process_where_clause(db, _where_clause, bound_names);
return stmt;
}

View File

@@ -147,7 +147,7 @@ public:
class multi_column_raw : public virtual raw {
public:
virtual ::shared_ptr<term> prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receiver) = 0;
virtual ::shared_ptr<term> prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receiver) const = 0;
};
};

View File

@@ -47,8 +47,8 @@
std::vector<const column_definition*> cql3::token_relation::get_column_definitions(const schema& s) {
std::vector<const column_definition*> res;
std::transform(_entities.begin(), _entities.end(), std::back_inserter(res),
[this, &s](auto& cr) {
return &this->to_column_definition(s, cr);
[this, &s](const auto& cr) {
return &this->to_column_definition(s, *cr);
});
return res;
}
@@ -83,7 +83,7 @@ std::vector<::shared_ptr<cql3::column_specification>> cql3::token_relation::to_r
database& db, schema_ptr schema,
variable_specifications& bound_names) {
auto column_defs = get_column_definitions(*schema);
auto term = to_term(to_receivers(*schema, column_defs), _value, db,
auto term = to_term(to_receivers(*schema, column_defs), *_value, db,
schema->ks_name(), bound_names);
return ::make_shared<restrictions::token_restriction::EQ>(column_defs, term);
}
@@ -102,7 +102,7 @@ std::vector<::shared_ptr<cql3::column_specification>> cql3::token_relation::to_r
statements::bound bound,
bool inclusive) {
auto column_defs = get_column_definitions(*schema);
auto term = to_term(to_receivers(*schema, column_defs), _value, db,
auto term = to_term(to_receivers(*schema, column_defs), *_value, db,
schema->ks_name(), bound_names);
return ::make_shared<restrictions::token_restriction::slice>(column_defs,
bound, inclusive, term);
@@ -127,9 +127,9 @@ sstring cql3::token_relation::to_string() const {
::shared_ptr<cql3::term> cql3::token_relation::to_term(
const std::vector<::shared_ptr<column_specification>>& receivers,
::shared_ptr<term::raw> raw, database& db, const sstring& keyspace,
const term::raw& raw, database& db, const sstring& keyspace,
variable_specifications& bound_names) const {
auto term = raw->prepare(db, keyspace, receivers.front());
auto term = raw.prepare(db, keyspace, receivers.front());
term->collect_marker_specification(bound_names);
return term;
}

View File

@@ -123,7 +123,7 @@ public:
protected:
::shared_ptr<term> to_term(const std::vector<::shared_ptr<column_specification>>& receivers,
::shared_ptr<term::raw> raw,
const term::raw& raw,
database& db,
const sstring& keyspace,
variable_specifications& bound_names) const override;

View File

@@ -56,7 +56,7 @@ tuples::literal::prepare(database& db, const sstring& keyspace, shared_ptr<colum
}
shared_ptr<term>
tuples::literal::prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receivers) {
tuples::literal::prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receivers) const {
if (_elements.size() != receivers.size()) {
throw exceptions::invalid_request_exception(format("Expected {:d} elements in value tuple, but got {:d}: {}", receivers.size(), _elements.size(), *this));
}

View File

@@ -66,7 +66,7 @@ public:
}
virtual shared_ptr<term> prepare(database& db, const sstring& keyspace, shared_ptr<column_specification> receiver) const override;
virtual shared_ptr<term> prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receivers) override;
virtual shared_ptr<term> prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receivers) const override;
private:
void validate_assignable_to(database& db, const sstring& keyspace, const column_specification& receiver) const {
@@ -234,7 +234,7 @@ public:
public:
using abstract_marker::raw::raw;
virtual ::shared_ptr<term> prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receivers) override {
virtual ::shared_ptr<term> prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receivers) const override {
return make_shared<tuples::marker>(_bind_index, make_receiver(receivers));
}
@@ -276,7 +276,7 @@ public:
public:
using abstract_marker::raw::raw;
virtual ::shared_ptr<term> prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receivers) override {
virtual ::shared_ptr<term> prepare(database& db, const sstring& keyspace, const std::vector<shared_ptr<column_specification>>& receivers) const override {
return make_shared<tuples::in_marker>(_bind_index, make_in_receiver(receivers));
}