Skip to content

Commit

Permalink
schema_tables: simplify merge_functions and avoid extra compilation
Browse files Browse the repository at this point in the history
Currently, we have 2 mere_functions methods, where one is only the only
call to the other. We can replace them with a simple one.

The merge_functions method compiles a UDF (using create_func) only to
read its signature. We can avoid that by reading it from the row ourselves.

Signed-off-by: Wojciech Mitros <[email protected]>
  • Loading branch information
wmitros committed Jul 20, 2022
1 parent 5a30f9b commit d7a9330
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions db/schema_tables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1784,28 +1784,25 @@ static shared_ptr<cql3::functions::user_aggregate> create_aggregate(replica::dat
return ::make_shared<cql3::functions::user_aggregate>(name, initcond, std::move(state_func), std::move(reduce_func), std::move(final_func));
}

static future<> merge_functions(distributed<service::storage_proxy>& proxy, schema_result before, schema_result after,
std::function<shared_ptr<cql3::functions::function>(replica::database& db, const query::result_set_row& row)> create) {
static future<> merge_functions(distributed<service::storage_proxy>& proxy, schema_result before, schema_result after) {
auto diff = diff_rows(before, after);

co_await proxy.local().get_db().invoke_on_all([&] (replica::database& db) {
for (const auto& val : diff.created) {
cql3::functions::functions::add_function(create(db, *val));
cql3::functions::functions::add_function(create_func(db, *val));
}
for (const auto& val : diff.dropped) {
auto func = create(db, *val);
cql3::functions::functions::remove_function(func->name(), func->arg_types());
cql3::functions::function_name name{
val->get_nonnull<sstring>("keyspace_name"), val->get_nonnull<sstring>("function_name")};
auto arg_types = read_arg_types(db, *val, name.keyspace);
cql3::functions::functions::remove_function(name, arg_types);
}
for (const auto& val : diff.altered) {
cql3::functions::functions::replace_function(create(db, *val));
cql3::functions::functions::replace_function(create_func(db, *val));
}
});
}

static future<> merge_functions(distributed<service::storage_proxy>& proxy, schema_result before, schema_result after) {
co_await merge_functions(proxy, before, after, create_func);
}

static future<> merge_aggregates(distributed<service::storage_proxy>& proxy, schema_result before, schema_result after,
schema_result scylla_before, schema_result scylla_after) {
auto diff = diff_aggregates_rows(before, after, scylla_before, scylla_after);
Expand Down

0 comments on commit d7a9330

Please sign in to comment.