| 217 | |
| 218 | |
| 219 | BlockIO InterpreterKillQueryQuery::execute() |
| 220 | { |
| 221 | const auto & query = query_ptr->as<ASTKillQueryQuery &>(); |
| 222 | |
| 223 | if (!query.cluster.empty()) |
| 224 | return executeDDLQueryOnCluster(query_ptr, getContext(), getRequiredAccessForDDLOnCluster()); |
| 225 | |
| 226 | BlockIO res_io; |
| 227 | switch (query.type) |
| 228 | { |
| 229 | case ASTKillQueryQuery::Type::Query: |
| 230 | { |
| 231 | auto context = getContext(); |
| 232 | auto where_clause = DB::collectWhereORClausePredicate(query.where_expression, getContext()); |
| 233 | String query_id; |
| 234 | std::for_each(where_clause.begin(), where_clause.end(), [&query_id](const std::map<String, Field> & wheres) { |
| 235 | auto iter = wheres.find("query_id"); |
| 236 | if (iter != wheres.end()) |
| 237 | query_id = iter->second.get<String>(); |
| 238 | }); |
| 239 | if (!query_id.empty()) |
| 240 | context->getQueueManager()->cancel(query_id); |
| 241 | Block processes_block = getSelectResult("query_id, user, query", "system.processes"); |
| 242 | if (!processes_block) |
| 243 | return res_io; |
| 244 | |
| 245 | ProcessList & process_list = context->getProcessList(); |
| 246 | QueryDescriptors queries_to_stop = extractQueriesExceptMeAndCheckAccess(processes_block, context); |
| 247 | |
| 248 | auto header = processes_block.cloneEmpty(); |
| 249 | header.insert(0, {ColumnString::create(), std::make_shared<DataTypeString>(), "kill_status"}); |
| 250 | |
| 251 | if (!query.sync || query.test) |
| 252 | { |
| 253 | MutableColumns res_columns = header.cloneEmptyColumns(); |
| 254 | for (const auto & query_desc : queries_to_stop) |
| 255 | { |
| 256 | auto code = (query.test) ? CancellationCode::Unknown |
| 257 | : process_list.sendCancelToQuery(query_desc.query_id, (context->is_tenant_user() ? formatTenantEntityName(query_desc.user) : query_desc.user), true); |
| 258 | insertResultRow(query_desc.source_num, code, processes_block, header, res_columns); |
| 259 | } |
| 260 | |
| 261 | res_io.in = std::make_shared<OneBlockInputStream>(header.cloneWithColumns(std::move(res_columns))); |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | res_io.in = std::make_shared<SyncKillQueryInputStream>( |
| 266 | process_list, std::move(queries_to_stop), std::move(processes_block), header); |
| 267 | } |
| 268 | |
| 269 | break; |
| 270 | } |
| 271 | case ASTKillQueryQuery::Type::Mutation: |
| 272 | { |
| 273 | Block mutations_block = getSelectResult("database, table, mutation_id, command", "system.mutations"); |
| 274 | if (!mutations_block) |
| 275 | return res_io; |
| 276 |
nothing calls this directly
no test coverage detected